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