|
shun-iwasawa |
82a8f5 |
/*
|
|
shun-iwasawa |
82a8f5 |
* jdmrg565.c
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* This file was part of the Independent JPEG Group's software:
|
|
shun-iwasawa |
82a8f5 |
* Copyright (C) 1994-1996, Thomas G. Lane.
|
|
shun-iwasawa |
82a8f5 |
* libjpeg-turbo Modifications:
|
|
shun-iwasawa |
82a8f5 |
* Copyright (C) 2013, Linaro Limited.
|
|
shun-iwasawa |
82a8f5 |
* Copyright (C) 2014-2015, 2018, 2020, 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 code for merged upsampling/color conversion.
|
|
shun-iwasawa |
82a8f5 |
*/
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION in_row_group_ctr,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY output_buf)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
|
shun-iwasawa |
82a8f5 |
register int y, cred, cgreen, cblue;
|
|
shun-iwasawa |
82a8f5 |
int cb, cr;
|
|
shun-iwasawa |
82a8f5 |
register JSAMPROW outptr;
|
|
shun-iwasawa |
82a8f5 |
JSAMPROW inptr0, inptr1, inptr2;
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION col;
|
|
shun-iwasawa |
82a8f5 |
/* copy these pointers into registers if possible */
|
|
shun-iwasawa |
82a8f5 |
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
|
shun-iwasawa |
82a8f5 |
int *Crrtab = upsample->Cr_r_tab;
|
|
shun-iwasawa |
82a8f5 |
int *Cbbtab = upsample->Cb_b_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Crgtab = upsample->Cr_g_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Cbgtab = upsample->Cb_g_tab;
|
|
shun-iwasawa |
82a8f5 |
unsigned int r, g, b;
|
|
shun-iwasawa |
82a8f5 |
JLONG rgb;
|
|
shun-iwasawa |
82a8f5 |
SHIFT_TEMPS
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
inptr0 = input_buf[0][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
inptr1 = input_buf[1][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
inptr2 = input_buf[2][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
outptr = output_buf[0];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Loop for each pair of output pixels */
|
|
shun-iwasawa |
82a8f5 |
for (col = cinfo->output_width >> 1; col > 0; col--) {
|
|
shun-iwasawa |
82a8f5 |
/* Do the chroma part of the calculation */
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1++);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2++);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Fetch 2 Y values and emit 2 pixels */
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
WRITE_TWO_PIXELS(outptr, rgb);
|
|
shun-iwasawa |
82a8f5 |
outptr += 4;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* If image width is odd, do the last output column separately */
|
|
shun-iwasawa |
82a8f5 |
if (cinfo->output_width & 1) {
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
*(INT16 *)outptr = (INT16)rgb;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
|
|
shun-iwasawa |
82a8f5 |
JSAMPIMAGE input_buf,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION in_row_group_ctr,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY output_buf)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
|
shun-iwasawa |
82a8f5 |
register int y, cred, cgreen, cblue;
|
|
shun-iwasawa |
82a8f5 |
int cb, cr;
|
|
shun-iwasawa |
82a8f5 |
register JSAMPROW outptr;
|
|
shun-iwasawa |
82a8f5 |
JSAMPROW inptr0, inptr1, inptr2;
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION col;
|
|
shun-iwasawa |
82a8f5 |
/* copy these pointers into registers if possible */
|
|
shun-iwasawa |
82a8f5 |
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
|
shun-iwasawa |
82a8f5 |
int *Crrtab = upsample->Cr_r_tab;
|
|
shun-iwasawa |
82a8f5 |
int *Cbbtab = upsample->Cb_b_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Crgtab = upsample->Cr_g_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Cbgtab = upsample->Cb_g_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
|
|
shun-iwasawa |
82a8f5 |
unsigned int r, g, b;
|
|
shun-iwasawa |
82a8f5 |
JLONG rgb;
|
|
shun-iwasawa |
82a8f5 |
SHIFT_TEMPS
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
inptr0 = input_buf[0][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
inptr1 = input_buf[1][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
inptr2 = input_buf[2][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
outptr = output_buf[0];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Loop for each pair of output pixels */
|
|
shun-iwasawa |
82a8f5 |
for (col = cinfo->output_width >> 1; col > 0; col--) {
|
|
shun-iwasawa |
82a8f5 |
/* Do the chroma part of the calculation */
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1++);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2++);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Fetch 2 Y values and emit 2 pixels */
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d0)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d0)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d0)];
|
|
shun-iwasawa |
82a8f5 |
d0 = DITHER_ROTATE(d0);
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d0)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d0)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d0)];
|
|
shun-iwasawa |
82a8f5 |
d0 = DITHER_ROTATE(d0);
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
WRITE_TWO_PIXELS(outptr, rgb);
|
|
shun-iwasawa |
82a8f5 |
outptr += 4;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* If image width is odd, do the last output column separately */
|
|
shun-iwasawa |
82a8f5 |
if (cinfo->output_width & 1) {
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d0)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d0)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d0)];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
*(INT16 *)outptr = (INT16)rgb;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION in_row_group_ctr,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY output_buf)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
|
shun-iwasawa |
82a8f5 |
register int y, cred, cgreen, cblue;
|
|
shun-iwasawa |
82a8f5 |
int cb, cr;
|
|
shun-iwasawa |
82a8f5 |
register JSAMPROW outptr0, outptr1;
|
|
shun-iwasawa |
82a8f5 |
JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION col;
|
|
shun-iwasawa |
82a8f5 |
/* copy these pointers into registers if possible */
|
|
shun-iwasawa |
82a8f5 |
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
|
shun-iwasawa |
82a8f5 |
int *Crrtab = upsample->Cr_r_tab;
|
|
shun-iwasawa |
82a8f5 |
int *Cbbtab = upsample->Cb_b_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Crgtab = upsample->Cr_g_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Cbgtab = upsample->Cb_g_tab;
|
|
shun-iwasawa |
82a8f5 |
unsigned int r, g, b;
|
|
shun-iwasawa |
82a8f5 |
JLONG rgb;
|
|
shun-iwasawa |
82a8f5 |
SHIFT_TEMPS
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
inptr00 = input_buf[0][in_row_group_ctr * 2];
|
|
shun-iwasawa |
82a8f5 |
inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];
|
|
shun-iwasawa |
82a8f5 |
inptr1 = input_buf[1][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
inptr2 = input_buf[2][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
outptr0 = output_buf[0];
|
|
shun-iwasawa |
82a8f5 |
outptr1 = output_buf[1];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Loop for each group of output pixels */
|
|
shun-iwasawa |
82a8f5 |
for (col = cinfo->output_width >> 1; col > 0; col--) {
|
|
shun-iwasawa |
82a8f5 |
/* Do the chroma part of the calculation */
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1++);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2++);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Fetch 4 Y values and emit 4 pixels */
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
WRITE_TWO_PIXELS(outptr0, rgb);
|
|
shun-iwasawa |
82a8f5 |
outptr0 += 4;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
WRITE_TWO_PIXELS(outptr1, rgb);
|
|
shun-iwasawa |
82a8f5 |
outptr1 += 4;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* If image width is odd, do the last output column separately */
|
|
shun-iwasawa |
82a8f5 |
if (cinfo->output_width & 1) {
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
*(INT16 *)outptr0 = (INT16)rgb;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
*(INT16 *)outptr1 = (INT16)rgb;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
|
|
shun-iwasawa |
82a8f5 |
JSAMPIMAGE input_buf,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION in_row_group_ctr,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY output_buf)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
|
shun-iwasawa |
82a8f5 |
register int y, cred, cgreen, cblue;
|
|
shun-iwasawa |
82a8f5 |
int cb, cr;
|
|
shun-iwasawa |
82a8f5 |
register JSAMPROW outptr0, outptr1;
|
|
shun-iwasawa |
82a8f5 |
JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION col;
|
|
shun-iwasawa |
82a8f5 |
/* copy these pointers into registers if possible */
|
|
shun-iwasawa |
82a8f5 |
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
|
shun-iwasawa |
82a8f5 |
int *Crrtab = upsample->Cr_r_tab;
|
|
shun-iwasawa |
82a8f5 |
int *Cbbtab = upsample->Cb_b_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Crgtab = upsample->Cr_g_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG *Cbgtab = upsample->Cb_g_tab;
|
|
shun-iwasawa |
82a8f5 |
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
|
|
shun-iwasawa |
82a8f5 |
JLONG d1 = dither_matrix[(cinfo->output_scanline + 1) & DITHER_MASK];
|
|
shun-iwasawa |
82a8f5 |
unsigned int r, g, b;
|
|
shun-iwasawa |
82a8f5 |
JLONG rgb;
|
|
shun-iwasawa |
82a8f5 |
SHIFT_TEMPS
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
inptr00 = input_buf[0][in_row_group_ctr * 2];
|
|
shun-iwasawa |
82a8f5 |
inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];
|
|
shun-iwasawa |
82a8f5 |
inptr1 = input_buf[1][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
inptr2 = input_buf[2][in_row_group_ctr];
|
|
shun-iwasawa |
82a8f5 |
outptr0 = output_buf[0];
|
|
shun-iwasawa |
82a8f5 |
outptr1 = output_buf[1];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Loop for each group of output pixels */
|
|
shun-iwasawa |
82a8f5 |
for (col = cinfo->output_width >> 1; col > 0; col--) {
|
|
shun-iwasawa |
82a8f5 |
/* Do the chroma part of the calculation */
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1++);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2++);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Fetch 4 Y values and emit 4 pixels */
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d0)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d0)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d0)];
|
|
shun-iwasawa |
82a8f5 |
d0 = DITHER_ROTATE(d0);
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d0)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d0)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d0)];
|
|
shun-iwasawa |
82a8f5 |
d0 = DITHER_ROTATE(d0);
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
WRITE_TWO_PIXELS(outptr0, rgb);
|
|
shun-iwasawa |
82a8f5 |
outptr0 += 4;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d1)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d1)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d1)];
|
|
shun-iwasawa |
82a8f5 |
d1 = DITHER_ROTATE(d1);
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01++);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d1)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d1)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d1)];
|
|
shun-iwasawa |
82a8f5 |
d1 = DITHER_ROTATE(d1);
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
WRITE_TWO_PIXELS(outptr1, rgb);
|
|
shun-iwasawa |
82a8f5 |
outptr1 += 4;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* If image width is odd, do the last output column separately */
|
|
shun-iwasawa |
82a8f5 |
if (cinfo->output_width & 1) {
|
|
shun-iwasawa |
82a8f5 |
cb = GETJSAMPLE(*inptr1);
|
|
shun-iwasawa |
82a8f5 |
cr = GETJSAMPLE(*inptr2);
|
|
shun-iwasawa |
82a8f5 |
cred = Crrtab[cr];
|
|
shun-iwasawa |
82a8f5 |
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
shun-iwasawa |
82a8f5 |
cblue = Cbbtab[cb];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d0)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d0)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d0)];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
*(INT16 *)outptr0 = (INT16)rgb;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01);
|
|
shun-iwasawa |
82a8f5 |
r = range_limit[DITHER_565_R(y + cred, d1)];
|
|
shun-iwasawa |
82a8f5 |
g = range_limit[DITHER_565_G(y + cgreen, d1)];
|
|
shun-iwasawa |
82a8f5 |
b = range_limit[DITHER_565_B(y + cblue, d1)];
|
|
shun-iwasawa |
82a8f5 |
rgb = PACK_SHORT_565(r, g, b);
|
|
shun-iwasawa |
82a8f5 |
*(INT16 *)outptr1 = (INT16)rgb;
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|