Coverage Report

Created: 2025-08-03 06:59

/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
986k
{
35
986k
#if BITS_IN_JSAMPLE != 16
36
986k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
986k
  register int y, cb, cr;
38
986k
  register _JSAMPROW outptr;
39
986k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
986k
  register JDIMENSION col;
41
986k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
986k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
986k
  register int *Crrtab = cconvert->Cr_r_tab;
45
986k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
986k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
986k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
986k
  SHIFT_TEMPS
49
50
3.01M
  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
108M
    for (col = 0; col < num_cols; col++) {
57
106M
      y  = inptr0[col];
58
106M
      cb = inptr1[col];
59
106M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
106M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
106M
      outptr[RGB_GREEN] = range_limit[y +
63
106M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
106M
                                                SCALEBITS))];
65
106M
      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
14.4M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
#endif
71
106M
      outptr += RGB_PIXELSIZE;
72
106M
    }
73
2.02M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
986k
}
jdcolor.c:ycc_extrgb_convert_internal
Line
Count
Source
34
952k
{
35
952k
#if BITS_IN_JSAMPLE != 16
36
952k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
952k
  register int y, cb, cr;
38
952k
  register _JSAMPROW outptr;
39
952k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
952k
  register JDIMENSION col;
41
952k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
952k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
952k
  register int *Crrtab = cconvert->Cr_r_tab;
45
952k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
952k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
952k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
952k
  SHIFT_TEMPS
49
50
2.89M
  while (--num_rows >= 0) {
51
1.94M
    inptr0 = input_buf[0][input_row];
52
1.94M
    inptr1 = input_buf[1][input_row];
53
1.94M
    inptr2 = input_buf[2][input_row];
54
1.94M
    input_row++;
55
1.94M
    outptr = *output_buf++;
56
93.5M
    for (col = 0; col < num_cols; col++) {
57
91.5M
      y  = inptr0[col];
58
91.5M
      cb = inptr1[col];
59
91.5M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
91.5M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
91.5M
      outptr[RGB_GREEN] = range_limit[y +
63
91.5M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
91.5M
                                                SCALEBITS))];
65
91.5M
      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
91.5M
      outptr += RGB_PIXELSIZE;
72
91.5M
    }
73
1.94M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
952k
}
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
33.6k
{
35
33.6k
#if BITS_IN_JSAMPLE != 16
36
33.6k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
33.6k
  register int y, cb, cr;
38
33.6k
  register _JSAMPROW outptr;
39
33.6k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
33.6k
  register JDIMENSION col;
41
33.6k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
33.6k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
33.6k
  register int *Crrtab = cconvert->Cr_r_tab;
45
33.6k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
33.6k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
33.6k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
33.6k
  SHIFT_TEMPS
49
50
114k
  while (--num_rows >= 0) {
51
80.3k
    inptr0 = input_buf[0][input_row];
52
80.3k
    inptr1 = input_buf[1][input_row];
53
80.3k
    inptr2 = input_buf[2][input_row];
54
80.3k
    input_row++;
55
80.3k
    outptr = *output_buf++;
56
14.4M
    for (col = 0; col < num_cols; col++) {
57
14.4M
      y  = inptr0[col];
58
14.4M
      cb = inptr1[col];
59
14.4M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
14.4M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
14.4M
      outptr[RGB_GREEN] = range_limit[y +
63
14.4M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
14.4M
                                                SCALEBITS))];
65
14.4M
      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
14.4M
#ifdef RGB_ALPHA
69
14.4M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
14.4M
#endif
71
14.4M
      outptr += RGB_PIXELSIZE;
72
14.4M
    }
73
80.3k
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
33.6k
}
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.41M
{
92
9.41M
  register _JSAMPROW inptr, outptr;
93
9.41M
  register JDIMENSION col;
94
9.41M
  JDIMENSION num_cols = cinfo->output_width;
95
96
26.6M
  while (--num_rows >= 0) {
97
17.2M
    inptr = input_buf[0][input_row++];
98
17.2M
    outptr = *output_buf++;
99
831M
    for (col = 0; col < num_cols; col++) {
100
814M
      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
54.9M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
#endif
106
814M
      outptr += RGB_PIXELSIZE;
107
814M
    }
108
17.2M
  }
109
9.41M
}
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
731M
    for (col = 0; col < num_cols; col++) {
100
718M
      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
718M
      outptr += RGB_PIXELSIZE;
107
718M
    }
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.86M
{
92
1.86M
  register _JSAMPROW inptr, outptr;
93
1.86M
  register JDIMENSION col;
94
1.86M
  JDIMENSION num_cols = cinfo->output_width;
95
96
3.72M
  while (--num_rows >= 0) {
97
1.86M
    inptr = input_buf[0][input_row++];
98
1.86M
    outptr = *output_buf++;
99
43.2M
    for (col = 0; col < num_cols; col++) {
100
41.4M
      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
41.4M
      outptr += RGB_PIXELSIZE;
107
41.4M
    }
108
1.86M
  }
109
1.86M
}
jdcolor.c:gray_extbgrx_convert_internal
Line
Count
Source
91
294k
{
92
294k
  register _JSAMPROW inptr, outptr;
93
294k
  register JDIMENSION col;
94
294k
  JDIMENSION num_cols = cinfo->output_width;
95
96
930k
  while (--num_rows >= 0) {
97
636k
    inptr = input_buf[0][input_row++];
98
636k
    outptr = *output_buf++;
99
31.2M
    for (col = 0; col < num_cols; col++) {
100
30.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
30.6M
#ifdef RGB_ALPHA
104
30.6M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
30.6M
#endif
106
30.6M
      outptr += RGB_PIXELSIZE;
107
30.6M
    }
108
636k
  }
109
294k
}
Unexecuted instantiation: jdcolor.c:gray_extxbgr_convert_internal
jdcolor.c:gray_extxrgb_convert_internal
Line
Count
Source
91
1.39M
{
92
1.39M
  register _JSAMPROW inptr, outptr;
93
1.39M
  register JDIMENSION col;
94
1.39M
  JDIMENSION num_cols = cinfo->output_width;
95
96
2.79M
  while (--num_rows >= 0) {
97
1.39M
    inptr = input_buf[0][input_row++];
98
1.39M
    outptr = *output_buf++;
99
25.7M
    for (col = 0; col < num_cols; col++) {
100
24.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
24.3M
#ifdef RGB_ALPHA
104
24.3M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
24.3M
#endif
106
24.3M
      outptr += RGB_PIXELSIZE;
107
24.3M
    }
108
1.39M
  }
109
1.39M
}
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
205k
{
122
205k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
205k
  register _JSAMPROW outptr;
124
205k
  register JDIMENSION col;
125
205k
  JDIMENSION num_cols = cinfo->output_width;
126
127
493k
  while (--num_rows >= 0) {
128
287k
    inptr0 = input_buf[0][input_row];
129
287k
    inptr1 = input_buf[1][input_row];
130
287k
    inptr2 = input_buf[2][input_row];
131
287k
    input_row++;
132
287k
    outptr = *output_buf++;
133
18.6M
    for (col = 0; col < num_cols; col++) {
134
18.3M
      outptr[RGB_RED] = inptr0[col];
135
18.3M
      outptr[RGB_GREEN] = inptr1[col];
136
18.3M
      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.80M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
#endif
142
18.3M
      outptr += RGB_PIXELSIZE;
143
18.3M
    }
144
287k
  }
145
205k
}
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
71.2k
{
122
71.2k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
71.2k
  register _JSAMPROW outptr;
124
71.2k
  register JDIMENSION col;
125
71.2k
  JDIMENSION num_cols = cinfo->output_width;
126
127
147k
  while (--num_rows >= 0) {
128
76.4k
    inptr0 = input_buf[0][input_row];
129
76.4k
    inptr1 = input_buf[1][input_row];
130
76.4k
    inptr2 = input_buf[2][input_row];
131
76.4k
    input_row++;
132
76.4k
    outptr = *output_buf++;
133
9.62M
    for (col = 0; col < num_cols; col++) {
134
9.54M
      outptr[RGB_RED] = inptr0[col];
135
9.54M
      outptr[RGB_GREEN] = inptr1[col];
136
9.54M
      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.54M
      outptr += RGB_PIXELSIZE;
143
9.54M
    }
144
76.4k
  }
145
71.2k
}
jdcolor.c:rgb_extbgrx_convert_internal
Line
Count
Source
121
81.1k
{
122
81.1k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
81.1k
  register _JSAMPROW outptr;
124
81.1k
  register JDIMENSION col;
125
81.1k
  JDIMENSION num_cols = cinfo->output_width;
126
127
234k
  while (--num_rows >= 0) {
128
153k
    inptr0 = input_buf[0][input_row];
129
153k
    inptr1 = input_buf[1][input_row];
130
153k
    inptr2 = input_buf[2][input_row];
131
153k
    input_row++;
132
153k
    outptr = *output_buf++;
133
3.44M
    for (col = 0; col < num_cols; col++) {
134
3.29M
      outptr[RGB_RED] = inptr0[col];
135
3.29M
      outptr[RGB_GREEN] = inptr1[col];
136
3.29M
      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.29M
#ifdef RGB_ALPHA
140
3.29M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
3.29M
#endif
142
3.29M
      outptr += RGB_PIXELSIZE;
143
3.29M
    }
144
153k
  }
145
81.1k
}
Unexecuted instantiation: jdcolor.c:rgb_extxbgr_convert_internal
jdcolor.c:rgb_extxrgb_convert_internal
Line
Count
Source
121
53.4k
{
122
53.4k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
53.4k
  register _JSAMPROW outptr;
124
53.4k
  register JDIMENSION col;
125
53.4k
  JDIMENSION num_cols = cinfo->output_width;
126
127
110k
  while (--num_rows >= 0) {
128
57.3k
    inptr0 = input_buf[0][input_row];
129
57.3k
    inptr1 = input_buf[1][input_row];
130
57.3k
    inptr2 = input_buf[2][input_row];
131
57.3k
    input_row++;
132
57.3k
    outptr = *output_buf++;
133
5.56M
    for (col = 0; col < num_cols; col++) {
134
5.51M
      outptr[RGB_RED] = inptr0[col];
135
5.51M
      outptr[RGB_GREEN] = inptr1[col];
136
5.51M
      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.51M
#ifdef RGB_ALPHA
140
5.51M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
5.51M
#endif
142
5.51M
      outptr += RGB_PIXELSIZE;
143
5.51M
    }
144
57.3k
  }
145
53.4k
}
Unexecuted instantiation: jdcolor.c:rgb_rgb_convert_internal