/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
*
* Copyright (C) 1994-1996, 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 decompression postprocessing controller.
* This controller manages the upsampling, color conversion, and color
* quantization/reduction steps; specifically, it controls the buffering
* between upsample/color conversion and color quantization/reduction.
*
* If no color quantization/reduction is required, then this module has no
* entirely.
*/
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
/* Private buffer controller object */
typedef struct {
/* Color quantization source buffer: this holds output data from
* For two-pass color quantization, we need a full-image buffer;
* for one-pass operation, a strip buffer is sufficient.
*/
/* for two-pass mode only: */
/* Forward declarations */
METHODDEF(void) post_process_1pass
#ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) post_process_2pass
#endif
/*
* Initialize for a processing pass.
*/
METHODDEF(void)
{
switch (pass_mode) {
case JBUF_PASS_THRU:
if (cinfo->quantize_colors) {
/* Single-pass processing with color quantization. */
/* We could be doing buffered-image output before starting a 2-pass
* color quantization; in that case, jinit_d_post_controller did not
* allocate a strip buffer. Use the virtual-array buffer as workspace.
*/
}
} else {
/* For single-pass processing without color quantization,
* I have no work to do; just call the upsampler directly.
*/
}
break;
#ifdef QUANT_2PASS_SUPPORTED
case JBUF_SAVE_AND_PASS:
/* First pass of 2-pass quantization */
break;
case JBUF_CRANK_DEST:
/* Second pass of 2-pass quantization */
break;
#endif /* QUANT_2PASS_SUPPORTED */
default:
break;
}
}
/*
* Process some data in the one-pass (strip buffer) case.
* This is used for color precision reduction as well as one-pass quantization.
*/
METHODDEF(void)
{
/* Fill the buffer, but not more than what we can dump out in one go. */
/* Note we rely on the upsampler to detect bottom of image. */
num_rows = 0;
/* Quantize and emit data. */
*out_row_ctr += num_rows;
}
#ifdef QUANT_2PASS_SUPPORTED
/*
* Process some data in the first pass of 2-pass quantization.
*/
METHODDEF(void)
{
/* Reposition virtual buffer if at start of strip. */
}
/* Upsample some data (up to a strip height's worth). */
/* Allow quantizer to scan new data. No data is emitted, */
/* but we advance out_row_ctr so outer loop can tell when we're done. */
*out_row_ctr += num_rows;
}
/* Advance if we filled the strip. */
}
}
/*
* Process some data in the second pass of 2-pass quantization.
*/
METHODDEF(void)
{
/* Reposition virtual buffer if at start of strip. */
}
/* Determine number of rows to emit. */
/* We have to check bottom of image here, can't depend on upsampler. */
/* Quantize and emit data. */
(int) num_rows);
*out_row_ctr += num_rows;
/* Advance if we filled the strip. */
}
}
#endif /* QUANT_2PASS_SUPPORTED */
/*
* Initialize postprocessing controller.
*/
GLOBAL(void)
{
post = (my_post_ptr)
/* Create the quantization buffer, if needed */
if (cinfo->quantize_colors) {
/* The buffer strip height is max_v_samp_factor, which is typically
* an efficient number of rows for upsampling to return.
* (In the presence of output rescaling, we might want to be smarter?)
*/
if (need_full_buffer) {
/* Two-pass color quantization: need full-image storage. */
/* We round up the number of rows to a multiple of the strip height. */
#ifdef QUANT_2PASS_SUPPORTED
(long) post->strip_height),
post->strip_height);
#else
#endif /* QUANT_2PASS_SUPPORTED */
} else {
/* One-pass color quantization: just make a strip buffer. */
post->strip_height);
}
}
}