0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1994-1996, 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 the compression preprocessing controller. 0N/A * This controller manages the color conversion, downsampling, 0N/A * and edge expansion steps. 0N/A * Most of the complexity here is associated with buffering input rows 0N/A * as required by the downsampler. See the comments at the head of 0N/A/* At present, jcsample.c can request context rows only for smoothing. 0N/A * In the future, we might also need context rows for CCIR601 sampling 0N/A * or other more-complex downsampling procedures. The code to support 0N/A * context rows should be compiled only if needed. 0N/A * For the simple (no-context-row) case, we just need to buffer one 0N/A * row group's worth of pixels for the downsampling step. At the bottom of 0N/A * the image, we pad to a full row group by replicating the last pixel row. 0N/A * The downsampler's last output row is then replicated if needed to pad 0N/A * out to a full iMCU row. 0N/A * When providing context rows, we must buffer three row groups' worth of 0N/A * pixels. Three row groups are physically allocated, but the row pointer 0N/A * arrays are made five row groups high, with the extra pointers above and 0N/A * below "wrapping around" to point to the last and first real row groups. 0N/A * This allows the downsampler to access the proper context rows. 0N/A * At the top and bottom of the image, we create dummy context rows by 0N/A * copying the first or last real pixel row. This copying could be avoided 0N/A * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the 0N/A * trouble on the compression side. 0N/A/* Private buffer controller object */ 0N/A /* Downsampling input buffer. This buffer holds color-converted data 0N/A * until we have enough to do a downsample step. 0N/A * Initialize for a processing pass. 0N/A /* Initialize total-height counter for detecting bottom of image */ 0N/A /* Mark the conversion buffer empty */ 0N/A /* Preset additional state variables for context mode. 0N/A * These aren't used in non-context mode, so we needn't test which mode. 0N/A /* Set next_buf_stop to stop after two row groups have been read in. */ 0N/A * Expand an image vertically from height input_rows to height output_rows, 0N/A * by duplicating the bottom row. 0N/A * Process some data in the simple no-context case. 0N/A * Preprocessor output data is counted in "row groups". A row group 0N/A * is defined to be v_samp_factor sample rows of each component. 0N/A * Downsampling will produce this much data from each max_v_samp_factor 0N/A /* Do color conversion to fill the conversion buffer. */ 0N/A /* If at bottom of image, pad to fill the conversion buffer. */ 0N/A /* If we've filled the conversion buffer, empty it. */ 0N/A /* If at bottom of image, pad the output to a full iMCU height. 0N/A * Note we assume the caller is providing a one-iMCU-height output buffer! 0N/A break;
/* can exit outer loop without test */ 0N/A * Process some data in the context case. 0N/A /* Do color conversion to fill the conversion buffer. */ 0N/A /* Pad at top of image, if first time through */ 0N/A /* Return for more data, unless we are at the bottom of the image. */ 0N/A /* When at bottom of image, pad to fill the conversion buffer. */ 0N/A /* If we've gotten enough data, downsample a row group. */ 0N/A /* Advance pointers with wraparound as necessary. */ 0N/A * Create the wrapped-around downsampling input buffer needed for context mode. 0N/A /* Grab enough space for fake row pointers for all the components; 0N/A * we need five row groups' worth of pointers for each component. 0N/A /* Allocate the actual buffer space (3 row groups) for this component. 0N/A * We make the buffer wide enough to allow the downsampler to edge-expand 0N/A * horizontally within the buffer, if it so chooses. 0N/A /* Copy true buffer row pointers into the middle of the fake row array */ 0N/A /* Fill in the above and below wraparound pointers */ 0N/A#
endif /* CONTEXT_ROWS_SUPPORTED */ 0N/A * Initialize preprocessing controller. 0N/A /* Allocate the color conversion buffer. 0N/A * We make the buffer wide enough to allow the downsampler to edge-expand 0N/A * horizontally within the buffer, if it so chooses. 0N/A /* Set up to provide context rows */ 0N/A /* No context, just make it tall enough for one row group */