Path: blob/master/3rdparty/libjpeg-turbo/src/jdcolext.c
16337 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, 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,31JSAMPIMAGE input_buf, JDIMENSION input_row,32JSAMPARRAY output_buf, int num_rows)33{34my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;35register int y, cb, cr;36register JSAMPROW outptr;37register JSAMPROW inptr0, inptr1, inptr2;38register JDIMENSION col;39JDIMENSION num_cols = cinfo->output_width;40/* copy these pointers into registers if possible */41register JSAMPLE * range_limit = cinfo->sample_range_limit;42register int * Crrtab = cconvert->Cr_r_tab;43register int * Cbbtab = cconvert->Cb_b_tab;44register JLONG * Crgtab = cconvert->Cr_g_tab;45register JLONG * Cbgtab = cconvert->Cb_g_tab;46SHIFT_TEMPS4748while (--num_rows >= 0) {49inptr0 = input_buf[0][input_row];50inptr1 = input_buf[1][input_row];51inptr2 = input_buf[2][input_row];52input_row++;53outptr = *output_buf++;54for (col = 0; col < num_cols; col++) {55y = GETJSAMPLE(inptr0[col]);56cb = GETJSAMPLE(inptr1[col]);57cr = GETJSAMPLE(inptr2[col]);58/* Range-limiting is essential due to noise introduced by DCT losses. */59outptr[RGB_RED] = range_limit[y + Crrtab[cr]];60outptr[RGB_GREEN] = range_limit[y +61((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],62SCALEBITS))];63outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];64/* Set unused byte to 0xFF so it can be interpreted as an opaque */65/* alpha channel value */66#ifdef RGB_ALPHA67outptr[RGB_ALPHA] = 0xFF;68#endif69outptr += RGB_PIXELSIZE;70}71}72}737475/*76* Convert grayscale to RGB: just duplicate the graylevel three times.77* This is provided to support applications that don't want to cope78* with grayscale as a separate case.79*/8081INLINE82LOCAL(void)83gray_rgb_convert_internal (j_decompress_ptr cinfo,84JSAMPIMAGE input_buf, JDIMENSION input_row,85JSAMPARRAY output_buf, int num_rows)86{87register JSAMPROW inptr, outptr;88register JDIMENSION col;89JDIMENSION num_cols = cinfo->output_width;9091while (--num_rows >= 0) {92inptr = input_buf[0][input_row++];93outptr = *output_buf++;94for (col = 0; col < num_cols; col++) {95/* We can dispense with GETJSAMPLE() here */96outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];97/* Set unused byte to 0xFF so it can be interpreted as an opaque */98/* alpha channel value */99#ifdef RGB_ALPHA100outptr[RGB_ALPHA] = 0xFF;101#endif102outptr += RGB_PIXELSIZE;103}104}105}106107108/*109* Convert RGB to extended RGB: just swap the order of source pixels110*/111112INLINE113LOCAL(void)114rgb_rgb_convert_internal (j_decompress_ptr cinfo,115JSAMPIMAGE input_buf, JDIMENSION input_row,116JSAMPARRAY output_buf, int num_rows)117{118register JSAMPROW inptr0, inptr1, inptr2;119register JSAMPROW outptr;120register JDIMENSION col;121JDIMENSION num_cols = cinfo->output_width;122123while (--num_rows >= 0) {124inptr0 = input_buf[0][input_row];125inptr1 = input_buf[1][input_row];126inptr2 = input_buf[2][input_row];127input_row++;128outptr = *output_buf++;129for (col = 0; col < num_cols; col++) {130/* We can dispense with GETJSAMPLE() here */131outptr[RGB_RED] = inptr0[col];132outptr[RGB_GREEN] = inptr1[col];133outptr[RGB_BLUE] = inptr2[col];134/* Set unused byte to 0xFF so it can be interpreted as an opaque */135/* alpha channel value */136#ifdef RGB_ALPHA137outptr[RGB_ALPHA] = 0xFF;138#endif139outptr += RGB_PIXELSIZE;140}141}142}143144145