Coverage Report

Created: 2026-10-28 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libjpeg-turbo/src/jdcol565.c
Line
Count
Source
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, 2026, 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
#if BITS_IN_JSAMPLE != 16
25
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
26
  register int y, cb, cr;
27
  register _JSAMPROW outptr;
28
  register _JSAMPROW inptr0, inptr1, inptr2;
29
  register JDIMENSION col;
30
  /* copy these pointers into registers if possible */
31
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
32
  register int *Crrtab = cconvert->Cr_r_tab;
33
  register int *Cbbtab = cconvert->Cb_b_tab;
34
  register JLONG *Crgtab = cconvert->Cr_g_tab;
35
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
36
  SHIFT_TEMPS
37
38
0
  while (--num_rows >= 0) {
39
0
    JLONG rgb;
40
0
    unsigned int r, g, b;
41
0
    JDIMENSION num_cols = cinfo->output_width;
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
0
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
97
#endif
98
0
}
Unexecuted instantiation: jdcolor-8.c:ycc_rgb565_convert_be
Unexecuted instantiation: jdcolor-8.c:ycc_rgb565_convert_le
Unexecuted instantiation: jdcolor-12.c:ycc_rgb565_convert_be
Unexecuted instantiation: jdcolor-12.c:ycc_rgb565_convert_le
Unexecuted instantiation: jdcolor-16.c:ycc_rgb565_convert_be
Unexecuted instantiation: jdcolor-16.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
#if BITS_IN_JSAMPLE != 16
108
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
109
  register int y, cb, cr;
110
  register _JSAMPROW outptr;
111
  register _JSAMPROW inptr0, inptr1, inptr2;
112
  register int row;
113
  register JDIMENSION col;
114
  /* copy these pointers into registers if possible */
115
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
116
  register int *Crrtab = cconvert->Cr_r_tab;
117
  register int *Cbbtab = cconvert->Cb_b_tab;
118
  register JLONG *Crgtab = cconvert->Cr_g_tab;
119
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
120
  SHIFT_TEMPS
121
122
0
  for (row = 0; row < num_rows; row++) {
123
0
    JLONG rgb;
124
0
    unsigned int r, g, b;
125
0
    JDIMENSION num_cols = cinfo->output_width;
126
0
    JLONG d0 = dither_matrix[(cinfo->output_scanline + row) & DITHER_MASK];
127
128
0
    inptr0 = input_buf[0][input_row];
129
0
    inptr1 = input_buf[1][input_row];
130
0
    inptr2 = input_buf[2][input_row];
131
0
    input_row++;
132
0
    outptr = *output_buf++;
133
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
134
0
      y  = *inptr0++;
135
0
      cb = *inptr1++;
136
0
      cr = *inptr2++;
137
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
138
0
      g = range_limit[DITHER_565_G(y +
139
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
140
0
                                                     SCALEBITS)), d0)];
141
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
142
0
      d0 = DITHER_ROTATE(d0);
143
0
      rgb = PACK_SHORT_565(r, g, b);
144
0
      *(INT16 *)outptr = (INT16)rgb;
145
0
      outptr += 2;
146
0
      num_cols--;
147
0
    }
148
0
    for (col = 0; col < (num_cols >> 1); col++) {
149
0
      y  = *inptr0++;
150
0
      cb = *inptr1++;
151
0
      cr = *inptr2++;
152
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
153
0
      g = range_limit[DITHER_565_G(y +
154
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
155
0
                                                     SCALEBITS)), d0)];
156
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
157
0
      d0 = DITHER_ROTATE(d0);
158
0
      rgb = PACK_SHORT_565(r, g, b);
159
160
0
      y  = *inptr0++;
161
0
      cb = *inptr1++;
162
0
      cr = *inptr2++;
163
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
164
0
      g = range_limit[DITHER_565_G(y +
165
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
166
0
                                                     SCALEBITS)), d0)];
167
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
168
0
      d0 = DITHER_ROTATE(d0);
169
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
170
171
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
172
0
      outptr += 4;
173
0
    }
174
0
    if (num_cols & 1) {
175
0
      y  = *inptr0;
176
0
      cb = *inptr1;
177
0
      cr = *inptr2;
178
0
      r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
179
0
      g = range_limit[DITHER_565_G(y +
180
0
                                   ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
181
0
                                                     SCALEBITS)), d0)];
182
0
      b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
183
0
      rgb = PACK_SHORT_565(r, g, b);
184
0
      *(INT16 *)outptr = (INT16)rgb;
185
0
    }
186
0
  }
187
#else
188
0
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
189
#endif
190
0
}
Unexecuted instantiation: jdcolor-8.c:ycc_rgb565D_convert_be
Unexecuted instantiation: jdcolor-8.c:ycc_rgb565D_convert_le
Unexecuted instantiation: jdcolor-12.c:ycc_rgb565D_convert_be
Unexecuted instantiation: jdcolor-12.c:ycc_rgb565D_convert_le
Unexecuted instantiation: jdcolor-16.c:ycc_rgb565D_convert_be
Unexecuted instantiation: jdcolor-16.c:ycc_rgb565D_convert_le
191
192
193
INLINE
194
LOCAL(void)
195
rgb_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
196
                            JDIMENSION input_row, _JSAMPARRAY output_buf,
197
                            int num_rows)
198
0
{
199
0
  register _JSAMPROW outptr;
200
0
  register _JSAMPROW inptr0, inptr1, inptr2;
201
0
  register JDIMENSION col;
202
0
  SHIFT_TEMPS
203
204
0
  while (--num_rows >= 0) {
205
0
    JLONG rgb;
206
0
    unsigned int r, g, b;
207
0
    JDIMENSION num_cols = cinfo->output_width;
208
209
0
    inptr0 = input_buf[0][input_row];
210
0
    inptr1 = input_buf[1][input_row];
211
0
    inptr2 = input_buf[2][input_row];
212
0
    input_row++;
213
0
    outptr = *output_buf++;
214
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
215
0
      r = *inptr0++;
216
0
      g = *inptr1++;
217
0
      b = *inptr2++;
218
0
      rgb = PACK_SHORT_565(r, g, b);
219
0
      *(INT16 *)outptr = (INT16)rgb;
220
0
      outptr += 2;
221
0
      num_cols--;
222
0
    }
223
0
    for (col = 0; col < (num_cols >> 1); col++) {
224
0
      r = *inptr0++;
225
0
      g = *inptr1++;
226
0
      b = *inptr2++;
227
0
      rgb = PACK_SHORT_565(r, g, b);
228
229
0
      r = *inptr0++;
230
0
      g = *inptr1++;
231
0
      b = *inptr2++;
232
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
233
234
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
235
0
      outptr += 4;
236
0
    }
237
0
    if (num_cols & 1) {
238
0
      r = *inptr0;
239
0
      g = *inptr1;
240
0
      b = *inptr2;
241
0
      rgb = PACK_SHORT_565(r, g, b);
242
0
      *(INT16 *)outptr = (INT16)rgb;
243
0
    }
244
0
  }
245
0
}
Unexecuted instantiation: jdcolor-8.c:rgb_rgb565_convert_be
Unexecuted instantiation: jdcolor-8.c:rgb_rgb565_convert_le
Unexecuted instantiation: jdcolor-12.c:rgb_rgb565_convert_be
Unexecuted instantiation: jdcolor-12.c:rgb_rgb565_convert_le
Unexecuted instantiation: jdcolor-16.c:rgb_rgb565_convert_be
Unexecuted instantiation: jdcolor-16.c:rgb_rgb565_convert_le
246
247
248
INLINE
249
LOCAL(void)
250
rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
251
                             JDIMENSION input_row, _JSAMPARRAY output_buf,
252
                             int num_rows)
253
0
{
254
0
  register _JSAMPROW outptr;
255
0
  register _JSAMPROW inptr0, inptr1, inptr2;
256
0
  register int row;
257
0
  register JDIMENSION col;
258
0
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
259
0
  SHIFT_TEMPS
260
261
0
  for (row = 0; row < num_rows; row++) {
262
0
    JLONG rgb;
263
0
    unsigned int r, g, b;
264
0
    JDIMENSION num_cols = cinfo->output_width;
265
0
    JLONG d0 = dither_matrix[(cinfo->output_scanline + row) & DITHER_MASK];
266
267
0
    inptr0 = input_buf[0][input_row];
268
0
    inptr1 = input_buf[1][input_row];
269
0
    inptr2 = input_buf[2][input_row];
270
0
    input_row++;
271
0
    outptr = *output_buf++;
272
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
273
0
      r = range_limit[DITHER_565_R(*inptr0++, d0)];
274
0
      g = range_limit[DITHER_565_G(*inptr1++, d0)];
275
0
      b = range_limit[DITHER_565_B(*inptr2++, d0)];
276
0
      d0 = DITHER_ROTATE(d0);
277
0
      rgb = PACK_SHORT_565(r, g, b);
278
0
      *(INT16 *)outptr = (INT16)rgb;
279
0
      outptr += 2;
280
0
      num_cols--;
281
0
    }
282
0
    for (col = 0; col < (num_cols >> 1); col++) {
283
0
      r = range_limit[DITHER_565_R(*inptr0++, d0)];
284
0
      g = range_limit[DITHER_565_G(*inptr1++, d0)];
285
0
      b = range_limit[DITHER_565_B(*inptr2++, d0)];
286
0
      d0 = DITHER_ROTATE(d0);
287
0
      rgb = PACK_SHORT_565(r, g, b);
288
289
0
      r = range_limit[DITHER_565_R(*inptr0++, d0)];
290
0
      g = range_limit[DITHER_565_G(*inptr1++, d0)];
291
0
      b = range_limit[DITHER_565_B(*inptr2++, d0)];
292
0
      d0 = DITHER_ROTATE(d0);
293
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
294
295
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
296
0
      outptr += 4;
297
0
    }
298
0
    if (num_cols & 1) {
299
0
      r = range_limit[DITHER_565_R(*inptr0, d0)];
300
0
      g = range_limit[DITHER_565_G(*inptr1, d0)];
301
0
      b = range_limit[DITHER_565_B(*inptr2, d0)];
302
0
      rgb = PACK_SHORT_565(r, g, b);
303
0
      *(INT16 *)outptr = (INT16)rgb;
304
0
    }
305
0
  }
306
0
}
Unexecuted instantiation: jdcolor-8.c:rgb_rgb565D_convert_be
Unexecuted instantiation: jdcolor-8.c:rgb_rgb565D_convert_le
Unexecuted instantiation: jdcolor-12.c:rgb_rgb565D_convert_be
Unexecuted instantiation: jdcolor-12.c:rgb_rgb565D_convert_le
Unexecuted instantiation: jdcolor-16.c:rgb_rgb565D_convert_be
Unexecuted instantiation: jdcolor-16.c:rgb_rgb565D_convert_le
307
308
309
INLINE
310
LOCAL(void)
311
gray_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
312
                             JDIMENSION input_row, _JSAMPARRAY output_buf,
313
                             int num_rows)
314
0
{
315
0
  register _JSAMPROW inptr, outptr;
316
0
  register JDIMENSION col;
317
318
0
  while (--num_rows >= 0) {
319
0
    JLONG rgb;
320
0
    unsigned int g;
321
0
    JDIMENSION num_cols = cinfo->output_width;
322
323
0
    inptr = input_buf[0][input_row++];
324
0
    outptr = *output_buf++;
325
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
326
0
      g = *inptr++;
327
0
      rgb = PACK_SHORT_565(g, g, g);
328
0
      *(INT16 *)outptr = (INT16)rgb;
329
0
      outptr += 2;
330
0
      num_cols--;
331
0
    }
332
0
    for (col = 0; col < (num_cols >> 1); col++) {
333
0
      g = *inptr++;
334
0
      rgb = PACK_SHORT_565(g, g, g);
335
0
      g = *inptr++;
336
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
337
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
338
0
      outptr += 4;
339
0
    }
340
0
    if (num_cols & 1) {
341
0
      g = *inptr;
342
0
      rgb = PACK_SHORT_565(g, g, g);
343
0
      *(INT16 *)outptr = (INT16)rgb;
344
0
    }
345
0
  }
346
0
}
Unexecuted instantiation: jdcolor-8.c:gray_rgb565_convert_be
Unexecuted instantiation: jdcolor-8.c:gray_rgb565_convert_le
Unexecuted instantiation: jdcolor-12.c:gray_rgb565_convert_be
Unexecuted instantiation: jdcolor-12.c:gray_rgb565_convert_le
Unexecuted instantiation: jdcolor-16.c:gray_rgb565_convert_be
Unexecuted instantiation: jdcolor-16.c:gray_rgb565_convert_le
347
348
349
INLINE
350
LOCAL(void)
351
gray_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
352
                              JDIMENSION input_row, _JSAMPARRAY output_buf,
353
                              int num_rows)
354
0
{
355
0
  register _JSAMPROW inptr, outptr;
356
0
  register int row;
357
0
  register JDIMENSION col;
358
0
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
359
360
0
  for (row = 0; row < num_rows; row++) {
361
0
    JLONG rgb;
362
0
    unsigned int g;
363
0
    JDIMENSION num_cols = cinfo->output_width;
364
0
    JLONG d0 = dither_matrix[(cinfo->output_scanline + row) & DITHER_MASK];
365
366
0
    inptr = input_buf[0][input_row++];
367
0
    outptr = *output_buf++;
368
0
    if (PACK_NEED_ALIGNMENT(outptr)) {
369
0
      g = *inptr++;
370
0
      g = range_limit[DITHER_565_R(g, d0)];
371
0
      d0 = DITHER_ROTATE(d0);
372
0
      rgb = PACK_SHORT_565(g, g, g);
373
0
      *(INT16 *)outptr = (INT16)rgb;
374
0
      outptr += 2;
375
0
      num_cols--;
376
0
    }
377
0
    for (col = 0; col < (num_cols >> 1); col++) {
378
0
      g = *inptr++;
379
0
      g = range_limit[DITHER_565_R(g, d0)];
380
0
      rgb = PACK_SHORT_565(g, g, g);
381
0
      d0 = DITHER_ROTATE(d0);
382
383
0
      g = *inptr++;
384
0
      g = range_limit[DITHER_565_R(g, d0)];
385
0
      rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
386
0
      d0 = DITHER_ROTATE(d0);
387
388
0
      WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
389
0
      outptr += 4;
390
0
    }
391
0
    if (num_cols & 1) {
392
0
      g = *inptr;
393
0
      g = range_limit[DITHER_565_R(g, d0)];
394
0
      rgb = PACK_SHORT_565(g, g, g);
395
0
      *(INT16 *)outptr = (INT16)rgb;
396
0
    }
397
0
  }
398
0
}
Unexecuted instantiation: jdcolor-8.c:gray_rgb565D_convert_be
Unexecuted instantiation: jdcolor-8.c:gray_rgb565D_convert_le
Unexecuted instantiation: jdcolor-12.c:gray_rgb565D_convert_be
Unexecuted instantiation: jdcolor-12.c:gray_rgb565D_convert_le
Unexecuted instantiation: jdcolor-16.c:gray_rgb565D_convert_be
Unexecuted instantiation: jdcolor-16.c:gray_rgb565D_convert_le