Coverage Report

Created: 2024-08-27 12:18

/src/libjpeg-turbo.main/jdcol565.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jdcol565.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * Modifications:
7
 * Copyright (C) 2013, Linaro Limited.
8
 * Copyright (C) 2014-2015, 2022, D. R. Commander.
9
 * For conditions of distribution and use, see the accompanying README.ijg
10
 * file.
11
 *
12
 * This file contains output colorspace conversion routines.
13
 */
14
15
/* This file is included by jdcolor.c */
16
17
18
INLINE
19
LOCAL(void)
20
ycc_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
21
                            JDIMENSION input_row, _JSAMPARRAY output_buf,
22
                            int num_rows)
23
0
{
24
0
#if BITS_IN_JSAMPLE != 16
25
0
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
26
0
  register int y, cb, cr;
27
0
  register _JSAMPROW outptr;
28
0
  register _JSAMPROW inptr0, inptr1, inptr2;
29
0
  register JDIMENSION col;
30
0
  JDIMENSION num_cols = cinfo->output_width;
31
  /* copy these pointers into registers if possible */
32
0
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
33
0
  register int *Crrtab = cconvert->Cr_r_tab;
34
0
  register int *Cbbtab = cconvert->Cb_b_tab;
35
0
  register JLONG *Crgtab = cconvert->Cr_g_tab;
36
0
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
37
0
  SHIFT_TEMPS
38
39
0
  while (--num_rows >= 0) {
40
0
    JLONG rgb;
41
0
    unsigned int r, g, b;
42
0
    inptr0 = input_buf[0][input_row];
43
0
    inptr1 = input_buf[1][input_row];
44
0
    inptr2 = input_buf[2][input_row];
45
0
    input_row++;
46
0
    outptr = *output_buf++;
47
48
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
49
0
      y  = *inptr0++;
50
0
      cb = *inptr1++;
51
0
      cr = *inptr2++;
52
0
      r = range_limit[y + Crrtab[cr]];
53
0
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
54
0
                                            SCALEBITS))];
55
0
      b = range_limit[y + Cbbtab[cb]];
56
0
      rgb = PACK_SHORT_565(r, g, b);
57
0
      *(INT16 *)outptr = (INT16)rgb;
58
0
      outptr += 2;
59
0
      num_cols--;
60
0
    }
61
0
    for (col = 0; col < (num_cols >> 1); col++) {
62
0
      y  = *inptr0++;
63
0
      cb = *inptr1++;
64
0
      cr = *inptr2++;
65
0
      r = range_limit[y + Crrtab[cr]];
66
0
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
67
0
                                            SCALEBITS))];
68
0
      b = range_limit[y + Cbbtab[cb]];
69
0
      rgb = PACK_SHORT_565(r, g, b);
70
71
0
      y  = *inptr0++;
72
0
      cb = *inptr1++;
73
0
      cr = *inptr2++;
74
0
      r = range_limit[y + Crrtab[cr]];
75
0
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
76
0
                                            SCALEBITS))];
77
0
      b = range_limit[y + Cbbtab[cb]];
78
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
79
80
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
81
0
      outptr += 4;
82
0
    }
83
0
    if (num_cols & 1) {
84
0
      y  = *inptr0;
85
0
      cb = *inptr1;
86
0
      cr = *inptr2;
87
0
      r = range_limit[y + Crrtab[cr]];
88
0
      g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
89
0
                                            SCALEBITS))];
90
0
      b = range_limit[y + Cbbtab[cb]];
91
0
      rgb = PACK_SHORT_565(r, g, b);
92
0
      *(INT16 *)outptr = (INT16)rgb;
93
0
    }
94
0
  }
95
#else
96
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
97
#endif
98
0
}
Unexecuted instantiation: jdcolor.c:ycc_rgb565_convert_be
Unexecuted instantiation: jdcolor.c:ycc_rgb565_convert_le
99
100
101
INLINE
102
LOCAL(void)
103
ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
104
                             JDIMENSION input_row, _JSAMPARRAY output_buf,
105
                             int num_rows)
106
0
{
107
0
#if BITS_IN_JSAMPLE != 16
108
0
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
109
0
  register int y, cb, cr;
110
0
  register _JSAMPROW outptr;
111
0
  register _JSAMPROW inptr0, inptr1, inptr2;
112
0
  register JDIMENSION col;
113
0
  JDIMENSION num_cols = cinfo->output_width;
114
  /* copy these pointers into registers if possible */
115
0
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
116
0
  register int *Crrtab = cconvert->Cr_r_tab;
117
0
  register int *Cbbtab = cconvert->Cb_b_tab;
118
0
  register JLONG *Crgtab = cconvert->Cr_g_tab;
119
0
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
120
0
  JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
121
0
  SHIFT_TEMPS
122
123
0
  while (--num_rows >= 0) {
124
0
    JLONG rgb;
125
0
    unsigned int r, g, b;
126
127
0
    inptr0 = input_buf[0][input_row];
128
0
    inptr1 = input_buf[1][input_row];
129
0
    inptr2 = input_buf[2][input_row];
130
0
    input_row++;
131
0
    outptr = *output_buf++;
132
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
133
0
      y  = *inptr0++;
134
0
      cb = *inptr1++;
135
0
      cr = *inptr2++;
136
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
137
0
      g = range_limit[DITHER_565_G(y +
138
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
139
0
                                                     SCALEBITS)), d0)];
140
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
141
0
      rgb = PACK_SHORT_565(r, g, b);
142
0
      *(INT16 *)outptr = (INT16)rgb;
143
0
      outptr += 2;
144
0
      num_cols--;
145
0
    }
146
0
    for (col = 0; col < (num_cols >> 1); col++) {
147
0
      y  = *inptr0++;
148
0
      cb = *inptr1++;
149
0
      cr = *inptr2++;
150
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
151
0
      g = range_limit[DITHER_565_G(y +
152
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
153
0
                                                     SCALEBITS)), d0)];
154
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
155
0
      d0 = DITHER_ROTATE(d0);
156
0
      rgb = PACK_SHORT_565(r, g, b);
157
158
0
      y  = *inptr0++;
159
0
      cb = *inptr1++;
160
0
      cr = *inptr2++;
161
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
162
0
      g = range_limit[DITHER_565_G(y +
163
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
164
0
                                                     SCALEBITS)), d0)];
165
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
166
0
      d0 = DITHER_ROTATE(d0);
167
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
168
169
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
170
0
      outptr += 4;
171
0
    }
172
0
    if (num_cols & 1) {
173
0
      y  = *inptr0;
174
0
      cb = *inptr1;
175
0
      cr = *inptr2;
176
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
177
0
      g = range_limit[DITHER_565_G(y +
178
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
179
0
                                                     SCALEBITS)), d0)];
180
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
181
0
      rgb = PACK_SHORT_565(r, g, b);
182
0
      *(INT16 *)outptr = (INT16)rgb;
183
0
    }
184
0
  }
185
#else
186
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
187
#endif
188
0
}
Unexecuted instantiation: jdcolor.c:ycc_rgb565D_convert_be
Unexecuted instantiation: jdcolor.c:ycc_rgb565D_convert_le
189
190
191
INLINE
192
LOCAL(void)
193
rgb_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
194
                            JDIMENSION input_row, _JSAMPARRAY output_buf,
195
                            int num_rows)
196
0
{
197
0
  register _JSAMPROW outptr;
198
0
  register _JSAMPROW inptr0, inptr1, inptr2;
199
0
  register JDIMENSION col;
200
0
  JDIMENSION num_cols = cinfo->output_width;
201
0
  SHIFT_TEMPS
202
203
0
  while (--num_rows >= 0) {
204
0
    JLONG rgb;
205
0
    unsigned int r, g, b;
206
207
0
    inptr0 = input_buf[0][input_row];
208
0
    inptr1 = input_buf[1][input_row];
209
0
    inptr2 = input_buf[2][input_row];
210
0
    input_row++;
211
0
    outptr = *output_buf++;
212
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
213
0
      r = *inptr0++;
214
0
      g = *inptr1++;
215
0
      b = *inptr2++;
216
0
      rgb = PACK_SHORT_565(r, g, b);
217
0
      *(INT16 *)outptr = (INT16)rgb;
218
0
      outptr += 2;
219
0
      num_cols--;
220
0
    }
221
0
    for (col = 0; col < (num_cols >> 1); col++) {
222
0
      r = *inptr0++;
223
0
      g = *inptr1++;
224
0
      b = *inptr2++;
225
0
      rgb = PACK_SHORT_565(r, g, b);
226
227
0
      r = *inptr0++;
228
0
      g = *inptr1++;
229
0
      b = *inptr2++;
230
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
231
232
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
233
0
      outptr += 4;
234
0
    }
235
0
    if (num_cols & 1) {
236
0
      r = *inptr0;
237
0
      g = *inptr1;
238
0
      b = *inptr2;
239
0
      rgb = PACK_SHORT_565(r, g, b);
240
0
      *(INT16 *)outptr = (INT16)rgb;
241
0
    }
242
0
  }
243
0
}
Unexecuted instantiation: jdcolor.c:rgb_rgb565_convert_be
Unexecuted instantiation: jdcolor.c:rgb_rgb565_convert_le
244
245
246
INLINE
247
LOCAL(void)
248
rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
249
                             JDIMENSION input_row, _JSAMPARRAY output_buf,
250
                             int num_rows)
251
0
{
252
0
  register _JSAMPROW outptr;
253
0
  register _JSAMPROW inptr0, inptr1, inptr2;
254
0
  register JDIMENSION col;
255
0
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
256
0
  JDIMENSION num_cols = cinfo->output_width;
257
0
  JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
258
0
  SHIFT_TEMPS
259
260
0
  while (--num_rows >= 0) {
261
0
    JLONG rgb;
262
0
    unsigned int r, g, b;
263
264
0
    inptr0 = input_buf[0][input_row];
265
0
    inptr1 = input_buf[1][input_row];
266
0
    inptr2 = input_buf[2][input_row];
267
0
    input_row++;
268
0
    outptr = *output_buf++;
269
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
270
0
      r = range_limit[DITHER_565_R(*inptr0++, d0)];
271
0
      g = range_limit[DITHER_565_G(*inptr1++, d0)];
272
0
      b = range_limit[DITHER_565_B(*inptr2++, d0)];
273
0
      rgb = PACK_SHORT_565(r, g, b);
274
0
      *(INT16 *)outptr = (INT16)rgb;
275
0
      outptr += 2;
276
0
      num_cols--;
277
0
    }
278
0
    for (col = 0; col < (num_cols >> 1); col++) {
279
0
      r = range_limit[DITHER_565_R(*inptr0++, d0)];
280
0
      g = range_limit[DITHER_565_G(*inptr1++, d0)];
281
0
      b = range_limit[DITHER_565_B(*inptr2++, d0)];
282
0
      d0 = DITHER_ROTATE(d0);
283
0
      rgb = PACK_SHORT_565(r, g, b);
284
285
0
      r = range_limit[DITHER_565_R(*inptr0++, d0)];
286
0
      g = range_limit[DITHER_565_G(*inptr1++, d0)];
287
0
      b = range_limit[DITHER_565_B(*inptr2++, d0)];
288
0
      d0 = DITHER_ROTATE(d0);
289
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
290
291
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
292
0
      outptr += 4;
293
0
    }
294
0
    if (num_cols & 1) {
295
0
      r = range_limit[DITHER_565_R(*inptr0, d0)];
296
0
      g = range_limit[DITHER_565_G(*inptr1, d0)];
297
0
      b = range_limit[DITHER_565_B(*inptr2, d0)];
298
0
      rgb = PACK_SHORT_565(r, g, b);
299
0
      *(INT16 *)outptr = (INT16)rgb;
300
0
    }
301
0
  }
302
0
}
Unexecuted instantiation: jdcolor.c:rgb_rgb565D_convert_be
Unexecuted instantiation: jdcolor.c:rgb_rgb565D_convert_le
303
304
305
INLINE
306
LOCAL(void)
307
gray_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
308
                             JDIMENSION input_row, _JSAMPARRAY output_buf,
309
                             int num_rows)
310
0
{
311
0
  register _JSAMPROW inptr, outptr;
312
0
  register JDIMENSION col;
313
0
  JDIMENSION num_cols = cinfo->output_width;
314
315
0
  while (--num_rows >= 0) {
316
0
    JLONG rgb;
317
0
    unsigned int g;
318
319
0
    inptr = input_buf[0][input_row++];
320
0
    outptr = *output_buf++;
321
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
322
0
      g = *inptr++;
323
0
      rgb = PACK_SHORT_565(g, g, g);
324
0
      *(INT16 *)outptr = (INT16)rgb;
325
0
      outptr += 2;
326
0
      num_cols--;
327
0
    }
328
0
    for (col = 0; col < (num_cols >> 1); col++) {
329
0
      g = *inptr++;
330
0
      rgb = PACK_SHORT_565(g, g, g);
331
0
      g = *inptr++;
332
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
333
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
334
0
      outptr += 4;
335
0
    }
336
0
    if (num_cols & 1) {
337
0
      g = *inptr;
338
0
      rgb = PACK_SHORT_565(g, g, g);
339
0
      *(INT16 *)outptr = (INT16)rgb;
340
0
    }
341
0
  }
342
0
}
Unexecuted instantiation: jdcolor.c:gray_rgb565_convert_be
Unexecuted instantiation: jdcolor.c:gray_rgb565_convert_le
343
344
345
INLINE
346
LOCAL(void)
347
gray_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
348
                              JDIMENSION input_row, _JSAMPARRAY output_buf,
349
                              int num_rows)
350
0
{
351
0
  register _JSAMPROW inptr, outptr;
352
0
  register JDIMENSION col;
353
0
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
354
0
  JDIMENSION num_cols = cinfo->output_width;
355
0
  JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
356
357
0
  while (--num_rows >= 0) {
358
0
    JLONG rgb;
359
0
    unsigned int g;
360
361
0
    inptr = input_buf[0][input_row++];
362
0
    outptr = *output_buf++;
363
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
364
0
      g = *inptr++;
365
0
      g = range_limit[DITHER_565_R(g, d0)];
366
0
      rgb = PACK_SHORT_565(g, g, g);
367
0
      *(INT16 *)outptr = (INT16)rgb;
368
0
      outptr += 2;
369
0
      num_cols--;
370
0
    }
371
0
    for (col = 0; col < (num_cols >> 1); col++) {
372
0
      g = *inptr++;
373
0
      g = range_limit[DITHER_565_R(g, d0)];
374
0
      rgb = PACK_SHORT_565(g, g, g);
375
0
      d0 = DITHER_ROTATE(d0);
376
377
0
      g = *inptr++;
378
0
      g = range_limit[DITHER_565_R(g, d0)];
379
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
380
0
      d0 = DITHER_ROTATE(d0);
381
382
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
383
0
      outptr += 4;
384
0
    }
385
0
    if (num_cols & 1) {
386
0
      g = *inptr;
387
0
      g = range_limit[DITHER_565_R(g, d0)];
388
0
      rgb = PACK_SHORT_565(g, g, g);
389
0
      *(INT16 *)outptr = (INT16)rgb;
390
0
    }
391
0
  }
392
0
}
Unexecuted instantiation: jdcolor.c:gray_rgb565D_convert_be
Unexecuted instantiation: jdcolor.c:gray_rgb565D_convert_le