|
shun-iwasawa |
82a8f5 |
/*
|
|
shun-iwasawa |
82a8f5 |
* jdmrgext.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) 2011, 2015, 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 |
/* This file is included by jdmerge.c */
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/*
|
|
shun-iwasawa |
82a8f5 |
* Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
|
|
shun-iwasawa |
82a8f5 |
*/
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
h2v1_merged_upsample_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 |
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 |
/* 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 |
/* Fetch 2 Y values and emit 2 pixels */
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0++);
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
outptr += RGB_PIXELSIZE;
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr0++);
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
outptr += RGB_PIXELSIZE;
|
|
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 |
outptr[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/*
|
|
shun-iwasawa |
82a8f5 |
* Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
|
|
shun-iwasawa |
82a8f5 |
*/
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
INLINE
|
|
shun-iwasawa |
82a8f5 |
LOCAL(void)
|
|
shun-iwasawa |
82a8f5 |
h2v2_merged_upsample_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 |
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 |
/* 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 |
/* Fetch 4 Y values and emit 4 pixels */
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00++);
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
outptr0 += RGB_PIXELSIZE;
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr00++);
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
outptr0 += RGB_PIXELSIZE;
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01++);
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
outptr1 += RGB_PIXELSIZE;
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01++);
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
outptr1 += RGB_PIXELSIZE;
|
|
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(*inptr00);
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr0[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
y = GETJSAMPLE(*inptr01);
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_RED] = range_limit[y + cred];
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
|
shun-iwasawa |
82a8f5 |
#ifdef RGB_ALPHA
|
|
shun-iwasawa |
82a8f5 |
outptr1[RGB_ALPHA] = 0xFF;
|
|
shun-iwasawa |
82a8f5 |
#endif
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|