0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1994-1997, Thomas G. Lane. 0N/A * This file is part of the Independent JPEG Group's software. 0N/A * For conditions of distribution and use, see the accompanying README file. 0N/A * This file contains the coefficient buffer controller for decompression. 0N/A * This controller is the top level of the JPEG decompressor proper. 0N/A * The coefficient buffer lies between entropy decoding and inverse-DCT steps. 0N/A * In buffered-image mode, this controller is the interface between 0N/A * input-oriented processing and output-oriented processing. 0N/A * Also, the input side (only) is used when reading a file for transcoding. 0N/A/* Block smoothing is only applicable for progressive JPEG, so: */ 0N/A/* Private buffer controller object */ 0N/A /* These variables keep track of the current location of the input side. */ 0N/A /* cinfo->input_iMCU_row is also used for this. */ 0N/A /* The output side's location is represented by cinfo->output_iMCU_row. */ 0N/A /* In single-pass modes, it's sufficient to buffer just one MCU. 0N/A * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks, 0N/A * and let the entropy decoder write into that workspace each time. 0N/A * (On 80x86, the workspace is FAR even though it's not really very big; 0N/A * this is to keep the module interfaces unchanged when a large coefficient 0N/A * buffer is necessary.) 0N/A * In multi-pass modes, this array points to the current MCU's blocks 0N/A * within the virtual arrays; it is used only by the input side. 0N/A /* In multi-pass modes, we need a virtual block array for each component. */ 0N/A /* When doing block smoothing, we latch coefficient Al values here */ 0N/A/* Forward declarations */ 0N/A/* Reset within-iMCU-row counters for a new row (input side) */ 0N/A /* In an interleaved scan, an MCU row is the same as an iMCU row. 0N/A * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. 0N/A * But at the bottom of the image, process only what's left. 0N/A * Initialize for an input processing pass. 0N/A * Initialize for an output processing pass. 0N/A /* If multipass, check to see whether to use block smoothing on this pass */ 0N/A * Decompress and return some data in the single-pass case. 0N/A * Always attempts to emit one fully interleaved MCU row ("iMCU" row). 0N/A * Input and output must run in lockstep since we have only a one-MCU buffer. 0N/A * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. 0N/A * NB: output_buf contains a plane for each component in image, 0N/A * which we index according to the component's SOF position. 0N/A /* Loop to process as much as one whole iMCU row */ 0N/A /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ 0N/A /* Suspension forced; update state counters and exit */ 0N/A /* Determine where data should go in output_buf and do the IDCT thing. 0N/A * We skip dummy blocks at the right and bottom edges (but blkn gets 0N/A * incremented past them!). Note the inner loop relies on having 0N/A * allocated the MCU_buffer[] blocks sequentially. 0N/A blkn = 0;
/* index of current DCT block within MCU */ 0N/A /* Don't bother to IDCT an uninteresting component. */ 0N/A /* Completed an MCU row, but perhaps not an iMCU row */ 0N/A /* Completed the iMCU row, advance counters for next one */ 0N/A /* Completed the scan */ 0N/A * Dummy consume-input routine for single-pass operation. 0N/A * Consume input data and store it in the full-image coefficient buffer. 0N/A * We read as much as one fully interleaved MCU row ("iMCU" row) per call, 0N/A * ie, v_samp_factor block rows for each component in the scan. 0N/A * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. 0N/A /* Align the virtual buffers for the components used in this scan. */ 0N/A /* Note: entropy decoder expects buffer to be zeroed, 0N/A * but this is handled automatically by the memory manager 0N/A * because we requested a pre-zeroed array. 0N/A /* Loop to process one whole iMCU row */ 0N/A /* Construct list of pointers to DCT blocks belonging to this MCU */ 0N/A blkn = 0;
/* index of current DCT block within MCU */ 0N/A /* Try to fetch the MCU. */ 0N/A /* Suspension forced; update state counters and exit */ 0N/A /* Completed an MCU row, but perhaps not an iMCU row */ 0N/A /* Completed the iMCU row, advance counters for next one */ 0N/A /* Completed the scan */ 0N/A * Decompress and return some data in the multi-pass case. 0N/A * Always attempts to emit one fully interleaved MCU row ("iMCU" row). 0N/A * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. 0N/A * NB: output_buf contains a plane for each component in image. 0N/A /* Force some input to be done if we are getting ahead of the input. */ 0N/A /* OK, output from the virtual arrays. */ 0N/A /* Don't bother to IDCT an uninteresting component. */ 0N/A /* Align the virtual buffer for this component. */ 0N/A /* Count non-dummy DCT block rows in this iMCU row. */ 0N/A /* NB: can't use last_row_height here; it is input-side-dependent! */ 0N/A /* Loop over all DCT blocks to be processed. */ 0N/A#
endif /* D_MULTISCAN_FILES_SUPPORTED */ 0N/A * This code applies interblock smoothing as described by section K.8 0N/A * of the JPEG standard: the first 5 AC coefficients are estimated from 0N/A * the DC values of a DCT block and its 8 neighboring blocks. 0N/A * We apply smoothing only for progressive JPEG decoding, and only if 0N/A * the coefficients it can estimate are not yet known to full precision. 0N/A/* Natural-order array positions of the first 5 zigzag-order coefficients */ 0N/A * Determine whether block smoothing is applicable and safe. 0N/A * We also latch the current states of the coef_bits[] entries for the 0N/A * AC coefficients; otherwise, if the input side of the decompressor 0N/A * advances into a new scan, we might think the coefficients are known 0N/A * more accurately than they really are. 0N/A /* Allocate latch area if not already done */ 0N/A /* All components' quantization values must already be latched. */ 0N/A /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ 0N/A /* DC values must be at least partly known for all components. */ 0N/A /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ 0N/A * Variant of decompress_data for use when doing block smoothing. 0N/A /* Force some input to be done if we are getting ahead of the input. */ 0N/A /* If input is working on current scan, we ordinarily want it to 0N/A * have completed the current row. But if input scan is DC, 0N/A * we want it to keep one row ahead so that next block row's DC 0N/A * values are up to date. 0N/A /* OK, output from the virtual arrays. */ 0N/A /* Don't bother to IDCT an uninteresting component. */ 0N/A /* Count non-dummy DCT block rows in this iMCU row. */ 0N/A /* NB: can't use last_row_height here; it is input-side-dependent! */ 0N/A /* Align the virtual buffer for this component. */ 0N/A /* Fetch component-dependent info */ 0N/A /* Loop over all DCT blocks to be processed. */ 0N/A /* We fetch the surrounding DC values using a sliding-register approach. 0N/A * Initialize all nine here so as to do the right thing on narrow pics. 0N/A /* Fetch current DCT block into workspace so we can modify it. */ 0N/A /* Update DC values */ 0N/A /* Compute coefficient estimates per K.8. 0N/A * An estimate is applied only if coefficient is still zero, 0N/A * and is not known to be fully accurate. 0N/A /* OK, do the IDCT */ 0N/A /* Advance for next column */ 0N/A#
endif /* BLOCK_SMOOTHING_SUPPORTED */ 0N/A * Initialize coefficient buffer controller. 0N/A /* Create the coefficient buffer. */ 0N/A /* Allocate a full-image virtual array for each component, */ 0N/A /* padded to a multiple of samp_factor DCT blocks in each direction. */ 0N/A /* Note we ask for a pre-zeroed array. */ 0N/A /* If block smoothing could be used, need a bigger window */ 0N/A /* We only need a single-MCU buffer. */