/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
*
* Copyright (C) 1994-1997, 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 "jpeglib.h"
/* Block smoothing is only applicable for progressive JPEG, so: */
#ifndef D_PROGRESSIVE_SUPPORTED
#endif
/* Private buffer controller object */
typedef struct {
/* These variables keep track of the current location of the input side. */
/* cinfo->input_iMCU_row is also used for this. */
/* 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.
*/
#ifdef D_MULTISCAN_FILES_SUPPORTED
/* In multi-pass modes, we need a virtual block array for each component. */
#endif
#ifdef BLOCK_SMOOTHING_SUPPORTED
/* When doing block smoothing, we latch coefficient Al values here */
int * coef_bits_latch;
#endif
/* Forward declarations */
#ifdef D_MULTISCAN_FILES_SUPPORTED
METHODDEF(int) decompress_data
#endif
#ifdef BLOCK_SMOOTHING_SUPPORTED
#endif
LOCAL(void)
/* Reset within-iMCU-row counters for a new row (input side) */
{
/* 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.
*/
} else {
else
}
coef->MCU_vert_offset = 0;
}
/*
* Initialize for an input processing pass.
*/
METHODDEF(void)
{
cinfo->input_iMCU_row = 0;
}
/*
* Initialize for an output processing pass.
*/
METHODDEF(void)
{
#ifdef BLOCK_SMOOTHING_SUPPORTED
/* If multipass, check to see whether to use block smoothing on this pass */
else
}
#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,
* which we index according to the component's SOF position.
*/
METHODDEF(int)
{
/* Loop to process as much as one whole iMCU row */
yoffset++) {
MCU_col_num++) {
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
/* Suspension forced; update state counters and exit */
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 */
/* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed) {
continue;
}
}
}
}
}
}
/* Completed an MCU row, but perhaps not an iMCU row */
}
/* Completed the iMCU row, advance counters for next one */
cinfo->output_iMCU_row++;
return JPEG_ROW_COMPLETED;
}
/* Completed the scan */
return JPEG_SCAN_COMPLETED;
}
/*
* Dummy consume-input routine for single-pass operation.
*/
METHODDEF(int)
{
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)
{
/* Align the virtual buffers for the components used in this scan. */
/* 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 */
yoffset++) {
MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */
}
}
}
/* Try to fetch the MCU. */
/* Suspension forced; update state counters and exit */
return JPEG_SUSPENDED;
}
}
/* Completed an MCU row, but perhaps not an iMCU row */
}
/* Completed the iMCU row, advance counters for next one */
return JPEG_ROW_COMPLETED;
}
/* Completed the scan */
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)
{
/* Force some input to be done if we are getting ahead of the input. */
return JPEG_SUSPENDED;
}
/* OK, output from the virtual arrays. */
/* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed)
continue;
/* Align the virtual buffer for this component. */
/* Count non-dummy DCT block rows in this iMCU row. */
else {
/* NB: can't use last_row_height here; it is input-side-dependent! */
}
/* Loop over all DCT blocks to be processed. */
output_col = 0;
buffer_ptr++;
}
}
}
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.
*/
/* Natural-order array positions of the first 5 zigzag-order coefficients */
/*
* 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.
*/
{
int * coef_bits;
int * coef_bits_latch;
return FALSE;
/* Allocate latch area if not already done */
coef->coef_bits_latch = (int *)
(SAVED_COEFS * SIZEOF(int)));
/* All components' quantization values must already be latched. */
return FALSE;
/* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
return FALSE;
/* DC values must be at least partly known for all components. */
if (coef_bits[0] < 0)
return FALSE;
/* Block smoothing is helpful if some AC coefficients remain inaccurate. */
}
}
return smoothing_useful;
}
/*
* Variant of decompress_data for use when doing block smoothing.
*/
METHODDEF(int)
{
int *coef_bits;
/* Force some input to be done if we are getting ahead of the input. */
/* 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.
*/
break;
}
return JPEG_SUSPENDED;
}
/* OK, output from the virtual arrays. */
/* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed)
continue;
/* Count non-dummy DCT block rows in this iMCU row. */
} else {
/* NB: can't use last_row_height here; it is input-side-dependent! */
}
/* Align the virtual buffer for this component. */
if (cinfo->output_iMCU_row > 0) {
} else {
}
/* Fetch component-dependent info */
/* Loop over all DCT blocks to be processed. */
else
else
/* 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.
*/
output_col = 0;
/* Fetch current DCT block into workspace so we can modify it. */
/* Update DC values */
if (block_num < last_block_column) {
}
/* 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 (num >= 0) {
} else {
}
}
/* AC10 */
if (num >= 0) {
} else {
}
}
/* AC20 */
if (num >= 0) {
} else {
}
}
/* AC11 */
if (num >= 0) {
} else {
}
}
/* AC02 */
if (num >= 0) {
} else {
}
}
/* OK, do the IDCT */
/* Advance for next column */
}
}
}
return JPEG_ROW_COMPLETED;
return JPEG_SCAN_COMPLETED;
}
#endif /* BLOCK_SMOOTHING_SUPPORTED */
/*
* Initialize coefficient buffer controller.
*/
GLOBAL(void)
{
coef = (my_coef_ptr)
#ifdef BLOCK_SMOOTHING_SUPPORTED
#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. */
#ifdef BLOCK_SMOOTHING_SUPPORTED
/* If block smoothing could be used, need a bigger window */
if (cinfo->progressive_mode)
access_rows *= 3;
#endif
(long) compptr->h_samp_factor),
(long) compptr->v_samp_factor),
}
#else
#endif
} else {
/* We only need a single-MCU buffer. */
int i;
for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
}
}
}