Coverage Report

Created: 2025-07-18 07:07

/src/libjpeg-turbo.3.0.x/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, 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_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
32
                         JDIMENSION input_row, _JSAMPARRAY output_buf,
33
                         int num_rows)
34
1.10M
{
35
1.10M
#if BITS_IN_JSAMPLE != 16
36
1.10M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
1.10M
  register int y, cb, cr;
38
1.10M
  register _JSAMPROW outptr;
39
1.10M
  register _JSAMPROW inptr0, inptr1, inptr2;
40
1.10M
  register JDIMENSION col;
41
1.10M
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
1.10M
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
1.10M
  register int *Crrtab = cconvert->Cr_r_tab;
45
1.10M
  register int *Cbbtab = cconvert->Cb_b_tab;
46
1.10M
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
1.10M
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
1.10M
  SHIFT_TEMPS
49
50
3.25M
  while (--num_rows >= 0) {
51
2.14M
    inptr0 = input_buf[0][input_row];
52
2.14M
    inptr1 = input_buf[1][input_row];
53
2.14M
    inptr2 = input_buf[2][input_row];
54
2.14M
    input_row++;
55
2.14M
    outptr = *output_buf++;
56
115M
    for (col = 0; col < num_cols; col++) {
57
112M
      y  = inptr0[col];
58
112M
      cb = inptr1[col];
59
112M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
112M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
112M
      outptr[RGB_GREEN] = range_limit[y +
63
112M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
112M
                                                SCALEBITS))];
65
112M
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
66
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
67
      /* opaque alpha channel value */
68
#ifdef RGB_ALPHA
69
16.0M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
#endif
71
112M
      outptr += RGB_PIXELSIZE;
72
112M
    }
73
2.14M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
1.10M
}
jdcolor.c:ycc_extrgb_convert_internal
Line
Count
Source
34
1.05M
{
35
1.05M
#if BITS_IN_JSAMPLE != 16
36
1.05M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
1.05M
  register int y, cb, cr;
38
1.05M
  register _JSAMPROW outptr;
39
1.05M
  register _JSAMPROW inptr0, inptr1, inptr2;
40
1.05M
  register JDIMENSION col;
41
1.05M
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
1.05M
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
1.05M
  register int *Crrtab = cconvert->Cr_r_tab;
45
1.05M
  register int *Cbbtab = cconvert->Cb_b_tab;
46
1.05M
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
1.05M
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
1.05M
  SHIFT_TEMPS
49
50
3.08M
  while (--num_rows >= 0) {
51
2.02M
    inptr0 = input_buf[0][input_row];
52
2.02M
    inptr1 = input_buf[1][input_row];
53
2.02M
    inptr2 = input_buf[2][input_row];
54
2.02M
    input_row++;
55
2.02M
    outptr = *output_buf++;
56
98.8M
    for (col = 0; col < num_cols; col++) {
57
96.7M
      y  = inptr0[col];
58
96.7M
      cb = inptr1[col];
59
96.7M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
96.7M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
96.7M
      outptr[RGB_GREEN] = range_limit[y +
63
96.7M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
96.7M
                                                SCALEBITS))];
65
96.7M
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
66
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
67
      /* opaque alpha channel value */
68
#ifdef RGB_ALPHA
69
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
#endif
71
96.7M
      outptr += RGB_PIXELSIZE;
72
96.7M
    }
73
2.02M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
1.05M
}
Unexecuted instantiation: jdcolor.c:ycc_extrgbx_convert_internal
Unexecuted instantiation: jdcolor.c:ycc_extbgr_convert_internal
jdcolor.c:ycc_extbgrx_convert_internal
Line
Count
Source
34
52.0k
{
35
52.0k
#if BITS_IN_JSAMPLE != 16
36
52.0k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
52.0k
  register int y, cb, cr;
38
52.0k
  register _JSAMPROW outptr;
39
52.0k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
52.0k
  register JDIMENSION col;
41
52.0k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
52.0k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
52.0k
  register int *Crrtab = cconvert->Cr_r_tab;
45
52.0k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
52.0k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
52.0k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
52.0k
  SHIFT_TEMPS
49
50
167k
  while (--num_rows >= 0) {
51
115k
    inptr0 = input_buf[0][input_row];
52
115k
    inptr1 = input_buf[1][input_row];
53
115k
    inptr2 = input_buf[2][input_row];
54
115k
    input_row++;
55
115k
    outptr = *output_buf++;
56
16.1M
    for (col = 0; col < num_cols; col++) {
57
16.0M
      y  = inptr0[col];
58
16.0M
      cb = inptr1[col];
59
16.0M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
16.0M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
16.0M
      outptr[RGB_GREEN] = range_limit[y +
63
16.0M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
16.0M
                                                SCALEBITS))];
65
16.0M
      outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
66
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
67
      /* opaque alpha channel value */
68
16.0M
#ifdef RGB_ALPHA
69
16.0M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
16.0M
#endif
71
16.0M
      outptr += RGB_PIXELSIZE;
72
16.0M
    }
73
115k
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
52.0k
}
Unexecuted instantiation: jdcolor.c:ycc_extxbgr_convert_internal
Unexecuted instantiation: jdcolor.c:ycc_extxrgb_convert_internal
Unexecuted instantiation: jdcolor.c:ycc_rgb_convert_internal
78
79
80
/*
81
 * Convert grayscale to RGB: just duplicate the graylevel three times.
82
 * This is provided to support applications that don't want to cope
83
 * with grayscale as a separate case.
84
 */
85
86
INLINE
87
LOCAL(void)
88
gray_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
89
                          JDIMENSION input_row, _JSAMPARRAY output_buf,
90
                          int num_rows)
91
9.08M
{
92
9.08M
  register _JSAMPROW inptr, outptr;
93
9.08M
  register JDIMENSION col;
94
9.08M
  JDIMENSION num_cols = cinfo->output_width;
95
96
25.9M
  while (--num_rows >= 0) {
97
16.8M
    inptr = input_buf[0][input_row++];
98
16.8M
    outptr = *output_buf++;
99
811M
    for (col = 0; col < num_cols; col++) {
100
794M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
101
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
102
      /* opaque alpha channel value */
103
#ifdef RGB_ALPHA
104
52.0M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
#endif
106
794M
      outptr += RGB_PIXELSIZE;
107
794M
    }
108
16.8M
  }
109
9.08M
}
jdcolor.c:gray_extrgb_convert_internal
Line
Count
Source
91
5.85M
{
92
5.85M
  register _JSAMPROW inptr, outptr;
93
5.85M
  register JDIMENSION col;
94
5.85M
  JDIMENSION num_cols = cinfo->output_width;
95
96
19.2M
  while (--num_rows >= 0) {
97
13.3M
    inptr = input_buf[0][input_row++];
98
13.3M
    outptr = *output_buf++;
99
717M
    for (col = 0; col < num_cols; col++) {
100
704M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
101
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
102
      /* opaque alpha channel value */
103
#ifdef RGB_ALPHA
104
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
#endif
106
704M
      outptr += RGB_PIXELSIZE;
107
704M
    }
108
13.3M
  }
109
5.85M
}
Unexecuted instantiation: jdcolor.c:gray_extrgbx_convert_internal
jdcolor.c:gray_extbgr_convert_internal
Line
Count
Source
91
1.72M
{
92
1.72M
  register _JSAMPROW inptr, outptr;
93
1.72M
  register JDIMENSION col;
94
1.72M
  JDIMENSION num_cols = cinfo->output_width;
95
96
3.45M
  while (--num_rows >= 0) {
97
1.72M
    inptr = input_buf[0][input_row++];
98
1.72M
    outptr = *output_buf++;
99
40.3M
    for (col = 0; col < num_cols; col++) {
100
38.6M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
101
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
102
      /* opaque alpha channel value */
103
#ifdef RGB_ALPHA
104
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
#endif
106
38.6M
      outptr += RGB_PIXELSIZE;
107
38.6M
    }
108
1.72M
  }
109
1.72M
}
jdcolor.c:gray_extbgrx_convert_internal
Line
Count
Source
91
209k
{
92
209k
  register _JSAMPROW inptr, outptr;
93
209k
  register JDIMENSION col;
94
209k
  JDIMENSION num_cols = cinfo->output_width;
95
96
675k
  while (--num_rows >= 0) {
97
465k
    inptr = input_buf[0][input_row++];
98
465k
    outptr = *output_buf++;
99
29.7M
    for (col = 0; col < num_cols; col++) {
100
29.3M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
101
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
102
      /* opaque alpha channel value */
103
29.3M
#ifdef RGB_ALPHA
104
29.3M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
29.3M
#endif
106
29.3M
      outptr += RGB_PIXELSIZE;
107
29.3M
    }
108
465k
  }
109
209k
}
Unexecuted instantiation: jdcolor.c:gray_extxbgr_convert_internal
jdcolor.c:gray_extxrgb_convert_internal
Line
Count
Source
91
1.29M
{
92
1.29M
  register _JSAMPROW inptr, outptr;
93
1.29M
  register JDIMENSION col;
94
1.29M
  JDIMENSION num_cols = cinfo->output_width;
95
96
2.58M
  while (--num_rows >= 0) {
97
1.29M
    inptr = input_buf[0][input_row++];
98
1.29M
    outptr = *output_buf++;
99
24.0M
    for (col = 0; col < num_cols; col++) {
100
22.7M
      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
101
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
102
      /* opaque alpha channel value */
103
22.7M
#ifdef RGB_ALPHA
104
22.7M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
22.7M
#endif
106
22.7M
      outptr += RGB_PIXELSIZE;
107
22.7M
    }
108
1.29M
  }
109
1.29M
}
Unexecuted instantiation: jdcolor.c:gray_rgb_convert_internal
110
111
112
/*
113
 * Convert RGB to extended RGB: just swap the order of source pixels
114
 */
115
116
INLINE
117
LOCAL(void)
118
rgb_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
119
                         JDIMENSION input_row, _JSAMPARRAY output_buf,
120
                         int num_rows)
121
279k
{
122
279k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
279k
  register _JSAMPROW outptr;
124
279k
  register JDIMENSION col;
125
279k
  JDIMENSION num_cols = cinfo->output_width;
126
127
663k
  while (--num_rows >= 0) {
128
384k
    inptr0 = input_buf[0][input_row];
129
384k
    inptr1 = input_buf[1][input_row];
130
384k
    inptr2 = input_buf[2][input_row];
131
384k
    input_row++;
132
384k
    outptr = *output_buf++;
133
18.0M
    for (col = 0; col < num_cols; col++) {
134
17.6M
      outptr[RGB_RED] = inptr0[col];
135
17.6M
      outptr[RGB_GREEN] = inptr1[col];
136
17.6M
      outptr[RGB_BLUE] = inptr2[col];
137
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
138
      /* opaque alpha channel value */
139
#ifdef RGB_ALPHA
140
8.59M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
#endif
142
17.6M
      outptr += RGB_PIXELSIZE;
143
17.6M
    }
144
384k
  }
145
279k
}
Unexecuted instantiation: jdcolor.c:rgb_extrgb_convert_internal
Unexecuted instantiation: jdcolor.c:rgb_extrgbx_convert_internal
jdcolor.c:rgb_extbgr_convert_internal
Line
Count
Source
121
109k
{
122
109k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
109k
  register _JSAMPROW outptr;
124
109k
  register JDIMENSION col;
125
109k
  JDIMENSION num_cols = cinfo->output_width;
126
127
223k
  while (--num_rows >= 0) {
128
114k
    inptr0 = input_buf[0][input_row];
129
114k
    inptr1 = input_buf[1][input_row];
130
114k
    inptr2 = input_buf[2][input_row];
131
114k
    input_row++;
132
114k
    outptr = *output_buf++;
133
9.18M
    for (col = 0; col < num_cols; col++) {
134
9.06M
      outptr[RGB_RED] = inptr0[col];
135
9.06M
      outptr[RGB_GREEN] = inptr1[col];
136
9.06M
      outptr[RGB_BLUE] = inptr2[col];
137
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
138
      /* opaque alpha channel value */
139
#ifdef RGB_ALPHA
140
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
#endif
142
9.06M
      outptr += RGB_PIXELSIZE;
143
9.06M
    }
144
114k
  }
145
109k
}
jdcolor.c:rgb_extbgrx_convert_internal
Line
Count
Source
121
88.2k
{
122
88.2k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
88.2k
  register _JSAMPROW outptr;
124
88.2k
  register JDIMENSION col;
125
88.2k
  JDIMENSION num_cols = cinfo->output_width;
126
127
272k
  while (--num_rows >= 0) {
128
184k
    inptr0 = input_buf[0][input_row];
129
184k
    inptr1 = input_buf[1][input_row];
130
184k
    inptr2 = input_buf[2][input_row];
131
184k
    input_row++;
132
184k
    outptr = *output_buf++;
133
3.57M
    for (col = 0; col < num_cols; col++) {
134
3.39M
      outptr[RGB_RED] = inptr0[col];
135
3.39M
      outptr[RGB_GREEN] = inptr1[col];
136
3.39M
      outptr[RGB_BLUE] = inptr2[col];
137
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
138
      /* opaque alpha channel value */
139
3.39M
#ifdef RGB_ALPHA
140
3.39M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
3.39M
#endif
142
3.39M
      outptr += RGB_PIXELSIZE;
143
3.39M
    }
144
184k
  }
145
88.2k
}
Unexecuted instantiation: jdcolor.c:rgb_extxbgr_convert_internal
jdcolor.c:rgb_extxrgb_convert_internal
Line
Count
Source
121
81.8k
{
122
81.8k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
81.8k
  register _JSAMPROW outptr;
124
81.8k
  register JDIMENSION col;
125
81.8k
  JDIMENSION num_cols = cinfo->output_width;
126
127
167k
  while (--num_rows >= 0) {
128
85.8k
    inptr0 = input_buf[0][input_row];
129
85.8k
    inptr1 = input_buf[1][input_row];
130
85.8k
    inptr2 = input_buf[2][input_row];
131
85.8k
    input_row++;
132
85.8k
    outptr = *output_buf++;
133
5.29M
    for (col = 0; col < num_cols; col++) {
134
5.20M
      outptr[RGB_RED] = inptr0[col];
135
5.20M
      outptr[RGB_GREEN] = inptr1[col];
136
5.20M
      outptr[RGB_BLUE] = inptr2[col];
137
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
138
      /* opaque alpha channel value */
139
5.20M
#ifdef RGB_ALPHA
140
5.20M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
5.20M
#endif
142
5.20M
      outptr += RGB_PIXELSIZE;
143
5.20M
    }
144
85.8k
  }
145
81.8k
}
Unexecuted instantiation: jdcolor.c:rgb_rgb_convert_internal