Coverage Report

Created: 2025-12-14 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jdcolext.c
Line
Count
Source
1
/*
2
 * jdcolext.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright (C) 2009, 2011, 2015, 2022-2023, 2025, D. R. Commander.
8
 * For conditions of distribution and use, see the accompanying README.ijg
9
 * file.
10
 *
11
 * This file contains output colorspace conversion routines.
12
 */
13
14
15
/* This file is included by jdcolor.c */
16
17
18
/*
19
 * Convert some rows of samples to the output colorspace.
20
 *
21
 * Note that we change from noninterleaved, one-plane-per-component format
22
 * to interleaved-pixel format.  The output buffer is therefore three times
23
 * as wide as the input buffer.
24
 * A starting row offset is provided only for the input buffer.  The caller
25
 * can easily adjust the passed output_buf value to accommodate any row
26
 * offset required on that side.
27
 */
28
29
INLINE
30
LOCAL(void)
31
ycc_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
32
                JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
33
941k
{
34
#if BITS_IN_JSAMPLE != 16
35
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
36
  register int y, cb, cr;
37
  register _JSAMPROW outptr;
38
  register _JSAMPROW inptr0, inptr1, inptr2;
39
  register JDIMENSION col;
40
  JDIMENSION num_cols = cinfo->output_width;
41
  /* copy these pointers into registers if possible */
42
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
43
  register int *Crrtab = cconvert->Cr_r_tab;
44
  register int *Cbbtab = cconvert->Cb_b_tab;
45
  register JLONG *Crgtab = cconvert->Cr_g_tab;
46
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
47
  SHIFT_TEMPS
48
49
2.97M
  while (--num_rows >= 0) {
50
2.03M
    inptr0 = input_buf[0][input_row];
51
2.03M
    inptr1 = input_buf[1][input_row];
52
2.03M
    inptr2 = input_buf[2][input_row];
53
2.03M
    input_row++;
54
2.03M
    outptr = *output_buf++;
55
54.3M
    for (col = 0; col < num_cols; col++) {
56
52.2M
      y  = inptr0[col];
57
52.2M
      cb = inptr1[col];
58
52.2M
      cr = inptr2[col];
59
      /* Range-limiting is essential due to noise introduced by DCT losses. */
60
52.2M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
61
52.2M
      outptr[RGB_GREEN] = range_limit[y +
62
52.2M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
63
52.2M
                                                SCALEBITS))];
64
52.2M
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
65
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
66
      /* opaque alpha channel value */
67
#ifdef RGB_ALPHA
68
6.76M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
69
#endif
70
52.2M
      outptr += RGB_PIXELSIZE;
71
52.2M
    }
72
2.03M
  }
73
#else
74
0
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
75
#endif
76
941k
}
Unexecuted instantiation: jdcolor-8.c:ycc_extrgb_convert
Unexecuted instantiation: jdcolor-8.c:ycc_extrgbx_convert
Unexecuted instantiation: jdcolor-8.c:ycc_extbgr_convert
Unexecuted instantiation: jdcolor-8.c:ycc_extbgrx_convert
Unexecuted instantiation: jdcolor-8.c:ycc_extxbgr_convert
Unexecuted instantiation: jdcolor-8.c:ycc_extxrgb_convert
Unexecuted instantiation: jdcolor-8.c:ycc_rgb_convert
jdcolor-12.c:ycc_extrgb_convert
Line
Count
Source
33
751k
{
34
751k
#if BITS_IN_JSAMPLE != 16
35
751k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
36
751k
  register int y, cb, cr;
37
751k
  register _JSAMPROW outptr;
38
751k
  register _JSAMPROW inptr0, inptr1, inptr2;
39
751k
  register JDIMENSION col;
40
751k
  JDIMENSION num_cols = cinfo->output_width;
41
  /* copy these pointers into registers if possible */
42
751k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
43
751k
  register int *Crrtab = cconvert->Cr_r_tab;
44
751k
  register int *Cbbtab = cconvert->Cb_b_tab;
45
751k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
46
751k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
47
751k
  SHIFT_TEMPS
48
49
2.34M
  while (--num_rows >= 0) {
50
1.59M
    inptr0 = input_buf[0][input_row];
51
1.59M
    inptr1 = input_buf[1][input_row];
52
1.59M
    inptr2 = input_buf[2][input_row];
53
1.59M
    input_row++;
54
1.59M
    outptr = *output_buf++;
55
47.0M
    for (col = 0; col < num_cols; col++) {
56
45.5M
      y  = inptr0[col];
57
45.5M
      cb = inptr1[col];
58
45.5M
      cr = inptr2[col];
59
      /* Range-limiting is essential due to noise introduced by DCT losses. */
60
45.5M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
61
45.5M
      outptr[RGB_GREEN] = range_limit[y +
62
45.5M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
63
45.5M
                                                SCALEBITS))];
64
45.5M
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
65
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
66
      /* opaque alpha channel value */
67
#ifdef RGB_ALPHA
68
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
69
#endif
70
45.5M
      outptr += RGB_PIXELSIZE;
71
45.5M
    }
72
1.59M
  }
73
#else
74
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
75
#endif
76
751k
}
Unexecuted instantiation: jdcolor-12.c:ycc_extrgbx_convert
Unexecuted instantiation: jdcolor-12.c:ycc_extbgr_convert
jdcolor-12.c:ycc_extbgrx_convert
Line
Count
Source
33
189k
{
34
189k
#if BITS_IN_JSAMPLE != 16
35
189k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
36
189k
  register int y, cb, cr;
37
189k
  register _JSAMPROW outptr;
38
189k
  register _JSAMPROW inptr0, inptr1, inptr2;
39
189k
  register JDIMENSION col;
40
189k
  JDIMENSION num_cols = cinfo->output_width;
41
  /* copy these pointers into registers if possible */
42
189k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
43
189k
  register int *Crrtab = cconvert->Cr_r_tab;
44
189k
  register int *Cbbtab = cconvert->Cb_b_tab;
45
189k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
46
189k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
47
189k
  SHIFT_TEMPS
48
49
629k
  while (--num_rows >= 0) {
50
440k
    inptr0 = input_buf[0][input_row];
51
440k
    inptr1 = input_buf[1][input_row];
52
440k
    inptr2 = input_buf[2][input_row];
53
440k
    input_row++;
54
440k
    outptr = *output_buf++;
55
7.20M
    for (col = 0; col < num_cols; col++) {
56
6.76M
      y  = inptr0[col];
57
6.76M
      cb = inptr1[col];
58
6.76M
      cr = inptr2[col];
59
      /* Range-limiting is essential due to noise introduced by DCT losses. */
60
6.76M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
61
6.76M
      outptr[RGB_GREEN] = range_limit[y +
62
6.76M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
63
6.76M
                                                SCALEBITS))];
64
6.76M
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
65
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
66
      /* opaque alpha channel value */
67
6.76M
#ifdef RGB_ALPHA
68
6.76M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
69
6.76M
#endif
70
6.76M
      outptr += RGB_PIXELSIZE;
71
6.76M
    }
72
440k
  }
73
#else
74
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
75
#endif
76
189k
}
Unexecuted instantiation: jdcolor-12.c:ycc_extxbgr_convert
Unexecuted instantiation: jdcolor-12.c:ycc_extxrgb_convert
Unexecuted instantiation: jdcolor-12.c:ycc_rgb_convert
Unexecuted instantiation: jdcolor-16.c:ycc_extrgb_convert
Unexecuted instantiation: jdcolor-16.c:ycc_extrgbx_convert
Unexecuted instantiation: jdcolor-16.c:ycc_extbgr_convert
Unexecuted instantiation: jdcolor-16.c:ycc_extbgrx_convert
Unexecuted instantiation: jdcolor-16.c:ycc_extxbgr_convert
Unexecuted instantiation: jdcolor-16.c:ycc_extxrgb_convert
Unexecuted instantiation: jdcolor-16.c:ycc_rgb_convert
77
78
79
/*
80
 * Convert grayscale to RGB: just duplicate the graylevel three times.
81
 * This is provided to support applications that don't want to cope
82
 * with grayscale as a separate case.
83
 */
84
85
INLINE
86
LOCAL(void)
87
gray_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
88
                 JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
89
4.11M
{
90
4.11M
  register _JSAMPROW inptr, outptr;
91
4.11M
  register JDIMENSION col;
92
4.11M
  JDIMENSION num_cols = cinfo->output_width;
93
94
11.2M
  while (--num_rows >= 0) {
95
7.11M
    inptr = input_buf[0][input_row++];
96
7.11M
    outptr = *output_buf++;
97
596M
    for (col = 0; col < num_cols; col++) {
98
589M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
99
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
100
      /* opaque alpha channel value */
101
#ifdef RGB_ALPHA
102
20.2M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
103
#endif
104
589M
      outptr += RGB_PIXELSIZE;
105
589M
    }
106
7.11M
  }
107
4.11M
}
jdcolor-8.c:gray_extrgb_convert
Line
Count
Source
89
1.87M
{
90
1.87M
  register _JSAMPROW inptr, outptr;
91
1.87M
  register JDIMENSION col;
92
1.87M
  JDIMENSION num_cols = cinfo->output_width;
93
94
5.06M
  while (--num_rows >= 0) {
95
3.18M
    inptr = input_buf[0][input_row++];
96
3.18M
    outptr = *output_buf++;
97
319M
    for (col = 0; col < num_cols; col++) {
98
316M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
99
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
100
      /* opaque alpha channel value */
101
#ifdef RGB_ALPHA
102
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
103
#endif
104
316M
      outptr += RGB_PIXELSIZE;
105
316M
    }
106
3.18M
  }
107
1.87M
}
Unexecuted instantiation: jdcolor-8.c:gray_extrgbx_convert
Unexecuted instantiation: jdcolor-8.c:gray_extbgr_convert
jdcolor-8.c:gray_extbgrx_convert
Line
Count
Source
89
19.6k
{
90
19.6k
  register _JSAMPROW inptr, outptr;
91
19.6k
  register JDIMENSION col;
92
19.6k
  JDIMENSION num_cols = cinfo->output_width;
93
94
63.5k
  while (--num_rows >= 0) {
95
43.8k
    inptr = input_buf[0][input_row++];
96
43.8k
    outptr = *output_buf++;
97
3.77M
    for (col = 0; col < num_cols; col++) {
98
3.73M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
99
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
100
      /* opaque alpha channel value */
101
3.73M
#ifdef RGB_ALPHA
102
3.73M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
103
3.73M
#endif
104
3.73M
      outptr += RGB_PIXELSIZE;
105
3.73M
    }
106
43.8k
  }
107
19.6k
}
Unexecuted instantiation: jdcolor-8.c:gray_extxbgr_convert
Unexecuted instantiation: jdcolor-8.c:gray_extxrgb_convert
Unexecuted instantiation: jdcolor-8.c:gray_rgb_convert
jdcolor-12.c:gray_extrgb_convert
Line
Count
Source
89
2.00M
{
90
2.00M
  register _JSAMPROW inptr, outptr;
91
2.00M
  register JDIMENSION col;
92
2.00M
  JDIMENSION num_cols = cinfo->output_width;
93
94
5.51M
  while (--num_rows >= 0) {
95
3.50M
    inptr = input_buf[0][input_row++];
96
3.50M
    outptr = *output_buf++;
97
255M
    for (col = 0; col < num_cols; col++) {
98
252M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
99
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
100
      /* opaque alpha channel value */
101
#ifdef RGB_ALPHA
102
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
103
#endif
104
252M
      outptr += RGB_PIXELSIZE;
105
252M
    }
106
3.50M
  }
107
2.00M
}
Unexecuted instantiation: jdcolor-12.c:gray_extrgbx_convert
Unexecuted instantiation: jdcolor-12.c:gray_extbgr_convert
jdcolor-12.c:gray_extbgrx_convert
Line
Count
Source
89
211k
{
90
211k
  register _JSAMPROW inptr, outptr;
91
211k
  register JDIMENSION col;
92
211k
  JDIMENSION num_cols = cinfo->output_width;
93
94
595k
  while (--num_rows >= 0) {
95
383k
    inptr = input_buf[0][input_row++];
96
383k
    outptr = *output_buf++;
97
16.9M
    for (col = 0; col < num_cols; col++) {
98
16.5M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
99
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
100
      /* opaque alpha channel value */
101
16.5M
#ifdef RGB_ALPHA
102
16.5M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
103
16.5M
#endif
104
16.5M
      outptr += RGB_PIXELSIZE;
105
16.5M
    }
106
383k
  }
107
211k
}
Unexecuted instantiation: jdcolor-12.c:gray_extxbgr_convert
Unexecuted instantiation: jdcolor-12.c:gray_extxrgb_convert
Unexecuted instantiation: jdcolor-12.c:gray_rgb_convert
Unexecuted instantiation: jdcolor-16.c:gray_extrgb_convert
Unexecuted instantiation: jdcolor-16.c:gray_extrgbx_convert
Unexecuted instantiation: jdcolor-16.c:gray_extbgr_convert
Unexecuted instantiation: jdcolor-16.c:gray_extbgrx_convert
Unexecuted instantiation: jdcolor-16.c:gray_extxbgr_convert
Unexecuted instantiation: jdcolor-16.c:gray_extxrgb_convert
Unexecuted instantiation: jdcolor-16.c:gray_rgb_convert
108
109
110
/*
111
 * Convert RGB to extended RGB: just swap the order of source pixels
112
 */
113
114
INLINE
115
LOCAL(void)
116
rgb_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
117
                JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
118
37.3k
{
119
37.3k
  register _JSAMPROW inptr0, inptr1, inptr2;
120
37.3k
  register _JSAMPROW outptr;
121
37.3k
  register JDIMENSION col;
122
37.3k
  JDIMENSION num_cols = cinfo->output_width;
123
124
141k
  while (--num_rows >= 0) {
125
104k
    inptr0 = input_buf[0][input_row];
126
104k
    inptr1 = input_buf[1][input_row];
127
104k
    inptr2 = input_buf[2][input_row];
128
104k
    input_row++;
129
104k
    outptr = *output_buf++;
130
2.55M
    for (col = 0; col < num_cols; col++) {
131
2.44M
      outptr[RGB_RED] = inptr0[col];
132
2.44M
      outptr[RGB_GREEN] = inptr1[col];
133
2.44M
      outptr[RGB_BLUE] = inptr2[col];
134
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
135
      /* opaque alpha channel value */
136
#ifdef RGB_ALPHA
137
2.44M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
138
#endif
139
2.44M
      outptr += RGB_PIXELSIZE;
140
2.44M
    }
141
104k
  }
142
37.3k
}
Unexecuted instantiation: jdcolor-8.c:rgb_extrgb_convert
Unexecuted instantiation: jdcolor-8.c:rgb_extrgbx_convert
Unexecuted instantiation: jdcolor-8.c:rgb_extbgr_convert
jdcolor-8.c:rgb_extbgrx_convert
Line
Count
Source
118
36.1k
{
119
36.1k
  register _JSAMPROW inptr0, inptr1, inptr2;
120
36.1k
  register _JSAMPROW outptr;
121
36.1k
  register JDIMENSION col;
122
36.1k
  JDIMENSION num_cols = cinfo->output_width;
123
124
138k
  while (--num_rows >= 0) {
125
102k
    inptr0 = input_buf[0][input_row];
126
102k
    inptr1 = input_buf[1][input_row];
127
102k
    inptr2 = input_buf[2][input_row];
128
102k
    input_row++;
129
102k
    outptr = *output_buf++;
130
1.15M
    for (col = 0; col < num_cols; col++) {
131
1.05M
      outptr[RGB_RED] = inptr0[col];
132
1.05M
      outptr[RGB_GREEN] = inptr1[col];
133
1.05M
      outptr[RGB_BLUE] = inptr2[col];
134
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
135
      /* opaque alpha channel value */
136
1.05M
#ifdef RGB_ALPHA
137
1.05M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
138
1.05M
#endif
139
1.05M
      outptr += RGB_PIXELSIZE;
140
1.05M
    }
141
102k
  }
142
36.1k
}
Unexecuted instantiation: jdcolor-8.c:rgb_extxbgr_convert
Unexecuted instantiation: jdcolor-8.c:rgb_extxrgb_convert
Unexecuted instantiation: jdcolor-8.c:rgb_rgb_convert
Unexecuted instantiation: jdcolor-12.c:rgb_extrgb_convert
Unexecuted instantiation: jdcolor-12.c:rgb_extrgbx_convert
Unexecuted instantiation: jdcolor-12.c:rgb_extbgr_convert
jdcolor-12.c:rgb_extbgrx_convert
Line
Count
Source
118
786
{
119
786
  register _JSAMPROW inptr0, inptr1, inptr2;
120
786
  register _JSAMPROW outptr;
121
786
  register JDIMENSION col;
122
786
  JDIMENSION num_cols = cinfo->output_width;
123
124
2.85k
  while (--num_rows >= 0) {
125
2.07k
    inptr0 = input_buf[0][input_row];
126
2.07k
    inptr1 = input_buf[1][input_row];
127
2.07k
    inptr2 = input_buf[2][input_row];
128
2.07k
    input_row++;
129
2.07k
    outptr = *output_buf++;
130
1.37M
    for (col = 0; col < num_cols; col++) {
131
1.36M
      outptr[RGB_RED] = inptr0[col];
132
1.36M
      outptr[RGB_GREEN] = inptr1[col];
133
1.36M
      outptr[RGB_BLUE] = inptr2[col];
134
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
135
      /* opaque alpha channel value */
136
1.36M
#ifdef RGB_ALPHA
137
1.36M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
138
1.36M
#endif
139
1.36M
      outptr += RGB_PIXELSIZE;
140
1.36M
    }
141
2.07k
  }
142
786
}
Unexecuted instantiation: jdcolor-12.c:rgb_extxbgr_convert
Unexecuted instantiation: jdcolor-12.c:rgb_extxrgb_convert
Unexecuted instantiation: jdcolor-12.c:rgb_rgb_convert
Unexecuted instantiation: jdcolor-16.c:rgb_extrgb_convert
Unexecuted instantiation: jdcolor-16.c:rgb_extrgbx_convert
Unexecuted instantiation: jdcolor-16.c:rgb_extbgr_convert
jdcolor-16.c:rgb_extbgrx_convert
Line
Count
Source
118
338
{
119
338
  register _JSAMPROW inptr0, inptr1, inptr2;
120
338
  register _JSAMPROW outptr;
121
338
  register JDIMENSION col;
122
338
  JDIMENSION num_cols = cinfo->output_width;
123
124
743
  while (--num_rows >= 0) {
125
405
    inptr0 = input_buf[0][input_row];
126
405
    inptr1 = input_buf[1][input_row];
127
405
    inptr2 = input_buf[2][input_row];
128
405
    input_row++;
129
405
    outptr = *output_buf++;
130
28.3k
    for (col = 0; col < num_cols; col++) {
131
27.9k
      outptr[RGB_RED] = inptr0[col];
132
27.9k
      outptr[RGB_GREEN] = inptr1[col];
133
27.9k
      outptr[RGB_BLUE] = inptr2[col];
134
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
135
      /* opaque alpha channel value */
136
27.9k
#ifdef RGB_ALPHA
137
27.9k
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
138
27.9k
#endif
139
27.9k
      outptr += RGB_PIXELSIZE;
140
27.9k
    }
141
405
  }
142
338
}
Unexecuted instantiation: jdcolor-16.c:rgb_extxbgr_convert
Unexecuted instantiation: jdcolor-16.c:rgb_extxrgb_convert
Unexecuted instantiation: jdcolor-16.c:rgb_rgb_convert