blob: deec618f268ef39d02a4e30a0095a566b45dfeb7 [file] [log] [blame]
Thomas G. Lanebc79e061995-08-02 00:00:00 +00001/*
2 * jdinput.c
3 *
DRCa73e8702012-12-31 02:52:30 +00004 * This file was part of the Independent JPEG Group's software:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00005 * Copyright (C) 1991-1997, Thomas G. Lane.
DRCa6ef2822013-09-28 03:23:49 +00006 * libjpeg-turbo Modifications:
Leon Scroggins III3993b372018-07-16 10:43:45 -04007 * Copyright (C) 2010, 2016, 2018, D. R. Commander.
DRC0ef076f2016-02-19 18:32:10 -06008 * Copyright (C) 2015, Google, Inc.
9 * For conditions of distribution and use, see the accompanying README.ijg
10 * file.
Thomas G. Lanebc79e061995-08-02 00:00:00 +000011 *
12 * This file contains input control logic for the JPEG decompressor.
13 * These routines are concerned with controlling the decompressor's input
14 * processing (marker reading and coefficient decoding). The actual input
15 * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c.
16 */
17
18#define JPEG_INTERNALS
19#include "jinclude.h"
20#include "jpeglib.h"
DRC36a6eec2010-10-08 08:05:44 +000021#include "jpegcomp.h"
Thomas G. Lanebc79e061995-08-02 00:00:00 +000022
23
24/* Private state */
25
26typedef struct {
27 struct jpeg_input_controller pub; /* public fields */
28
DRCe5eaf372014-05-09 18:00:32 +000029 boolean inheaders; /* TRUE until first SOS is reached */
Thomas G. Lanebc79e061995-08-02 00:00:00 +000030} my_input_controller;
31
Alex Naidis6eb7d372016-10-16 23:10:08 +020032typedef my_input_controller *my_inputctl_ptr;
Thomas G. Lanebc79e061995-08-02 00:00:00 +000033
34
35/* Forward declarations */
Leon Scroggins III3993b372018-07-16 10:43:45 -040036METHODDEF(int) consume_markers(j_decompress_ptr cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +000037
38
39/*
40 * Routines to calculate various quantities related to the size of the image.
41 */
42
Thomas G. Lane489583f1996-02-07 00:00:00 +000043LOCAL(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -040044initial_setup(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +000045/* Called once, when first SOS marker is reached */
46{
47 int ci;
48 jpeg_component_info *compptr;
49
50 /* Make sure image isn't bigger than I can handle */
Leon Scroggins III3993b372018-07-16 10:43:45 -040051 if ((long)cinfo->image_height > (long)JPEG_MAX_DIMENSION ||
52 (long)cinfo->image_width > (long)JPEG_MAX_DIMENSION)
53 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION);
Thomas G. Lanebc79e061995-08-02 00:00:00 +000054
55 /* For now, precision must match compiled-in value... */
56 if (cinfo->data_precision != BITS_IN_JSAMPLE)
57 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
58
59 /* Check that number of components won't exceed internal array sizes */
60 if (cinfo->num_components > MAX_COMPONENTS)
61 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
DRCe5eaf372014-05-09 18:00:32 +000062 MAX_COMPONENTS);
Thomas G. Lanebc79e061995-08-02 00:00:00 +000063
64 /* Compute maximum sampling factors; check factor validity */
65 cinfo->max_h_samp_factor = 1;
66 cinfo->max_v_samp_factor = 1;
67 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
68 ci++, compptr++) {
Leon Scroggins III3993b372018-07-16 10:43:45 -040069 if (compptr->h_samp_factor <= 0 ||
70 compptr->h_samp_factor > MAX_SAMP_FACTOR ||
71 compptr->v_samp_factor <= 0 ||
72 compptr->v_samp_factor > MAX_SAMP_FACTOR)
Thomas G. Lanebc79e061995-08-02 00:00:00 +000073 ERREXIT(cinfo, JERR_BAD_SAMPLING);
74 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
DRCe5eaf372014-05-09 18:00:32 +000075 compptr->h_samp_factor);
Thomas G. Lanebc79e061995-08-02 00:00:00 +000076 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
DRCe5eaf372014-05-09 18:00:32 +000077 compptr->v_samp_factor);
Thomas G. Lanebc79e061995-08-02 00:00:00 +000078 }
79
Leon Scroggins III3993b372018-07-16 10:43:45 -040080#if JPEG_LIB_VERSION >= 80
81 cinfo->block_size = DCTSIZE;
82 cinfo->natural_order = jpeg_natural_order;
83 cinfo->lim_Se = DCTSIZE2 - 1;
DRC36a6eec2010-10-08 08:05:44 +000084#endif
Guido Vollbeding989630f2010-01-10 00:00:00 +000085
Thomas G. Lanebc79e061995-08-02 00:00:00 +000086 /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
87 * In the full decompressor, this will be overridden by jdmaster.c;
88 * but in the transcoder, jdmaster.c is not used, so we must do it here.
89 */
DRC36a6eec2010-10-08 08:05:44 +000090#if JPEG_LIB_VERSION >= 70
91 cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE;
92#else
Thomas G. Lanebc79e061995-08-02 00:00:00 +000093 cinfo->min_DCT_scaled_size = DCTSIZE;
DRC36a6eec2010-10-08 08:05:44 +000094#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +000095
96 /* Compute dimensions of components */
97 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
98 ci++, compptr++) {
DRC36a6eec2010-10-08 08:05:44 +000099#if JPEG_LIB_VERSION >= 70
100 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE;
101#else
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000102 compptr->DCT_scaled_size = DCTSIZE;
DRC36a6eec2010-10-08 08:05:44 +0000103#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000104 /* Size in DCT blocks */
105 compptr->width_in_blocks = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400106 jdiv_round_up((long)cinfo->image_width * (long)compptr->h_samp_factor,
107 (long)(cinfo->max_h_samp_factor * DCTSIZE));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000108 compptr->height_in_blocks = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400109 jdiv_round_up((long)cinfo->image_height * (long)compptr->v_samp_factor,
110 (long)(cinfo->max_v_samp_factor * DCTSIZE));
DRC0ef076f2016-02-19 18:32:10 -0600111 /* Set the first and last MCU columns to decompress from multi-scan images.
112 * By default, decompress all of the MCU columns.
113 */
114 cinfo->master->first_MCU_col[ci] = 0;
115 cinfo->master->last_MCU_col[ci] = compptr->width_in_blocks - 1;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000116 /* downsampled_width and downsampled_height will also be overridden by
117 * jdmaster.c if we are doing full decompression. The transcoder library
118 * doesn't use these values, but the calling application might.
119 */
120 /* Size in samples */
121 compptr->downsampled_width = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400122 jdiv_round_up((long)cinfo->image_width * (long)compptr->h_samp_factor,
123 (long)cinfo->max_h_samp_factor);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000124 compptr->downsampled_height = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400125 jdiv_round_up((long)cinfo->image_height * (long)compptr->v_samp_factor,
126 (long)cinfo->max_v_samp_factor);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000127 /* Mark component needed, until color conversion says otherwise */
128 compptr->component_needed = TRUE;
129 /* Mark no quantization table yet saved for component */
130 compptr->quant_table = NULL;
131 }
132
133 /* Compute number of fully interleaved MCU rows. */
134 cinfo->total_iMCU_rows = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400135 jdiv_round_up((long)cinfo->image_height,
136 (long)(cinfo->max_v_samp_factor * DCTSIZE));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000137
138 /* Decide whether file contains multiple scans */
139 if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
140 cinfo->inputctl->has_multiple_scans = TRUE;
141 else
142 cinfo->inputctl->has_multiple_scans = FALSE;
143}
144
145
Thomas G. Lane489583f1996-02-07 00:00:00 +0000146LOCAL(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400147per_scan_setup(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000148/* Do computations that are needed before processing a JPEG scan */
149/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
150{
151 int ci, mcublks, tmp;
152 jpeg_component_info *compptr;
DRCe5eaf372014-05-09 18:00:32 +0000153
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000154 if (cinfo->comps_in_scan == 1) {
DRCe5eaf372014-05-09 18:00:32 +0000155
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000156 /* Noninterleaved (single-component) scan */
157 compptr = cinfo->cur_comp_info[0];
DRCe5eaf372014-05-09 18:00:32 +0000158
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000159 /* Overall image size in MCUs */
160 cinfo->MCUs_per_row = compptr->width_in_blocks;
161 cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
DRCe5eaf372014-05-09 18:00:32 +0000162
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000163 /* For noninterleaved scan, always one block per MCU */
164 compptr->MCU_width = 1;
165 compptr->MCU_height = 1;
166 compptr->MCU_blocks = 1;
DRC49967cd2010-10-09 19:57:51 +0000167 compptr->MCU_sample_width = compptr->_DCT_scaled_size;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000168 compptr->last_col_width = 1;
169 /* For noninterleaved scans, it is convenient to define last_row_height
170 * as the number of block rows present in the last iMCU row.
171 */
Leon Scroggins III3993b372018-07-16 10:43:45 -0400172 tmp = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000173 if (tmp == 0) tmp = compptr->v_samp_factor;
174 compptr->last_row_height = tmp;
DRCe5eaf372014-05-09 18:00:32 +0000175
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000176 /* Prepare array describing MCU composition */
177 cinfo->blocks_in_MCU = 1;
178 cinfo->MCU_membership[0] = 0;
DRCe5eaf372014-05-09 18:00:32 +0000179
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000180 } else {
DRCe5eaf372014-05-09 18:00:32 +0000181
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000182 /* Interleaved (multi-component) scan */
183 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
184 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
DRCe5eaf372014-05-09 18:00:32 +0000185 MAX_COMPS_IN_SCAN);
186
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000187 /* Overall image size in MCUs */
188 cinfo->MCUs_per_row = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400189 jdiv_round_up((long)cinfo->image_width,
190 (long)(cinfo->max_h_samp_factor * DCTSIZE));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000191 cinfo->MCU_rows_in_scan = (JDIMENSION)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400192 jdiv_round_up((long)cinfo->image_height,
193 (long)(cinfo->max_v_samp_factor * DCTSIZE));
DRCe5eaf372014-05-09 18:00:32 +0000194
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000195 cinfo->blocks_in_MCU = 0;
DRCe5eaf372014-05-09 18:00:32 +0000196
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000197 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
198 compptr = cinfo->cur_comp_info[ci];
199 /* Sampling factors give # of blocks of component in each MCU */
200 compptr->MCU_width = compptr->h_samp_factor;
201 compptr->MCU_height = compptr->v_samp_factor;
202 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
Leon Scroggins III3993b372018-07-16 10:43:45 -0400203 compptr->MCU_sample_width = compptr->MCU_width *
204 compptr->_DCT_scaled_size;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000205 /* Figure number of non-dummy blocks in last MCU column & row */
Leon Scroggins III3993b372018-07-16 10:43:45 -0400206 tmp = (int)(compptr->width_in_blocks % compptr->MCU_width);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000207 if (tmp == 0) tmp = compptr->MCU_width;
208 compptr->last_col_width = tmp;
Leon Scroggins III3993b372018-07-16 10:43:45 -0400209 tmp = (int)(compptr->height_in_blocks % compptr->MCU_height);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000210 if (tmp == 0) tmp = compptr->MCU_height;
211 compptr->last_row_height = tmp;
212 /* Prepare array describing MCU composition */
213 mcublks = compptr->MCU_blocks;
214 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
DRCe5eaf372014-05-09 18:00:32 +0000215 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000216 while (mcublks-- > 0) {
DRCe5eaf372014-05-09 18:00:32 +0000217 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000218 }
219 }
DRCe5eaf372014-05-09 18:00:32 +0000220
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000221 }
222}
223
224
225/*
226 * Save away a copy of the Q-table referenced by each component present
227 * in the current scan, unless already saved during a prior scan.
228 *
229 * In a multiple-scan JPEG file, the encoder could assign different components
230 * the same Q-table slot number, but change table definitions between scans
231 * so that each component uses a different Q-table. (The IJG encoder is not
232 * currently capable of doing this, but other encoders might.) Since we want
233 * to be able to dequantize all the components at the end of the file, this
234 * means that we have to save away the table actually used for each component.
235 * We do this by copying the table at the start of the first scan containing
236 * the component.
Leon Scroggins III3993b372018-07-16 10:43:45 -0400237 * Rec. ITU-T T.81 | ISO/IEC 10918-1 prohibits the encoder from changing the
238 * contents of a Q-table slot between scans of a component using that slot. If
239 * the encoder does so anyway, this decoder will simply use the Q-table values
240 * that were current at the start of the first scan for the component.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000241 *
242 * The decompressor output side looks only at the saved quant tables,
243 * not at the current Q-table slots.
244 */
245
Thomas G. Lane489583f1996-02-07 00:00:00 +0000246LOCAL(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400247latch_quant_tables(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000248{
249 int ci, qtblno;
250 jpeg_component_info *compptr;
Alex Naidis6eb7d372016-10-16 23:10:08 +0200251 JQUANT_TBL *qtbl;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000252
253 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
254 compptr = cinfo->cur_comp_info[ci];
255 /* No work if we already saved Q-table for this component */
256 if (compptr->quant_table != NULL)
257 continue;
258 /* Make sure specified quantization table is present */
259 qtblno = compptr->quant_tbl_no;
260 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
DRCe5eaf372014-05-09 18:00:32 +0000261 cinfo->quant_tbl_ptrs[qtblno] == NULL)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000262 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
263 /* OK, save away the quantization table */
264 qtbl = (JQUANT_TBL *)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400265 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
DRC5de454b2014-05-18 19:04:03 +0000266 sizeof(JQUANT_TBL));
267 MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], sizeof(JQUANT_TBL));
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000268 compptr->quant_table = qtbl;
269 }
270}
271
272
273/*
274 * Initialize the input modules to read a scan of compressed data.
275 * The first call to this is done by jdmaster.c after initializing
276 * the entire decompressor (during jpeg_start_decompress).
277 * Subsequent calls come from consume_markers, below.
278 */
279
Thomas G. Lane489583f1996-02-07 00:00:00 +0000280METHODDEF(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400281start_input_pass(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000282{
283 per_scan_setup(cinfo);
284 latch_quant_tables(cinfo);
285 (*cinfo->entropy->start_pass) (cinfo);
286 (*cinfo->coef->start_input_pass) (cinfo);
287 cinfo->inputctl->consume_input = cinfo->coef->consume_data;
288}
289
290
291/*
292 * Finish up after inputting a compressed-data scan.
293 * This is called by the coefficient controller after it's read all
294 * the expected data of the scan.
295 */
296
Thomas G. Lane489583f1996-02-07 00:00:00 +0000297METHODDEF(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400298finish_input_pass(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000299{
300 cinfo->inputctl->consume_input = consume_markers;
301}
302
303
304/*
305 * Read JPEG markers before, between, or after compressed-data scans.
306 * Change state as necessary when a new scan is reached.
307 * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
308 *
309 * The consume_input method pointer points either here or to the
310 * coefficient controller's consume_data routine, depending on whether
311 * we are reading a compressed data segment or inter-segment markers.
312 */
313
Thomas G. Lane489583f1996-02-07 00:00:00 +0000314METHODDEF(int)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400315consume_markers(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000316{
Leon Scroggins III3993b372018-07-16 10:43:45 -0400317 my_inputctl_ptr inputctl = (my_inputctl_ptr)cinfo->inputctl;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000318 int val;
319
320 if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
321 return JPEG_REACHED_EOI;
322
323 val = (*cinfo->marker->read_markers) (cinfo);
324
325 switch (val) {
DRCe5eaf372014-05-09 18:00:32 +0000326 case JPEG_REACHED_SOS: /* Found SOS */
327 if (inputctl->inheaders) { /* 1st SOS */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000328 initial_setup(cinfo);
329 inputctl->inheaders = FALSE;
330 /* Note: start_input_pass must be called by jdmaster.c
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000331 * before any more input can be consumed. jdapimin.c is
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000332 * responsible for enforcing this sequencing.
333 */
DRCe5eaf372014-05-09 18:00:32 +0000334 } else { /* 2nd or later SOS marker */
Leon Scroggins III3993b372018-07-16 10:43:45 -0400335 if (!inputctl->pub.has_multiple_scans)
DRCe5eaf372014-05-09 18:00:32 +0000336 ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000337 start_input_pass(cinfo);
338 }
339 break;
DRCe5eaf372014-05-09 18:00:32 +0000340 case JPEG_REACHED_EOI: /* Found EOI */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000341 inputctl->pub.eoi_reached = TRUE;
DRCe5eaf372014-05-09 18:00:32 +0000342 if (inputctl->inheaders) { /* Tables-only datastream, apparently */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000343 if (cinfo->marker->saw_SOF)
DRCe5eaf372014-05-09 18:00:32 +0000344 ERREXIT(cinfo, JERR_SOF_NO_SOS);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000345 } else {
346 /* Prevent infinite loop in coef ctlr's decompress_data routine
347 * if user set output_scan_number larger than number of scans.
348 */
349 if (cinfo->output_scan_number > cinfo->input_scan_number)
DRCe5eaf372014-05-09 18:00:32 +0000350 cinfo->output_scan_number = cinfo->input_scan_number;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000351 }
352 break;
353 case JPEG_SUSPENDED:
354 break;
355 }
356
357 return val;
358}
359
360
361/*
362 * Reset state to begin a fresh datastream.
363 */
364
Thomas G. Lane489583f1996-02-07 00:00:00 +0000365METHODDEF(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400366reset_input_controller(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000367{
Leon Scroggins III3993b372018-07-16 10:43:45 -0400368 my_inputctl_ptr inputctl = (my_inputctl_ptr)cinfo->inputctl;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000369
370 inputctl->pub.consume_input = consume_markers;
371 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
372 inputctl->pub.eoi_reached = FALSE;
373 inputctl->inheaders = TRUE;
374 /* Reset other modules */
Leon Scroggins III3993b372018-07-16 10:43:45 -0400375 (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000376 (*cinfo->marker->reset_marker_reader) (cinfo);
377 /* Reset progression state -- would be cleaner if entropy decoder did this */
378 cinfo->coef_bits = NULL;
379}
380
381
382/*
383 * Initialize the input controller module.
384 * This is called only once, when the decompression object is created.
385 */
386
Thomas G. Lane489583f1996-02-07 00:00:00 +0000387GLOBAL(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400388jinit_input_controller(j_decompress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000389{
390 my_inputctl_ptr inputctl;
391
392 /* Create subobject in permanent pool */
393 inputctl = (my_inputctl_ptr)
Leon Scroggins III3993b372018-07-16 10:43:45 -0400394 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
DRC5de454b2014-05-18 19:04:03 +0000395 sizeof(my_input_controller));
Leon Scroggins III3993b372018-07-16 10:43:45 -0400396 cinfo->inputctl = (struct jpeg_input_controller *)inputctl;
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000397 /* Initialize method pointers */
398 inputctl->pub.consume_input = consume_markers;
399 inputctl->pub.reset_input_controller = reset_input_controller;
400 inputctl->pub.start_input_pass = start_input_pass;
401 inputctl->pub.finish_input_pass = finish_input_pass;
402 /* Initialize state: can't use reset_input_controller since we don't
403 * want to try to reset other modules yet.
404 */
405 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
406 inputctl->pub.eoi_reached = FALSE;
407 inputctl->inheaders = TRUE;
408}