Path: blob/master/thirdparty/libjpeg-turbo/src/jccolext.c
9904 views
/*1* jccolext.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1991-1996, Thomas G. Lane.5* libjpeg-turbo Modifications:6* Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.7* For conditions of distribution and use, see the accompanying README.ijg8* file.9*10* This file contains input colorspace conversion routines.11*/121314/* This file is included by jccolor.c */151617/*18* Convert some rows of samples to the JPEG colorspace.19*20* Note that we change from the application's interleaved-pixel format21* to our internal noninterleaved, one-plane-per-component format.22* The input buffer is therefore three times as wide as the output buffer.23*24* A starting row offset is provided only for the output buffer. The caller25* can easily adjust the passed input_buf value to accommodate any row26* offset required on that side.27*/2829INLINE30LOCAL(void)31rgb_ycc_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,32_JSAMPIMAGE output_buf, JDIMENSION output_row,33int num_rows)34{35#if BITS_IN_JSAMPLE != 1636my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;37register int r, g, b;38register JLONG *ctab = cconvert->rgb_ycc_tab;39register _JSAMPROW inptr;40register _JSAMPROW outptr0, outptr1, outptr2;41register JDIMENSION col;42JDIMENSION num_cols = cinfo->image_width;4344while (--num_rows >= 0) {45inptr = *input_buf++;46outptr0 = output_buf[0][output_row];47outptr1 = output_buf[1][output_row];48outptr2 = output_buf[2][output_row];49output_row++;50for (col = 0; col < num_cols; col++) {51r = RANGE_LIMIT(inptr[RGB_RED]);52g = RANGE_LIMIT(inptr[RGB_GREEN]);53b = RANGE_LIMIT(inptr[RGB_BLUE]);54inptr += RGB_PIXELSIZE;55/* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations56* must be too; we do not need an explicit range-limiting operation.57* Hence the value being shifted is never negative, and we don't58* need the general RIGHT_SHIFT macro.59*/60/* Y */61outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +62ctab[b + B_Y_OFF]) >> SCALEBITS);63/* Cb */64outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +65ctab[b + B_CB_OFF]) >> SCALEBITS);66/* Cr */67outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +68ctab[b + B_CR_OFF]) >> SCALEBITS);69}70}71#else72ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);73#endif74}757677/**************** Cases other than RGB -> YCbCr **************/787980/*81* Convert some rows of samples to the JPEG colorspace.82* This version handles RGB->grayscale conversion, which is the same83* as the RGB->Y portion of RGB->YCbCr.84* We assume rgb_ycc_start has been called (we only use the Y tables).85*/8687INLINE88LOCAL(void)89rgb_gray_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,90_JSAMPIMAGE output_buf, JDIMENSION output_row,91int num_rows)92{93#if BITS_IN_JSAMPLE != 1694my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;95register int r, g, b;96register JLONG *ctab = cconvert->rgb_ycc_tab;97register _JSAMPROW inptr;98register _JSAMPROW outptr;99register JDIMENSION col;100JDIMENSION num_cols = cinfo->image_width;101102while (--num_rows >= 0) {103inptr = *input_buf++;104outptr = output_buf[0][output_row];105output_row++;106for (col = 0; col < num_cols; col++) {107r = RANGE_LIMIT(inptr[RGB_RED]);108g = RANGE_LIMIT(inptr[RGB_GREEN]);109b = RANGE_LIMIT(inptr[RGB_BLUE]);110inptr += RGB_PIXELSIZE;111/* Y */112outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +113ctab[b + B_Y_OFF]) >> SCALEBITS);114}115}116#else117ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);118#endif119}120121122/*123* Convert some rows of samples to the JPEG colorspace.124* This version handles extended RGB->plain RGB conversion125*/126127INLINE128LOCAL(void)129rgb_rgb_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,130_JSAMPIMAGE output_buf, JDIMENSION output_row,131int num_rows)132{133register _JSAMPROW inptr;134register _JSAMPROW outptr0, outptr1, outptr2;135register JDIMENSION col;136JDIMENSION num_cols = cinfo->image_width;137138while (--num_rows >= 0) {139inptr = *input_buf++;140outptr0 = output_buf[0][output_row];141outptr1 = output_buf[1][output_row];142outptr2 = output_buf[2][output_row];143output_row++;144for (col = 0; col < num_cols; col++) {145outptr0[col] = inptr[RGB_RED];146outptr1[col] = inptr[RGB_GREEN];147outptr2[col] = inptr[RGB_BLUE];148inptr += RGB_PIXELSIZE;149}150}151}152153154