Path: blob/master/3rdparty/libjpeg-turbo/src/jdmrgext.c
16337 views
/*1* jdmrgext.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1994-1996, Thomas G. Lane.5* libjpeg-turbo Modifications:6* Copyright (C) 2011, 2015, D. R. Commander.7* For conditions of distribution and use, see the accompanying README.ijg8* file.9*10* This file contains code for merged upsampling/color conversion.11*/121314/* This file is included by jdmerge.c */151617/*18* Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.19*/2021INLINE22LOCAL(void)23h2v1_merged_upsample_internal (j_decompress_ptr cinfo,24JSAMPIMAGE input_buf,25JDIMENSION in_row_group_ctr,26JSAMPARRAY output_buf)27{28my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;29register int y, cred, cgreen, cblue;30int cb, cr;31register JSAMPROW outptr;32JSAMPROW inptr0, inptr1, inptr2;33JDIMENSION col;34/* copy these pointers into registers if possible */35register JSAMPLE * range_limit = cinfo->sample_range_limit;36int * Crrtab = upsample->Cr_r_tab;37int * Cbbtab = upsample->Cb_b_tab;38JLONG * Crgtab = upsample->Cr_g_tab;39JLONG * Cbgtab = upsample->Cb_g_tab;40SHIFT_TEMPS4142inptr0 = input_buf[0][in_row_group_ctr];43inptr1 = input_buf[1][in_row_group_ctr];44inptr2 = input_buf[2][in_row_group_ctr];45outptr = output_buf[0];46/* Loop for each pair of output pixels */47for (col = cinfo->output_width >> 1; col > 0; col--) {48/* Do the chroma part of the calculation */49cb = GETJSAMPLE(*inptr1++);50cr = GETJSAMPLE(*inptr2++);51cred = Crrtab[cr];52cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);53cblue = Cbbtab[cb];54/* Fetch 2 Y values and emit 2 pixels */55y = GETJSAMPLE(*inptr0++);56outptr[RGB_RED] = range_limit[y + cred];57outptr[RGB_GREEN] = range_limit[y + cgreen];58outptr[RGB_BLUE] = range_limit[y + cblue];59#ifdef RGB_ALPHA60outptr[RGB_ALPHA] = 0xFF;61#endif62outptr += RGB_PIXELSIZE;63y = GETJSAMPLE(*inptr0++);64outptr[RGB_RED] = range_limit[y + cred];65outptr[RGB_GREEN] = range_limit[y + cgreen];66outptr[RGB_BLUE] = range_limit[y + cblue];67#ifdef RGB_ALPHA68outptr[RGB_ALPHA] = 0xFF;69#endif70outptr += RGB_PIXELSIZE;71}72/* If image width is odd, do the last output column separately */73if (cinfo->output_width & 1) {74cb = GETJSAMPLE(*inptr1);75cr = GETJSAMPLE(*inptr2);76cred = Crrtab[cr];77cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);78cblue = Cbbtab[cb];79y = GETJSAMPLE(*inptr0);80outptr[RGB_RED] = range_limit[y + cred];81outptr[RGB_GREEN] = range_limit[y + cgreen];82outptr[RGB_BLUE] = range_limit[y + cblue];83#ifdef RGB_ALPHA84outptr[RGB_ALPHA] = 0xFF;85#endif86}87}888990/*91* Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.92*/9394INLINE95LOCAL(void)96h2v2_merged_upsample_internal (j_decompress_ptr cinfo,97JSAMPIMAGE input_buf,98JDIMENSION in_row_group_ctr,99JSAMPARRAY output_buf)100{101my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;102register int y, cred, cgreen, cblue;103int cb, cr;104register JSAMPROW outptr0, outptr1;105JSAMPROW inptr00, inptr01, inptr1, inptr2;106JDIMENSION col;107/* copy these pointers into registers if possible */108register JSAMPLE * range_limit = cinfo->sample_range_limit;109int * Crrtab = upsample->Cr_r_tab;110int * Cbbtab = upsample->Cb_b_tab;111JLONG * Crgtab = upsample->Cr_g_tab;112JLONG * Cbgtab = upsample->Cb_g_tab;113SHIFT_TEMPS114115inptr00 = input_buf[0][in_row_group_ctr*2];116inptr01 = input_buf[0][in_row_group_ctr*2 + 1];117inptr1 = input_buf[1][in_row_group_ctr];118inptr2 = input_buf[2][in_row_group_ctr];119outptr0 = output_buf[0];120outptr1 = output_buf[1];121/* Loop for each group of output pixels */122for (col = cinfo->output_width >> 1; col > 0; col--) {123/* Do the chroma part of the calculation */124cb = GETJSAMPLE(*inptr1++);125cr = GETJSAMPLE(*inptr2++);126cred = Crrtab[cr];127cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);128cblue = Cbbtab[cb];129/* Fetch 4 Y values and emit 4 pixels */130y = GETJSAMPLE(*inptr00++);131outptr0[RGB_RED] = range_limit[y + cred];132outptr0[RGB_GREEN] = range_limit[y + cgreen];133outptr0[RGB_BLUE] = range_limit[y + cblue];134#ifdef RGB_ALPHA135outptr0[RGB_ALPHA] = 0xFF;136#endif137outptr0 += RGB_PIXELSIZE;138y = GETJSAMPLE(*inptr00++);139outptr0[RGB_RED] = range_limit[y + cred];140outptr0[RGB_GREEN] = range_limit[y + cgreen];141outptr0[RGB_BLUE] = range_limit[y + cblue];142#ifdef RGB_ALPHA143outptr0[RGB_ALPHA] = 0xFF;144#endif145outptr0 += RGB_PIXELSIZE;146y = GETJSAMPLE(*inptr01++);147outptr1[RGB_RED] = range_limit[y + cred];148outptr1[RGB_GREEN] = range_limit[y + cgreen];149outptr1[RGB_BLUE] = range_limit[y + cblue];150#ifdef RGB_ALPHA151outptr1[RGB_ALPHA] = 0xFF;152#endif153outptr1 += RGB_PIXELSIZE;154y = GETJSAMPLE(*inptr01++);155outptr1[RGB_RED] = range_limit[y + cred];156outptr1[RGB_GREEN] = range_limit[y + cgreen];157outptr1[RGB_BLUE] = range_limit[y + cblue];158#ifdef RGB_ALPHA159outptr1[RGB_ALPHA] = 0xFF;160#endif161outptr1 += RGB_PIXELSIZE;162}163/* If image width is odd, do the last output column separately */164if (cinfo->output_width & 1) {165cb = GETJSAMPLE(*inptr1);166cr = GETJSAMPLE(*inptr2);167cred = Crrtab[cr];168cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);169cblue = Cbbtab[cb];170y = GETJSAMPLE(*inptr00);171outptr0[RGB_RED] = range_limit[y + cred];172outptr0[RGB_GREEN] = range_limit[y + cgreen];173outptr0[RGB_BLUE] = range_limit[y + cblue];174#ifdef RGB_ALPHA175outptr0[RGB_ALPHA] = 0xFF;176#endif177y = GETJSAMPLE(*inptr01);178outptr1[RGB_RED] = range_limit[y + cred];179outptr1[RGB_GREEN] = range_limit[y + cgreen];180outptr1[RGB_BLUE] = range_limit[y + cblue];181#ifdef RGB_ALPHA182outptr1[RGB_ALPHA] = 0xFF;183#endif184}185}186187188