/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
*
* Copyright (C) 1991-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 master control logic for the JPEG compressor.
* These routines are concerned with parameter validation, initial setup,
* and inter-pass control (determining the number of passes and the work
* to be done in each pass).
*/
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
/* Private state */
typedef enum {
} c_pass_type;
typedef struct {
/*
* Support routines that do various essential calculations.
*/
LOCAL(void)
/* Do computations that are needed before master selection phase */
{
int ci;
long samplesperrow;
/* Sanity check on image dimensions */
/* Make sure image isn't bigger than I can handle */
/* Width of an input scanline must be representable as JDIMENSION. */
if ((long) jd_samplesperrow != samplesperrow)
/* For now, precision must match compiled-in value... */
/* Check that number of components won't exceed internal array sizes */
/* Compute maximum sampling factors; check factor validity */
}
/* Compute dimensions of components */
/* Fill in the correct component_index value; don't rely on application */
/* For compression, we never do DCT scaling. */
/* Size in DCT blocks */
/* Size in samples */
(long) cinfo->max_h_samp_factor);
(long) cinfo->max_v_samp_factor);
/* Mark component needed (this flag isn't actually used for compression) */
}
/* Compute number of fully interleaved MCU rows (number of times that
* main controller will call coefficient controller).
*/
}
#ifdef C_MULTISCAN_FILES_SUPPORTED
LOCAL(void)
/* Verify that the scan script in cinfo->scan_info[] is valid; also
* determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
*/
{
#ifdef C_PROGRESSIVE_SUPPORTED
int * last_bitpos_ptr;
/* -1 until that coefficient has been seen; then last Al for it */
#endif
/* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
* for progressive JPEG, no scan can have this.
*/
#ifdef C_PROGRESSIVE_SUPPORTED
last_bitpos_ptr = & last_bitpos[0][0];
*last_bitpos_ptr++ = -1;
#else
#endif
} else {
}
/* Validate component indexes */
/* Components must appear in SOF order within each scan */
}
/* Validate progression parameters */
if (cinfo->progressive_mode) {
#ifdef C_PROGRESSIVE_SUPPORTED
/* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
* seems wrong: the upper bound ought to depend on data precision.
* Perhaps they really meant 0..N+1 for N-bit precision.
* Here we allow 0..10 for 8-bit data; Al larger than 10 results in
* out-of-range reconstructed DC values during the first DC scan,
* which might cause problems for some decoders.
*/
#if BITS_IN_JSAMPLE == 8
#else
#define MAX_AH_AL 13
#endif
if (Ss == 0) {
if (Se != 0) /* DC and AC together not OK */
} else {
}
if (last_bitpos_ptr[coefi] < 0) {
/* first scan of this coefficient */
if (Ah != 0)
} else {
/* not first scan */
}
}
}
#endif
} else {
/* For sequential JPEG, all progression parameters must be these: */
/* Make sure components are not sent twice */
if (component_sent[thisi])
}
}
}
/* Now verify that everything got sent. */
if (cinfo->progressive_mode) {
#ifdef C_PROGRESSIVE_SUPPORTED
/* For progressive mode, we only check that at least some DC data
* got sent for each component; the spec does not require that all bits
* of all coefficients be transmitted. Would it be wiser to enforce
* transmission of all coefficient bits??
*/
if (last_bitpos[ci][0] < 0)
}
#endif
} else {
if (! component_sent[ci])
}
}
}
#endif /* C_MULTISCAN_FILES_SUPPORTED */
LOCAL(void)
/* Set up the scan parameters for the current scan */
{
int ci;
#ifdef C_MULTISCAN_FILES_SUPPORTED
/* Prepare for current scan --- the script is already validated */
}
}
else
#endif
{
/* Prepare for single sequential-JPEG scan containing all components */
}
}
}
LOCAL(void)
/* Do computations that are needed before processing a JPEG scan */
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
{
/* Noninterleaved (single-component) scan */
/* Overall image size in MCUs */
/* For noninterleaved scan, always one block per MCU */
/* For noninterleaved scans, it is convenient to define last_row_height
* as the number of block rows present in the last iMCU row.
*/
/* Prepare array describing MCU composition */
cinfo->MCU_membership[0] = 0;
} else {
/* Interleaved (multi-component) scan */
/* Overall image size in MCUs */
cinfo->blocks_in_MCU = 0;
/* Sampling factors give # of blocks of component in each MCU */
/* Figure number of non-dummy blocks in last MCU column & row */
/* Prepare array describing MCU composition */
while (mcublks-- > 0) {
}
}
}
/* Convert restart specified in rows to actual MCU count. */
/* Note that count must fit in 16 bits, so we provide limiting. */
if (cinfo->restart_in_rows > 0) {
}
}
/*
* Per-pass setup.
* This is called at the beginning of each pass. We determine which modules
* will be active during this pass and give them appropriate start_pass calls.
* We also set is_last_pass to indicate whether any more passes will be
* required.
*/
METHODDEF(void)
{
case main_pass:
/* Initial pass: will collect input data, and do either Huffman
* optimization or data output for the first scan.
*/
if (! cinfo->raw_data_in) {
}
if (cinfo->optimize_coding) {
} else {
}
break;
#ifdef ENTROPY_OPT_SUPPORTED
case huff_opt_pass:
/* Do Huffman optimization for a scan after the first one. */
break;
}
/* Special case: Huffman DC refinement scans need no Huffman table
* and therefore we can skip the optimization pass for them.
*/
master->pass_number++;
/*FALLTHROUGH*/
#endif
case output_pass:
/* Do a data-output pass. */
/* We need not repeat per-scan setup if prior optimization pass did it. */
if (! cinfo->optimize_coding) {
}
if (master->scan_number == 0)
break;
default:
}
/* Set up progress monitor's pass info if present */
}
}
/*
* Special start-of-pass hook.
* This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
* In single-pass processing, we need this hook because we don't want to
* application write COM markers etc. between jpeg_start_compress and the
* jpeg_write_scanlines loop.
* In multi-pass processing, this routine is not used.
*/
METHODDEF(void)
{
}
/*
* Finish up at end of pass.
*/
METHODDEF(void)
{
/* The entropy coder always needs an end-of-pass call,
* either to analyze statistics or to flush its output buffer.
*/
/* Update state for next pass */
case main_pass:
/* next pass is either output of scan 0 (after optimization)
* or output of scan 1 (if no optimization).
*/
if (! cinfo->optimize_coding)
master->scan_number++;
break;
case huff_opt_pass:
/* next pass is always output of current scan */
break;
case output_pass:
/* next pass is either optimization or output of next scan */
if (cinfo->optimize_coding)
master->scan_number++;
break;
}
master->pass_number++;
}
/*
* Initialize master compression control.
*/
GLOBAL(void)
{
master = (my_master_ptr)
/* Validate parameters, determine derived values */
#ifdef C_MULTISCAN_FILES_SUPPORTED
#else
#endif
} else {
}
/* Initialize my private state */
if (transcode_only) {
/* no main pass in transcoding */
if (cinfo->optimize_coding)
else
} else {
/* for normal compression, first pass is always this type: */
}
master->scan_number = 0;
master->pass_number = 0;
if (cinfo->optimize_coding)
else
}