0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1991-1997, 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 output colorspace conversion routines. 0N/A/* Private subobject */ 0N/A /* Private state for YCC->RGB conversion */ 0N/A/**************** YCbCr -> RGB conversion: most common case **************/ 0N/A * YCbCr is defined per CCIR 601-1, except that Cb and Cr are 0N/A * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. 0N/A * The conversion equations to be implemented are therefore 0N/A * R = Y + 1.40200 * Cr 0N/A * G = Y - 0.34414 * Cb - 0.71414 * Cr 0N/A * B = Y + 1.77200 * Cb 0N/A * where Cb and Cr represent the incoming values less CENTERJSAMPLE. 0N/A * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) 0N/A * To avoid floating-point arithmetic, we represent the fractional constants 0N/A * as integers scaled up by 2^16 (about 4 digits precision); we have to divide 0N/A * the products by 2^16, with appropriate rounding, to get the correct answer. 0N/A * Notice that Y, being an integral input, does not contribute any fraction 0N/A * so it need not participate in the rounding. 0N/A * For even more speed, we avoid doing any multiplications in the inner loop 0N/A * by precalculating the constants times Cb and Cr for all possible values. 0N/A * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); 0N/A * for 12-bit samples it is still acceptable. It's not very reasonable for 0N/A * 16-bit samples, but if you want lossless storage you shouldn't be changing 0N/A * colorspace anyway. 0N/A * The Cr=>R and Cb=>B values can be rounded to integers in advance; the 0N/A * values for the G calculation are left scaled up, since we must add them 0N/A * together before rounding. 0N/A#
define SCALEBITS 16 /* speediest right-shift on some machines */ 0N/A * Initialize tables for YCC->RGB colorspace conversion. 0N/A /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ 0N/A /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ 0N/A /* Cr=>R value is nearest int to 1.40200 * x */ 0N/A /* Cb=>B value is nearest int to 1.77200 * x */ 0N/A /* Cr=>G value is scaled-up -0.71414 * x */ 0N/A /* Cb=>G value is scaled-up -0.34414 * x */ 0N/A /* We also add in ONE_HALF so that need not do it in inner loop */ 0N/A * Convert some rows of samples to the output colorspace. 0N/A * Note that we change from noninterleaved, one-plane-per-component format 0N/A * to interleaved-pixel format. The output buffer is therefore three times 0N/A * as wide as the input buffer. 0N/A * A starting row offset is provided only for the input buffer. The caller 0N/A * can easily adjust the passed output_buf value to accommodate any row 0N/A * offset required on that side. 0N/A /* copy these pointers into registers if possible */ 0N/A /* Range-limiting is essential due to noise introduced by DCT losses. */ 0N/A/**************** Cases other than YCbCr -> RGB **************/ 0N/A * Color conversion for no colorspace change: just copy the data, 0N/A * converting from separate-planes to interleaved representation. 0N/A * Color conversion for grayscale: just copy the data. 0N/A * This also works for YCbCr -> grayscale conversion, in which 0N/A * we just copy the Y (luminance) component and ignore chrominance. 0N/A * Convert grayscale to RGB: just duplicate the graylevel three times. 0N/A * This is provided to support applications that don't want to cope 0N/A * with grayscale as a separate case. 0N/A /* We can dispense with GETJSAMPLE() here */ 0N/A * Adobe-style YCCK->CMYK conversion. 0N/A * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same 0N/A * conversion as above, while passing K (black) unchanged. 0N/A * We assume build_ycc_rgb_table has been called. 0N/A /* copy these pointers into registers if possible */ 0N/A /* Range-limiting is essential due to noise introduced by DCT losses. */ 0N/A /* K passes through unchanged */ 0N/A * Empty method for start_pass. 0N/A /* no work needed */ 0N/A * Module initialization routine for output colorspace conversion. 0N/A /* Make sure num_components agrees with jpeg_color_space */ 0N/A default:
/* JCS_UNKNOWN can be anything */ 0N/A /* Set out_color_components and conversion method based on requested space. 0N/A * Also clear the component_needed flags for any unused components, 0N/A * so that earlier pipeline stages can avoid useless computation. 0N/A /* For color->grayscale conversion, only the Y (0) component is needed */ 0N/A /* Permit null conversion to same output space */ 0N/A }
else /* unsupported non-null conversion */