/*
* jdcoefct.c
*
- * Copyright (C) 1994-1997, Thomas G. Lane.
+ * Copyright (C) 1994-1998, 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.
+ * This controller is the top level of the lossy JPEG decompressor proper.
* The coefficient buffer lies between entropy decoding and inverse-DCT steps.
*
* In buffered-image mode, this controller is the interface between
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
+#include "jlossy.h"
/* Block smoothing is only applicable for progressive JPEG, so: */
#ifndef D_PROGRESSIVE_SUPPORTED
/* 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 */
/* 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,
+ * We allocate a workspace of D_MAX_DATA_UNITS_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
* 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];
+ JBLOCKROW MCU_buffer[D_MAX_DATA_UNITS_IN_MCU];
#ifdef D_MULTISCAN_FILES_SUPPORTED
/* In multi-pass modes, we need a virtual block array for each component. */
int * coef_bits_latch;
#define SAVED_COEFS 6 /* we save coef_bits[0..5] */
#endif
-} my_coef_controller;
+} d_coef_controller;
-typedef my_coef_controller * my_coef_ptr;
+typedef d_coef_controller * d_coef_ptr;
/* Forward declarations */
METHODDEF(int) decompress_onepass
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;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private;
/* 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.
start_output_pass (j_decompress_ptr cinfo)
{
#ifdef BLOCK_SMOOTHING_SUPPORTED
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ /* d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private; */
/* If multipass, check to see whether to use block smoothing on this pass */
- if (coef->pub.coef_arrays != NULL) {
+ if (lossyd->coef_arrays != NULL) {
if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
- coef->pub.decompress_data = decompress_smooth_data;
+ lossyd->pub.decompress_data = decompress_smooth_data;
else
- coef->pub.decompress_data = decompress_data;
+ lossyd->pub.decompress_data = decompress_data;
}
#endif
cinfo->output_iMCU_row = 0;
METHODDEF(int)
decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private;
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;
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)) {
+ (size_t) (cinfo->data_units_in_MCU * SIZEOF(JBLOCK)));
+ if (! (*lossyd->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;
compptr = cinfo->cur_comp_info[ci];
/* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed) {
- blkn += compptr->MCU_blocks;
+ blkn += compptr->MCU_data_units;
continue;
}
- inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
+ inverse_DCT = lossyd->inverse_DCT[compptr->component_index];
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
: compptr->last_col_width;
output_ptr = output_buf[compptr->component_index] +
- yoffset * compptr->DCT_scaled_size;
+ yoffset * compptr->codec_data_unit;
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 ||
(*inverse_DCT) (cinfo, compptr,
(JCOEFPTR) coef->MCU_buffer[blkn+xindex],
output_ptr, output_col);
- output_col += compptr->DCT_scaled_size;
+ output_col += compptr->codec_data_unit;
}
}
blkn += compptr->MCU_width;
- output_ptr += compptr->DCT_scaled_size;
+ output_ptr += compptr->codec_data_unit;
}
}
}
METHODDEF(int)
dummy_consume_data (j_decompress_ptr cinfo)
{
- cinfo = 0;
+ (void)cinfo;
return JPEG_SUSPENDED; /* Always indicate nothing was done */
}
METHODDEF(int)
consume_data (j_decompress_ptr cinfo)
{
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private;
JDIMENSION MCU_col_num; /* index of current MCU within row */
int blkn, ci, xindex, yindex, yoffset;
JDIMENSION start_col;
}
}
/* Try to fetch the MCU. */
- if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
+ if (! (*lossyd->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;
METHODDEF(int)
decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
JDIMENSION block_num;
int ci, block_row, block_rows;
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);
+ block_rows = (int) (compptr->height_in_data_units % compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor;
}
- inverse_DCT = cinfo->idct->inverse_DCT[ci];
+ inverse_DCT = lossyd->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++) {
+ for (block_num = 0; block_num < compptr->width_in_data_units; block_num++) {
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
output_ptr, output_col);
buffer_ptr++;
- output_col += compptr->DCT_scaled_size;
+ output_col += compptr->codec_data_unit;
}
- output_ptr += compptr->DCT_scaled_size;
+ output_ptr += compptr->codec_data_unit;
}
}
LOCAL(boolean)
smoothing_ok (j_decompress_ptr cinfo)
{
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private;
boolean smoothing_useful = FALSE;
int ci, coefi;
jpeg_component_info *compptr;
int * coef_bits;
int * coef_bits_latch;
- if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
+ if (! cinfo->process == JPROC_PROGRESSIVE || cinfo->coef_bits == NULL)
return FALSE;
/* Allocate latch area if not already done */
METHODDEF(int)
decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{
- my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef = (d_coef_ptr) lossyd->coef_private;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
JDIMENSION block_num, last_block_column;
int ci, block_row, block_rows, access_rows;
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);
+ block_rows = (int) (compptr->height_in_data_units % 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;
Q20 = quanttbl->quantval[Q20_POS];
Q11 = quanttbl->quantval[Q11_POS];
Q02 = quanttbl->quantval[Q02_POS];
- inverse_DCT = cinfo->idct->inverse_DCT[ci];
+ inverse_DCT = lossyd->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++) {
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;
+ last_block_column = compptr->width_in_data_units - 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);
DC4 = DC5; DC5 = DC6;
DC7 = DC8; DC8 = DC9;
buffer_ptr++, prev_block_row++, next_block_row++;
- output_col += compptr->DCT_scaled_size;
+ output_col += compptr->codec_data_unit;
}
- output_ptr += compptr->DCT_scaled_size;
+ output_ptr += compptr->codec_data_unit;
}
}
GLOBAL(void)
jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
{
- my_coef_ptr coef;
+ j_lossy_d_ptr lossyd = (j_lossy_d_ptr) cinfo->codec;
+ d_coef_ptr coef;
- coef = (my_coef_ptr)
+ coef = (d_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;
+ SIZEOF(d_coef_controller));
+ lossyd->coef_private = (void *) coef;
+ lossyd->coef_start_input_pass = start_input_pass;
+ lossyd->coef_start_output_pass = start_output_pass;
#ifdef BLOCK_SMOOTHING_SUPPORTED
coef->coef_bits_latch = NULL;
#endif
access_rows = compptr->v_samp_factor;
#ifdef BLOCK_SMOOTHING_SUPPORTED
/* If block smoothing could be used, need a bigger window */
- if (cinfo->progressive_mode)
+ if (cinfo->process == JPROC_PROGRESSIVE)
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,
+ (JDIMENSION) jround_up((long) compptr->width_in_data_units,
(long) compptr->h_samp_factor),
- (JDIMENSION) jround_up((long) compptr->height_in_blocks,
+ (JDIMENSION) jround_up((long) compptr->height_in_data_units,
(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 */
+ lossyd->pub.consume_data = consume_data;
+ lossyd->pub.decompress_data = decompress_data;
+ lossyd->coef_arrays = coef->whole_image; /* link to virtual arrays */
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
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++) {
+ D_MAX_DATA_UNITS_IN_MCU * SIZEOF(JBLOCK));
+ for (i = 0; i < D_MAX_DATA_UNITS_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 */
+ lossyd->pub.consume_data = dummy_consume_data;
+ lossyd->pub.decompress_data = decompress_onepass;
+ lossyd->coef_arrays = NULL; /* flag for no virtual arrays */
}
}