media/libjpeg/jdmrgext.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * jdmrgext.c
michael@0 3 *
michael@0 4 * This file was part of the Independent JPEG Group's software:
michael@0 5 * Copyright (C) 1994-1996, Thomas G. Lane.
michael@0 6 * libjpeg-turbo Modifications:
michael@0 7 * Copyright (C) 2011, D. R. Commander.
michael@0 8 * For conditions of distribution and use, see the accompanying README file.
michael@0 9 *
michael@0 10 * This file contains code for merged upsampling/color conversion.
michael@0 11 */
michael@0 12
michael@0 13
michael@0 14 /* This file is included by jdmerge.c */
michael@0 15
michael@0 16
michael@0 17 /*
michael@0 18 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
michael@0 19 */
michael@0 20
michael@0 21 INLINE
michael@0 22 LOCAL(void)
michael@0 23 h2v1_merged_upsample_internal (j_decompress_ptr cinfo,
michael@0 24 JSAMPIMAGE input_buf,
michael@0 25 JDIMENSION in_row_group_ctr,
michael@0 26 JSAMPARRAY output_buf)
michael@0 27 {
michael@0 28 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
michael@0 29 register int y, cred, cgreen, cblue;
michael@0 30 int cb, cr;
michael@0 31 register JSAMPROW outptr;
michael@0 32 JSAMPROW inptr0, inptr1, inptr2;
michael@0 33 JDIMENSION col;
michael@0 34 /* copy these pointers into registers if possible */
michael@0 35 register JSAMPLE * range_limit = cinfo->sample_range_limit;
michael@0 36 int * Crrtab = upsample->Cr_r_tab;
michael@0 37 int * Cbbtab = upsample->Cb_b_tab;
michael@0 38 INT32 * Crgtab = upsample->Cr_g_tab;
michael@0 39 INT32 * Cbgtab = upsample->Cb_g_tab;
michael@0 40 SHIFT_TEMPS
michael@0 41
michael@0 42 inptr0 = input_buf[0][in_row_group_ctr];
michael@0 43 inptr1 = input_buf[1][in_row_group_ctr];
michael@0 44 inptr2 = input_buf[2][in_row_group_ctr];
michael@0 45 outptr = output_buf[0];
michael@0 46 /* Loop for each pair of output pixels */
michael@0 47 for (col = cinfo->output_width >> 1; col > 0; col--) {
michael@0 48 /* Do the chroma part of the calculation */
michael@0 49 cb = GETJSAMPLE(*inptr1++);
michael@0 50 cr = GETJSAMPLE(*inptr2++);
michael@0 51 cred = Crrtab[cr];
michael@0 52 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
michael@0 53 cblue = Cbbtab[cb];
michael@0 54 /* Fetch 2 Y values and emit 2 pixels */
michael@0 55 y = GETJSAMPLE(*inptr0++);
michael@0 56 outptr[RGB_RED] = range_limit[y + cred];
michael@0 57 outptr[RGB_GREEN] = range_limit[y + cgreen];
michael@0 58 outptr[RGB_BLUE] = range_limit[y + cblue];
michael@0 59 #ifdef RGB_ALPHA
michael@0 60 outptr[RGB_ALPHA] = 0xFF;
michael@0 61 #endif
michael@0 62 outptr += RGB_PIXELSIZE;
michael@0 63 y = GETJSAMPLE(*inptr0++);
michael@0 64 outptr[RGB_RED] = range_limit[y + cred];
michael@0 65 outptr[RGB_GREEN] = range_limit[y + cgreen];
michael@0 66 outptr[RGB_BLUE] = range_limit[y + cblue];
michael@0 67 #ifdef RGB_ALPHA
michael@0 68 outptr[RGB_ALPHA] = 0xFF;
michael@0 69 #endif
michael@0 70 outptr += RGB_PIXELSIZE;
michael@0 71 }
michael@0 72 /* If image width is odd, do the last output column separately */
michael@0 73 if (cinfo->output_width & 1) {
michael@0 74 cb = GETJSAMPLE(*inptr1);
michael@0 75 cr = GETJSAMPLE(*inptr2);
michael@0 76 cred = Crrtab[cr];
michael@0 77 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
michael@0 78 cblue = Cbbtab[cb];
michael@0 79 y = GETJSAMPLE(*inptr0);
michael@0 80 outptr[RGB_RED] = range_limit[y + cred];
michael@0 81 outptr[RGB_GREEN] = range_limit[y + cgreen];
michael@0 82 outptr[RGB_BLUE] = range_limit[y + cblue];
michael@0 83 #ifdef RGB_ALPHA
michael@0 84 outptr[RGB_ALPHA] = 0xFF;
michael@0 85 #endif
michael@0 86 }
michael@0 87 }
michael@0 88
michael@0 89
michael@0 90 /*
michael@0 91 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
michael@0 92 */
michael@0 93
michael@0 94 INLINE
michael@0 95 LOCAL(void)
michael@0 96 h2v2_merged_upsample_internal (j_decompress_ptr cinfo,
michael@0 97 JSAMPIMAGE input_buf,
michael@0 98 JDIMENSION in_row_group_ctr,
michael@0 99 JSAMPARRAY output_buf)
michael@0 100 {
michael@0 101 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
michael@0 102 register int y, cred, cgreen, cblue;
michael@0 103 int cb, cr;
michael@0 104 register JSAMPROW outptr0, outptr1;
michael@0 105 JSAMPROW inptr00, inptr01, inptr1, inptr2;
michael@0 106 JDIMENSION col;
michael@0 107 /* copy these pointers into registers if possible */
michael@0 108 register JSAMPLE * range_limit = cinfo->sample_range_limit;
michael@0 109 int * Crrtab = upsample->Cr_r_tab;
michael@0 110 int * Cbbtab = upsample->Cb_b_tab;
michael@0 111 INT32 * Crgtab = upsample->Cr_g_tab;
michael@0 112 INT32 * Cbgtab = upsample->Cb_g_tab;
michael@0 113 SHIFT_TEMPS
michael@0 114
michael@0 115 inptr00 = input_buf[0][in_row_group_ctr*2];
michael@0 116 inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
michael@0 117 inptr1 = input_buf[1][in_row_group_ctr];
michael@0 118 inptr2 = input_buf[2][in_row_group_ctr];
michael@0 119 outptr0 = output_buf[0];
michael@0 120 outptr1 = output_buf[1];
michael@0 121 /* Loop for each group of output pixels */
michael@0 122 for (col = cinfo->output_width >> 1; col > 0; col--) {
michael@0 123 /* Do the chroma part of the calculation */
michael@0 124 cb = GETJSAMPLE(*inptr1++);
michael@0 125 cr = GETJSAMPLE(*inptr2++);
michael@0 126 cred = Crrtab[cr];
michael@0 127 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
michael@0 128 cblue = Cbbtab[cb];
michael@0 129 /* Fetch 4 Y values and emit 4 pixels */
michael@0 130 y = GETJSAMPLE(*inptr00++);
michael@0 131 outptr0[RGB_RED] = range_limit[y + cred];
michael@0 132 outptr0[RGB_GREEN] = range_limit[y + cgreen];
michael@0 133 outptr0[RGB_BLUE] = range_limit[y + cblue];
michael@0 134 #ifdef RGB_ALPHA
michael@0 135 outptr0[RGB_ALPHA] = 0xFF;
michael@0 136 #endif
michael@0 137 outptr0 += RGB_PIXELSIZE;
michael@0 138 y = GETJSAMPLE(*inptr00++);
michael@0 139 outptr0[RGB_RED] = range_limit[y + cred];
michael@0 140 outptr0[RGB_GREEN] = range_limit[y + cgreen];
michael@0 141 outptr0[RGB_BLUE] = range_limit[y + cblue];
michael@0 142 #ifdef RGB_ALPHA
michael@0 143 outptr0[RGB_ALPHA] = 0xFF;
michael@0 144 #endif
michael@0 145 outptr0 += RGB_PIXELSIZE;
michael@0 146 y = GETJSAMPLE(*inptr01++);
michael@0 147 outptr1[RGB_RED] = range_limit[y + cred];
michael@0 148 outptr1[RGB_GREEN] = range_limit[y + cgreen];
michael@0 149 outptr1[RGB_BLUE] = range_limit[y + cblue];
michael@0 150 #ifdef RGB_ALPHA
michael@0 151 outptr1[RGB_ALPHA] = 0xFF;
michael@0 152 #endif
michael@0 153 outptr1 += RGB_PIXELSIZE;
michael@0 154 y = GETJSAMPLE(*inptr01++);
michael@0 155 outptr1[RGB_RED] = range_limit[y + cred];
michael@0 156 outptr1[RGB_GREEN] = range_limit[y + cgreen];
michael@0 157 outptr1[RGB_BLUE] = range_limit[y + cblue];
michael@0 158 #ifdef RGB_ALPHA
michael@0 159 outptr1[RGB_ALPHA] = 0xFF;
michael@0 160 #endif
michael@0 161 outptr1 += RGB_PIXELSIZE;
michael@0 162 }
michael@0 163 /* If image width is odd, do the last output column separately */
michael@0 164 if (cinfo->output_width & 1) {
michael@0 165 cb = GETJSAMPLE(*inptr1);
michael@0 166 cr = GETJSAMPLE(*inptr2);
michael@0 167 cred = Crrtab[cr];
michael@0 168 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
michael@0 169 cblue = Cbbtab[cb];
michael@0 170 y = GETJSAMPLE(*inptr00);
michael@0 171 outptr0[RGB_RED] = range_limit[y + cred];
michael@0 172 outptr0[RGB_GREEN] = range_limit[y + cgreen];
michael@0 173 outptr0[RGB_BLUE] = range_limit[y + cblue];
michael@0 174 #ifdef RGB_ALPHA
michael@0 175 outptr0[RGB_ALPHA] = 0xFF;
michael@0 176 #endif
michael@0 177 y = GETJSAMPLE(*inptr01);
michael@0 178 outptr1[RGB_RED] = range_limit[y + cred];
michael@0 179 outptr1[RGB_GREEN] = range_limit[y + cgreen];
michael@0 180 outptr1[RGB_BLUE] = range_limit[y + cblue];
michael@0 181 #ifdef RGB_ALPHA
michael@0 182 outptr1[RGB_ALPHA] = 0xFF;
michael@0 183 #endif
michael@0 184 }
michael@0 185 }

mercurial