michael@0: /* michael@0: * jccolext.c michael@0: * michael@0: * This file was part of the Independent JPEG Group's software: michael@0: * Copyright (C) 1991-1996, Thomas G. Lane. michael@0: * libjpeg-turbo Modifications: michael@0: * Copyright (C) 2009-2012, D. R. Commander. michael@0: * For conditions of distribution and use, see the accompanying README file. michael@0: * michael@0: * This file contains input colorspace conversion routines. michael@0: */ michael@0: michael@0: michael@0: /* This file is included by jccolor.c */ michael@0: michael@0: michael@0: /* michael@0: * Convert some rows of samples to the JPEG colorspace. michael@0: * michael@0: * Note that we change from the application's interleaved-pixel format michael@0: * to our internal noninterleaved, one-plane-per-component format. michael@0: * The input buffer is therefore three times as wide as the output buffer. michael@0: * michael@0: * A starting row offset is provided only for the output buffer. The caller michael@0: * can easily adjust the passed input_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: rgb_ycc_convert_internal (j_compress_ptr cinfo, michael@0: JSAMPARRAY input_buf, JSAMPIMAGE output_buf, michael@0: JDIMENSION output_row, int num_rows) michael@0: { michael@0: my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; michael@0: register int r, g, b; michael@0: register INT32 * ctab = cconvert->rgb_ycc_tab; michael@0: register JSAMPROW inptr; michael@0: register JSAMPROW outptr0, outptr1, outptr2; michael@0: register JDIMENSION col; michael@0: JDIMENSION num_cols = cinfo->image_width; michael@0: michael@0: while (--num_rows >= 0) { michael@0: inptr = *input_buf++; michael@0: outptr0 = output_buf[0][output_row]; michael@0: outptr1 = output_buf[1][output_row]; michael@0: outptr2 = output_buf[2][output_row]; michael@0: output_row++; michael@0: for (col = 0; col < num_cols; col++) { michael@0: r = GETJSAMPLE(inptr[RGB_RED]); michael@0: g = GETJSAMPLE(inptr[RGB_GREEN]); michael@0: b = GETJSAMPLE(inptr[RGB_BLUE]); michael@0: inptr += RGB_PIXELSIZE; michael@0: /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations michael@0: * must be too; we do not need an explicit range-limiting operation. michael@0: * Hence the value being shifted is never negative, and we don't michael@0: * need the general RIGHT_SHIFT macro. michael@0: */ michael@0: /* Y */ michael@0: outptr0[col] = (JSAMPLE) michael@0: ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) michael@0: >> SCALEBITS); michael@0: /* Cb */ michael@0: outptr1[col] = (JSAMPLE) michael@0: ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) michael@0: >> SCALEBITS); michael@0: /* Cr */ michael@0: outptr2[col] = (JSAMPLE) michael@0: ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) michael@0: >> SCALEBITS); michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /**************** Cases other than RGB -> YCbCr **************/ michael@0: michael@0: michael@0: /* michael@0: * Convert some rows of samples to the JPEG colorspace. michael@0: * This version handles RGB->grayscale conversion, which is the same michael@0: * as the RGB->Y portion of RGB->YCbCr. michael@0: * We assume rgb_ycc_start has been called (we only use the Y tables). michael@0: */ michael@0: michael@0: INLINE michael@0: LOCAL(void) michael@0: rgb_gray_convert_internal (j_compress_ptr cinfo, michael@0: JSAMPARRAY input_buf, JSAMPIMAGE output_buf, michael@0: JDIMENSION output_row, int num_rows) michael@0: { michael@0: my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; michael@0: register int r, g, b; michael@0: register INT32 * ctab = cconvert->rgb_ycc_tab; michael@0: register JSAMPROW inptr; michael@0: register JSAMPROW outptr; michael@0: register JDIMENSION col; michael@0: JDIMENSION num_cols = cinfo->image_width; michael@0: michael@0: while (--num_rows >= 0) { michael@0: inptr = *input_buf++; michael@0: outptr = output_buf[0][output_row]; michael@0: output_row++; michael@0: for (col = 0; col < num_cols; col++) { michael@0: r = GETJSAMPLE(inptr[RGB_RED]); michael@0: g = GETJSAMPLE(inptr[RGB_GREEN]); michael@0: b = GETJSAMPLE(inptr[RGB_BLUE]); michael@0: inptr += RGB_PIXELSIZE; michael@0: /* Y */ michael@0: outptr[col] = (JSAMPLE) michael@0: ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) michael@0: >> SCALEBITS); michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Convert some rows of samples to the JPEG colorspace. michael@0: * This version handles extended RGB->plain RGB conversion michael@0: */ michael@0: michael@0: INLINE michael@0: LOCAL(void) michael@0: rgb_rgb_convert_internal (j_compress_ptr cinfo, michael@0: JSAMPARRAY input_buf, JSAMPIMAGE output_buf, michael@0: JDIMENSION output_row, int num_rows) michael@0: { michael@0: register JSAMPROW inptr; michael@0: register JSAMPROW outptr0, outptr1, outptr2; michael@0: register JDIMENSION col; michael@0: JDIMENSION num_cols = cinfo->image_width; michael@0: michael@0: while (--num_rows >= 0) { michael@0: inptr = *input_buf++; michael@0: outptr0 = output_buf[0][output_row]; michael@0: outptr1 = output_buf[1][output_row]; michael@0: outptr2 = output_buf[2][output_row]; michael@0: output_row++; michael@0: for (col = 0; col < num_cols; col++) { michael@0: outptr0[col] = GETJSAMPLE(inptr[RGB_RED]); michael@0: outptr1[col] = GETJSAMPLE(inptr[RGB_GREEN]); michael@0: outptr2[col] = GETJSAMPLE(inptr[RGB_BLUE]); michael@0: inptr += RGB_PIXELSIZE; michael@0: } michael@0: } michael@0: }