608N/A * reserved comment block 839N/A * DO NOT REMOVE OR ALTER! 608N/A * Copyright (C) 1991-1997, Thomas G. Lane. 608N/A * This file is part of the Independent JPEG Group's software. 608N/A * For conditions of distribution and use, see the accompanying README file. 608N/A * This file contains master control logic for the JPEG compressor. 608N/A * These routines are concerned with parameter validation, initial setup, 608N/A * and inter-pass control (determining the number of passes and the work 608N/A * to be done in each pass). * Support routines that do various essential calculations. /* Do computations that are needed before master selection phase */ /* 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. */ /* 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. */ /* 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). /* Verify that the scan script in cinfo->scan_info[] is valid; also * determine whether it uses progressive JPEG, and set cinfo->progressive_mode. /* -1 until that coefficient has been seen; then last Al for it */ /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1; * for progressive JPEG, no scan can have this. /* Validate component indexes */ /* Components must appear in SOF order within each scan */ /* Validate progression parameters */ /* 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 (
Se != 0)
/* DC and AC together not OK */ if (
ncomps !=
1)
/* AC scans must be for only one component */ /* first scan of this coefficient */ /* For sequential JPEG, all progression parameters must be these: */ /* Make sure components are not sent twice */ /* Now verify that everything got sent. */ /* 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?? #
endif /* C_MULTISCAN_FILES_SUPPORTED *//* Set up the scan parameters for the current scan */ /* Prepare for current scan --- the script is already validated */ /* Prepare for single sequential-JPEG scan containing all components */ /* 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 */ /* Interleaved (multi-component) scan */ /* Overall image size in MCUs */ /* 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 */ /* Convert restart specified in rows to actual MCU count. */ /* Note that count must fit in 16 bits, so we provide limiting. */ * 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 /* Initial pass: will collect input data, and do either Huffman * optimization or data output for the first scan. /* No immediate data output; postpone writing frame/scan headers */ /* Will write frame/scan headers at first jpeg_write_scanlines call */ /* Do Huffman optimization for a scan after the first one. */ /* Special case: Huffman DC refinement scans need no Huffman table * and therefore we can skip the optimization pass for them. /* Do a data-output pass. */ /* We need not repeat per-scan setup if prior optimization pass did it. */ /* 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 * write frame/scan headers during jpeg_start_compress; we want to let the * application write COM markers etc. between jpeg_start_compress and the * jpeg_write_scanlines loop. * In multi-pass processing, this routine is not used. * Finish up at end of pass. /* 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 */ /* next pass is either output of scan 0 (after optimization) * or output of scan 1 (if no optimization). /* next pass is always output of current scan */ /* next pass is either optimization or output of next scan */ * Initialize master compression control. /* Validate parameters, determine derived values */ /* Initialize my private state */ /* no main pass in transcoding */ /* for normal compression, first pass is always this type: */