4 * This file was part of the Independent JPEG Group's software:
5 * Copyright (C) 1994-1997, Thomas G. Lane.
6 * libjpeg-turbo Modifications:
7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8 * Copyright (C) 2010, 2015-2016, D. R. Commander.
9 * Copyright (C) 2015, Google, Inc.
10 * For conditions of distribution and use, see the accompanying README.ijg
13 * This file contains the coefficient buffer controller for decompression.
14 * This controller is the top level of the JPEG decompressor proper.
15 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
17 * In buffered-image mode, this controller is the interface between
18 * input-oriented processing and output-oriented processing.
19 * Also, the input side (only) is used when reading a file for transcoding.
27 /* Forward declarations */
28 METHODDEF(int) decompress_onepass
29 (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
30 #ifdef D_MULTISCAN_FILES_SUPPORTED
31 METHODDEF(int) decompress_data
32 (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
34 #ifdef BLOCK_SMOOTHING_SUPPORTED
35 LOCAL(boolean) smoothing_ok (j_decompress_ptr cinfo);
36 METHODDEF(int) decompress_smooth_data
37 (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
42 * Initialize for an input processing pass.
46 start_input_pass (j_decompress_ptr cinfo)
48 cinfo->input_iMCU_row = 0;
49 start_iMCU_row(cinfo);
54 * Initialize for an output processing pass.
58 start_output_pass (j_decompress_ptr cinfo)
60 #ifdef BLOCK_SMOOTHING_SUPPORTED
61 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
63 /* If multipass, check to see whether to use block smoothing on this pass */
64 if (coef->pub.coef_arrays != NULL) {
65 if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66 coef->pub.decompress_data = decompress_smooth_data;
68 coef->pub.decompress_data = decompress_data;
71 cinfo->output_iMCU_row = 0;
76 * Decompress and return some data in the single-pass case.
77 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
78 * Input and output must run in lockstep since we have only a one-MCU buffer.
79 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
81 * NB: output_buf contains a plane for each component in image,
82 * which we index according to the component's SOF position.
86 decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
88 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
89 JDIMENSION MCU_col_num; /* index of current MCU within row */
90 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92 int blkn, ci, xindex, yindex, yoffset, useful_width;
93 JSAMPARRAY output_ptr;
94 JDIMENSION start_col, output_col;
95 jpeg_component_info *compptr;
96 inverse_DCT_method_ptr inverse_DCT;
98 /* Loop to process as much as one whole iMCU row */
99 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
101 for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
103 /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
104 jzero_far((void *) coef->MCU_buffer[0],
105 (size_t) (cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106 if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
107 /* Suspension forced; update state counters and exit */
108 coef->MCU_vert_offset = yoffset;
109 coef->MCU_ctr = MCU_col_num;
110 return JPEG_SUSPENDED;
113 /* Only perform the IDCT on blocks that are contained within the desired
116 if (MCU_col_num >= cinfo->master->first_iMCU_col &&
117 MCU_col_num <= cinfo->master->last_iMCU_col) {
118 /* Determine where data should go in output_buf and do the IDCT thing.
119 * We skip dummy blocks at the right and bottom edges (but blkn gets
120 * incremented past them!). Note the inner loop relies on having
121 * allocated the MCU_buffer[] blocks sequentially.
123 blkn = 0; /* index of current DCT block within MCU */
124 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
125 compptr = cinfo->cur_comp_info[ci];
126 /* Don't bother to IDCT an uninteresting component. */
127 if (! compptr->component_needed) {
128 blkn += compptr->MCU_blocks;
131 inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
132 useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
133 : compptr->last_col_width;
134 output_ptr = output_buf[compptr->component_index] +
135 yoffset * compptr->_DCT_scaled_size;
136 start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
137 compptr->MCU_sample_width;
138 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
139 if (cinfo->input_iMCU_row < last_iMCU_row ||
140 yoffset+yindex < compptr->last_row_height) {
141 output_col = start_col;
142 for (xindex = 0; xindex < useful_width; xindex++) {
143 (*inverse_DCT) (cinfo, compptr,
144 (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
145 output_ptr, output_col);
146 output_col += compptr->_DCT_scaled_size;
149 blkn += compptr->MCU_width;
150 output_ptr += compptr->_DCT_scaled_size;
155 /* Completed an MCU row, but perhaps not an iMCU row */
158 /* Completed the iMCU row, advance counters for next one */
159 cinfo->output_iMCU_row++;
160 if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
161 start_iMCU_row(cinfo);
162 return JPEG_ROW_COMPLETED;
164 /* Completed the scan */
165 (*cinfo->inputctl->finish_input_pass) (cinfo);
166 return JPEG_SCAN_COMPLETED;
171 * Dummy consume-input routine for single-pass operation.
175 dummy_consume_data (j_decompress_ptr cinfo)
177 return JPEG_SUSPENDED; /* Always indicate nothing was done */
181 #ifdef D_MULTISCAN_FILES_SUPPORTED
184 * Consume input data and store it in the full-image coefficient buffer.
185 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
186 * ie, v_samp_factor block rows for each component in the scan.
187 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
191 consume_data (j_decompress_ptr cinfo)
193 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
194 JDIMENSION MCU_col_num; /* index of current MCU within row */
195 int blkn, ci, xindex, yindex, yoffset;
196 JDIMENSION start_col;
197 JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
198 JBLOCKROW buffer_ptr;
199 jpeg_component_info *compptr;
201 /* Align the virtual buffers for the components used in this scan. */
202 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
203 compptr = cinfo->cur_comp_info[ci];
204 buffer[ci] = (*cinfo->mem->access_virt_barray)
205 ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
206 cinfo->input_iMCU_row * compptr->v_samp_factor,
207 (JDIMENSION) compptr->v_samp_factor, TRUE);
208 /* Note: entropy decoder expects buffer to be zeroed,
209 * but this is handled automatically by the memory manager
210 * because we requested a pre-zeroed array.
214 /* Loop to process one whole iMCU row */
215 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
217 for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
219 /* Construct list of pointers to DCT blocks belonging to this MCU */
220 blkn = 0; /* index of current DCT block within MCU */
221 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
222 compptr = cinfo->cur_comp_info[ci];
223 start_col = MCU_col_num * compptr->MCU_width;
224 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
225 buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
226 for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
227 coef->MCU_buffer[blkn++] = buffer_ptr++;
231 /* Try to fetch the MCU. */
232 if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
233 /* Suspension forced; update state counters and exit */
234 coef->MCU_vert_offset = yoffset;
235 coef->MCU_ctr = MCU_col_num;
236 return JPEG_SUSPENDED;
239 /* Completed an MCU row, but perhaps not an iMCU row */
242 /* Completed the iMCU row, advance counters for next one */
243 if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
244 start_iMCU_row(cinfo);
245 return JPEG_ROW_COMPLETED;
247 /* Completed the scan */
248 (*cinfo->inputctl->finish_input_pass) (cinfo);
249 return JPEG_SCAN_COMPLETED;
254 * Decompress and return some data in the multi-pass case.
255 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
256 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
258 * NB: output_buf contains a plane for each component in image.
262 decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
264 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
265 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
266 JDIMENSION block_num;
267 int ci, block_row, block_rows;
269 JBLOCKROW buffer_ptr;
270 JSAMPARRAY output_ptr;
271 JDIMENSION output_col;
272 jpeg_component_info *compptr;
273 inverse_DCT_method_ptr inverse_DCT;
275 /* Force some input to be done if we are getting ahead of the input. */
276 while (cinfo->input_scan_number < cinfo->output_scan_number ||
277 (cinfo->input_scan_number == cinfo->output_scan_number &&
278 cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
279 if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
280 return JPEG_SUSPENDED;
283 /* OK, output from the virtual arrays. */
284 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
286 /* Don't bother to IDCT an uninteresting component. */
287 if (! compptr->component_needed)
289 /* Align the virtual buffer for this component. */
290 buffer = (*cinfo->mem->access_virt_barray)
291 ((j_common_ptr) cinfo, coef->whole_image[ci],
292 cinfo->output_iMCU_row * compptr->v_samp_factor,
293 (JDIMENSION) compptr->v_samp_factor, FALSE);
294 /* Count non-dummy DCT block rows in this iMCU row. */
295 if (cinfo->output_iMCU_row < last_iMCU_row)
296 block_rows = compptr->v_samp_factor;
298 /* NB: can't use last_row_height here; it is input-side-dependent! */
299 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
300 if (block_rows == 0) block_rows = compptr->v_samp_factor;
302 inverse_DCT = cinfo->idct->inverse_DCT[ci];
303 output_ptr = output_buf[ci];
304 /* Loop over all DCT blocks to be processed. */
305 for (block_row = 0; block_row < block_rows; block_row++) {
306 buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
308 for (block_num = cinfo->master->first_MCU_col[ci];
309 block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
310 (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
311 output_ptr, output_col);
313 output_col += compptr->_DCT_scaled_size;
315 output_ptr += compptr->_DCT_scaled_size;
319 if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
320 return JPEG_ROW_COMPLETED;
321 return JPEG_SCAN_COMPLETED;
324 #endif /* D_MULTISCAN_FILES_SUPPORTED */
327 #ifdef BLOCK_SMOOTHING_SUPPORTED
330 * This code applies interblock smoothing as described by section K.8
331 * of the JPEG standard: the first 5 AC coefficients are estimated from
332 * the DC values of a DCT block and its 8 neighboring blocks.
333 * We apply smoothing only for progressive JPEG decoding, and only if
334 * the coefficients it can estimate are not yet known to full precision.
337 /* Natural-order array positions of the first 5 zigzag-order coefficients */
345 * Determine whether block smoothing is applicable and safe.
346 * We also latch the current states of the coef_bits[] entries for the
347 * AC coefficients; otherwise, if the input side of the decompressor
348 * advances into a new scan, we might think the coefficients are known
349 * more accurately than they really are.
353 smoothing_ok (j_decompress_ptr cinfo)
355 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
356 boolean smoothing_useful = FALSE;
358 jpeg_component_info *compptr;
361 int *coef_bits_latch;
363 if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
366 /* Allocate latch area if not already done */
367 if (coef->coef_bits_latch == NULL)
368 coef->coef_bits_latch = (int *)
369 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
370 cinfo->num_components *
371 (SAVED_COEFS * sizeof(int)));
372 coef_bits_latch = coef->coef_bits_latch;
374 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
376 /* All components' quantization values must already be latched. */
377 if ((qtable = compptr->quant_table) == NULL)
379 /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
380 if (qtable->quantval[0] == 0 ||
381 qtable->quantval[Q01_POS] == 0 ||
382 qtable->quantval[Q10_POS] == 0 ||
383 qtable->quantval[Q20_POS] == 0 ||
384 qtable->quantval[Q11_POS] == 0 ||
385 qtable->quantval[Q02_POS] == 0)
387 /* DC values must be at least partly known for all components. */
388 coef_bits = cinfo->coef_bits[ci];
389 if (coef_bits[0] < 0)
391 /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
392 for (coefi = 1; coefi <= 5; coefi++) {
393 coef_bits_latch[coefi] = coef_bits[coefi];
394 if (coef_bits[coefi] != 0)
395 smoothing_useful = TRUE;
397 coef_bits_latch += SAVED_COEFS;
400 return smoothing_useful;
405 * Variant of decompress_data for use when doing block smoothing.
409 decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
411 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
412 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
413 JDIMENSION block_num, last_block_column;
414 int ci, block_row, block_rows, access_rows;
416 JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
417 JSAMPARRAY output_ptr;
418 JDIMENSION output_col;
419 jpeg_component_info *compptr;
420 inverse_DCT_method_ptr inverse_DCT;
421 boolean first_row, last_row;
424 JQUANT_TBL *quanttbl;
425 JLONG Q00,Q01,Q02,Q10,Q11,Q20, num;
426 int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
429 /* Keep a local variable to avoid looking it up more than once */
430 workspace = coef->workspace;
432 /* Force some input to be done if we are getting ahead of the input. */
433 while (cinfo->input_scan_number <= cinfo->output_scan_number &&
434 ! cinfo->inputctl->eoi_reached) {
435 if (cinfo->input_scan_number == cinfo->output_scan_number) {
436 /* If input is working on current scan, we ordinarily want it to
437 * have completed the current row. But if input scan is DC,
438 * we want it to keep one row ahead so that next block row's DC
439 * values are up to date.
441 JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
442 if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
445 if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
446 return JPEG_SUSPENDED;
449 /* OK, output from the virtual arrays. */
450 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
452 /* Don't bother to IDCT an uninteresting component. */
453 if (! compptr->component_needed)
455 /* Count non-dummy DCT block rows in this iMCU row. */
456 if (cinfo->output_iMCU_row < last_iMCU_row) {
457 block_rows = compptr->v_samp_factor;
458 access_rows = block_rows * 2; /* this and next iMCU row */
461 /* NB: can't use last_row_height here; it is input-side-dependent! */
462 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
463 if (block_rows == 0) block_rows = compptr->v_samp_factor;
464 access_rows = block_rows; /* this iMCU row only */
467 /* Align the virtual buffer for this component. */
468 if (cinfo->output_iMCU_row > 0) {
469 access_rows += compptr->v_samp_factor; /* prior iMCU row too */
470 buffer = (*cinfo->mem->access_virt_barray)
471 ((j_common_ptr) cinfo, coef->whole_image[ci],
472 (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
473 (JDIMENSION) access_rows, FALSE);
474 buffer += compptr->v_samp_factor; /* point to current iMCU row */
477 buffer = (*cinfo->mem->access_virt_barray)
478 ((j_common_ptr) cinfo, coef->whole_image[ci],
479 (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
482 /* Fetch component-dependent info */
483 coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
484 quanttbl = compptr->quant_table;
485 Q00 = quanttbl->quantval[0];
486 Q01 = quanttbl->quantval[Q01_POS];
487 Q10 = quanttbl->quantval[Q10_POS];
488 Q20 = quanttbl->quantval[Q20_POS];
489 Q11 = quanttbl->quantval[Q11_POS];
490 Q02 = quanttbl->quantval[Q02_POS];
491 inverse_DCT = cinfo->idct->inverse_DCT[ci];
492 output_ptr = output_buf[ci];
493 /* Loop over all DCT blocks to be processed. */
494 for (block_row = 0; block_row < block_rows; block_row++) {
495 buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
496 if (first_row && block_row == 0)
497 prev_block_row = buffer_ptr;
499 prev_block_row = buffer[block_row-1];
500 if (last_row && block_row == block_rows-1)
501 next_block_row = buffer_ptr;
503 next_block_row = buffer[block_row+1];
504 /* We fetch the surrounding DC values using a sliding-register approach.
505 * Initialize all nine here so as to do the right thing on narrow pics.
507 DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
508 DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
509 DC7 = DC8 = DC9 = (int) next_block_row[0][0];
511 last_block_column = compptr->width_in_blocks - 1;
512 for (block_num = cinfo->master->first_MCU_col[ci];
513 block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
514 /* Fetch current DCT block into workspace so we can modify it. */
515 jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
516 /* Update DC values */
517 if (block_num < last_block_column) {
518 DC3 = (int) prev_block_row[1][0];
519 DC6 = (int) buffer_ptr[1][0];
520 DC9 = (int) next_block_row[1][0];
522 /* Compute coefficient estimates per K.8.
523 * An estimate is applied only if coefficient is still zero,
524 * and is not known to be fully accurate.
527 if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
528 num = 36 * Q00 * (DC4 - DC6);
530 pred = (int) (((Q01<<7) + num) / (Q01<<8));
531 if (Al > 0 && pred >= (1<<Al))
534 pred = (int) (((Q01<<7) - num) / (Q01<<8));
535 if (Al > 0 && pred >= (1<<Al))
539 workspace[1] = (JCOEF) pred;
542 if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
543 num = 36 * Q00 * (DC2 - DC8);
545 pred = (int) (((Q10<<7) + num) / (Q10<<8));
546 if (Al > 0 && pred >= (1<<Al))
549 pred = (int) (((Q10<<7) - num) / (Q10<<8));
550 if (Al > 0 && pred >= (1<<Al))
554 workspace[8] = (JCOEF) pred;
557 if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
558 num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
560 pred = (int) (((Q20<<7) + num) / (Q20<<8));
561 if (Al > 0 && pred >= (1<<Al))
564 pred = (int) (((Q20<<7) - num) / (Q20<<8));
565 if (Al > 0 && pred >= (1<<Al))
569 workspace[16] = (JCOEF) pred;
572 if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
573 num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
575 pred = (int) (((Q11<<7) + num) / (Q11<<8));
576 if (Al > 0 && pred >= (1<<Al))
579 pred = (int) (((Q11<<7) - num) / (Q11<<8));
580 if (Al > 0 && pred >= (1<<Al))
584 workspace[9] = (JCOEF) pred;
587 if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
588 num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
590 pred = (int) (((Q02<<7) + num) / (Q02<<8));
591 if (Al > 0 && pred >= (1<<Al))
594 pred = (int) (((Q02<<7) - num) / (Q02<<8));
595 if (Al > 0 && pred >= (1<<Al))
599 workspace[2] = (JCOEF) pred;
601 /* OK, do the IDCT */
602 (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
603 output_ptr, output_col);
604 /* Advance for next column */
605 DC1 = DC2; DC2 = DC3;
606 DC4 = DC5; DC5 = DC6;
607 DC7 = DC8; DC8 = DC9;
608 buffer_ptr++, prev_block_row++, next_block_row++;
609 output_col += compptr->_DCT_scaled_size;
611 output_ptr += compptr->_DCT_scaled_size;
615 if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
616 return JPEG_ROW_COMPLETED;
617 return JPEG_SCAN_COMPLETED;
620 #endif /* BLOCK_SMOOTHING_SUPPORTED */
624 * Initialize coefficient buffer controller.
628 jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
633 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
634 sizeof(my_coef_controller));
635 cinfo->coef = (struct jpeg_d_coef_controller *) coef;
636 coef->pub.start_input_pass = start_input_pass;
637 coef->pub.start_output_pass = start_output_pass;
638 #ifdef BLOCK_SMOOTHING_SUPPORTED
639 coef->coef_bits_latch = NULL;
642 /* Create the coefficient buffer. */
643 if (need_full_buffer) {
644 #ifdef D_MULTISCAN_FILES_SUPPORTED
645 /* Allocate a full-image virtual array for each component, */
646 /* padded to a multiple of samp_factor DCT blocks in each direction. */
647 /* Note we ask for a pre-zeroed array. */
649 jpeg_component_info *compptr;
651 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
653 access_rows = compptr->v_samp_factor;
654 #ifdef BLOCK_SMOOTHING_SUPPORTED
655 /* If block smoothing could be used, need a bigger window */
656 if (cinfo->progressive_mode)
659 coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
660 ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
661 (JDIMENSION) jround_up((long) compptr->width_in_blocks,
662 (long) compptr->h_samp_factor),
663 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
664 (long) compptr->v_samp_factor),
665 (JDIMENSION) access_rows);
667 coef->pub.consume_data = consume_data;
668 coef->pub.decompress_data = decompress_data;
669 coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
671 ERREXIT(cinfo, JERR_NOT_COMPILED);
674 /* We only need a single-MCU buffer. */
679 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
680 D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
681 for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
682 coef->MCU_buffer[i] = buffer + i;
684 coef->pub.consume_data = dummy_consume_data;
685 coef->pub.decompress_data = decompress_onepass;
686 coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
689 /* Allocate the workspace buffer */
690 coef->workspace = (JCOEF *)
691 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
692 sizeof(JCOEF) * DCTSIZE2);