1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libjpeg/jdmrgext.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,185 @@ 1.4 +/* 1.5 + * jdmrgext.c 1.6 + * 1.7 + * This file was part of the Independent JPEG Group's software: 1.8 + * Copyright (C) 1994-1996, Thomas G. Lane. 1.9 + * libjpeg-turbo Modifications: 1.10 + * Copyright (C) 2011, D. R. Commander. 1.11 + * For conditions of distribution and use, see the accompanying README file. 1.12 + * 1.13 + * This file contains code for merged upsampling/color conversion. 1.14 + */ 1.15 + 1.16 + 1.17 +/* This file is included by jdmerge.c */ 1.18 + 1.19 + 1.20 +/* 1.21 + * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. 1.22 + */ 1.23 + 1.24 +INLINE 1.25 +LOCAL(void) 1.26 +h2v1_merged_upsample_internal (j_decompress_ptr cinfo, 1.27 + JSAMPIMAGE input_buf, 1.28 + JDIMENSION in_row_group_ctr, 1.29 + JSAMPARRAY output_buf) 1.30 +{ 1.31 + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; 1.32 + register int y, cred, cgreen, cblue; 1.33 + int cb, cr; 1.34 + register JSAMPROW outptr; 1.35 + JSAMPROW inptr0, inptr1, inptr2; 1.36 + JDIMENSION col; 1.37 + /* copy these pointers into registers if possible */ 1.38 + register JSAMPLE * range_limit = cinfo->sample_range_limit; 1.39 + int * Crrtab = upsample->Cr_r_tab; 1.40 + int * Cbbtab = upsample->Cb_b_tab; 1.41 + INT32 * Crgtab = upsample->Cr_g_tab; 1.42 + INT32 * Cbgtab = upsample->Cb_g_tab; 1.43 + SHIFT_TEMPS 1.44 + 1.45 + inptr0 = input_buf[0][in_row_group_ctr]; 1.46 + inptr1 = input_buf[1][in_row_group_ctr]; 1.47 + inptr2 = input_buf[2][in_row_group_ctr]; 1.48 + outptr = output_buf[0]; 1.49 + /* Loop for each pair of output pixels */ 1.50 + for (col = cinfo->output_width >> 1; col > 0; col--) { 1.51 + /* Do the chroma part of the calculation */ 1.52 + cb = GETJSAMPLE(*inptr1++); 1.53 + cr = GETJSAMPLE(*inptr2++); 1.54 + cred = Crrtab[cr]; 1.55 + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); 1.56 + cblue = Cbbtab[cb]; 1.57 + /* Fetch 2 Y values and emit 2 pixels */ 1.58 + y = GETJSAMPLE(*inptr0++); 1.59 + outptr[RGB_RED] = range_limit[y + cred]; 1.60 + outptr[RGB_GREEN] = range_limit[y + cgreen]; 1.61 + outptr[RGB_BLUE] = range_limit[y + cblue]; 1.62 +#ifdef RGB_ALPHA 1.63 + outptr[RGB_ALPHA] = 0xFF; 1.64 +#endif 1.65 + outptr += RGB_PIXELSIZE; 1.66 + y = GETJSAMPLE(*inptr0++); 1.67 + outptr[RGB_RED] = range_limit[y + cred]; 1.68 + outptr[RGB_GREEN] = range_limit[y + cgreen]; 1.69 + outptr[RGB_BLUE] = range_limit[y + cblue]; 1.70 +#ifdef RGB_ALPHA 1.71 + outptr[RGB_ALPHA] = 0xFF; 1.72 +#endif 1.73 + outptr += RGB_PIXELSIZE; 1.74 + } 1.75 + /* If image width is odd, do the last output column separately */ 1.76 + if (cinfo->output_width & 1) { 1.77 + cb = GETJSAMPLE(*inptr1); 1.78 + cr = GETJSAMPLE(*inptr2); 1.79 + cred = Crrtab[cr]; 1.80 + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); 1.81 + cblue = Cbbtab[cb]; 1.82 + y = GETJSAMPLE(*inptr0); 1.83 + outptr[RGB_RED] = range_limit[y + cred]; 1.84 + outptr[RGB_GREEN] = range_limit[y + cgreen]; 1.85 + outptr[RGB_BLUE] = range_limit[y + cblue]; 1.86 +#ifdef RGB_ALPHA 1.87 + outptr[RGB_ALPHA] = 0xFF; 1.88 +#endif 1.89 + } 1.90 +} 1.91 + 1.92 + 1.93 +/* 1.94 + * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. 1.95 + */ 1.96 + 1.97 +INLINE 1.98 +LOCAL(void) 1.99 +h2v2_merged_upsample_internal (j_decompress_ptr cinfo, 1.100 + JSAMPIMAGE input_buf, 1.101 + JDIMENSION in_row_group_ctr, 1.102 + JSAMPARRAY output_buf) 1.103 +{ 1.104 + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; 1.105 + register int y, cred, cgreen, cblue; 1.106 + int cb, cr; 1.107 + register JSAMPROW outptr0, outptr1; 1.108 + JSAMPROW inptr00, inptr01, inptr1, inptr2; 1.109 + JDIMENSION col; 1.110 + /* copy these pointers into registers if possible */ 1.111 + register JSAMPLE * range_limit = cinfo->sample_range_limit; 1.112 + int * Crrtab = upsample->Cr_r_tab; 1.113 + int * Cbbtab = upsample->Cb_b_tab; 1.114 + INT32 * Crgtab = upsample->Cr_g_tab; 1.115 + INT32 * Cbgtab = upsample->Cb_g_tab; 1.116 + SHIFT_TEMPS 1.117 + 1.118 + inptr00 = input_buf[0][in_row_group_ctr*2]; 1.119 + inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; 1.120 + inptr1 = input_buf[1][in_row_group_ctr]; 1.121 + inptr2 = input_buf[2][in_row_group_ctr]; 1.122 + outptr0 = output_buf[0]; 1.123 + outptr1 = output_buf[1]; 1.124 + /* Loop for each group of output pixels */ 1.125 + for (col = cinfo->output_width >> 1; col > 0; col--) { 1.126 + /* Do the chroma part of the calculation */ 1.127 + cb = GETJSAMPLE(*inptr1++); 1.128 + cr = GETJSAMPLE(*inptr2++); 1.129 + cred = Crrtab[cr]; 1.130 + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); 1.131 + cblue = Cbbtab[cb]; 1.132 + /* Fetch 4 Y values and emit 4 pixels */ 1.133 + y = GETJSAMPLE(*inptr00++); 1.134 + outptr0[RGB_RED] = range_limit[y + cred]; 1.135 + outptr0[RGB_GREEN] = range_limit[y + cgreen]; 1.136 + outptr0[RGB_BLUE] = range_limit[y + cblue]; 1.137 +#ifdef RGB_ALPHA 1.138 + outptr0[RGB_ALPHA] = 0xFF; 1.139 +#endif 1.140 + outptr0 += RGB_PIXELSIZE; 1.141 + y = GETJSAMPLE(*inptr00++); 1.142 + outptr0[RGB_RED] = range_limit[y + cred]; 1.143 + outptr0[RGB_GREEN] = range_limit[y + cgreen]; 1.144 + outptr0[RGB_BLUE] = range_limit[y + cblue]; 1.145 +#ifdef RGB_ALPHA 1.146 + outptr0[RGB_ALPHA] = 0xFF; 1.147 +#endif 1.148 + outptr0 += RGB_PIXELSIZE; 1.149 + y = GETJSAMPLE(*inptr01++); 1.150 + outptr1[RGB_RED] = range_limit[y + cred]; 1.151 + outptr1[RGB_GREEN] = range_limit[y + cgreen]; 1.152 + outptr1[RGB_BLUE] = range_limit[y + cblue]; 1.153 +#ifdef RGB_ALPHA 1.154 + outptr1[RGB_ALPHA] = 0xFF; 1.155 +#endif 1.156 + outptr1 += RGB_PIXELSIZE; 1.157 + y = GETJSAMPLE(*inptr01++); 1.158 + outptr1[RGB_RED] = range_limit[y + cred]; 1.159 + outptr1[RGB_GREEN] = range_limit[y + cgreen]; 1.160 + outptr1[RGB_BLUE] = range_limit[y + cblue]; 1.161 +#ifdef RGB_ALPHA 1.162 + outptr1[RGB_ALPHA] = 0xFF; 1.163 +#endif 1.164 + outptr1 += RGB_PIXELSIZE; 1.165 + } 1.166 + /* If image width is odd, do the last output column separately */ 1.167 + if (cinfo->output_width & 1) { 1.168 + cb = GETJSAMPLE(*inptr1); 1.169 + cr = GETJSAMPLE(*inptr2); 1.170 + cred = Crrtab[cr]; 1.171 + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); 1.172 + cblue = Cbbtab[cb]; 1.173 + y = GETJSAMPLE(*inptr00); 1.174 + outptr0[RGB_RED] = range_limit[y + cred]; 1.175 + outptr0[RGB_GREEN] = range_limit[y + cgreen]; 1.176 + outptr0[RGB_BLUE] = range_limit[y + cblue]; 1.177 +#ifdef RGB_ALPHA 1.178 + outptr0[RGB_ALPHA] = 0xFF; 1.179 +#endif 1.180 + y = GETJSAMPLE(*inptr01); 1.181 + outptr1[RGB_RED] = range_limit[y + cred]; 1.182 + outptr1[RGB_GREEN] = range_limit[y + cgreen]; 1.183 + outptr1[RGB_BLUE] = range_limit[y + cblue]; 1.184 +#ifdef RGB_ALPHA 1.185 + outptr1[RGB_ALPHA] = 0xFF; 1.186 +#endif 1.187 + } 1.188 +}