3
{ This file contains the coefficient buffer controller for decompression.
4
This controller is the top level of the JPEG decompressor proper.
5
The coefficient buffer lies between entropy decoding and inverse-DCT steps.
7
In buffered-image mode, this controller is the interface between
8
input-oriented processing and output-oriented processing.
9
Also, the input side (only) is used when reading a file for transcoding. }
11
{ Original: jdcoefct.c ; Copyright (C) 1994-1997, Thomas G. Lane. }
26
procedure jinit_d_coef_controller (cinfo : j_decompress_ptr;
27
need_full_buffer : boolean);
33
{ Block smoothing is only applicable for progressive JPEG, so: }
34
{$ifndef D_PROGRESSIVE_SUPPORTED}
35
{$undef BLOCK_SMOOTHING_SUPPORTED}
38
{ Private buffer controller object }
40
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
42
SAVED_COEFS = 6; { we save coef_bits[0..5] }
44
Latch = array[0..SAVED_COEFS-1] of int;
49
my_coef_ptr = ^my_coef_controller;
50
my_coef_controller = record
51
pub : jpeg_d_coef_controller; { public fields }
53
{ These variables keep track of the current location of the input side. }
54
{ cinfo^.input_iMCU_row is also used for this. }
55
MCU_ctr : JDIMENSION; { counts MCUs processed in current row }
56
MCU_vert_offset : int; { counts MCU rows within iMCU row }
57
MCU_rows_per_iMCU_row : int; { number of such rows needed }
59
{ The output side's location is represented by cinfo^.output_iMCU_row. }
61
{ In single-pass modes, it's sufficient to buffer just one MCU.
62
We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
63
and let the entropy decoder write into that workspace each time.
64
(On 80x86, the workspace is FAR even though it's not really very big;
65
this is to keep the module interfaces unchanged when a large coefficient
67
In multi-pass modes, this array points to the current MCU's blocks
68
within the virtual arrays; it is used only by the input side. }
70
MCU_buffer : array[0..D_MAX_BLOCKS_IN_MCU-1] of JBLOCKROW;
72
{$ifdef D_MULTISCAN_FILES_SUPPORTED}
73
{ In multi-pass modes, we need a virtual block array for each component. }
74
whole_image : jvirt_barray_tbl;
77
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
78
{ When doing block smoothing, we latch coefficient Al values here }
79
coef_bits_latch : Latch_Ptr;
83
{ Forward declarations }
85
function decompress_onepass (cinfo : j_decompress_ptr;
86
output_buf : JSAMPIMAGE) : int; far; forward;
87
{$ifdef D_MULTISCAN_FILES_SUPPORTED}
89
function decompress_data (cinfo : j_decompress_ptr;
90
output_buf : JSAMPIMAGE) : int; far; forward;
92
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
94
function smoothing_ok (cinfo : j_decompress_ptr) : boolean; forward;
97
function decompress_smooth_data (cinfo : j_decompress_ptr;
98
output_buf : JSAMPIMAGE) : int; far; forward;
103
procedure start_iMCU_row (cinfo : j_decompress_ptr);
104
{ Reset within-iMCU-row counters for a new row (input side) }
108
coef := my_coef_ptr (cinfo^.coef);
110
{ In an interleaved scan, an MCU row is the same as an iMCU row.
111
In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
112
But at the bottom of the image, process only what's left. }
114
if (cinfo^.comps_in_scan > 1) then
116
coef^.MCU_rows_per_iMCU_row := 1;
120
if (cinfo^.input_iMCU_row < (cinfo^.total_iMCU_rows-1)) then
121
coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.v_samp_factor
123
coef^.MCU_rows_per_iMCU_row := cinfo^.cur_comp_info[0]^.last_row_height;
127
coef^.MCU_vert_offset := 0;
131
{ Initialize for an input processing pass. }
134
procedure start_input_pass (cinfo : j_decompress_ptr); far;
136
cinfo^.input_iMCU_row := 0;
137
start_iMCU_row(cinfo);
141
{ Initialize for an output processing pass. }
144
procedure start_output_pass (cinfo : j_decompress_ptr); far;
148
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
149
coef := my_coef_ptr (cinfo^.coef);
151
{ If multipass, check to see whether to use block smoothing on this pass }
152
if (coef^.pub.coef_arrays <> NIL) then
154
if (cinfo^.do_block_smoothing) and smoothing_ok(cinfo) then
155
coef^.pub.decompress_data := decompress_smooth_data
157
coef^.pub.decompress_data := decompress_data;
160
cinfo^.output_iMCU_row := 0;
164
{ Decompress and return some data in the single-pass case.
165
Always attempts to emit one fully interleaved MCU row ("iMCU" row).
166
Input and output must run in lockstep since we have only a one-MCU buffer.
167
Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
169
NB: output_buf contains a plane for each component in image,
170
which we index according to the component's SOF position.}
173
function decompress_onepass (cinfo : j_decompress_ptr;
174
output_buf : JSAMPIMAGE) : int;
177
MCU_col_num : JDIMENSION; { index of current MCU within row }
178
last_MCU_col : JDIMENSION;
179
last_iMCU_row : JDIMENSION;
180
blkn, ci, xindex, yindex, yoffset, useful_width : int;
181
output_ptr : JSAMPARRAY;
182
start_col, output_col : JDIMENSION;
183
compptr : jpeg_component_info_ptr;
184
inverse_DCT : inverse_DCT_method_ptr;
186
coef := my_coef_ptr (cinfo^.coef);
187
last_MCU_col := cinfo^.MCUs_per_row - 1;
188
last_iMCU_row := cinfo^.total_iMCU_rows - 1;
190
{ Loop to process as much as one whole iMCU row }
191
for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
193
for MCU_col_num := coef^.MCU_ctr to last_MCU_col do
195
{ Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. }
196
jzero_far( coef^.MCU_buffer[0],
197
size_t (cinfo^.blocks_in_MCU * SIZEOF(JBLOCK)));
198
if (not cinfo^.entropy^.decode_mcu (cinfo, coef^.MCU_buffer)) then
200
{ Suspension forced; update state counters and exit }
201
coef^.MCU_vert_offset := yoffset;
202
coef^.MCU_ctr := MCU_col_num;
203
decompress_onepass := JPEG_SUSPENDED;
206
{ Determine where data should go in output_buf and do the IDCT thing.
207
We skip dummy blocks at the right and bottom edges (but blkn gets
208
incremented past them!). Note the inner loop relies on having
209
allocated the MCU_buffer[] blocks sequentially. }
211
blkn := 0; { index of current DCT block within MCU }
212
for ci := 0 to pred(cinfo^.comps_in_scan) do
214
compptr := cinfo^.cur_comp_info[ci];
215
{ Don't bother to IDCT an uninteresting component. }
216
if (not compptr^.component_needed) then
218
Inc(blkn, compptr^.MCU_blocks);
221
inverse_DCT := cinfo^.idct^.inverse_DCT[compptr^.component_index];
222
if (MCU_col_num < last_MCU_col) then
223
useful_width := compptr^.MCU_width
225
useful_width := compptr^.last_col_width;
227
output_ptr := JSAMPARRAY(@ output_buf^[compptr^.component_index]^
228
[yoffset * compptr^.DCT_scaled_size]);
229
start_col := MCU_col_num * compptr^.MCU_sample_width;
230
for yindex := 0 to pred(compptr^.MCU_height) do
232
if (cinfo^.input_iMCU_row < last_iMCU_row) or
233
(yoffset+yindex < compptr^.last_row_height) then
235
output_col := start_col;
236
for xindex := 0 to pred(useful_width) do
238
inverse_DCT (cinfo, compptr,
239
JCOEFPTR(coef^.MCU_buffer[blkn+xindex]),
240
output_ptr, output_col);
241
Inc(output_col, compptr^.DCT_scaled_size);
244
Inc(blkn, compptr^.MCU_width);
245
Inc(JSAMPROW_PTR(output_ptr), compptr^.DCT_scaled_size);
249
{ Completed an MCU row, but perhaps not an iMCU row }
252
{ Completed the iMCU row, advance counters for next one }
253
Inc(cinfo^.output_iMCU_row);
255
Inc(cinfo^.input_iMCU_row);
256
if (cinfo^.input_iMCU_row < cinfo^.total_iMCU_rows) then
258
start_iMCU_row(cinfo);
259
decompress_onepass := JPEG_ROW_COMPLETED;
262
{ Completed the scan }
263
cinfo^.inputctl^.finish_input_pass (cinfo);
264
decompress_onepass := JPEG_SCAN_COMPLETED;
267
{ Dummy consume-input routine for single-pass operation. }
270
function dummy_consume_data (cinfo : j_decompress_ptr) : int; far;
272
dummy_consume_data := JPEG_SUSPENDED; { Always indicate nothing was done }
276
{$ifdef D_MULTISCAN_FILES_SUPPORTED}
278
{ Consume input data and store it in the full-image coefficient buffer.
279
We read as much as one fully interleaved MCU row ("iMCU" row) per call,
280
ie, v_samp_factor block rows for each component in the scan.
281
Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.}
284
function consume_data (cinfo : j_decompress_ptr) : int; far;
287
MCU_col_num : JDIMENSION; { index of current MCU within row }
288
blkn, ci, xindex, yindex, yoffset : int;
289
start_col : JDIMENSION;
290
buffer : array[0..MAX_COMPS_IN_SCAN-1] of JBLOCKARRAY;
291
buffer_ptr : JBLOCKROW;
292
compptr : jpeg_component_info_ptr;
294
coef := my_coef_ptr (cinfo^.coef);
296
{ Align the virtual buffers for the components used in this scan. }
297
for ci := 0 to pred(cinfo^.comps_in_scan) do
299
compptr := cinfo^.cur_comp_info[ci];
300
buffer[ci] := cinfo^.mem^.access_virt_barray
301
(j_common_ptr (cinfo), coef^.whole_image[compptr^.component_index],
302
cinfo^.input_iMCU_row * compptr^.v_samp_factor,
303
JDIMENSION (compptr^.v_samp_factor), TRUE);
304
{ Note: entropy decoder expects buffer to be zeroed,
305
but this is handled automatically by the memory manager
306
because we requested a pre-zeroed array. }
310
{ Loop to process one whole iMCU row }
311
for yoffset := coef^.MCU_vert_offset to pred(coef^.MCU_rows_per_iMCU_row) do
313
for MCU_col_num := coef^.MCU_ctr to pred(cinfo^.MCUs_per_row) do
315
{ Construct list of pointers to DCT blocks belonging to this MCU }
316
blkn := 0; { index of current DCT block within MCU }
317
for ci := 0 to pred(cinfo^.comps_in_scan) do
319
compptr := cinfo^.cur_comp_info[ci];
320
start_col := MCU_col_num * compptr^.MCU_width;
321
for yindex := 0 to pred(compptr^.MCU_height) do
323
buffer_ptr := JBLOCKROW(@ buffer[ci]^[yindex+yoffset]^[start_col]);
324
for xindex := 0 to pred(compptr^.MCU_width) do
326
coef^.MCU_buffer[blkn] := buffer_ptr;
328
Inc(JBLOCK_PTR(buffer_ptr));
332
{ Try to fetch the MCU. }
333
if (not cinfo^.entropy^.decode_mcu (cinfo, coef^.MCU_buffer)) then
335
{ Suspension forced; update state counters and exit }
336
coef^.MCU_vert_offset := yoffset;
337
coef^.MCU_ctr := MCU_col_num;
338
consume_data := JPEG_SUSPENDED;
342
{ Completed an MCU row, but perhaps not an iMCU row }
345
{ Completed the iMCU row, advance counters for next one }
346
Inc(cinfo^.input_iMCU_row);
347
if (cinfo^.input_iMCU_row < cinfo^.total_iMCU_rows) then
349
start_iMCU_row(cinfo);
350
consume_data := JPEG_ROW_COMPLETED;
353
{ Completed the scan }
354
cinfo^.inputctl^.finish_input_pass (cinfo);
355
consume_data := JPEG_SCAN_COMPLETED;
359
{ Decompress and return some data in the multi-pass case.
360
Always attempts to emit one fully interleaved MCU row ("iMCU" row).
361
Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
363
NB: output_buf contains a plane for each component in image. }
366
function decompress_data (cinfo : j_decompress_ptr;
367
output_buf : JSAMPIMAGE) : int;
370
last_iMCU_row : JDIMENSION;
371
block_num : JDIMENSION;
372
ci, block_row, block_rows : int;
373
buffer : JBLOCKARRAY;
374
buffer_ptr : JBLOCKROW;
375
output_ptr : JSAMPARRAY;
376
output_col : JDIMENSION;
377
compptr : jpeg_component_info_ptr;
378
inverse_DCT : inverse_DCT_method_ptr;
380
coef := my_coef_ptr (cinfo^.coef);
381
last_iMCU_row := cinfo^.total_iMCU_rows - 1;
383
{ Force some input to be done if we are getting ahead of the input. }
384
while (cinfo^.input_scan_number < cinfo^.output_scan_number) or
385
((cinfo^.input_scan_number = cinfo^.output_scan_number) and
386
(cinfo^.input_iMCU_row <= cinfo^.output_iMCU_row)) do
388
if (cinfo^.inputctl^.consume_input(cinfo) = JPEG_SUSPENDED) then
390
decompress_data := JPEG_SUSPENDED;
395
{ OK, output from the virtual arrays. }
396
compptr := jpeg_component_info_ptr(cinfo^.comp_info);
397
for ci := 0 to pred(cinfo^.num_components) do
399
{ Don't bother to IDCT an uninteresting component. }
400
if (not compptr^.component_needed) then
402
{ Align the virtual buffer for this component. }
403
buffer := cinfo^.mem^.access_virt_barray
404
(j_common_ptr (cinfo), coef^.whole_image[ci],
405
cinfo^.output_iMCU_row * compptr^.v_samp_factor,
406
JDIMENSION (compptr^.v_samp_factor), FALSE);
407
{ Count non-dummy DCT block rows in this iMCU row. }
408
if (cinfo^.output_iMCU_row < last_iMCU_row) then
409
block_rows := compptr^.v_samp_factor
412
{ NB: can't use last_row_height here; it is input-side-dependent! }
413
block_rows := int(compptr^.height_in_blocks mod compptr^.v_samp_factor);
414
if (block_rows = 0) then
415
block_rows := compptr^.v_samp_factor;
417
inverse_DCT := cinfo^.idct^.inverse_DCT[ci];
418
output_ptr := output_buf^[ci];
419
{ Loop over all DCT blocks to be processed. }
420
for block_row := 0 to pred(block_rows) do
422
buffer_ptr := buffer^[block_row];
424
for block_num := 0 to pred(compptr^.width_in_blocks) do
426
inverse_DCT (cinfo, compptr, JCOEFPTR (buffer_ptr),
427
output_ptr, output_col);
428
Inc(JBLOCK_PTR(buffer_ptr));
429
Inc(output_col, compptr^.DCT_scaled_size);
431
Inc(JSAMPROW_PTR(output_ptr), compptr^.DCT_scaled_size);
436
Inc(cinfo^.output_iMCU_row);
437
if (cinfo^.output_iMCU_row < cinfo^.total_iMCU_rows) then
439
decompress_data := JPEG_ROW_COMPLETED;
442
decompress_data := JPEG_SCAN_COMPLETED;
445
{$endif} { D_MULTISCAN_FILES_SUPPORTED }
448
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
450
{ This code applies interblock smoothing as described by section K.8
451
of the JPEG standard: the first 5 AC coefficients are estimated from
452
the DC values of a DCT block and its 8 neighboring blocks.
453
We apply smoothing only for progressive JPEG decoding, and only if
454
the coefficients it can estimate are not yet known to full precision. }
456
{ Natural-order array positions of the first 5 zigzag-order coefficients }
464
{ Determine whether block smoothing is applicable and safe.
465
We also latch the current states of the coef_bits[] entries for the
466
AC coefficients; otherwise, if the input side of the decompressor
467
advances into a new scan, we might think the coefficients are known
468
more accurately than they really are. }
471
function smoothing_ok (cinfo : j_decompress_ptr) : boolean;
474
smoothing_useful : boolean;
476
compptr : jpeg_component_info_ptr;
477
qtable : JQUANT_TBL_PTR;
478
coef_bits : coef_bits_ptr;
479
coef_bits_latch : Latch_Ptr;
481
coef := my_coef_ptr (cinfo^.coef);
482
smoothing_useful := FALSE;
484
if (not cinfo^.progressive_mode) or (cinfo^.coef_bits = NIL) then
486
smoothing_ok := FALSE;
490
{ Allocate latch area if not already done }
491
if (coef^.coef_bits_latch = NIL) then
492
coef^.coef_bits_latch := Latch_Ptr(
493
cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
494
cinfo^.num_components *
495
(SAVED_COEFS * SIZEOF(int))) );
496
coef_bits_latch := (coef^.coef_bits_latch);
498
compptr := jpeg_component_info_ptr(cinfo^.comp_info);
499
for ci := 0 to pred(cinfo^.num_components) do
501
{ All components' quantization values must already be latched. }
502
qtable := compptr^.quant_table;
503
if (qtable = NIL) then
505
smoothing_ok := FALSE;
508
{ Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. }
509
if (qtable^.quantval[0] = 0) or
510
(qtable^.quantval[Q01_POS] = 0) or
511
(qtable^.quantval[Q10_POS] = 0) or
512
(qtable^.quantval[Q20_POS] = 0) or
513
(qtable^.quantval[Q11_POS] = 0) or
514
(qtable^.quantval[Q02_POS] = 0) then
516
smoothing_ok := FALSE;
519
{ DC values must be at least partly known for all components. }
520
coef_bits := @cinfo^.coef_bits^[ci]; { Nomssi }
521
if (coef_bits^[0] < 0) then
523
smoothing_ok := FALSE;
526
{ Block smoothing is helpful if some AC coefficients remain inaccurate. }
527
for coefi := 1 to 5 do
529
coef_bits_latch^[coefi] := coef_bits^[coefi];
530
if (coef_bits^[coefi] <> 0) then
531
smoothing_useful := TRUE;
533
Inc(coef_bits_latch {SAVED_COEFS});
537
smoothing_ok := smoothing_useful;
541
{ Variant of decompress_data for use when doing block smoothing. }
544
function decompress_smooth_data (cinfo : j_decompress_ptr;
545
output_buf : JSAMPIMAGE) : int;
548
last_iMCU_row : JDIMENSION;
549
block_num, last_block_column : JDIMENSION;
550
ci, block_row, block_rows, access_rows : int;
551
buffer : JBLOCKARRAY;
552
buffer_ptr, prev_block_row, next_block_row : JBLOCKROW;
553
output_ptr : JSAMPARRAY;
554
output_col : JDIMENSION;
555
compptr : jpeg_component_info_ptr;
556
inverse_DCT : inverse_DCT_method_ptr;
557
first_row, last_row : boolean;
559
coef_bits : Latch_Ptr; { coef_bits_ptr; }
560
quanttbl : JQUANT_TBL_PTR;
561
Q00,Q01,Q02,Q10,Q11,Q20, num : INT32;
562
DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9 : int;
567
coef := my_coef_ptr (cinfo^.coef);
568
last_iMCU_row := cinfo^.total_iMCU_rows - 1;
570
{ Force some input to be done if we are getting ahead of the input. }
571
while (cinfo^.input_scan_number <= cinfo^.output_scan_number) and
572
(not cinfo^.inputctl^.eoi_reached) do
574
if (cinfo^.input_scan_number = cinfo^.output_scan_number) then
576
{ If input is working on current scan, we ordinarily want it to
577
have completed the current row. But if input scan is DC,
578
we want it to keep one row ahead so that next block row's DC
579
values are up to date. }
581
if (cinfo^.Ss = 0) then
585
if (cinfo^.input_iMCU_row > cinfo^.output_iMCU_row+delta) then
588
if (cinfo^.inputctl^.consume_input(cinfo) = JPEG_SUSPENDED) then
590
decompress_smooth_data := JPEG_SUSPENDED;
595
{ OK, output from the virtual arrays. }
596
compptr := jpeg_component_info_ptr(cinfo^.comp_info);
597
for ci := 0 to (cinfo^.num_components-1) do
599
{ Don't bother to IDCT an uninteresting component. }
600
if (not compptr^.component_needed) then
602
{ Count non-dummy DCT block rows in this iMCU row. }
603
if (cinfo^.output_iMCU_row < last_iMCU_row) then
605
block_rows := compptr^.v_samp_factor;
606
access_rows := block_rows * 2; { this and next iMCU row }
611
{ NB: can't use last_row_height here; it is input-side-dependent! }
612
block_rows := int (compptr^.height_in_blocks mod compptr^.v_samp_factor);
613
if (block_rows = 0) then
614
block_rows := compptr^.v_samp_factor;
615
access_rows := block_rows; { this iMCU row only }
618
{ Align the virtual buffer for this component. }
619
if (cinfo^.output_iMCU_row > 0) then
621
Inc(access_rows, compptr^.v_samp_factor); { prior iMCU row too }
622
buffer := cinfo^.mem^.access_virt_barray
623
(j_common_ptr (cinfo), coef^.whole_image[ci],
624
(cinfo^.output_iMCU_row - 1) * compptr^.v_samp_factor,
625
JDIMENSION (access_rows), FALSE);
626
Inc(JBLOCKROW_PTR(buffer), compptr^.v_samp_factor); { point to current iMCU row }
631
buffer := cinfo^.mem^.access_virt_barray
632
(j_common_ptr (cinfo), coef^.whole_image[ci],
633
JDIMENSION (0), JDIMENSION (access_rows), FALSE);
636
{ Fetch component-dependent info }
637
coef_bits := coef^.coef_bits_latch;
638
Inc(coef_bits, ci); { ci * SAVED_COEFS}
639
quanttbl := compptr^.quant_table;
640
Q00 := quanttbl^.quantval[0];
641
Q01 := quanttbl^.quantval[Q01_POS];
642
Q10 := quanttbl^.quantval[Q10_POS];
643
Q20 := quanttbl^.quantval[Q20_POS];
644
Q11 := quanttbl^.quantval[Q11_POS];
645
Q02 := quanttbl^.quantval[Q02_POS];
646
inverse_DCT := cinfo^.idct^.inverse_DCT[ci];
647
output_ptr := output_buf^[ci];
648
{ Loop over all DCT blocks to be processed. }
649
for block_row := 0 to (block_rows-1) do
651
buffer_ptr := buffer^[block_row];
652
if (first_row) and (block_row = 0) then
653
prev_block_row := buffer_ptr
655
prev_block_row := buffer^[block_row-1];
656
if (last_row) and (block_row = block_rows-1) then
657
next_block_row := buffer_ptr
659
next_block_row := buffer^[block_row+1];
660
{ We fetch the surrounding DC values using a sliding-register approach.
661
Initialize all nine here so as to do the right thing on narrow pics.}
663
DC3 := int(prev_block_row^[0][0]);
666
DC6 := int(buffer_ptr^[0][0]);
669
DC9 := int(next_block_row^[0][0]);
673
last_block_column := compptr^.width_in_blocks - 1;
674
for block_num := 0 to last_block_column do
676
{ Fetch current DCT block into workspace so we can modify it. }
677
jcopy_block_row(buffer_ptr, JBLOCKROW (@workspace), JDIMENSION(1));
679
if (block_num < last_block_column) then
681
DC3 := int (prev_block_row^[1][0]);
682
DC6 := int (buffer_ptr^[1][0]);
683
DC9 := int (next_block_row^[1][0]);
685
{ Compute coefficient estimates per K.8.
686
An estimate is applied only if coefficient is still zero,
687
and is not known to be fully accurate. }
691
if (Al <> 0) and (workspace[1] = 0) then
693
num := 36 * Q00 * (DC4 - DC6);
696
pred := int (((Q01 shl 7) + num) div (Q01 shl 8));
697
if (Al > 0) and (pred >= (1 shl Al)) then
698
pred := (1 shl Al)-1;
702
pred := int (((Q01 shl 7) - num) div (Q01 shl 8));
703
if (Al > 0) and (pred >= (1 shl Al)) then
704
pred := (1 shl Al)-1;
707
workspace[1] := JCOEF (pred);
711
if (Al <> 0) and (workspace[8] = 0) then
713
num := 36 * Q00 * (DC2 - DC8);
716
pred := int (((Q10 shl 7) + num) div (Q10 shl 8));
717
if (Al > 0) and (pred >= (1 shl Al)) then
718
pred := (1 shl Al)-1;
722
pred := int (((Q10 shl 7) - num) div (Q10 shl 8));
723
if (Al > 0) and (pred >= (1 shl Al)) then
724
pred := (1 shl Al)-1;
727
workspace[8] := JCOEF (pred);
731
if (Al <> 0) and (workspace[16] = 0) then
733
num := 9 * Q00 * (DC2 + DC8 - 2*DC5);
736
pred := int (((Q20 shl 7) + num) div (Q20 shl 8));
737
if (Al > 0) and (pred >= (1 shl Al)) then
738
pred := (1 shl Al)-1;
742
pred := int (((Q20 shl 7) - num) div (Q20 shl 8));
743
if (Al > 0) and (pred >= (1 shl Al)) then
744
pred := (1 shl Al)-1;
747
workspace[16] := JCOEF (pred);
751
if (Al <> 0) and (workspace[9] = 0) then
753
num := 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
756
pred := int (((Q11 shl 7) + num) div (Q11 shl 8));
757
if (Al > 0) and (pred >= (1 shl Al)) then
758
pred := (1 shl Al)-1;
762
pred := int (((Q11 shl 7) - num) div (Q11 shl 8));
763
if (Al > 0) and (pred >= (1 shl Al)) then
764
pred := (1 shl Al)-1;
767
workspace[9] := JCOEF (pred);
771
if (Al <> 0) and (workspace[2] = 0) then
773
num := 9 * Q00 * (DC4 + DC6 - 2*DC5);
776
pred := int (((Q02 shl 7) + num) div (Q02 shl 8));
777
if (Al > 0) and (pred >= (1 shl Al)) then
778
pred := (1 shl Al)-1;
782
pred := int (((Q02 shl 7) - num) div (Q02 shl 8));
783
if (Al > 0) and (pred >= (1 shl Al)) then
784
pred := (1 shl Al)-1;
787
workspace[2] := JCOEF (pred);
790
inverse_DCT (cinfo, compptr, JCOEFPTR (@workspace),
791
output_ptr, output_col);
792
{ Advance for next column }
793
DC1 := DC2; DC2 := DC3;
794
DC4 := DC5; DC5 := DC6;
795
DC7 := DC8; DC8 := DC9;
796
Inc(JBLOCK_PTR(buffer_ptr));
797
Inc(JBLOCK_PTR(prev_block_row));
798
Inc(JBLOCK_PTR(next_block_row));
799
Inc(output_col, compptr^.DCT_scaled_size);
801
Inc(JSAMPROW_PTR(output_ptr), compptr^.DCT_scaled_size);
806
Inc(cinfo^.output_iMCU_row);
807
if (cinfo^.output_iMCU_row < cinfo^.total_iMCU_rows) then
809
decompress_smooth_data := JPEG_ROW_COMPLETED;
812
decompress_smooth_data := JPEG_SCAN_COMPLETED;
815
{$endif} { BLOCK_SMOOTHING_SUPPORTED }
818
{ Initialize coefficient buffer controller. }
821
procedure jinit_d_coef_controller (cinfo : j_decompress_ptr;
822
need_full_buffer : boolean);
825
{$ifdef D_MULTISCAN_FILES_SUPPORTED}
827
ci, access_rows : int;
828
compptr : jpeg_component_info_ptr;
835
cinfo^.mem^.alloc_small (j_common_ptr (cinfo), JPOOL_IMAGE,
836
SIZEOF(my_coef_controller)) );
837
cinfo^.coef := jpeg_d_coef_controller_ptr(coef);
838
coef^.pub.start_input_pass := start_input_pass;
839
coef^.pub.start_output_pass := start_output_pass;
840
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
841
coef^.coef_bits_latch := NIL;
844
{ Create the coefficient buffer. }
845
if (need_full_buffer) then
847
{$ifdef D_MULTISCAN_FILES_SUPPORTED}
848
{ Allocate a full-image virtual array for each component, }
849
{ padded to a multiple of samp_factor DCT blocks in each direction. }
850
{ Note we ask for a pre-zeroed array. }
852
compptr := jpeg_component_info_ptr(cinfo^.comp_info);
853
for ci := 0 to pred(cinfo^.num_components) do
855
access_rows := compptr^.v_samp_factor;
856
{$ifdef BLOCK_SMOOTHING_SUPPORTED}
857
{ If block smoothing could be used, need a bigger window }
858
if (cinfo^.progressive_mode) then
859
access_rows := access_rows * 3;
861
coef^.whole_image[ci] := cinfo^.mem^.request_virt_barray
862
(j_common_ptr (cinfo), JPOOL_IMAGE, TRUE,
863
JDIMENSION (jround_up( long(compptr^.width_in_blocks),
864
long(compptr^.h_samp_factor) )),
865
JDIMENSION (jround_up( long(compptr^.height_in_blocks),
866
long(compptr^.v_samp_factor) )),
867
JDIMENSION (access_rows));
870
coef^.pub.consume_data := consume_data;
871
coef^.pub.decompress_data := decompress_data;
872
coef^.pub.coef_arrays := @(coef^.whole_image);
873
{ link to virtual arrays }
875
ERREXIT(j_common_ptr(cinfo), JERR_NOT_COMPILED);
880
{ We only need a single-MCU buffer. }
881
buffer := JBLOCK_PTR (
882
cinfo^.mem^.alloc_large (j_common_ptr (cinfo), JPOOL_IMAGE,
883
D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)) );
884
for i := 0 to pred(D_MAX_BLOCKS_IN_MCU) do
886
coef^.MCU_buffer[i] := JBLOCKROW(buffer);
889
coef^.pub.consume_data := dummy_consume_data;
890
coef^.pub.decompress_data := decompress_onepass;
891
coef^.pub.coef_arrays := NIL; { flag for no virtual arrays }