/src/libjpeg-turbo.main/jdmrg565.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * jdmrg565.c |
3 | | * |
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) 2013, Linaro Limited. |
8 | | * Copyright (C) 2014-2015, 2018, 2020, D. R. Commander. |
9 | | * For conditions of distribution and use, see the accompanying README.ijg |
10 | | * file. |
11 | | * |
12 | | * This file contains code for merged upsampling/color conversion. |
13 | | */ |
14 | | |
15 | | |
16 | | INLINE |
17 | | LOCAL(void) |
18 | | h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, |
19 | | JDIMENSION in_row_group_ctr, |
20 | | JSAMPARRAY output_buf) |
21 | 0 | { |
22 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
23 | 0 | register int y, cred, cgreen, cblue; |
24 | 0 | int cb, cr; |
25 | 0 | register JSAMPROW outptr; |
26 | 0 | JSAMPROW inptr0, inptr1, inptr2; |
27 | 0 | JDIMENSION col; |
28 | | /* copy these pointers into registers if possible */ |
29 | 0 | register JSAMPLE *range_limit = cinfo->sample_range_limit; |
30 | 0 | int *Crrtab = upsample->Cr_r_tab; |
31 | 0 | int *Cbbtab = upsample->Cb_b_tab; |
32 | 0 | JLONG *Crgtab = upsample->Cr_g_tab; |
33 | 0 | JLONG *Cbgtab = upsample->Cb_g_tab; |
34 | 0 | unsigned int r, g, b; |
35 | 0 | JLONG rgb; |
36 | 0 | SHIFT_TEMPS |
37 | |
|
38 | 0 | inptr0 = input_buf[0][in_row_group_ctr]; |
39 | 0 | inptr1 = input_buf[1][in_row_group_ctr]; |
40 | 0 | inptr2 = input_buf[2][in_row_group_ctr]; |
41 | 0 | outptr = output_buf[0]; |
42 | | |
43 | | /* Loop for each pair of output pixels */ |
44 | 0 | for (col = cinfo->output_width >> 1; col > 0; col--) { |
45 | | /* Do the chroma part of the calculation */ |
46 | 0 | cb = *inptr1++; |
47 | 0 | cr = *inptr2++; |
48 | 0 | cred = Crrtab[cr]; |
49 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
50 | 0 | cblue = Cbbtab[cb]; |
51 | | |
52 | | /* Fetch 2 Y values and emit 2 pixels */ |
53 | 0 | y = *inptr0++; |
54 | 0 | r = range_limit[y + cred]; |
55 | 0 | g = range_limit[y + cgreen]; |
56 | 0 | b = range_limit[y + cblue]; |
57 | 0 | rgb = PACK_SHORT_565(r, g, b); |
58 | |
|
59 | 0 | y = *inptr0++; |
60 | 0 | r = range_limit[y + cred]; |
61 | 0 | g = range_limit[y + cgreen]; |
62 | 0 | b = range_limit[y + cblue]; |
63 | 0 | rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); |
64 | |
|
65 | 0 | WRITE_TWO_PIXELS(outptr, rgb); |
66 | 0 | outptr += 4; |
67 | 0 | } |
68 | | |
69 | | /* If image width is odd, do the last output column separately */ |
70 | 0 | if (cinfo->output_width & 1) { |
71 | 0 | cb = *inptr1; |
72 | 0 | cr = *inptr2; |
73 | 0 | cred = Crrtab[cr]; |
74 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
75 | 0 | cblue = Cbbtab[cb]; |
76 | 0 | y = *inptr0; |
77 | 0 | r = range_limit[y + cred]; |
78 | 0 | g = range_limit[y + cgreen]; |
79 | 0 | b = range_limit[y + cblue]; |
80 | 0 | rgb = PACK_SHORT_565(r, g, b); |
81 | 0 | *(INT16 *)outptr = (INT16)rgb; |
82 | 0 | } |
83 | 0 | } Unexecuted instantiation: jdmerge.c:h2v1_merged_upsample_565_be Unexecuted instantiation: jdmerge.c:h2v1_merged_upsample_565_le |
84 | | |
85 | | |
86 | | INLINE |
87 | | LOCAL(void) |
88 | | h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo, |
89 | | JSAMPIMAGE input_buf, |
90 | | JDIMENSION in_row_group_ctr, |
91 | | JSAMPARRAY output_buf) |
92 | 0 | { |
93 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
94 | 0 | register int y, cred, cgreen, cblue; |
95 | 0 | int cb, cr; |
96 | 0 | register JSAMPROW outptr; |
97 | 0 | JSAMPROW inptr0, inptr1, inptr2; |
98 | 0 | JDIMENSION col; |
99 | | /* copy these pointers into registers if possible */ |
100 | 0 | register JSAMPLE *range_limit = cinfo->sample_range_limit; |
101 | 0 | int *Crrtab = upsample->Cr_r_tab; |
102 | 0 | int *Cbbtab = upsample->Cb_b_tab; |
103 | 0 | JLONG *Crgtab = upsample->Cr_g_tab; |
104 | 0 | JLONG *Cbgtab = upsample->Cb_g_tab; |
105 | 0 | JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; |
106 | 0 | unsigned int r, g, b; |
107 | 0 | JLONG rgb; |
108 | 0 | SHIFT_TEMPS |
109 | |
|
110 | 0 | inptr0 = input_buf[0][in_row_group_ctr]; |
111 | 0 | inptr1 = input_buf[1][in_row_group_ctr]; |
112 | 0 | inptr2 = input_buf[2][in_row_group_ctr]; |
113 | 0 | outptr = output_buf[0]; |
114 | | |
115 | | /* Loop for each pair of output pixels */ |
116 | 0 | for (col = cinfo->output_width >> 1; col > 0; col--) { |
117 | | /* Do the chroma part of the calculation */ |
118 | 0 | cb = *inptr1++; |
119 | 0 | cr = *inptr2++; |
120 | 0 | cred = Crrtab[cr]; |
121 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
122 | 0 | cblue = Cbbtab[cb]; |
123 | | |
124 | | /* Fetch 2 Y values and emit 2 pixels */ |
125 | 0 | y = *inptr0++; |
126 | 0 | r = range_limit[DITHER_565_R(y + cred, d0)]; |
127 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d0)]; |
128 | 0 | b = range_limit[DITHER_565_B(y + cblue, d0)]; |
129 | 0 | d0 = DITHER_ROTATE(d0); |
130 | 0 | rgb = PACK_SHORT_565(r, g, b); |
131 | |
|
132 | 0 | y = *inptr0++; |
133 | 0 | r = range_limit[DITHER_565_R(y + cred, d0)]; |
134 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d0)]; |
135 | 0 | b = range_limit[DITHER_565_B(y + cblue, d0)]; |
136 | 0 | d0 = DITHER_ROTATE(d0); |
137 | 0 | rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); |
138 | |
|
139 | 0 | WRITE_TWO_PIXELS(outptr, rgb); |
140 | 0 | outptr += 4; |
141 | 0 | } |
142 | | |
143 | | /* If image width is odd, do the last output column separately */ |
144 | 0 | if (cinfo->output_width & 1) { |
145 | 0 | cb = *inptr1; |
146 | 0 | cr = *inptr2; |
147 | 0 | cred = Crrtab[cr]; |
148 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
149 | 0 | cblue = Cbbtab[cb]; |
150 | 0 | y = *inptr0; |
151 | 0 | r = range_limit[DITHER_565_R(y + cred, d0)]; |
152 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d0)]; |
153 | 0 | b = range_limit[DITHER_565_B(y + cblue, d0)]; |
154 | 0 | rgb = PACK_SHORT_565(r, g, b); |
155 | 0 | *(INT16 *)outptr = (INT16)rgb; |
156 | 0 | } |
157 | 0 | } Unexecuted instantiation: jdmerge.c:h2v1_merged_upsample_565D_be Unexecuted instantiation: jdmerge.c:h2v1_merged_upsample_565D_le |
158 | | |
159 | | |
160 | | INLINE |
161 | | LOCAL(void) |
162 | | h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, |
163 | | JDIMENSION in_row_group_ctr, |
164 | | JSAMPARRAY output_buf) |
165 | 0 | { |
166 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
167 | 0 | register int y, cred, cgreen, cblue; |
168 | 0 | int cb, cr; |
169 | 0 | register JSAMPROW outptr0, outptr1; |
170 | 0 | JSAMPROW inptr00, inptr01, inptr1, inptr2; |
171 | 0 | JDIMENSION col; |
172 | | /* copy these pointers into registers if possible */ |
173 | 0 | register JSAMPLE *range_limit = cinfo->sample_range_limit; |
174 | 0 | int *Crrtab = upsample->Cr_r_tab; |
175 | 0 | int *Cbbtab = upsample->Cb_b_tab; |
176 | 0 | JLONG *Crgtab = upsample->Cr_g_tab; |
177 | 0 | JLONG *Cbgtab = upsample->Cb_g_tab; |
178 | 0 | unsigned int r, g, b; |
179 | 0 | JLONG rgb; |
180 | 0 | SHIFT_TEMPS |
181 | |
|
182 | 0 | inptr00 = input_buf[0][in_row_group_ctr * 2]; |
183 | 0 | inptr01 = input_buf[0][in_row_group_ctr * 2 + 1]; |
184 | 0 | inptr1 = input_buf[1][in_row_group_ctr]; |
185 | 0 | inptr2 = input_buf[2][in_row_group_ctr]; |
186 | 0 | outptr0 = output_buf[0]; |
187 | 0 | outptr1 = output_buf[1]; |
188 | | |
189 | | /* Loop for each group of output pixels */ |
190 | 0 | for (col = cinfo->output_width >> 1; col > 0; col--) { |
191 | | /* Do the chroma part of the calculation */ |
192 | 0 | cb = *inptr1++; |
193 | 0 | cr = *inptr2++; |
194 | 0 | cred = Crrtab[cr]; |
195 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
196 | 0 | cblue = Cbbtab[cb]; |
197 | | |
198 | | /* Fetch 4 Y values and emit 4 pixels */ |
199 | 0 | y = *inptr00++; |
200 | 0 | r = range_limit[y + cred]; |
201 | 0 | g = range_limit[y + cgreen]; |
202 | 0 | b = range_limit[y + cblue]; |
203 | 0 | rgb = PACK_SHORT_565(r, g, b); |
204 | |
|
205 | 0 | y = *inptr00++; |
206 | 0 | r = range_limit[y + cred]; |
207 | 0 | g = range_limit[y + cgreen]; |
208 | 0 | b = range_limit[y + cblue]; |
209 | 0 | rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); |
210 | |
|
211 | 0 | WRITE_TWO_PIXELS(outptr0, rgb); |
212 | 0 | outptr0 += 4; |
213 | |
|
214 | 0 | y = *inptr01++; |
215 | 0 | r = range_limit[y + cred]; |
216 | 0 | g = range_limit[y + cgreen]; |
217 | 0 | b = range_limit[y + cblue]; |
218 | 0 | rgb = PACK_SHORT_565(r, g, b); |
219 | |
|
220 | 0 | y = *inptr01++; |
221 | 0 | r = range_limit[y + cred]; |
222 | 0 | g = range_limit[y + cgreen]; |
223 | 0 | b = range_limit[y + cblue]; |
224 | 0 | rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); |
225 | |
|
226 | 0 | WRITE_TWO_PIXELS(outptr1, rgb); |
227 | 0 | outptr1 += 4; |
228 | 0 | } |
229 | | |
230 | | /* If image width is odd, do the last output column separately */ |
231 | 0 | if (cinfo->output_width & 1) { |
232 | 0 | cb = *inptr1; |
233 | 0 | cr = *inptr2; |
234 | 0 | cred = Crrtab[cr]; |
235 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
236 | 0 | cblue = Cbbtab[cb]; |
237 | |
|
238 | 0 | y = *inptr00; |
239 | 0 | r = range_limit[y + cred]; |
240 | 0 | g = range_limit[y + cgreen]; |
241 | 0 | b = range_limit[y + cblue]; |
242 | 0 | rgb = PACK_SHORT_565(r, g, b); |
243 | 0 | *(INT16 *)outptr0 = (INT16)rgb; |
244 | |
|
245 | 0 | y = *inptr01; |
246 | 0 | r = range_limit[y + cred]; |
247 | 0 | g = range_limit[y + cgreen]; |
248 | 0 | b = range_limit[y + cblue]; |
249 | 0 | rgb = PACK_SHORT_565(r, g, b); |
250 | 0 | *(INT16 *)outptr1 = (INT16)rgb; |
251 | 0 | } |
252 | 0 | } Unexecuted instantiation: jdmerge.c:h2v2_merged_upsample_565_be Unexecuted instantiation: jdmerge.c:h2v2_merged_upsample_565_le |
253 | | |
254 | | |
255 | | INLINE |
256 | | LOCAL(void) |
257 | | h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo, |
258 | | JSAMPIMAGE input_buf, |
259 | | JDIMENSION in_row_group_ctr, |
260 | | JSAMPARRAY output_buf) |
261 | 0 | { |
262 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
263 | 0 | register int y, cred, cgreen, cblue; |
264 | 0 | int cb, cr; |
265 | 0 | register JSAMPROW outptr0, outptr1; |
266 | 0 | JSAMPROW inptr00, inptr01, inptr1, inptr2; |
267 | 0 | JDIMENSION col; |
268 | | /* copy these pointers into registers if possible */ |
269 | 0 | register JSAMPLE *range_limit = cinfo->sample_range_limit; |
270 | 0 | int *Crrtab = upsample->Cr_r_tab; |
271 | 0 | int *Cbbtab = upsample->Cb_b_tab; |
272 | 0 | JLONG *Crgtab = upsample->Cr_g_tab; |
273 | 0 | JLONG *Cbgtab = upsample->Cb_g_tab; |
274 | 0 | JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; |
275 | 0 | JLONG d1 = dither_matrix[(cinfo->output_scanline + 1) & DITHER_MASK]; |
276 | 0 | unsigned int r, g, b; |
277 | 0 | JLONG rgb; |
278 | 0 | SHIFT_TEMPS |
279 | |
|
280 | 0 | inptr00 = input_buf[0][in_row_group_ctr * 2]; |
281 | 0 | inptr01 = input_buf[0][in_row_group_ctr * 2 + 1]; |
282 | 0 | inptr1 = input_buf[1][in_row_group_ctr]; |
283 | 0 | inptr2 = input_buf[2][in_row_group_ctr]; |
284 | 0 | outptr0 = output_buf[0]; |
285 | 0 | outptr1 = output_buf[1]; |
286 | | |
287 | | /* Loop for each group of output pixels */ |
288 | 0 | for (col = cinfo->output_width >> 1; col > 0; col--) { |
289 | | /* Do the chroma part of the calculation */ |
290 | 0 | cb = *inptr1++; |
291 | 0 | cr = *inptr2++; |
292 | 0 | cred = Crrtab[cr]; |
293 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
294 | 0 | cblue = Cbbtab[cb]; |
295 | | |
296 | | /* Fetch 4 Y values and emit 4 pixels */ |
297 | 0 | y = *inptr00++; |
298 | 0 | r = range_limit[DITHER_565_R(y + cred, d0)]; |
299 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d0)]; |
300 | 0 | b = range_limit[DITHER_565_B(y + cblue, d0)]; |
301 | 0 | d0 = DITHER_ROTATE(d0); |
302 | 0 | rgb = PACK_SHORT_565(r, g, b); |
303 | |
|
304 | 0 | y = *inptr00++; |
305 | 0 | r = range_limit[DITHER_565_R(y + cred, d0)]; |
306 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d0)]; |
307 | 0 | b = range_limit[DITHER_565_B(y + cblue, d0)]; |
308 | 0 | d0 = DITHER_ROTATE(d0); |
309 | 0 | rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); |
310 | |
|
311 | 0 | WRITE_TWO_PIXELS(outptr0, rgb); |
312 | 0 | outptr0 += 4; |
313 | |
|
314 | 0 | y = *inptr01++; |
315 | 0 | r = range_limit[DITHER_565_R(y + cred, d1)]; |
316 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d1)]; |
317 | 0 | b = range_limit[DITHER_565_B(y + cblue, d1)]; |
318 | 0 | d1 = DITHER_ROTATE(d1); |
319 | 0 | rgb = PACK_SHORT_565(r, g, b); |
320 | |
|
321 | 0 | y = *inptr01++; |
322 | 0 | r = range_limit[DITHER_565_R(y + cred, d1)]; |
323 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d1)]; |
324 | 0 | b = range_limit[DITHER_565_B(y + cblue, d1)]; |
325 | 0 | d1 = DITHER_ROTATE(d1); |
326 | 0 | rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); |
327 | |
|
328 | 0 | WRITE_TWO_PIXELS(outptr1, rgb); |
329 | 0 | outptr1 += 4; |
330 | 0 | } |
331 | | |
332 | | /* If image width is odd, do the last output column separately */ |
333 | 0 | if (cinfo->output_width & 1) { |
334 | 0 | cb = *inptr1; |
335 | 0 | cr = *inptr2; |
336 | 0 | cred = Crrtab[cr]; |
337 | 0 | cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); |
338 | 0 | cblue = Cbbtab[cb]; |
339 | |
|
340 | 0 | y = *inptr00; |
341 | 0 | r = range_limit[DITHER_565_R(y + cred, d0)]; |
342 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d0)]; |
343 | 0 | b = range_limit[DITHER_565_B(y + cblue, d0)]; |
344 | 0 | rgb = PACK_SHORT_565(r, g, b); |
345 | 0 | *(INT16 *)outptr0 = (INT16)rgb; |
346 | |
|
347 | 0 | y = *inptr01; |
348 | 0 | r = range_limit[DITHER_565_R(y + cred, d1)]; |
349 | 0 | g = range_limit[DITHER_565_G(y + cgreen, d1)]; |
350 | 0 | b = range_limit[DITHER_565_B(y + cblue, d1)]; |
351 | 0 | rgb = PACK_SHORT_565(r, g, b); |
352 | 0 | *(INT16 *)outptr1 = (INT16)rgb; |
353 | 0 | } |
354 | 0 | } Unexecuted instantiation: jdmerge.c:h2v2_merged_upsample_565D_be Unexecuted instantiation: jdmerge.c:h2v2_merged_upsample_565D_le |