Path: blob/master/3rdparty/libjpeg-turbo/src/jdmrg565.c
16337 views
/*1* jdmrg565.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) 2013, Linaro Limited.7* Copyright (C) 2014-2015, D. R. Commander.8* For conditions of distribution and use, see the accompanying README.ijg9* file.10*11* This file contains code for merged upsampling/color conversion.12*/131415INLINE16LOCAL(void)17h2v1_merged_upsample_565_internal (j_decompress_ptr cinfo,18JSAMPIMAGE input_buf,19JDIMENSION in_row_group_ctr,20JSAMPARRAY output_buf)21{22my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;23register int y, cred, cgreen, cblue;24int cb, cr;25register JSAMPROW outptr;26JSAMPROW inptr0, inptr1, inptr2;27JDIMENSION col;28/* copy these pointers into registers if possible */29register JSAMPLE * range_limit = cinfo->sample_range_limit;30int * Crrtab = upsample->Cr_r_tab;31int * Cbbtab = upsample->Cb_b_tab;32JLONG * Crgtab = upsample->Cr_g_tab;33JLONG * Cbgtab = upsample->Cb_g_tab;34unsigned int r, g, b;35JLONG rgb;36SHIFT_TEMPS3738inptr0 = input_buf[0][in_row_group_ctr];39inptr1 = input_buf[1][in_row_group_ctr];40inptr2 = input_buf[2][in_row_group_ctr];41outptr = output_buf[0];4243/* Loop for each pair of output pixels */44for (col = cinfo->output_width >> 1; col > 0; col--) {45/* Do the chroma part of the calculation */46cb = GETJSAMPLE(*inptr1++);47cr = GETJSAMPLE(*inptr2++);48cred = Crrtab[cr];49cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);50cblue = Cbbtab[cb];5152/* Fetch 2 Y values and emit 2 pixels */53y = GETJSAMPLE(*inptr0++);54r = range_limit[y + cred];55g = range_limit[y + cgreen];56b = range_limit[y + cblue];57rgb = PACK_SHORT_565(r, g, b);5859y = GETJSAMPLE(*inptr0++);60r = range_limit[y + cred];61g = range_limit[y + cgreen];62b = range_limit[y + cblue];63rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));6465WRITE_TWO_PIXELS(outptr, rgb);66outptr += 4;67}6869/* If image width is odd, do the last output column separately */70if (cinfo->output_width & 1) {71cb = GETJSAMPLE(*inptr1);72cr = GETJSAMPLE(*inptr2);73cred = Crrtab[cr];74cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);75cblue = Cbbtab[cb];76y = GETJSAMPLE(*inptr0);77r = range_limit[y + cred];78g = range_limit[y + cgreen];79b = range_limit[y + cblue];80rgb = PACK_SHORT_565(r, g, b);81*(INT16*)outptr = (INT16)rgb;82}83}848586INLINE87LOCAL(void)88h2v1_merged_upsample_565D_internal (j_decompress_ptr cinfo,89JSAMPIMAGE input_buf,90JDIMENSION in_row_group_ctr,91JSAMPARRAY output_buf)92{93my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;94register int y, cred, cgreen, cblue;95int cb, cr;96register JSAMPROW outptr;97JSAMPROW inptr0, inptr1, inptr2;98JDIMENSION col;99/* copy these pointers into registers if possible */100register JSAMPLE * range_limit = cinfo->sample_range_limit;101int * Crrtab = upsample->Cr_r_tab;102int * Cbbtab = upsample->Cb_b_tab;103JLONG * Crgtab = upsample->Cr_g_tab;104JLONG * Cbgtab = upsample->Cb_g_tab;105JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];106unsigned int r, g, b;107JLONG rgb;108SHIFT_TEMPS109110inptr0 = input_buf[0][in_row_group_ctr];111inptr1 = input_buf[1][in_row_group_ctr];112inptr2 = input_buf[2][in_row_group_ctr];113outptr = output_buf[0];114115/* Loop for each pair of output pixels */116for (col = cinfo->output_width >> 1; col > 0; col--) {117/* Do the chroma part of the calculation */118cb = GETJSAMPLE(*inptr1++);119cr = GETJSAMPLE(*inptr2++);120cred = Crrtab[cr];121cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);122cblue = Cbbtab[cb];123124/* Fetch 2 Y values and emit 2 pixels */125y = GETJSAMPLE(*inptr0++);126r = range_limit[DITHER_565_R(y + cred, d0)];127g = range_limit[DITHER_565_G(y + cgreen, d0)];128b = range_limit[DITHER_565_B(y + cblue, d0)];129d0 = DITHER_ROTATE(d0);130rgb = PACK_SHORT_565(r, g, b);131132y = GETJSAMPLE(*inptr0++);133r = range_limit[DITHER_565_R(y + cred, d0)];134g = range_limit[DITHER_565_G(y + cgreen, d0)];135b = range_limit[DITHER_565_B(y + cblue, d0)];136d0 = DITHER_ROTATE(d0);137rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));138139WRITE_TWO_PIXELS(outptr, rgb);140outptr += 4;141}142143/* If image width is odd, do the last output column separately */144if (cinfo->output_width & 1) {145cb = GETJSAMPLE(*inptr1);146cr = GETJSAMPLE(*inptr2);147cred = Crrtab[cr];148cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);149cblue = Cbbtab[cb];150y = GETJSAMPLE(*inptr0);151r = range_limit[DITHER_565_R(y + cred, d0)];152g = range_limit[DITHER_565_G(y + cgreen, d0)];153b = range_limit[DITHER_565_B(y + cblue, d0)];154rgb = PACK_SHORT_565(r, g, b);155*(INT16*)outptr = (INT16)rgb;156}157}158159160INLINE161LOCAL(void)162h2v2_merged_upsample_565_internal (j_decompress_ptr cinfo,163JSAMPIMAGE input_buf,164JDIMENSION in_row_group_ctr,165JSAMPARRAY output_buf)166{167my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;168register int y, cred, cgreen, cblue;169int cb, cr;170register JSAMPROW outptr0, outptr1;171JSAMPROW inptr00, inptr01, inptr1, inptr2;172JDIMENSION col;173/* copy these pointers into registers if possible */174register JSAMPLE * range_limit = cinfo->sample_range_limit;175int * Crrtab = upsample->Cr_r_tab;176int * Cbbtab = upsample->Cb_b_tab;177JLONG * Crgtab = upsample->Cr_g_tab;178JLONG * Cbgtab = upsample->Cb_g_tab;179unsigned int r, g, b;180JLONG rgb;181SHIFT_TEMPS182183inptr00 = input_buf[0][in_row_group_ctr * 2];184inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];185inptr1 = input_buf[1][in_row_group_ctr];186inptr2 = input_buf[2][in_row_group_ctr];187outptr0 = output_buf[0];188outptr1 = output_buf[1];189190/* Loop for each group of output pixels */191for (col = cinfo->output_width >> 1; col > 0; col--) {192/* Do the chroma part of the calculation */193cb = GETJSAMPLE(*inptr1++);194cr = GETJSAMPLE(*inptr2++);195cred = Crrtab[cr];196cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);197cblue = Cbbtab[cb];198199/* Fetch 4 Y values and emit 4 pixels */200y = GETJSAMPLE(*inptr00++);201r = range_limit[y + cred];202g = range_limit[y + cgreen];203b = range_limit[y + cblue];204rgb = PACK_SHORT_565(r, g, b);205206y = GETJSAMPLE(*inptr00++);207r = range_limit[y + cred];208g = range_limit[y + cgreen];209b = range_limit[y + cblue];210rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));211212WRITE_TWO_PIXELS(outptr0, rgb);213outptr0 += 4;214215y = GETJSAMPLE(*inptr01++);216r = range_limit[y + cred];217g = range_limit[y + cgreen];218b = range_limit[y + cblue];219rgb = PACK_SHORT_565(r, g, b);220221y = GETJSAMPLE(*inptr01++);222r = range_limit[y + cred];223g = range_limit[y + cgreen];224b = range_limit[y + cblue];225rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));226227WRITE_TWO_PIXELS(outptr1, rgb);228outptr1 += 4;229}230231/* If image width is odd, do the last output column separately */232if (cinfo->output_width & 1) {233cb = GETJSAMPLE(*inptr1);234cr = GETJSAMPLE(*inptr2);235cred = Crrtab[cr];236cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);237cblue = Cbbtab[cb];238239y = GETJSAMPLE(*inptr00);240r = range_limit[y + cred];241g = range_limit[y + cgreen];242b = range_limit[y + cblue];243rgb = PACK_SHORT_565(r, g, b);244*(INT16*)outptr0 = (INT16)rgb;245246y = GETJSAMPLE(*inptr01);247r = range_limit[y + cred];248g = range_limit[y + cgreen];249b = range_limit[y + cblue];250rgb = PACK_SHORT_565(r, g, b);251*(INT16*)outptr1 = (INT16)rgb;252}253}254255256INLINE257LOCAL(void)258h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo,259JSAMPIMAGE input_buf,260JDIMENSION in_row_group_ctr,261JSAMPARRAY output_buf)262{263my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;264register int y, cred, cgreen, cblue;265int cb, cr;266register JSAMPROW outptr0, outptr1;267JSAMPROW inptr00, inptr01, inptr1, inptr2;268JDIMENSION col;269/* copy these pointers into registers if possible */270register JSAMPLE * range_limit = cinfo->sample_range_limit;271int * Crrtab = upsample->Cr_r_tab;272int * Cbbtab = upsample->Cb_b_tab;273JLONG * Crgtab = upsample->Cr_g_tab;274JLONG * Cbgtab = upsample->Cb_g_tab;275JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];276JLONG d1 = dither_matrix[(cinfo->output_scanline+1) & DITHER_MASK];277unsigned int r, g, b;278JLONG rgb;279SHIFT_TEMPS280281inptr00 = input_buf[0][in_row_group_ctr*2];282inptr01 = input_buf[0][in_row_group_ctr*2 + 1];283inptr1 = input_buf[1][in_row_group_ctr];284inptr2 = input_buf[2][in_row_group_ctr];285outptr0 = output_buf[0];286outptr1 = output_buf[1];287288/* Loop for each group of output pixels */289for (col = cinfo->output_width >> 1; col > 0; col--) {290/* Do the chroma part of the calculation */291cb = GETJSAMPLE(*inptr1++);292cr = GETJSAMPLE(*inptr2++);293cred = Crrtab[cr];294cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);295cblue = Cbbtab[cb];296297/* Fetch 4 Y values and emit 4 pixels */298y = GETJSAMPLE(*inptr00++);299r = range_limit[DITHER_565_R(y + cred, d0)];300g = range_limit[DITHER_565_G(y + cgreen, d0)];301b = range_limit[DITHER_565_B(y + cblue, d0)];302d0 = DITHER_ROTATE(d0);303rgb = PACK_SHORT_565(r, g, b);304305y = GETJSAMPLE(*inptr00++);306r = range_limit[DITHER_565_R(y + cred, d1)];307g = range_limit[DITHER_565_G(y + cgreen, d1)];308b = range_limit[DITHER_565_B(y + cblue, d1)];309d1 = DITHER_ROTATE(d1);310rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));311312WRITE_TWO_PIXELS(outptr0, rgb);313outptr0 += 4;314315y = GETJSAMPLE(*inptr01++);316r = range_limit[DITHER_565_R(y + cred, d0)];317g = range_limit[DITHER_565_G(y + cgreen, d0)];318b = range_limit[DITHER_565_B(y + cblue, d0)];319d0 = DITHER_ROTATE(d0);320rgb = PACK_SHORT_565(r, g, b);321322y = GETJSAMPLE(*inptr01++);323r = range_limit[DITHER_565_R(y + cred, d1)];324g = range_limit[DITHER_565_G(y + cgreen, d1)];325b = range_limit[DITHER_565_B(y + cblue, d1)];326d1 = DITHER_ROTATE(d1);327rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));328329WRITE_TWO_PIXELS(outptr1, rgb);330outptr1 += 4;331}332333/* If image width is odd, do the last output column separately */334if (cinfo->output_width & 1) {335cb = GETJSAMPLE(*inptr1);336cr = GETJSAMPLE(*inptr2);337cred = Crrtab[cr];338cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);339cblue = Cbbtab[cb];340341y = GETJSAMPLE(*inptr00);342r = range_limit[DITHER_565_R(y + cred, d0)];343g = range_limit[DITHER_565_G(y + cgreen, d0)];344b = range_limit[DITHER_565_B(y + cblue, d0)];345rgb = PACK_SHORT_565(r, g, b);346*(INT16*)outptr0 = (INT16)rgb;347348y = GETJSAMPLE(*inptr01);349r = range_limit[DITHER_565_R(y + cred, d1)];350g = range_limit[DITHER_565_G(y + cgreen, d1)];351b = range_limit[DITHER_565_B(y + cblue, d1)];352rgb = PACK_SHORT_565(r, g, b);353*(INT16*)outptr1 = (INT16)rgb;354}355}356357358