0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1991-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 upsampling routines. 0N/A * Upsampling input data is counted in "row groups". A row group 0N/A * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) 0N/A * sample rows of each component. Upsampling will normally produce 0N/A * max_v_samp_factor pixel rows from each row group (but this could vary 0N/A * if the upsampler is applying a scale factor of its own). 0N/A * An excellent reference for image resampling is 0N/A * Digital Image Warping, George Wolberg, 1990. 0N/A * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. 0N/A/* Pointer to routine to upsample a single component */ 0N/A/* Private subobject */ 0N/A /* Color conversion buffer. When using separate upsampling and color 0N/A * conversion steps, this buffer holds one upsampled row group until it 0N/A * has been color converted and output. 0N/A * Note: we do not allocate any storage for component(s) which are full-size, 0N/A * ie do not need rescaling. The corresponding entry of color_buf[] is 0N/A * simply set to point to the input data array, thereby avoiding copying. 0N/A /* Per-component upsampling method pointers */ 0N/A /* Height of an input row group for each component. */ 0N/A /* These arrays save pixel expansion factors so that int_expand need not 0N/A * recompute them each time. They are unused for other upsampling methods. 0N/A * Initialize for an upsampling pass. 0N/A /* Mark the conversion buffer empty */ 0N/A /* Initialize total-height counter for detecting bottom of image */ 0N/A * Control routine to do upsampling (and color conversion). 0N/A * In this version we upsample each component independently. 0N/A * We upsample one row group into the conversion buffer, then apply 0N/A * color conversion a row at a time. 0N/A /* Fill the conversion buffer, if it's empty */ 0N/A /* Invoke per-component upsample method. Notice we pass a POINTER 0N/A * to color_buf[ci], so that fullsize_upsample can change it. 0N/A /* Color-convert and emit rows */ 0N/A /* How many we have in the buffer: */ 0N/A /* Not more than the distance to the end of the image. Need this test 0N/A * in case the image height is not a multiple of max_v_samp_factor: 0N/A /* And not more than what the client can accept: */ 0N/A /* When the buffer is emptied, declare this input row group consumed */ 0N/A * These are the routines invoked by sep_upsample to upsample pixel values 0N/A * of a single component. One row group is processed per call. 0N/A * For full-size components, we just make color_buf[ci] point at the 0N/A * input buffer, and thus avoid copying any data. Note that this is 0N/A * safe only because sep_upsample doesn't declare the input row group 0N/A * "consumed" until we are done color converting and emitting it. 0N/A * This is a no-op version used for "uninteresting" components. 0N/A * These components will not be referenced by color conversion. 0N/A * This version handles any integral sampling ratios. 0N/A * This is not used for typical JPEG files, so it need not be fast. 0N/A * Nor, for that matter, is it particularly accurate: the algorithm is 0N/A * simple replication of the input pixel onto the corresponding output 0N/A * pixels. The hi-falutin sampling literature refers to this as a 0N/A * "box filter". A box filter tends to introduce visible artifacts, 0N/A * so if you are actually going to use 3:1 or 4:1 sampling ratios 0N/A * you would be well advised to improve this code. 0N/A /* Generate one output row with proper horizontal expansion */ 0N/A /* Generate any additional output rows by duplicating the first one */ 0N/A * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. 0N/A * It's still a box filter. 0N/A * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. 0N/A * It's still a box filter. 0N/A * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. 0N/A * The upsampling algorithm is linear interpolation between pixel centers, 0N/A * also known as a "triangle filter". This is a good compromise between 0N/A * speed and visual quality. The centers of the output pixels are 1/4 and 3/4 0N/A * of the way between input pixel centers. 0N/A * A note about the "bias" calculations: when rounding fractional values to 0N/A * integer, we do not want to always round 0.5 up to the next integer. 0N/A * If we did that, we'd introduce a noticeable bias towards larger values. 0N/A * Instead, this code is arranged so that 0.5 will be rounded up or down at 0N/A * alternate pixel locations (a simple ordered dither pattern). 0N/A /* Special case for first column */ 0N/A /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ 0N/A /* Special case for last column */ 0N/A * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. 0N/A * Again a triangle filter; see comments for h2v1 case, above. 0N/A * It is OK for us to reference the adjacent input rows because we demanded 0N/A * context from the main buffer controller (see initialization code). 0N/A for (v = 0; v <
2; v++) {
0N/A /* inptr0 points to nearest input row, inptr1 points to next nearest */ 0N/A if (v == 0)
/* next nearest is row above */ 0N/A else /* next nearest is row below */ 0N/A /* Special case for first column */ 0N/A /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ 0N/A /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ 0N/A /* Special case for last column */ 0N/A * Module initialization routine for upsampling. 0N/A /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, 0N/A * so don't ask for it. 0N/A /* Verify we can handle the sampling factors, select per-component methods, 0N/A * and create storage as needed. 0N/A /* Compute size of an "input group" after IDCT scaling. This many samples 0N/A * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. 0N/A /* Don't bother to upsample an uninteresting component. */ 0N/A /* Fullsize components can be processed without any work. */ 0N/A /* Special cases for 2h1v upsampling */ 0N/A /* Special cases for 2h2v upsampling */ 0N/A /* Generic integral-factors upsampling method */