Path: blob/master/3rdparty/libjpeg-turbo/src/jccolext.c
16337 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, 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,32JSAMPARRAY input_buf, JSAMPIMAGE output_buf,33JDIMENSION output_row, int num_rows)34{35my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;36register int r, g, b;37register JLONG * ctab = cconvert->rgb_ycc_tab;38register JSAMPROW inptr;39register JSAMPROW outptr0, outptr1, outptr2;40register JDIMENSION col;41JDIMENSION num_cols = cinfo->image_width;4243while (--num_rows >= 0) {44inptr = *input_buf++;45outptr0 = output_buf[0][output_row];46outptr1 = output_buf[1][output_row];47outptr2 = output_buf[2][output_row];48output_row++;49for (col = 0; col < num_cols; col++) {50r = GETJSAMPLE(inptr[RGB_RED]);51g = GETJSAMPLE(inptr[RGB_GREEN]);52b = GETJSAMPLE(inptr[RGB_BLUE]);53inptr += RGB_PIXELSIZE;54/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations55* must be too; we do not need an explicit range-limiting operation.56* Hence the value being shifted is never negative, and we don't57* need the general RIGHT_SHIFT macro.58*/59/* Y */60outptr0[col] = (JSAMPLE)61((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])62>> SCALEBITS);63/* Cb */64outptr1[col] = (JSAMPLE)65((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])66>> SCALEBITS);67/* Cr */68outptr2[col] = (JSAMPLE)69((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])70>> SCALEBITS);71}72}73}747576/**************** Cases other than RGB -> YCbCr **************/777879/*80* Convert some rows of samples to the JPEG colorspace.81* This version handles RGB->grayscale conversion, which is the same82* as the RGB->Y portion of RGB->YCbCr.83* We assume rgb_ycc_start has been called (we only use the Y tables).84*/8586INLINE87LOCAL(void)88rgb_gray_convert_internal (j_compress_ptr cinfo,89JSAMPARRAY input_buf, JSAMPIMAGE output_buf,90JDIMENSION output_row, int num_rows)91{92my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;93register int r, g, b;94register JLONG * ctab = cconvert->rgb_ycc_tab;95register JSAMPROW inptr;96register JSAMPROW outptr;97register JDIMENSION col;98JDIMENSION num_cols = cinfo->image_width;99100while (--num_rows >= 0) {101inptr = *input_buf++;102outptr = output_buf[0][output_row];103output_row++;104for (col = 0; col < num_cols; col++) {105r = GETJSAMPLE(inptr[RGB_RED]);106g = GETJSAMPLE(inptr[RGB_GREEN]);107b = GETJSAMPLE(inptr[RGB_BLUE]);108inptr += RGB_PIXELSIZE;109/* Y */110outptr[col] = (JSAMPLE)111((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])112>> SCALEBITS);113}114}115}116117118/*119* Convert some rows of samples to the JPEG colorspace.120* This version handles extended RGB->plain RGB conversion121*/122123INLINE124LOCAL(void)125rgb_rgb_convert_internal (j_compress_ptr cinfo,126JSAMPARRAY input_buf, JSAMPIMAGE output_buf,127JDIMENSION output_row, int num_rows)128{129register JSAMPROW inptr;130register JSAMPROW outptr0, outptr1, outptr2;131register JDIMENSION col;132JDIMENSION num_cols = cinfo->image_width;133134while (--num_rows >= 0) {135inptr = *input_buf++;136outptr0 = output_buf[0][output_row];137outptr1 = output_buf[1][output_row];138outptr2 = output_buf[2][output_row];139output_row++;140for (col = 0; col < num_cols; col++) {141outptr0[col] = GETJSAMPLE(inptr[RGB_RED]);142outptr1[col] = GETJSAMPLE(inptr[RGB_GREEN]);143outptr2[col] = GETJSAMPLE(inptr[RGB_BLUE]);144inptr += RGB_PIXELSIZE;145}146}147}148149150