3 { Original: jdinput.c ; Copyright (C) 1991-1997, Thomas G. Lane. }
5 { This file is part of the Independent JPEG Group's software.
6 For conditions of distribution and use, see the accompanying README file.
8 This file contains input control logic for the JPEG decompressor.
9 These routines are concerned with controlling the decompressor's input
10 processing (marker reading and coefficient decoding). The actual input
11 reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. }
13 interface
15 {$I imjconfig.inc}
17 uses
18 imjmorecfg,
19 imjpeglib,
20 imjdeferr,
21 imjerror,
24 { Initialize the input controller module.
25 This is called only once, when the decompression object is created. }
27 {GLOBAL}
30 implementation
32 { Private state }
34 type
44 { Forward declarations }
45 {METHODDEF}
49 { Routines to calculate various quantities related to the size of the image. }
51 {LOCAL}
53 { Called once, when first SOS marker is reached }
54 var
57 begin
58 { Make sure image isn't bigger than I can handle }
63 { For now, precision must match compiled-in value... }
67 { Check that number of components won't exceed internal array sizes }
70 MAX_COMPONENTS);
72 { Compute maximum sampling factors; check factor validity }
77 begin
81 {cinfo^.max_h_samp_factor := MAX(cinfo^.max_h_samp_factor,
82 compptr^.h_samp_factor);
83 cinfo^.max_v_samp_factor := MAX(cinfo^.max_v_samp_factor,
84 compptr^.v_samp_factor);}
92 { We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
93 In the full decompressor, this will be overridden by jdmaster.c;
94 but in the transcoder, jdmaster.c is not used, so we must do it here. }
98 { Compute dimensions of components }
101 begin
103 { Size in DCT blocks }
110 { downsampled_width and downsampled_height will also be overridden by
111 jdmaster.c if we are doing full decompression. The transcoder library
112 doesn't use these values, but the calling application might. }
114 { Size in samples }
121 { Mark component needed, until color conversion says otherwise }
123 { Mark no quantization table yet saved for component }
128 { Compute number of fully interleaved MCU rows. }
133 { Decide whether file contains multiple scans }
137 else
142 {LOCAL}
144 { Do computations that are needed before processing a JPEG scan }
145 { cinfo^.comps_in_scan and cinfo^.cur_comp_info[] were set from SOS marker }
146 var
149 begin
151 begin
152 { Noninterleaved (single-component) scan }
155 { Overall image size in MCUs }
159 { For noninterleaved scan, always one block per MCU }
165 { For noninterleaved scans, it is convenient to define last_row_height
166 as the number of block rows present in the last iMCU row. }
173 { Prepare array describing MCU composition }
177 end
178 else
179 begin
181 { Interleaved (multi-component) scan }
184 MAX_COMPS_IN_SCAN);
186 { Overall image size in MCUs }
197 begin
199 { Sampling factors give # of blocks of component in each MCU }
204 { Figure number of non-dummy blocks in last MCU column & row }
213 { Prepare array describing MCU composition }
218 begin
229 { Save away a copy of the Q-table referenced by each component present
230 in the current scan, unless already saved during a prior scan.
232 In a multiple-scan JPEG file, the encoder could assign different components
233 the same Q-table slot number, but change table definitions between scans
234 so that each component uses a different Q-table. (The IJG encoder is not
235 currently capable of doing this, but other encoders might.) Since we want
236 to be able to dequantize all the components at the end of the file, this
237 means that we have to save away the table actually used for each component.
238 We do this by copying the table at the start of the first scan containing
239 the component.
240 The JPEG spec prohibits the encoder from changing the contents of a Q-table
241 slot between scans of a component using that slot. If the encoder does so
242 anyway, this decoder will simply use the Q-table values that were current
243 at the start of the first scan for the component.
245 The decompressor output side looks only at the saved quant tables,
246 not at the current Q-table slots. }
248 {LOCAL}
250 var
254 begin
256 begin
258 { No work if we already saved Q-table for this component }
260 continue;
261 { Make sure specified quantization table is present }
266 { OK, save away the quantization table }
276 { Initialize the input modules to read a scan of compressed data.
277 The first call to this is done by jdmaster.c after initializing
278 the entire decompressor (during jpeg_start_decompress).
279 Subsequent calls come from consume_markers, below. }
281 {METHODDEF}
283 begin
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. }
296 {METHODDEF}
298 begin
303 { Read JPEG markers before, between, or after compressed-data scans.
304 Change state as necessary when a new scan is reached.
305 Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
307 The consume_input method pointer points either here or to the
308 coefficient controller's consume_data routine, depending on whether
309 we are reading a compressed data segment or inter-segment markers. }
311 {METHODDEF}
313 var
316 begin
320 begin
322 exit;
329 begin
334 { Note: start_input_pass must be called by jdmaster.c
335 before any more input can be consumed. jdapimin.c is
336 responsible for enforcing this sequencing. }
337 end
338 else
346 begin
352 end
353 else
354 begin
355 { Prevent infinite loop in coef ctlr's decompress_data routine
356 if user set output_scan_number larger than number of scans. }
362 JPEG_SUSPENDED:;
369 { Reset state to begin a fresh datastream. }
371 {METHODDEF}
373 var
375 begin
382 { Reset other modules }
385 { Reset progression state -- would be cleaner if entropy decoder did this }
390 { Initialize the input controller module.
391 This is called only once, when the decompression object is created. }
393 {GLOBAL}
395 var
397 begin
398 { Create subobject in permanent pool }
403 { Initialize method pointers }
408 { Initialize state: can't use reset_input_controller since we don't
409 want to try to reset other modules yet. }