0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1995-1998, Thomas G. Lane. 0N/A * This file is part of the Independent JPEG Group's software. 0N/A * For conditions of distribution and use, see the accompanying README file. 0N/A * This file contains library routines for transcoding compression, 0N/A * that is, writing raw DCT coefficient arrays to an output JPEG file. 0N/A * The routines in jcapimin.c will also be needed by a transcoder. 0N/A/* Forward declarations */ 0N/A * Compression initialization for writing raw-coefficient data. 0N/A * Before calling this, all parameters and a data destination must be set up. 0N/A * Call jpeg_finish_compress() to actually write the data. 0N/A * The number of passed virtual arrays must match cinfo->num_components. 0N/A * Note that the virtual arrays need not be filled or even realized at 0N/A * the time write_coefficients is called; indeed, if the virtual arrays 0N/A * were requested from this compression object's memory manager, they 0N/A * typically will be realized during this routine and filled afterwards. 0N/A /* Mark all tables to be written */ 0N/A /* (Re)initialize error mgr and destination modules */ 0N/A /* Perform master selection of active modules */ 0N/A /* Wait for jpeg_finish_compress() call */ 0N/A * Initialize the compression object with default parameters, 0N/A * then copy from the source object all parameters needed for lossless 0N/A * transcoding. Parameters that can be varied without loss (such as 0N/A * scan script and Huffman optimization) are left in their default states. 0N/A /* Safety check to ensure start_compress not called yet. */ 0N/A /* Copy fundamental image dimensions */ 0N/A /* Initialize all parameters to default values */ 0N/A /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. 0N/A * Fix it to get the right header markers for the image colorspace. 0N/A /* Copy the source's quantization tables. */ 0N/A /* Copy the source's per-component info. 0N/A * Note we assume jpeg_set_defaults has allocated the dest comp_info array. 0N/A /* Make sure saved quantization table for component matches the qtable 0N/A * slot. If not, the input file re-used this qtable slot. 0N/A * IJG encoder currently cannot duplicate this. 0N/A /* Note: we do not copy the source's Huffman table assignments; 0N/A * instead we rely on jpeg_set_colorspace to have made a suitable choice. 0N/A /* Also copy JFIF version and resolution information, if available. 0N/A * Strictly speaking this isn't "critical" info, but it's nearly 0N/A * always appropriate to copy it if available. In particular, 0N/A * if the application chooses to copy JFIF 1.02 extension markers from 0N/A * the source file, we need to copy the version to make sure we don't 0N/A * emit a file that has 1.02 extensions but a claimed version of 1.01. 0N/A * We will *not*, however, copy version info from mislabeled "2.01" files. 0N/A * Master selection of compression modules for transcoding. 0N/A * This substitutes for jcinit.c's initialization of the full compressor. 0N/A /* Although we don't actually use input_components for transcoding, 0N/A * jcmaster.c's initial_setup will complain if input_components is 0. 0N/A /* Entropy encoding: either Huffman or arithmetic coding. */ 0N/A /* We need a special coefficient buffer controller. */ 0N/A /* We can now tell the memory manager to allocate virtual arrays. */ 0N/A /* Write the datastream header (SOI, JFIF) immediately. 0N/A * Frame and scan headers are postponed till later. 0N/A * This lets application insert special markers after the SOI. 0N/A * The rest of this file is a special implementation of the coefficient 0N/A * buffer controller. This is similar to jccoefct.c, but it handles only 0N/A * output from presupplied virtual arrays. Furthermore, we generate any 0N/A * dummy padding blocks on-the-fly rather than expecting them to be present 0N/A/* Private buffer controller object */ 0N/A /* Virtual block array for each component. */ 0N/A/* Reset within-iMCU-row counters for a new row */ 0N/A /* In an interleaved scan, an MCU row is the same as an iMCU row. 0N/A * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. 0N/A * But at the bottom of the image, process only what's left. 0N/A * Initialize for a processing pass. 0N/A * Process some data. 0N/A * We process the equivalent of one fully interleaved MCU row ("iMCU" row) 0N/A * per call, ie, v_samp_factor block rows for each component in the scan. 0N/A * The data is obtained from the virtual arrays and fed to the entropy coder. 0N/A * Returns TRUE if the iMCU row is completed, FALSE if suspended. 0N/A * NB: input_buf is ignored; it is likely to be a NULL pointer. 0N/A /* Align the virtual buffers for the components used in this scan. */ 0N/A /* Loop to process one whole iMCU row */ 0N/A /* Construct list of pointers to DCT blocks belonging to this MCU */ 0N/A blkn = 0;
/* index of current DCT block within MCU */ 0N/A /* Fill in pointers to real blocks in this row */ 0N/A /* At bottom of image, need a whole row of dummy blocks */ 0N/A /* Fill in any dummy blocks needed in this row. 0N/A * all zeroes in the AC entries, DC entries equal to previous 0N/A * block's DC value. The init routine has already zeroed the 0N/A * AC entries, so we need only set the DC entries correctly. 0N/A /* Try to write the MCU. */ 0N/A /* Suspension forced; update state counters and exit */ 0N/A /* Completed an MCU row, but perhaps not an iMCU row */ 0N/A /* Completed the iMCU row, advance counters for next one */ 0N/A * Initialize coefficient buffer controller. 0N/A * Each passed coefficient array must be the right size for that 0N/A * coefficient: width_in_blocks wide and height_in_blocks high, 0N/A * with unitheight at least v_samp_factor. 0N/A /* Save pointer to virtual arrays */ 0N/A /* Allocate and pre-zero space for dummy DCT blocks. */