3 { Original: jdpostct.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
5 { This file contains the decompression postprocessing controller.
6 This controller manages the upsampling, color conversion, and color
7 quantization/reduction steps; specifically, it controls the buffering
8 between upsample/color conversion and color quantization/reduction.
10 If no color quantization/reduction is required, then this module has no
11 work to do, and it just hands off to the upsample/color conversion code.
12 An integrated upsample/convert/quantize process would replace this module
13 entirely. }
15 interface
17 {$I imjconfig.inc}
19 uses
20 imjmorecfg,
21 imjinclude,
22 imjdeferr,
23 imjerror,
24 imjutils,
25 imjpeglib;
27 { Initialize postprocessing controller. }
29 {GLOBAL}
32 implementation
35 { Private buffer controller object }
37 type
42 { Color quantization source buffer: this holds output data from
43 the upsample/color conversion step to be passed to the quantizer.
44 For two-pass color quantization, we need a full-image buffer;
45 for one-pass operation, a strip buffer is sufficient. }
50 { for two-pass mode only: }
55 { Forward declarations }
56 {METHODDEF}
64 {$ifdef QUANT_2PASS_SUPPORTED}
65 {METHODDEF}
73 {METHODDEF}
81 {$endif}
84 { Initialize for a processing pass. }
86 {METHODDEF}
89 var
91 begin
95 JBUF_PASS_THRU:
97 begin
98 { Single-pass processing with color quantization. }
100 { We could be doing buffered-image output before starting a 2-pass
101 color quantization; in that case, jinit_d_post_controller did not
102 allocate a strip buffer. Use the virtual-array buffer as workspace. }
104 begin
109 end
110 else
111 begin
112 { For single-pass processing without color quantization,
113 I have no work to do; just call the upsampler directly. }
118 {$ifdef QUANT_2PASS_SUPPORTED}
119 JBUF_SAVE_AND_PASS:
120 begin
121 { First pass of 2-pass quantization }
126 JBUF_CRANK_DEST:
127 begin
128 { Second pass of 2-pass quantization }
134 else
142 { Process some data in the one-pass (strip buffer) case.
143 This is used for color precision reduction as well as one-pass quantization. }
145 {METHODDEF}
153 var
156 begin
159 { Fill the buffer, but not more than what we can dump out in one go. }
160 { Note we rely on the upsampler to detect bottom of image. }
166 input_buf,
167 in_row_group_ctr,
168 in_row_groups_avail,
171 max_rows);
172 { Quantize and emit data. }
183 {$ifdef QUANT_2PASS_SUPPORTED}
185 { Process some data in the first pass of 2-pass quantization. }
187 {METHODDEF}
195 var
198 begin
201 { Reposition virtual buffer if at start of strip. }
203 begin
209 { Upsample some data (up to a strip height's worth). }
215 { Allow quantizer to scan new data. No data is emitted, }
216 { but we advance out_row_ctr so outer loop can tell when we're done. }
218 begin
229 { Advance if we filled the strip. }
231 begin
238 { Process some data in the second pass of 2-pass quantization. }
240 {METHODDEF}
248 var
251 begin
254 { Reposition virtual buffer if at start of strip. }
256 begin
262 { Determine number of rows to emit. }
267 { We have to check bottom of image here, can't depend on upsampler. }
272 { Quantize and emit data. }
279 { Advance if we filled the strip. }
282 begin
291 { Initialize postprocessing controller. }
293 {GLOBAL}
296 var
298 begin
307 { Create the quantization buffer, if needed }
309 begin
310 { The buffer strip height is max_v_samp_factor, which is typically
311 an efficient number of rows for upsampling to return.
312 (In the presence of output rescaling, we might want to be smarter?) }
316 begin
317 { Two-pass color quantization: need full-image storage. }
318 { We round up the number of rows to a multiple of the strip height. }
319 {$ifdef QUANT_2PASS_SUPPORTED}
326 {$else}
329 end
330 else
331 begin
332 { One-pass color quantization: just make a strip buffer. }