Path: blob/master/thirdparty/libjpeg-turbo/src/jdcolext.c
9904 views
/*1* jdcolext.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1991-1997, Thomas G. Lane.5* libjpeg-turbo Modifications:6* Copyright (C) 2009, 2011, 2015, 2022-2023, D. R. Commander.7* For conditions of distribution and use, see the accompanying README.ijg8* file.9*10* This file contains output colorspace conversion routines.11*/121314/* This file is included by jdcolor.c */151617/*18* Convert some rows of samples to the output colorspace.19*20* Note that we change from noninterleaved, one-plane-per-component format21* to interleaved-pixel format. The output buffer is therefore three times22* as wide as the input buffer.23* A starting row offset is provided only for the input buffer. The caller24* can easily adjust the passed output_buf value to accommodate any row25* offset required on that side.26*/2728INLINE29LOCAL(void)30ycc_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,31JDIMENSION input_row, _JSAMPARRAY output_buf,32int num_rows)33{34#if BITS_IN_JSAMPLE != 1635my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;36register int y, cb, cr;37register _JSAMPROW outptr;38register _JSAMPROW inptr0, inptr1, inptr2;39register JDIMENSION col;40JDIMENSION num_cols = cinfo->output_width;41/* copy these pointers into registers if possible */42register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;43register int *Crrtab = cconvert->Cr_r_tab;44register int *Cbbtab = cconvert->Cb_b_tab;45register JLONG *Crgtab = cconvert->Cr_g_tab;46register JLONG *Cbgtab = cconvert->Cb_g_tab;47SHIFT_TEMPS4849while (--num_rows >= 0) {50inptr0 = input_buf[0][input_row];51inptr1 = input_buf[1][input_row];52inptr2 = input_buf[2][input_row];53input_row++;54outptr = *output_buf++;55for (col = 0; col < num_cols; col++) {56y = inptr0[col];57cb = inptr1[col];58cr = inptr2[col];59/* Range-limiting is essential due to noise introduced by DCT losses. */60outptr[RGB_RED] = range_limit[y + Crrtab[cr]];61outptr[RGB_GREEN] = range_limit[y +62((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],63SCALEBITS))];64outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];65/* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */66/* opaque alpha channel value */67#ifdef RGB_ALPHA68outptr[RGB_ALPHA] = _MAXJSAMPLE;69#endif70outptr += RGB_PIXELSIZE;71}72}73#else74ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);75#endif76}777879/*80* Convert grayscale to RGB: just duplicate the graylevel three times.81* This is provided to support applications that don't want to cope82* with grayscale as a separate case.83*/8485INLINE86LOCAL(void)87gray_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,88JDIMENSION input_row, _JSAMPARRAY output_buf,89int num_rows)90{91register _JSAMPROW inptr, outptr;92register JDIMENSION col;93JDIMENSION num_cols = cinfo->output_width;9495while (--num_rows >= 0) {96inptr = input_buf[0][input_row++];97outptr = *output_buf++;98for (col = 0; col < num_cols; col++) {99outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];100/* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */101/* opaque alpha channel value */102#ifdef RGB_ALPHA103outptr[RGB_ALPHA] = _MAXJSAMPLE;104#endif105outptr += RGB_PIXELSIZE;106}107}108}109110111/*112* Convert RGB to extended RGB: just swap the order of source pixels113*/114115INLINE116LOCAL(void)117rgb_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,118JDIMENSION input_row, _JSAMPARRAY output_buf,119int num_rows)120{121register _JSAMPROW inptr0, inptr1, inptr2;122register _JSAMPROW outptr;123register JDIMENSION col;124JDIMENSION num_cols = cinfo->output_width;125126while (--num_rows >= 0) {127inptr0 = input_buf[0][input_row];128inptr1 = input_buf[1][input_row];129inptr2 = input_buf[2][input_row];130input_row++;131outptr = *output_buf++;132for (col = 0; col < num_cols; col++) {133outptr[RGB_RED] = inptr0[col];134outptr[RGB_GREEN] = inptr1[col];135outptr[RGB_BLUE] = inptr2[col];136/* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */137/* opaque alpha channel value */138#ifdef RGB_ALPHA139outptr[RGB_ALPHA] = _MAXJSAMPLE;140#endif141outptr += RGB_PIXELSIZE;142}143}144}145146147