chromium/third_party/libjpeg_turbo/jdcolor.c

/*
 * jdcolor.c
 *
 * This file was part of the Independent JPEG Group's software:
 * Copyright (C) 1991-1997, Thomas G. Lane.
 * Modified 2011 by Guido Vollbeding.
 * libjpeg-turbo Modifications:
 * Copyright 2009 Pierre Ossman <[email protected]> for Cendio AB
 * Copyright (C) 2009, 2011-2012, 2014-2015, D. R. Commander.
 * Copyright (C) 2013, Linaro Limited.
 * For conditions of distribution and use, see the accompanying README.ijg
 * file.
 *
 * This file contains output colorspace conversion routines.
 */

#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
#include "jsimd.h"


/* Private subobject */

my_color_deconverter;

my_cconvert_ptr;


/**************** YCbCr -> RGB conversion: most common case **************/
/****************   RGB -> Y   conversion: less common case **************/

/*
 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
 * The conversion equations to be implemented are therefore
 *
 *      R = Y                + 1.40200 * Cr
 *      G = Y - 0.34414 * Cb - 0.71414 * Cr
 *      B = Y + 1.77200 * Cb
 *
 *      Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
 *
 * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
 *
 * To avoid floating-point arithmetic, we represent the fractional constants
 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
 * the products by 2^16, with appropriate rounding, to get the correct answer.
 * Notice that Y, being an integral input, does not contribute any fraction
 * so it need not participate in the rounding.
 *
 * For even more speed, we avoid doing any multiplications in the inner loop
 * by precalculating the constants times Cb and Cr for all possible values.
 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
 * for 12-bit samples it is still acceptable.  It's not very reasonable for
 * 16-bit samples, but if you want lossless storage you shouldn't be changing
 * colorspace anyway.
 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
 * values for the G calculation are left scaled up, since we must add them
 * together before rounding.
 */

#define SCALEBITS
#define ONE_HALF
#define FIX(x)

/* We allocate one big table for RGB->Y conversion and divide it up into
 * three parts, instead of doing three alloc_small requests.  This lets us
 * use a single table base address, which can be held in a register in the
 * inner loops on many machines (more than can hold all three addresses,
 * anyway).
 */

#define R_Y_OFF
#define G_Y_OFF
#define B_Y_OFF
#define TABLE_SIZE


/* Include inline routines for colorspace extensions */

#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_PIXELSIZE

#define RGB_RED
#define RGB_GREEN
#define RGB_BLUE
#define RGB_PIXELSIZE
#define ycc_rgb_convert_internal
#define gray_rgb_convert_internal
#define rgb_rgb_convert_internal
#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_PIXELSIZE
#undef ycc_rgb_convert_internal
#undef gray_rgb_convert_internal
#undef rgb_rgb_convert_internal

#define RGB_RED
#define RGB_GREEN
#define RGB_BLUE
#define RGB_ALPHA
#define RGB_PIXELSIZE
#define ycc_rgb_convert_internal
#define gray_rgb_convert_internal
#define rgb_rgb_convert_internal
#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_ALPHA
#undef RGB_PIXELSIZE
#undef ycc_rgb_convert_internal
#undef gray_rgb_convert_internal
#undef rgb_rgb_convert_internal

#define RGB_RED
#define RGB_GREEN
#define RGB_BLUE
#define RGB_PIXELSIZE
#define ycc_rgb_convert_internal
#define gray_rgb_convert_internal
#define rgb_rgb_convert_internal
#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_PIXELSIZE
#undef ycc_rgb_convert_internal
#undef gray_rgb_convert_internal
#undef rgb_rgb_convert_internal

#define RGB_RED
#define RGB_GREEN
#define RGB_BLUE
#define RGB_ALPHA
#define RGB_PIXELSIZE
#define ycc_rgb_convert_internal
#define gray_rgb_convert_internal
#define rgb_rgb_convert_internal
#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_ALPHA
#undef RGB_PIXELSIZE
#undef ycc_rgb_convert_internal
#undef gray_rgb_convert_internal
#undef rgb_rgb_convert_internal

#define RGB_RED
#define RGB_GREEN
#define RGB_BLUE
#define RGB_ALPHA
#define RGB_PIXELSIZE
#define ycc_rgb_convert_internal
#define gray_rgb_convert_internal
#define rgb_rgb_convert_internal
#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_ALPHA
#undef RGB_PIXELSIZE
#undef ycc_rgb_convert_internal
#undef gray_rgb_convert_internal
#undef rgb_rgb_convert_internal

#define RGB_RED
#define RGB_GREEN
#define RGB_BLUE
#define RGB_ALPHA
#define RGB_PIXELSIZE
#define ycc_rgb_convert_internal
#define gray_rgb_convert_internal
#define rgb_rgb_convert_internal
#include "jdcolext.c"
#undef RGB_RED
#undef RGB_GREEN
#undef RGB_BLUE
#undef RGB_ALPHA
#undef RGB_PIXELSIZE
#undef ycc_rgb_convert_internal
#undef gray_rgb_convert_internal
#undef rgb_rgb_convert_internal


/*
 * Initialize tables for YCC->RGB colorspace conversion.
 */

LOCAL(void)
build_ycc_rgb_table(j_decompress_ptr cinfo)
{}


/*
 * Convert some rows of samples to the output colorspace.
 */

METHODDEF(void)
ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/**************** Cases other than YCbCr -> RGB **************/


/*
 * Initialize for RGB->grayscale colorspace conversion.
 */

LOCAL(void)
build_rgb_y_table(j_decompress_ptr cinfo)
{}


/*
 * Convert RGB to grayscale.
 */

METHODDEF(void)
rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                 JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * Color conversion for no colorspace change: just copy the data,
 * converting from separate-planes to interleaved representation.
 */

METHODDEF(void)
null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
             JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * Color conversion for grayscale: just copy the data.
 * This also works for YCbCr -> grayscale conversion, in which
 * we just copy the Y (luminance) component and ignore chrominance.
 */

METHODDEF(void)
grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                  JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * Convert grayscale to RGB
 */

METHODDEF(void)
gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                 JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * Convert plain RGB to extended RGB
 */

METHODDEF(void)
rgb_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * Adobe-style YCCK->CMYK conversion.
 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
 * conversion as above, while passing K (black) unchanged.
 * We assume build_ycc_rgb_table has been called.
 */

METHODDEF(void)
ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                  JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * RGB565 conversion
 */

#define PACK_SHORT_565_LE(r, g, b)
#define PACK_SHORT_565_BE(r, g, b)

#define PACK_TWO_PIXELS_LE(l, r)
#define PACK_TWO_PIXELS_BE(l, r)

#define PACK_NEED_ALIGNMENT(ptr)

#define WRITE_TWO_ALIGNED_PIXELS(addr, pixels)

#define DITHER_565_R(r, dither)
#define DITHER_565_G(g, dither)
#define DITHER_565_B(b, dither)


/* Declarations for ordered dithering
 *
 * We use a 4x4 ordered dither array packed into 32 bits.  This array is
 * sufficient for dithering RGB888 to RGB565.
 */

#define DITHER_MASK
#define DITHER_ROTATE(x)
static const JLONG dither_matrix[4] =;


static INLINE boolean is_big_endian(void)
{}


/* Include inline routines for RGB565 conversion */

#define PACK_SHORT_565
#define PACK_TWO_PIXELS
#define ycc_rgb565_convert_internal
#define ycc_rgb565D_convert_internal
#define rgb_rgb565_convert_internal
#define rgb_rgb565D_convert_internal
#define gray_rgb565_convert_internal
#define gray_rgb565D_convert_internal
#include "jdcol565.c"
#undef PACK_SHORT_565
#undef PACK_TWO_PIXELS
#undef ycc_rgb565_convert_internal
#undef ycc_rgb565D_convert_internal
#undef rgb_rgb565_convert_internal
#undef rgb_rgb565D_convert_internal
#undef gray_rgb565_convert_internal
#undef gray_rgb565D_convert_internal

#define PACK_SHORT_565
#define PACK_TWO_PIXELS
#define ycc_rgb565_convert_internal
#define ycc_rgb565D_convert_internal
#define rgb_rgb565_convert_internal
#define rgb_rgb565D_convert_internal
#define gray_rgb565_convert_internal
#define gray_rgb565D_convert_internal
#include "jdcol565.c"
#undef PACK_SHORT_565
#undef PACK_TWO_PIXELS
#undef ycc_rgb565_convert_internal
#undef ycc_rgb565D_convert_internal
#undef rgb_rgb565_convert_internal
#undef rgb_rgb565D_convert_internal
#undef gray_rgb565_convert_internal
#undef gray_rgb565D_convert_internal


METHODDEF(void)
ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                   JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


METHODDEF(void)
ycc_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                    JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


METHODDEF(void)
rgb_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                   JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


METHODDEF(void)
rgb_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                    JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


METHODDEF(void)
gray_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                    JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


METHODDEF(void)
gray_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
                     JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{}


/*
 * Empty method for start_pass.
 */

METHODDEF(void)
start_pass_dcolor(j_decompress_ptr cinfo)
{}


/*
 * Module initialization routine for output colorspace conversion.
 */

GLOBAL(void)
jinit_color_deconverter(j_decompress_ptr cinfo)
{}