-/*\r
-\r
- * jdcoefct.c\r
-\r
- *\r
-\r
- * Copyright (C) 1994-1995, Thomas G. Lane.\r
-\r
- * This file is part of the Independent JPEG Group's software.\r
-\r
- * For conditions of distribution and use, see the accompanying README file.\r
-\r
- *\r
-\r
- * This file contains the coefficient buffer controller for decompression.\r
-\r
- * This controller is the top level of the JPEG decompressor proper.\r
-\r
- * The coefficient buffer lies between entropy decoding and inverse-DCT steps.\r
-\r
- *\r
-\r
- * In buffered-image mode, this controller is the interface between\r
-\r
- * input-oriented processing and output-oriented processing.\r
-\r
- * Also, the input side (only) is used when reading a file for transcoding.\r
-\r
- */\r
-\r
-\r
-\r
-#define JPEG_INTERNALS\r
-\r
-#include "jinclude.h"\r
-\r
-#include "radiant_jpeglib.h"\r
-\r
-\r
-\r
-/* Block smoothing is only applicable for progressive JPEG, so: */\r
-\r
-#ifndef D_PROGRESSIVE_SUPPORTED\r
-\r
-#undef BLOCK_SMOOTHING_SUPPORTED\r
-\r
-#endif\r
-\r
-\r
-\r
-/* Private buffer controller object */\r
-\r
-\r
-\r
-typedef struct {\r
-\r
- struct jpeg_d_coef_controller pub; /* public fields */\r
-\r
-\r
-\r
- /* These variables keep track of the current location of the input side. */\r
-\r
- /* cinfo->input_iMCU_row is also used for this. */\r
-\r
- JDIMENSION MCU_ctr; /* counts MCUs processed in current row */\r
-\r
- int MCU_vert_offset; /* counts MCU rows within iMCU row */\r
-\r
- int MCU_rows_per_iMCU_row; /* number of such rows needed */\r
-\r
-\r
-\r
- /* The output side's location is represented by cinfo->output_iMCU_row. */\r
-\r
-\r
-\r
- /* In single-pass modes, it's sufficient to buffer just one MCU.\r
-\r
- * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,\r
-\r
- * and let the entropy decoder write into that workspace each time.\r
-\r
- * (On 80x86, the workspace is FAR even though it's not really very big;\r
-\r
- * this is to keep the module interfaces unchanged when a large coefficient\r
-\r
- * buffer is necessary.)\r
-\r
- * In multi-pass modes, this array points to the current MCU's blocks\r
-\r
- * within the virtual arrays; it is used only by the input side.\r
-\r
- */\r
-\r
- JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];\r
-\r
-\r
-\r
-#ifdef D_MULTISCAN_FILES_SUPPORTED\r
-\r
- /* In multi-pass modes, we need a virtual block array for each component. */\r
-\r
- jvirt_barray_ptr whole_image[MAX_COMPONENTS];\r
-\r
-#endif\r
-\r
-\r
-\r
-#ifdef BLOCK_SMOOTHING_SUPPORTED\r
-\r
- /* When doing block smoothing, we latch coefficient Al values here */\r
-\r
- int * coef_bits_latch;\r
-\r
-#define SAVED_COEFS 6 /* we save coef_bits[0..5] */\r
-\r
-#endif\r
-\r
-} my_coef_controller;\r
-\r
-\r
-\r
-typedef my_coef_controller * my_coef_ptr;\r
-\r
-\r
-\r
-/* Forward declarations */\r
-\r
-METHODDEF int decompress_onepass\r
-\r
- JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));\r
-\r
-#ifdef D_MULTISCAN_FILES_SUPPORTED\r
-\r
-METHODDEF int decompress_data\r
-\r
- JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));\r
-\r
-#endif\r
-\r
-#ifdef BLOCK_SMOOTHING_SUPPORTED\r
-\r
-LOCAL boolean smoothing_ok JPP((j_decompress_ptr cinfo));\r
-\r
-METHODDEF int decompress_smooth_data\r
-\r
- JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
-\r
-LOCAL void\r
-\r
-start_iMCU_row (j_decompress_ptr cinfo)\r
-\r
-/* Reset within-iMCU-row counters for a new row (input side) */\r
-\r
-{\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
-\r
-\r
- /* In an interleaved scan, an MCU row is the same as an iMCU row.\r
-\r
- * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.\r
-\r
- * But at the bottom of the image, process only what's left.\r
-\r
- */\r
-\r
- if (cinfo->comps_in_scan > 1) {\r
-\r
- coef->MCU_rows_per_iMCU_row = 1;\r
-\r
- } else {\r
-\r
- if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))\r
-\r
- coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;\r
-\r
- else\r
-\r
- coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;\r
-\r
- }\r
-\r
-\r
-\r
- coef->MCU_ctr = 0;\r
-\r
- coef->MCU_vert_offset = 0;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Initialize for an input processing pass.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF void\r
-\r
-start_input_pass (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- cinfo->input_iMCU_row = 0;\r
-\r
- start_iMCU_row(cinfo);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Initialize for an output processing pass.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF void\r
-\r
-start_output_pass (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
-#ifdef BLOCK_SMOOTHING_SUPPORTED\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
-\r
-\r
- /* If multipass, check to see whether to use block smoothing on this pass */\r
-\r
- if (coef->pub.coef_arrays != NULL) {\r
-\r
- if (cinfo->do_block_smoothing && smoothing_ok(cinfo))\r
-\r
- coef->pub.decompress_data = decompress_smooth_data;\r
-\r
- else\r
-\r
- coef->pub.decompress_data = decompress_data;\r
-\r
- }\r
-\r
-#endif\r
-\r
- cinfo->output_iMCU_row = 0;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Decompress and return some data in the single-pass case.\r
-\r
- * Always attempts to emit one fully interleaved MCU row ("iMCU" row).\r
-\r
- * Input and output must run in lockstep since we have only a one-MCU buffer.\r
-\r
- * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.\r
-\r
- *\r
-\r
- * NB: output_buf contains a plane for each component in image.\r
-\r
- * For single pass, this is the same as the components in the scan.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF int\r
-\r
-decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)\r
-\r
-{\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
- JDIMENSION MCU_col_num; /* index of current MCU within row */\r
-\r
- JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;\r
-\r
- JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\r
-\r
- int blkn, ci, xindex, yindex, yoffset, useful_width;\r
-\r
- JSAMPARRAY output_ptr;\r
-\r
- JDIMENSION start_col, output_col;\r
-\r
- jpeg_component_info *compptr;\r
-\r
- inverse_DCT_method_ptr inverse_DCT;\r
-\r
-\r
-\r
- /* Loop to process as much as one whole iMCU row */\r
-\r
- for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\r
-\r
- yoffset++) {\r
-\r
- for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;\r
-\r
- MCU_col_num++) {\r
-\r
- /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */\r
-\r
- jzero_far((void FAR *) coef->MCU_buffer[0],\r
-\r
- (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));\r
-\r
- if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {\r
-\r
- /* Suspension forced; update state counters and exit */\r
-\r
- coef->MCU_vert_offset = yoffset;\r
-\r
- coef->MCU_ctr = MCU_col_num;\r
-\r
- return JPEG_SUSPENDED;\r
-\r
- }\r
-\r
- /* Determine where data should go in output_buf and do the IDCT thing.\r
-\r
- * We skip dummy blocks at the right and bottom edges (but blkn gets\r
-\r
- * incremented past them!). Note the inner loop relies on having\r
-\r
- * allocated the MCU_buffer[] blocks sequentially.\r
-\r
- */\r
-\r
- blkn = 0; /* index of current DCT block within MCU */\r
-\r
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\r
-\r
- compptr = cinfo->cur_comp_info[ci];\r
-\r
- /* Don't bother to IDCT an uninteresting component. */\r
-\r
- if (! compptr->component_needed) {\r
-\r
- blkn += compptr->MCU_blocks;\r
-\r
- continue;\r
-\r
- }\r
-\r
- inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];\r
-\r
- useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width\r
-\r
- : compptr->last_col_width;\r
-\r
- output_ptr = output_buf[ci] + yoffset * compptr->DCT_scaled_size;\r
-\r
- start_col = MCU_col_num * compptr->MCU_sample_width;\r
-\r
- for (yindex = 0; yindex < compptr->MCU_height; yindex++) {\r
-\r
- if (cinfo->input_iMCU_row < last_iMCU_row ||\r
-\r
- yoffset+yindex < compptr->last_row_height) {\r
-\r
- output_col = start_col;\r
-\r
- for (xindex = 0; xindex < useful_width; xindex++) {\r
-\r
- (*inverse_DCT) (cinfo, compptr,\r
-\r
- (JCOEFPTR) coef->MCU_buffer[blkn+xindex],\r
-\r
- output_ptr, output_col);\r
-\r
- output_col += compptr->DCT_scaled_size;\r
-\r
- }\r
-\r
- }\r
-\r
- blkn += compptr->MCU_width;\r
-\r
- output_ptr += compptr->DCT_scaled_size;\r
-\r
- }\r
-\r
- }\r
-\r
- }\r
-\r
- /* Completed an MCU row, but perhaps not an iMCU row */\r
-\r
- coef->MCU_ctr = 0;\r
-\r
- }\r
-\r
- /* Completed the iMCU row, advance counters for next one */\r
-\r
- cinfo->output_iMCU_row++;\r
-\r
- if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {\r
-\r
- start_iMCU_row(cinfo);\r
-\r
- return JPEG_ROW_COMPLETED;\r
-\r
- }\r
-\r
- /* Completed the scan */\r
-\r
- (*cinfo->inputctl->finish_input_pass) (cinfo);\r
-\r
- return JPEG_SCAN_COMPLETED;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Dummy consume-input routine for single-pass operation.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF int\r
-\r
-dummy_consume_data (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- return JPEG_SUSPENDED; /* Always indicate nothing was done */\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-#ifdef D_MULTISCAN_FILES_SUPPORTED\r
-\r
-\r
-\r
-/*\r
-\r
- * Consume input data and store it in the full-image coefficient buffer.\r
-\r
- * We read as much as one fully interleaved MCU row ("iMCU" row) per call,\r
-\r
- * ie, v_samp_factor block rows for each component in the scan.\r
-\r
- * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF int\r
-\r
-consume_data (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
- JDIMENSION MCU_col_num; /* index of current MCU within row */\r
-\r
- int blkn, ci, xindex, yindex, yoffset;\r
-\r
- JDIMENSION start_col;\r
-\r
- JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];\r
-\r
- JBLOCKROW buffer_ptr;\r
-\r
- jpeg_component_info *compptr;\r
-\r
-\r
-\r
- /* Align the virtual buffers for the components used in this scan. */\r
-\r
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\r
-\r
- compptr = cinfo->cur_comp_info[ci];\r
-\r
- buffer[ci] = (*cinfo->mem->access_virt_barray)\r
-\r
- ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],\r
-\r
- cinfo->input_iMCU_row * compptr->v_samp_factor,\r
-\r
- (JDIMENSION) compptr->v_samp_factor, TRUE);\r
-\r
- /* Note: entropy decoder expects buffer to be zeroed,\r
-\r
- * but this is handled automatically by the memory manager\r
-\r
- * because we requested a pre-zeroed array.\r
-\r
- */\r
-\r
- }\r
-\r
-\r
-\r
- /* Loop to process one whole iMCU row */\r
-\r
- for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\r
-\r
- yoffset++) {\r
-\r
- for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;\r
-\r
- MCU_col_num++) {\r
-\r
- /* Construct list of pointers to DCT blocks belonging to this MCU */\r
-\r
- blkn = 0; /* index of current DCT block within MCU */\r
-\r
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\r
-\r
- compptr = cinfo->cur_comp_info[ci];\r
-\r
- start_col = MCU_col_num * compptr->MCU_width;\r
-\r
- for (yindex = 0; yindex < compptr->MCU_height; yindex++) {\r
-\r
- buffer_ptr = buffer[ci][yindex+yoffset] + start_col;\r
-\r
- for (xindex = 0; xindex < compptr->MCU_width; xindex++) {\r
-\r
- coef->MCU_buffer[blkn++] = buffer_ptr++;\r
-\r
- }\r
-\r
- }\r
-\r
- }\r
-\r
- /* Try to fetch the MCU. */\r
-\r
- if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {\r
-\r
- /* Suspension forced; update state counters and exit */\r
-\r
- coef->MCU_vert_offset = yoffset;\r
-\r
- coef->MCU_ctr = MCU_col_num;\r
-\r
- return JPEG_SUSPENDED;\r
-\r
- }\r
-\r
- }\r
-\r
- /* Completed an MCU row, but perhaps not an iMCU row */\r
-\r
- coef->MCU_ctr = 0;\r
-\r
- }\r
-\r
- /* Completed the iMCU row, advance counters for next one */\r
-\r
- if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {\r
-\r
- start_iMCU_row(cinfo);\r
-\r
- return JPEG_ROW_COMPLETED;\r
-\r
- }\r
-\r
- /* Completed the scan */\r
-\r
- (*cinfo->inputctl->finish_input_pass) (cinfo);\r
-\r
- return JPEG_SCAN_COMPLETED;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Decompress and return some data in the multi-pass case.\r
-\r
- * Always attempts to emit one fully interleaved MCU row ("iMCU" row).\r
-\r
- * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.\r
-\r
- *\r
-\r
- * NB: output_buf contains a plane for each component in image.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF int\r
-\r
-decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)\r
-\r
-{\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
- JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\r
-\r
- JDIMENSION block_num;\r
-\r
- int ci, block_row, block_rows;\r
-\r
- JBLOCKARRAY buffer;\r
-\r
- JBLOCKROW buffer_ptr;\r
-\r
- JSAMPARRAY output_ptr;\r
-\r
- JDIMENSION output_col;\r
-\r
- jpeg_component_info *compptr;\r
-\r
- inverse_DCT_method_ptr inverse_DCT;\r
-\r
-\r
-\r
- /* Force some input to be done if we are getting ahead of the input. */\r
-\r
- while (cinfo->input_scan_number < cinfo->output_scan_number ||\r
-\r
- (cinfo->input_scan_number == cinfo->output_scan_number &&\r
-\r
- cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {\r
-\r
- if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)\r
-\r
- return JPEG_SUSPENDED;\r
-\r
- }\r
-\r
-\r
-\r
- /* OK, output from the virtual arrays. */\r
-\r
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\r
-\r
- ci++, compptr++) {\r
-\r
- /* Don't bother to IDCT an uninteresting component. */\r
-\r
- if (! compptr->component_needed)\r
-\r
- continue;\r
-\r
- /* Align the virtual buffer for this component. */\r
-\r
- buffer = (*cinfo->mem->access_virt_barray)\r
-\r
- ((j_common_ptr) cinfo, coef->whole_image[ci],\r
-\r
- cinfo->output_iMCU_row * compptr->v_samp_factor,\r
-\r
- (JDIMENSION) compptr->v_samp_factor, FALSE);\r
-\r
- /* Count non-dummy DCT block rows in this iMCU row. */\r
-\r
- if (cinfo->output_iMCU_row < last_iMCU_row)\r
-\r
- block_rows = compptr->v_samp_factor;\r
-\r
- else {\r
-\r
- /* NB: can't use last_row_height here; it is input-side-dependent! */\r
-\r
- block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\r
-\r
- if (block_rows == 0) block_rows = compptr->v_samp_factor;\r
-\r
- }\r
-\r
- inverse_DCT = cinfo->idct->inverse_DCT[ci];\r
-\r
- output_ptr = output_buf[ci];\r
-\r
- /* Loop over all DCT blocks to be processed. */\r
-\r
- for (block_row = 0; block_row < block_rows; block_row++) {\r
-\r
- buffer_ptr = buffer[block_row];\r
-\r
- output_col = 0;\r
-\r
- for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {\r
-\r
- (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,\r
-\r
- output_ptr, output_col);\r
-\r
- buffer_ptr++;\r
-\r
- output_col += compptr->DCT_scaled_size;\r
-\r
- }\r
-\r
- output_ptr += compptr->DCT_scaled_size;\r
-\r
- }\r
-\r
- }\r
-\r
-\r
-\r
- if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)\r
-\r
- return JPEG_ROW_COMPLETED;\r
-\r
- return JPEG_SCAN_COMPLETED;\r
-\r
-}\r
-\r
-\r
-\r
-#endif /* D_MULTISCAN_FILES_SUPPORTED */\r
-\r
-\r
-\r
-\r
-\r
-#ifdef BLOCK_SMOOTHING_SUPPORTED\r
-\r
-\r
-\r
-/*\r
-\r
- * This code applies interblock smoothing as described by section K.8\r
-\r
- * of the JPEG standard: the first 5 AC coefficients are estimated from\r
-\r
- * the DC values of a DCT block and its 8 neighboring blocks.\r
-\r
- * We apply smoothing only for progressive JPEG decoding, and only if\r
-\r
- * the coefficients it can estimate are not yet known to full precision.\r
-\r
- */\r
-\r
-\r
-\r
-/*\r
-\r
- * Determine whether block smoothing is applicable and safe.\r
-\r
- * We also latch the current states of the coef_bits[] entries for the\r
-\r
- * AC coefficients; otherwise, if the input side of the decompressor\r
-\r
- * advances into a new scan, we might think the coefficients are known\r
-\r
- * more accurately than they really are.\r
-\r
- */\r
-\r
-\r
-\r
-LOCAL boolean\r
-\r
-smoothing_ok (j_decompress_ptr cinfo)\r
-\r
-{\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
- boolean smoothing_useful = FALSE;\r
-\r
- int ci, coefi;\r
-\r
- jpeg_component_info *compptr;\r
-\r
- JQUANT_TBL * qtable;\r
-\r
- int * coef_bits;\r
-\r
- int * coef_bits_latch;\r
-\r
-\r
-\r
- if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)\r
-\r
- return FALSE;\r
-\r
-\r
-\r
- /* Allocate latch area if not already done */\r
-\r
- if (coef->coef_bits_latch == NULL)\r
-\r
- coef->coef_bits_latch = (int *)\r
-\r
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\r
-\r
- cinfo->num_components *\r
-\r
- (SAVED_COEFS * SIZEOF(int)));\r
-\r
- coef_bits_latch = coef->coef_bits_latch;\r
-\r
-\r
-\r
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\r
-\r
- ci++, compptr++) {\r
-\r
- /* All components' quantization values must already be latched. */\r
-\r
- if ((qtable = compptr->quant_table) == NULL)\r
-\r
- return FALSE;\r
-\r
- /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */\r
-\r
- for (coefi = 0; coefi <= 5; coefi++) {\r
-\r
- if (qtable->quantval[coefi] == 0)\r
-\r
- return FALSE;\r
-\r
- }\r
-\r
- /* DC values must be at least partly known for all components. */\r
-\r
- coef_bits = cinfo->coef_bits[ci];\r
-\r
- if (coef_bits[0] < 0)\r
-\r
- return FALSE;\r
-\r
- /* Block smoothing is helpful if some AC coefficients remain inaccurate. */\r
-\r
- for (coefi = 1; coefi <= 5; coefi++) {\r
-\r
- coef_bits_latch[coefi] = coef_bits[coefi];\r
-\r
- if (coef_bits[coefi] != 0)\r
-\r
- smoothing_useful = TRUE;\r
-\r
- }\r
-\r
- coef_bits_latch += SAVED_COEFS;\r
-\r
- }\r
-\r
-\r
-\r
- return smoothing_useful;\r
-\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Variant of decompress_data for use when doing block smoothing.\r
-\r
- */\r
-\r
-\r
-\r
-METHODDEF int\r
-\r
-decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)\r
-\r
-{\r
-\r
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\r
-\r
- JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\r
-\r
- JDIMENSION block_num, last_block_column;\r
-\r
- int ci, block_row, block_rows, access_rows;\r
-\r
- JBLOCKARRAY buffer;\r
-\r
- JBLOCKROW buffer_ptr, prev_block_row, next_block_row;\r
-\r
- JSAMPARRAY output_ptr;\r
-\r
- JDIMENSION output_col;\r
-\r
- jpeg_component_info *compptr;\r
-\r
- inverse_DCT_method_ptr inverse_DCT;\r
-\r
- boolean first_row, last_row;\r
-\r
- JBLOCK workspace;\r
-\r
- int *coef_bits;\r
-\r
- JQUANT_TBL *quanttbl;\r
-\r
- INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;\r
-\r
- int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;\r
-\r
- int Al, pred;\r
-\r
-\r
-\r
- /* Force some input to be done if we are getting ahead of the input. */\r
-\r
- while (cinfo->input_scan_number <= cinfo->output_scan_number &&\r
-\r
- ! cinfo->inputctl->eoi_reached) {\r
-\r
- if (cinfo->input_scan_number == cinfo->output_scan_number) {\r
-\r
- /* If input is working on current scan, we ordinarily want it to\r
-\r
- * have completed the current row. But if input scan is DC,\r
-\r
- * we want it to keep one row ahead so that next block row's DC\r
-\r
- * values are up to date.\r
-\r
- */\r
-\r
- JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;\r
-\r
- if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)\r
-\r
- break;\r
-\r
- }\r
-\r
- if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)\r
-\r
- return JPEG_SUSPENDED;\r
-\r
- }\r
-\r
-\r
-\r
- /* OK, output from the virtual arrays. */\r
-\r
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\r
-\r
- ci++, compptr++) {\r
-\r
- /* Don't bother to IDCT an uninteresting component. */\r
-\r
- if (! compptr->component_needed)\r
-\r
- continue;\r
-\r
- /* Count non-dummy DCT block rows in this iMCU row. */\r
-\r
- if (cinfo->output_iMCU_row < last_iMCU_row) {\r
-\r
- block_rows = compptr->v_samp_factor;\r
-\r
- access_rows = block_rows * 2; /* this and next iMCU row */\r
-\r
- last_row = FALSE;\r
-\r
- } else {\r
-\r
- /* NB: can't use last_row_height here; it is input-side-dependent! */\r
-\r
- block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\r
-\r
- if (block_rows == 0) block_rows = compptr->v_samp_factor;\r
-\r
- access_rows = block_rows; /* this iMCU row only */\r
-\r
- last_row = TRUE;\r
-\r
- }\r
-\r
- /* Align the virtual buffer for this component. */\r
-\r
- if (cinfo->output_iMCU_row > 0) {\r
-\r
- access_rows += compptr->v_samp_factor; /* prior iMCU row too */\r
-\r
- buffer = (*cinfo->mem->access_virt_barray)\r
-\r
- ((j_common_ptr) cinfo, coef->whole_image[ci],\r
-\r
- (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,\r
-\r
- (JDIMENSION) access_rows, FALSE);\r
-\r
- buffer += compptr->v_samp_factor; /* point to current iMCU row */\r
-\r
- first_row = FALSE;\r
-\r
- } else {\r
-\r
- buffer = (*cinfo->mem->access_virt_barray)\r
-\r
- ((j_common_ptr) cinfo, coef->whole_image[ci],\r
-\r
- (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);\r
-\r
- first_row = TRUE;\r
-\r
- }\r
-\r
- /* Fetch component-dependent info */\r
-\r
- coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);\r
-\r
- quanttbl = compptr->quant_table;\r
-\r
- Q00 = quanttbl->quantval[0];\r
-\r
- Q01 = quanttbl->quantval[1];\r
-\r
- Q10 = quanttbl->quantval[2];\r
-\r
- Q20 = quanttbl->quantval[3];\r
-\r
- Q11 = quanttbl->quantval[4];\r
-\r
- Q02 = quanttbl->quantval[5];\r
-\r
- inverse_DCT = cinfo->idct->inverse_DCT[ci];\r
-\r
- output_ptr = output_buf[ci];\r
-\r
- /* Loop over all DCT blocks to be processed. */\r
-\r
- for (block_row = 0; block_row < block_rows; block_row++) {\r
-\r
- buffer_ptr = buffer[block_row];\r
-\r
- if (first_row && block_row == 0)\r
-\r
- prev_block_row = buffer_ptr;\r
-\r
- else\r
-\r
- prev_block_row = buffer[block_row-1];\r
-\r
- if (last_row && block_row == block_rows-1)\r
-\r
- next_block_row = buffer_ptr;\r
-\r
- else\r
-\r
- next_block_row = buffer[block_row+1];\r
-\r
- /* We fetch the surrounding DC values using a sliding-register approach.\r
-\r
- * Initialize all nine here so as to do the right thing on narrow pics.\r
-\r
- */\r
-\r
- DC1 = DC2 = DC3 = (int) prev_block_row[0][0];\r
-\r
- DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];\r
-\r
- DC7 = DC8 = DC9 = (int) next_block_row[0][0];\r
-\r
- output_col = 0;\r
-\r
- last_block_column = compptr->width_in_blocks - 1;\r
-\r
- for (block_num = 0; block_num <= last_block_column; block_num++) {\r
-\r
- /* Fetch current DCT block into workspace so we can modify it. */\r
-\r
- jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);\r
-\r
- /* Update DC values */\r
-\r
- if (block_num < last_block_column) {\r
-\r
- DC3 = (int) prev_block_row[1][0];\r
-\r
- DC6 = (int) buffer_ptr[1][0];\r
-\r
- DC9 = (int) next_block_row[1][0];\r
-\r
- }\r
-\r
- /* Compute coefficient estimates per K.8.\r
-\r
- * An estimate is applied only if coefficient is still zero,\r
-\r
- * and is not known to be fully accurate.\r
-\r
- */\r
-\r
- /* AC01 */\r
-\r
- if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {\r
-\r
- num = 36 * Q00 * (DC4 - DC6);\r
-\r
- if (num >= 0) {\r
-\r
- pred = (int) (((Q01<<7) + num) / (Q01<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- } else {\r
-\r
- pred = (int) (((Q01<<7) - num) / (Q01<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- pred = -pred;\r
-\r
- }\r
-\r
- workspace[1] = (JCOEF) pred;\r
-\r
- }\r
-\r
- /* AC10 */\r
-\r
- if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {\r
-\r
- num = 36 * Q00 * (DC2 - DC8);\r
-\r
- if (num >= 0) {\r
-\r
- pred = (int) (((Q10<<7) + num) / (Q10<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- } else {\r
-\r
- pred = (int) (((Q10<<7) - num) / (Q10<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- pred = -pred;\r
-\r
- }\r
-\r
- workspace[8] = (JCOEF) pred;\r
-\r
- }\r
-\r
- /* AC20 */\r
-\r
- if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {\r
-\r
- num = 9 * Q00 * (DC2 + DC8 - 2*DC5);\r
-\r
- if (num >= 0) {\r
-\r
- pred = (int) (((Q20<<7) + num) / (Q20<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- } else {\r
-\r
- pred = (int) (((Q20<<7) - num) / (Q20<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- pred = -pred;\r
-\r
- }\r
-\r
- workspace[16] = (JCOEF) pred;\r
-\r
- }\r
-\r
- /* AC11 */\r
-\r
- if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {\r
-\r
- num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);\r
-\r
- if (num >= 0) {\r
-\r
- pred = (int) (((Q11<<7) + num) / (Q11<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- } else {\r
-\r
- pred = (int) (((Q11<<7) - num) / (Q11<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- pred = -pred;\r
-\r
- }\r
-\r
- workspace[9] = (JCOEF) pred;\r
-\r
- }\r
-\r
- /* AC02 */\r
-\r
- if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {\r
-\r
- num = 9 * Q00 * (DC4 + DC6 - 2*DC5);\r
-\r
- if (num >= 0) {\r
-\r
- pred = (int) (((Q02<<7) + num) / (Q02<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- } else {\r
-\r
- pred = (int) (((Q02<<7) - num) / (Q02<<8));\r
-\r
- if (Al > 0 && pred >= (1<<Al))\r
-\r
- pred = (1<<Al)-1;\r
-\r
- pred = -pred;\r
-\r
- }\r
-\r
- workspace[2] = (JCOEF) pred;\r
-\r
- }\r
-\r
- /* OK, do the IDCT */\r
-\r
- (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,\r
-\r
- output_ptr, output_col);\r
-\r
- /* Advance for next column */\r
-\r
- DC1 = DC2; DC2 = DC3;\r
-\r
- DC4 = DC5; DC5 = DC6;\r
-\r
- DC7 = DC8; DC8 = DC9;\r
-\r
- buffer_ptr++, prev_block_row++, next_block_row++;\r
-\r
- output_col += compptr->DCT_scaled_size;\r
-\r
- }\r
-\r
- output_ptr += compptr->DCT_scaled_size;\r
-\r
- }\r
-\r
- }\r
-\r
-\r
-\r
- if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)\r
-\r
- return JPEG_ROW_COMPLETED;\r
-\r
- return JPEG_SCAN_COMPLETED;\r
-\r
-}\r
-\r
-\r
-\r
-#endif /* BLOCK_SMOOTHING_SUPPORTED */\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
- * Initialize coefficient buffer controller.\r
-\r
- */\r
-\r
-\r
-\r
-GLOBAL void\r
-\r
-jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)\r
-\r
-{\r
-\r
- my_coef_ptr coef;\r
-\r
-\r
-\r
- coef = (my_coef_ptr)\r
-\r
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\r
-\r
- SIZEOF(my_coef_controller));\r
-\r
- cinfo->coef = (struct jpeg_d_coef_controller *) coef;\r
-\r
- coef->pub.start_input_pass = start_input_pass;\r
-\r
- coef->pub.start_output_pass = start_output_pass;\r
-\r
-#ifdef BLOCK_SMOOTHING_SUPPORTED\r
-\r
- coef->coef_bits_latch = NULL;\r
-\r
-#endif\r
-\r
-\r
-\r
- /* Create the coefficient buffer. */\r
-\r
- if (need_full_buffer) {\r
-\r
-#ifdef D_MULTISCAN_FILES_SUPPORTED\r
-\r
- /* Allocate a full-image virtual array for each component, */\r
-\r
- /* padded to a multiple of samp_factor DCT blocks in each direction. */\r
-\r
- /* Note we ask for a pre-zeroed array. */\r
-\r
- int ci, access_rows;\r
-\r
- jpeg_component_info *compptr;\r
-\r
-\r
-\r
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\r
-\r
- ci++, compptr++) {\r
-\r
- access_rows = compptr->v_samp_factor;\r
-\r
-#ifdef BLOCK_SMOOTHING_SUPPORTED\r
-\r
- /* If block smoothing could be used, need a bigger window */\r
-\r
- if (cinfo->progressive_mode)\r
-\r
- access_rows *= 3;\r
-\r
-#endif\r
-\r
- coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)\r
-\r
- ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,\r
-\r
- (JDIMENSION) jround_up((long) compptr->width_in_blocks,\r
-\r
- (long) compptr->h_samp_factor),\r
-\r
- (JDIMENSION) jround_up((long) compptr->height_in_blocks,\r
-\r
- (long) compptr->v_samp_factor),\r
-\r
- (JDIMENSION) access_rows);\r
-\r
- }\r
-\r
- coef->pub.consume_data = consume_data;\r
-\r
- coef->pub.decompress_data = decompress_data;\r
-\r
- coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */\r
-\r
-#else\r
-\r
- ERREXIT(cinfo, JERR_NOT_COMPILED);\r
-\r
-#endif\r
-\r
- } else {\r
-\r
- /* We only need a single-MCU buffer. */\r
-\r
- JBLOCKROW buffer;\r
-\r
- int i;\r
-\r
-\r
-\r
- buffer = (JBLOCKROW)\r
-\r
- (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,\r
-\r
- D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));\r
-\r
- for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {\r
-\r
- coef->MCU_buffer[i] = buffer + i;\r
-\r
- }\r
-\r
- coef->pub.consume_data = dummy_consume_data;\r
-\r
- coef->pub.decompress_data = decompress_onepass;\r
-\r
- coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */\r
-\r
- }\r
-\r
-}\r
-\r
+/*
+
+ * jdcoefct.c
+
+ *
+
+ * Copyright (C) 1994-1995, Thomas G. Lane.
+
+ * This file is part of the Independent JPEG Group's software.
+
+ * For conditions of distribution and use, see the accompanying README file.
+
+ *
+
+ * This file contains the coefficient buffer controller for decompression.
+
+ * This controller is the top level of the JPEG decompressor proper.
+
+ * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
+
+ *
+
+ * In buffered-image mode, this controller is the interface between
+
+ * input-oriented processing and output-oriented processing.
+
+ * Also, the input side (only) is used when reading a file for transcoding.
+
+ */
+
+
+
+#define JPEG_INTERNALS
+
+#include "jinclude.h"
+
+#include "radiant_jpeglib.h"
+
+
+
+/* Block smoothing is only applicable for progressive JPEG, so: */
+
+#ifndef D_PROGRESSIVE_SUPPORTED
+
+#undef BLOCK_SMOOTHING_SUPPORTED
+
+#endif
+
+
+
+/* Private buffer controller object */
+
+
+
+typedef struct {
+
+ struct jpeg_d_coef_controller pub; /* public fields */
+
+
+
+ /* These variables keep track of the current location of the input side. */
+
+ /* cinfo->input_iMCU_row is also used for this. */
+
+ JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
+
+ int MCU_vert_offset; /* counts MCU rows within iMCU row */
+
+ int MCU_rows_per_iMCU_row; /* number of such rows needed */
+
+
+
+ /* The output side's location is represented by cinfo->output_iMCU_row. */
+
+
+
+ /* In single-pass modes, it's sufficient to buffer just one MCU.
+
+ * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
+
+ * and let the entropy decoder write into that workspace each time.
+
+ * (On 80x86, the workspace is FAR even though it's not really very big;
+
+ * this is to keep the module interfaces unchanged when a large coefficient
+
+ * buffer is necessary.)
+
+ * In multi-pass modes, this array points to the current MCU's blocks
+
+ * within the virtual arrays; it is used only by the input side.
+
+ */
+
+ JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
+
+
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+ /* In multi-pass modes, we need a virtual block array for each component. */
+
+ jvirt_barray_ptr whole_image[MAX_COMPONENTS];
+
+#endif
+
+
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+ /* When doing block smoothing, we latch coefficient Al values here */
+
+ int * coef_bits_latch;
+
+#define SAVED_COEFS 6 /* we save coef_bits[0..5] */
+
+#endif
+
+} my_coef_controller;
+
+
+
+typedef my_coef_controller * my_coef_ptr;
+
+
+
+/* Forward declarations */
+
+METHODDEF int decompress_onepass
+
+ JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+METHODDEF int decompress_data
+
+ JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
+
+#endif
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+LOCAL boolean smoothing_ok JPP((j_decompress_ptr cinfo));
+
+METHODDEF int decompress_smooth_data
+
+ JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
+
+#endif
+
+
+
+
+
+LOCAL void
+
+start_iMCU_row (j_decompress_ptr cinfo)
+
+/* Reset within-iMCU-row counters for a new row (input side) */
+
+{
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+
+
+ /* In an interleaved scan, an MCU row is the same as an iMCU row.
+
+ * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
+
+ * But at the bottom of the image, process only what's left.
+
+ */
+
+ if (cinfo->comps_in_scan > 1) {
+
+ coef->MCU_rows_per_iMCU_row = 1;
+
+ } else {
+
+ if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
+
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
+
+ else
+
+ coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
+
+ }
+
+
+
+ coef->MCU_ctr = 0;
+
+ coef->MCU_vert_offset = 0;
+
+}
+
+
+
+
+
+/*
+
+ * Initialize for an input processing pass.
+
+ */
+
+
+
+METHODDEF void
+
+start_input_pass (j_decompress_ptr cinfo)
+
+{
+
+ cinfo->input_iMCU_row = 0;
+
+ start_iMCU_row(cinfo);
+
+}
+
+
+
+
+
+/*
+
+ * Initialize for an output processing pass.
+
+ */
+
+
+
+METHODDEF void
+
+start_output_pass (j_decompress_ptr cinfo)
+
+{
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+
+
+ /* If multipass, check to see whether to use block smoothing on this pass */
+
+ if (coef->pub.coef_arrays != NULL) {
+
+ if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
+
+ coef->pub.decompress_data = decompress_smooth_data;
+
+ else
+
+ coef->pub.decompress_data = decompress_data;
+
+ }
+
+#endif
+
+ cinfo->output_iMCU_row = 0;
+
+}
+
+
+
+
+
+/*
+
+ * Decompress and return some data in the single-pass case.
+
+ * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
+
+ * Input and output must run in lockstep since we have only a one-MCU buffer.
+
+ * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
+
+ *
+
+ * NB: output_buf contains a plane for each component in image.
+
+ * For single pass, this is the same as the components in the scan.
+
+ */
+
+
+
+METHODDEF int
+
+decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
+
+{
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+
+ JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
+
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+
+ int blkn, ci, xindex, yindex, yoffset, useful_width;
+
+ JSAMPARRAY output_ptr;
+
+ JDIMENSION start_col, output_col;
+
+ jpeg_component_info *compptr;
+
+ inverse_DCT_method_ptr inverse_DCT;
+
+
+
+ /* Loop to process as much as one whole iMCU row */
+
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+
+ yoffset++) {
+
+ for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
+
+ MCU_col_num++) {
+
+ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
+
+ jzero_far((void FAR *) coef->MCU_buffer[0],
+
+ (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
+
+ if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
+
+ /* Suspension forced; update state counters and exit */
+
+ coef->MCU_vert_offset = yoffset;
+
+ coef->MCU_ctr = MCU_col_num;
+
+ return JPEG_SUSPENDED;
+
+ }
+
+ /* Determine where data should go in output_buf and do the IDCT thing.
+
+ * We skip dummy blocks at the right and bottom edges (but blkn gets
+
+ * incremented past them!). Note the inner loop relies on having
+
+ * allocated the MCU_buffer[] blocks sequentially.
+
+ */
+
+ blkn = 0; /* index of current DCT block within MCU */
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+
+ compptr = cinfo->cur_comp_info[ci];
+
+ /* Don't bother to IDCT an uninteresting component. */
+
+ if (! compptr->component_needed) {
+
+ blkn += compptr->MCU_blocks;
+
+ continue;
+
+ }
+
+ inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
+
+ useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
+
+ : compptr->last_col_width;
+
+ output_ptr = output_buf[ci] + yoffset * compptr->DCT_scaled_size;
+
+ start_col = MCU_col_num * compptr->MCU_sample_width;
+
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+
+ if (cinfo->input_iMCU_row < last_iMCU_row ||
+
+ yoffset+yindex < compptr->last_row_height) {
+
+ output_col = start_col;
+
+ for (xindex = 0; xindex < useful_width; xindex++) {
+
+ (*inverse_DCT) (cinfo, compptr,
+
+ (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
+
+ output_ptr, output_col);
+
+ output_col += compptr->DCT_scaled_size;
+
+ }
+
+ }
+
+ blkn += compptr->MCU_width;
+
+ output_ptr += compptr->DCT_scaled_size;
+
+ }
+
+ }
+
+ }
+
+ /* Completed an MCU row, but perhaps not an iMCU row */
+
+ coef->MCU_ctr = 0;
+
+ }
+
+ /* Completed the iMCU row, advance counters for next one */
+
+ cinfo->output_iMCU_row++;
+
+ if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
+
+ start_iMCU_row(cinfo);
+
+ return JPEG_ROW_COMPLETED;
+
+ }
+
+ /* Completed the scan */
+
+ (*cinfo->inputctl->finish_input_pass) (cinfo);
+
+ return JPEG_SCAN_COMPLETED;
+
+}
+
+
+
+
+
+/*
+
+ * Dummy consume-input routine for single-pass operation.
+
+ */
+
+
+
+METHODDEF int
+
+dummy_consume_data (j_decompress_ptr cinfo)
+
+{
+
+ return JPEG_SUSPENDED; /* Always indicate nothing was done */
+
+}
+
+
+
+
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+
+
+/*
+
+ * Consume input data and store it in the full-image coefficient buffer.
+
+ * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
+
+ * ie, v_samp_factor block rows for each component in the scan.
+
+ * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
+
+ */
+
+
+
+METHODDEF int
+
+consume_data (j_decompress_ptr cinfo)
+
+{
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ JDIMENSION MCU_col_num; /* index of current MCU within row */
+
+ int blkn, ci, xindex, yindex, yoffset;
+
+ JDIMENSION start_col;
+
+ JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
+
+ JBLOCKROW buffer_ptr;
+
+ jpeg_component_info *compptr;
+
+
+
+ /* Align the virtual buffers for the components used in this scan. */
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+
+ compptr = cinfo->cur_comp_info[ci];
+
+ buffer[ci] = (*cinfo->mem->access_virt_barray)
+
+ ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
+
+ cinfo->input_iMCU_row * compptr->v_samp_factor,
+
+ (JDIMENSION) compptr->v_samp_factor, TRUE);
+
+ /* Note: entropy decoder expects buffer to be zeroed,
+
+ * but this is handled automatically by the memory manager
+
+ * because we requested a pre-zeroed array.
+
+ */
+
+ }
+
+
+
+ /* Loop to process one whole iMCU row */
+
+ for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
+
+ yoffset++) {
+
+ for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
+
+ MCU_col_num++) {
+
+ /* Construct list of pointers to DCT blocks belonging to this MCU */
+
+ blkn = 0; /* index of current DCT block within MCU */
+
+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
+
+ compptr = cinfo->cur_comp_info[ci];
+
+ start_col = MCU_col_num * compptr->MCU_width;
+
+ for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
+
+ buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
+
+ for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
+
+ coef->MCU_buffer[blkn++] = buffer_ptr++;
+
+ }
+
+ }
+
+ }
+
+ /* Try to fetch the MCU. */
+
+ if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
+
+ /* Suspension forced; update state counters and exit */
+
+ coef->MCU_vert_offset = yoffset;
+
+ coef->MCU_ctr = MCU_col_num;
+
+ return JPEG_SUSPENDED;
+
+ }
+
+ }
+
+ /* Completed an MCU row, but perhaps not an iMCU row */
+
+ coef->MCU_ctr = 0;
+
+ }
+
+ /* Completed the iMCU row, advance counters for next one */
+
+ if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
+
+ start_iMCU_row(cinfo);
+
+ return JPEG_ROW_COMPLETED;
+
+ }
+
+ /* Completed the scan */
+
+ (*cinfo->inputctl->finish_input_pass) (cinfo);
+
+ return JPEG_SCAN_COMPLETED;
+
+}
+
+
+
+
+
+/*
+
+ * Decompress and return some data in the multi-pass case.
+
+ * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
+
+ * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
+
+ *
+
+ * NB: output_buf contains a plane for each component in image.
+
+ */
+
+
+
+METHODDEF int
+
+decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
+
+{
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+
+ JDIMENSION block_num;
+
+ int ci, block_row, block_rows;
+
+ JBLOCKARRAY buffer;
+
+ JBLOCKROW buffer_ptr;
+
+ JSAMPARRAY output_ptr;
+
+ JDIMENSION output_col;
+
+ jpeg_component_info *compptr;
+
+ inverse_DCT_method_ptr inverse_DCT;
+
+
+
+ /* Force some input to be done if we are getting ahead of the input. */
+
+ while (cinfo->input_scan_number < cinfo->output_scan_number ||
+
+ (cinfo->input_scan_number == cinfo->output_scan_number &&
+
+ cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
+
+ if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
+
+ return JPEG_SUSPENDED;
+
+ }
+
+
+
+ /* OK, output from the virtual arrays. */
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+
+ ci++, compptr++) {
+
+ /* Don't bother to IDCT an uninteresting component. */
+
+ if (! compptr->component_needed)
+
+ continue;
+
+ /* Align the virtual buffer for this component. */
+
+ buffer = (*cinfo->mem->access_virt_barray)
+
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+
+ cinfo->output_iMCU_row * compptr->v_samp_factor,
+
+ (JDIMENSION) compptr->v_samp_factor, FALSE);
+
+ /* Count non-dummy DCT block rows in this iMCU row. */
+
+ if (cinfo->output_iMCU_row < last_iMCU_row)
+
+ block_rows = compptr->v_samp_factor;
+
+ else {
+
+ /* NB: can't use last_row_height here; it is input-side-dependent! */
+
+ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+
+ if (block_rows == 0) block_rows = compptr->v_samp_factor;
+
+ }
+
+ inverse_DCT = cinfo->idct->inverse_DCT[ci];
+
+ output_ptr = output_buf[ci];
+
+ /* Loop over all DCT blocks to be processed. */
+
+ for (block_row = 0; block_row < block_rows; block_row++) {
+
+ buffer_ptr = buffer[block_row];
+
+ output_col = 0;
+
+ for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
+
+ (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
+
+ output_ptr, output_col);
+
+ buffer_ptr++;
+
+ output_col += compptr->DCT_scaled_size;
+
+ }
+
+ output_ptr += compptr->DCT_scaled_size;
+
+ }
+
+ }
+
+
+
+ if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
+
+ return JPEG_ROW_COMPLETED;
+
+ return JPEG_SCAN_COMPLETED;
+
+}
+
+
+
+#endif /* D_MULTISCAN_FILES_SUPPORTED */
+
+
+
+
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+
+
+/*
+
+ * This code applies interblock smoothing as described by section K.8
+
+ * of the JPEG standard: the first 5 AC coefficients are estimated from
+
+ * the DC values of a DCT block and its 8 neighboring blocks.
+
+ * We apply smoothing only for progressive JPEG decoding, and only if
+
+ * the coefficients it can estimate are not yet known to full precision.
+
+ */
+
+
+
+/*
+
+ * Determine whether block smoothing is applicable and safe.
+
+ * We also latch the current states of the coef_bits[] entries for the
+
+ * AC coefficients; otherwise, if the input side of the decompressor
+
+ * advances into a new scan, we might think the coefficients are known
+
+ * more accurately than they really are.
+
+ */
+
+
+
+LOCAL boolean
+
+smoothing_ok (j_decompress_ptr cinfo)
+
+{
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ boolean smoothing_useful = FALSE;
+
+ int ci, coefi;
+
+ jpeg_component_info *compptr;
+
+ JQUANT_TBL * qtable;
+
+ int * coef_bits;
+
+ int * coef_bits_latch;
+
+
+
+ if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
+
+ return FALSE;
+
+
+
+ /* Allocate latch area if not already done */
+
+ if (coef->coef_bits_latch == NULL)
+
+ coef->coef_bits_latch = (int *)
+
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+
+ cinfo->num_components *
+
+ (SAVED_COEFS * SIZEOF(int)));
+
+ coef_bits_latch = coef->coef_bits_latch;
+
+
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+
+ ci++, compptr++) {
+
+ /* All components' quantization values must already be latched. */
+
+ if ((qtable = compptr->quant_table) == NULL)
+
+ return FALSE;
+
+ /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
+
+ for (coefi = 0; coefi <= 5; coefi++) {
+
+ if (qtable->quantval[coefi] == 0)
+
+ return FALSE;
+
+ }
+
+ /* DC values must be at least partly known for all components. */
+
+ coef_bits = cinfo->coef_bits[ci];
+
+ if (coef_bits[0] < 0)
+
+ return FALSE;
+
+ /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
+
+ for (coefi = 1; coefi <= 5; coefi++) {
+
+ coef_bits_latch[coefi] = coef_bits[coefi];
+
+ if (coef_bits[coefi] != 0)
+
+ smoothing_useful = TRUE;
+
+ }
+
+ coef_bits_latch += SAVED_COEFS;
+
+ }
+
+
+
+ return smoothing_useful;
+
+}
+
+
+
+
+
+/*
+
+ * Variant of decompress_data for use when doing block smoothing.
+
+ */
+
+
+
+METHODDEF int
+
+decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
+
+{
+
+ my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+
+ JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
+
+ JDIMENSION block_num, last_block_column;
+
+ int ci, block_row, block_rows, access_rows;
+
+ JBLOCKARRAY buffer;
+
+ JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
+
+ JSAMPARRAY output_ptr;
+
+ JDIMENSION output_col;
+
+ jpeg_component_info *compptr;
+
+ inverse_DCT_method_ptr inverse_DCT;
+
+ boolean first_row, last_row;
+
+ JBLOCK workspace;
+
+ int *coef_bits;
+
+ JQUANT_TBL *quanttbl;
+
+ INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
+
+ int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
+
+ int Al, pred;
+
+
+
+ /* Force some input to be done if we are getting ahead of the input. */
+
+ while (cinfo->input_scan_number <= cinfo->output_scan_number &&
+
+ ! cinfo->inputctl->eoi_reached) {
+
+ if (cinfo->input_scan_number == cinfo->output_scan_number) {
+
+ /* If input is working on current scan, we ordinarily want it to
+
+ * have completed the current row. But if input scan is DC,
+
+ * we want it to keep one row ahead so that next block row's DC
+
+ * values are up to date.
+
+ */
+
+ JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
+
+ if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
+
+ break;
+
+ }
+
+ if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
+
+ return JPEG_SUSPENDED;
+
+ }
+
+
+
+ /* OK, output from the virtual arrays. */
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+
+ ci++, compptr++) {
+
+ /* Don't bother to IDCT an uninteresting component. */
+
+ if (! compptr->component_needed)
+
+ continue;
+
+ /* Count non-dummy DCT block rows in this iMCU row. */
+
+ if (cinfo->output_iMCU_row < last_iMCU_row) {
+
+ block_rows = compptr->v_samp_factor;
+
+ access_rows = block_rows * 2; /* this and next iMCU row */
+
+ last_row = FALSE;
+
+ } else {
+
+ /* NB: can't use last_row_height here; it is input-side-dependent! */
+
+ block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
+
+ if (block_rows == 0) block_rows = compptr->v_samp_factor;
+
+ access_rows = block_rows; /* this iMCU row only */
+
+ last_row = TRUE;
+
+ }
+
+ /* Align the virtual buffer for this component. */
+
+ if (cinfo->output_iMCU_row > 0) {
+
+ access_rows += compptr->v_samp_factor; /* prior iMCU row too */
+
+ buffer = (*cinfo->mem->access_virt_barray)
+
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+
+ (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
+
+ (JDIMENSION) access_rows, FALSE);
+
+ buffer += compptr->v_samp_factor; /* point to current iMCU row */
+
+ first_row = FALSE;
+
+ } else {
+
+ buffer = (*cinfo->mem->access_virt_barray)
+
+ ((j_common_ptr) cinfo, coef->whole_image[ci],
+
+ (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
+
+ first_row = TRUE;
+
+ }
+
+ /* Fetch component-dependent info */
+
+ coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
+
+ quanttbl = compptr->quant_table;
+
+ Q00 = quanttbl->quantval[0];
+
+ Q01 = quanttbl->quantval[1];
+
+ Q10 = quanttbl->quantval[2];
+
+ Q20 = quanttbl->quantval[3];
+
+ Q11 = quanttbl->quantval[4];
+
+ Q02 = quanttbl->quantval[5];
+
+ inverse_DCT = cinfo->idct->inverse_DCT[ci];
+
+ output_ptr = output_buf[ci];
+
+ /* Loop over all DCT blocks to be processed. */
+
+ for (block_row = 0; block_row < block_rows; block_row++) {
+
+ buffer_ptr = buffer[block_row];
+
+ if (first_row && block_row == 0)
+
+ prev_block_row = buffer_ptr;
+
+ else
+
+ prev_block_row = buffer[block_row-1];
+
+ if (last_row && block_row == block_rows-1)
+
+ next_block_row = buffer_ptr;
+
+ else
+
+ next_block_row = buffer[block_row+1];
+
+ /* We fetch the surrounding DC values using a sliding-register approach.
+
+ * Initialize all nine here so as to do the right thing on narrow pics.
+
+ */
+
+ DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
+
+ DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
+
+ DC7 = DC8 = DC9 = (int) next_block_row[0][0];
+
+ output_col = 0;
+
+ last_block_column = compptr->width_in_blocks - 1;
+
+ for (block_num = 0; block_num <= last_block_column; block_num++) {
+
+ /* Fetch current DCT block into workspace so we can modify it. */
+
+ jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
+
+ /* Update DC values */
+
+ if (block_num < last_block_column) {
+
+ DC3 = (int) prev_block_row[1][0];
+
+ DC6 = (int) buffer_ptr[1][0];
+
+ DC9 = (int) next_block_row[1][0];
+
+ }
+
+ /* Compute coefficient estimates per K.8.
+
+ * An estimate is applied only if coefficient is still zero,
+
+ * and is not known to be fully accurate.
+
+ */
+
+ /* AC01 */
+
+ if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
+
+ num = 36 * Q00 * (DC4 - DC6);
+
+ if (num >= 0) {
+
+ pred = (int) (((Q01<<7) + num) / (Q01<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ } else {
+
+ pred = (int) (((Q01<<7) - num) / (Q01<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ pred = -pred;
+
+ }
+
+ workspace[1] = (JCOEF) pred;
+
+ }
+
+ /* AC10 */
+
+ if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
+
+ num = 36 * Q00 * (DC2 - DC8);
+
+ if (num >= 0) {
+
+ pred = (int) (((Q10<<7) + num) / (Q10<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ } else {
+
+ pred = (int) (((Q10<<7) - num) / (Q10<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ pred = -pred;
+
+ }
+
+ workspace[8] = (JCOEF) pred;
+
+ }
+
+ /* AC20 */
+
+ if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
+
+ num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
+
+ if (num >= 0) {
+
+ pred = (int) (((Q20<<7) + num) / (Q20<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ } else {
+
+ pred = (int) (((Q20<<7) - num) / (Q20<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ pred = -pred;
+
+ }
+
+ workspace[16] = (JCOEF) pred;
+
+ }
+
+ /* AC11 */
+
+ if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
+
+ num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
+
+ if (num >= 0) {
+
+ pred = (int) (((Q11<<7) + num) / (Q11<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ } else {
+
+ pred = (int) (((Q11<<7) - num) / (Q11<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ pred = -pred;
+
+ }
+
+ workspace[9] = (JCOEF) pred;
+
+ }
+
+ /* AC02 */
+
+ if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
+
+ num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
+
+ if (num >= 0) {
+
+ pred = (int) (((Q02<<7) + num) / (Q02<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ } else {
+
+ pred = (int) (((Q02<<7) - num) / (Q02<<8));
+
+ if (Al > 0 && pred >= (1<<Al))
+
+ pred = (1<<Al)-1;
+
+ pred = -pred;
+
+ }
+
+ workspace[2] = (JCOEF) pred;
+
+ }
+
+ /* OK, do the IDCT */
+
+ (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
+
+ output_ptr, output_col);
+
+ /* Advance for next column */
+
+ DC1 = DC2; DC2 = DC3;
+
+ DC4 = DC5; DC5 = DC6;
+
+ DC7 = DC8; DC8 = DC9;
+
+ buffer_ptr++, prev_block_row++, next_block_row++;
+
+ output_col += compptr->DCT_scaled_size;
+
+ }
+
+ output_ptr += compptr->DCT_scaled_size;
+
+ }
+
+ }
+
+
+
+ if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
+
+ return JPEG_ROW_COMPLETED;
+
+ return JPEG_SCAN_COMPLETED;
+
+}
+
+
+
+#endif /* BLOCK_SMOOTHING_SUPPORTED */
+
+
+
+
+
+/*
+
+ * Initialize coefficient buffer controller.
+
+ */
+
+
+
+GLOBAL void
+
+jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
+
+{
+
+ my_coef_ptr coef;
+
+
+
+ coef = (my_coef_ptr)
+
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+
+ SIZEOF(my_coef_controller));
+
+ cinfo->coef = (struct jpeg_d_coef_controller *) coef;
+
+ coef->pub.start_input_pass = start_input_pass;
+
+ coef->pub.start_output_pass = start_output_pass;
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+ coef->coef_bits_latch = NULL;
+
+#endif
+
+
+
+ /* Create the coefficient buffer. */
+
+ if (need_full_buffer) {
+
+#ifdef D_MULTISCAN_FILES_SUPPORTED
+
+ /* Allocate a full-image virtual array for each component, */
+
+ /* padded to a multiple of samp_factor DCT blocks in each direction. */
+
+ /* Note we ask for a pre-zeroed array. */
+
+ int ci, access_rows;
+
+ jpeg_component_info *compptr;
+
+
+
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
+
+ ci++, compptr++) {
+
+ access_rows = compptr->v_samp_factor;
+
+#ifdef BLOCK_SMOOTHING_SUPPORTED
+
+ /* If block smoothing could be used, need a bigger window */
+
+ if (cinfo->progressive_mode)
+
+ access_rows *= 3;
+
+#endif
+
+ coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
+
+ ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
+
+ (JDIMENSION) jround_up((long) compptr->width_in_blocks,
+
+ (long) compptr->h_samp_factor),
+
+ (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+
+ (long) compptr->v_samp_factor),
+
+ (JDIMENSION) access_rows);
+
+ }
+
+ coef->pub.consume_data = consume_data;
+
+ coef->pub.decompress_data = decompress_data;
+
+ coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
+
+#else
+
+ ERREXIT(cinfo, JERR_NOT_COMPILED);
+
+#endif
+
+ } else {
+
+ /* We only need a single-MCU buffer. */
+
+ JBLOCKROW buffer;
+
+ int i;
+
+
+
+ buffer = (JBLOCKROW)
+
+ (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+
+ D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
+
+ for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
+
+ coef->MCU_buffer[i] = buffer + i;
+
+ }
+
+ coef->pub.consume_data = dummy_consume_data;
+
+ coef->pub.decompress_data = decompress_onepass;
+
+ coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
+
+ }
+
+}
+