michael@0: /* michael@0: * jdcolext.c michael@0: * michael@0: * This file was part of the Independent JPEG Group's software: michael@0: * Copyright (C) 1991-1997, Thomas G. Lane. michael@0: * libjpeg-turbo Modifications: michael@0: * Copyright (C) 2009, 2011, D. R. Commander. michael@0: * For conditions of distribution and use, see the accompanying README file. michael@0: * michael@0: * This file contains output colorspace conversion routines. michael@0: */ michael@0: michael@0: michael@0: /* This file is included by jdcolor.c */ michael@0: michael@0: michael@0: /* michael@0: * Convert some rows of samples to the output colorspace. michael@0: * michael@0: * Note that we change from noninterleaved, one-plane-per-component format michael@0: * to interleaved-pixel format. The output buffer is therefore three times michael@0: * as wide as the input buffer. michael@0: * A starting row offset is provided only for the input buffer. The caller michael@0: * can easily adjust the passed output_buf value to accommodate any row michael@0: * offset required on that side. michael@0: */ michael@0: michael@0: INLINE michael@0: LOCAL(void) michael@0: ycc_rgb_convert_internal (j_decompress_ptr cinfo, michael@0: JSAMPIMAGE input_buf, JDIMENSION input_row, michael@0: JSAMPARRAY output_buf, int num_rows) michael@0: { michael@0: my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; michael@0: register int y, cb, cr; michael@0: register JSAMPROW outptr; michael@0: register JSAMPROW inptr0, inptr1, inptr2; michael@0: register JDIMENSION col; michael@0: JDIMENSION num_cols = cinfo->output_width; michael@0: /* copy these pointers into registers if possible */ michael@0: register JSAMPLE * range_limit = cinfo->sample_range_limit; michael@0: register int * Crrtab = cconvert->Cr_r_tab; michael@0: register int * Cbbtab = cconvert->Cb_b_tab; michael@0: register INT32 * Crgtab = cconvert->Cr_g_tab; michael@0: register INT32 * Cbgtab = cconvert->Cb_g_tab; michael@0: SHIFT_TEMPS michael@0: michael@0: while (--num_rows >= 0) { michael@0: inptr0 = input_buf[0][input_row]; michael@0: inptr1 = input_buf[1][input_row]; michael@0: inptr2 = input_buf[2][input_row]; michael@0: input_row++; michael@0: outptr = *output_buf++; michael@0: for (col = 0; col < num_cols; col++) { michael@0: y = GETJSAMPLE(inptr0[col]); michael@0: cb = GETJSAMPLE(inptr1[col]); michael@0: cr = GETJSAMPLE(inptr2[col]); michael@0: /* Range-limiting is essential due to noise introduced by DCT losses. */ michael@0: outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; michael@0: outptr[RGB_GREEN] = range_limit[y + michael@0: ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], michael@0: SCALEBITS))]; michael@0: outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; michael@0: /* Set unused byte to 0xFF so it can be interpreted as an opaque */ michael@0: /* alpha channel value */ michael@0: #ifdef RGB_ALPHA michael@0: outptr[RGB_ALPHA] = 0xFF; michael@0: #endif michael@0: outptr += RGB_PIXELSIZE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Convert grayscale to RGB: just duplicate the graylevel three times. michael@0: * This is provided to support applications that don't want to cope michael@0: * with grayscale as a separate case. michael@0: */ michael@0: michael@0: INLINE michael@0: LOCAL(void) michael@0: gray_rgb_convert_internal (j_decompress_ptr cinfo, michael@0: JSAMPIMAGE input_buf, JDIMENSION input_row, michael@0: JSAMPARRAY output_buf, int num_rows) michael@0: { michael@0: register JSAMPROW inptr, outptr; michael@0: register JDIMENSION col; michael@0: JDIMENSION num_cols = cinfo->output_width; michael@0: michael@0: while (--num_rows >= 0) { michael@0: inptr = input_buf[0][input_row++]; michael@0: outptr = *output_buf++; michael@0: for (col = 0; col < num_cols; col++) { michael@0: /* We can dispense with GETJSAMPLE() here */ michael@0: outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col]; michael@0: /* Set unused byte to 0xFF so it can be interpreted as an opaque */ michael@0: /* alpha channel value */ michael@0: #ifdef RGB_ALPHA michael@0: outptr[RGB_ALPHA] = 0xFF; michael@0: #endif michael@0: outptr += RGB_PIXELSIZE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Convert RGB to extended RGB: just swap the order of source pixels michael@0: */ michael@0: michael@0: INLINE michael@0: LOCAL(void) michael@0: rgb_rgb_convert_internal (j_decompress_ptr cinfo, michael@0: JSAMPIMAGE input_buf, JDIMENSION input_row, michael@0: JSAMPARRAY output_buf, int num_rows) michael@0: { michael@0: register JSAMPROW inptr0, inptr1, inptr2; michael@0: register JSAMPROW outptr; michael@0: register JDIMENSION col; michael@0: JDIMENSION num_cols = cinfo->output_width; michael@0: michael@0: while (--num_rows >= 0) { michael@0: inptr0 = input_buf[0][input_row]; michael@0: inptr1 = input_buf[1][input_row]; michael@0: inptr2 = input_buf[2][input_row]; michael@0: input_row++; michael@0: outptr = *output_buf++; michael@0: for (col = 0; col < num_cols; col++) { michael@0: /* We can dispense with GETJSAMPLE() here */ michael@0: outptr[RGB_RED] = inptr0[col]; michael@0: outptr[RGB_GREEN] = inptr1[col]; michael@0: outptr[RGB_BLUE] = inptr2[col]; michael@0: /* Set unused byte to 0xFF so it can be interpreted as an opaque */ michael@0: /* alpha channel value */ michael@0: #ifdef RGB_ALPHA michael@0: outptr[RGB_ALPHA] = 0xFF; michael@0: #endif michael@0: outptr += RGB_PIXELSIZE; michael@0: } michael@0: } michael@0: }