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