Coverage Report

Created: 2025-08-26 06:42

/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
976k
{
35
976k
#if BITS_IN_JSAMPLE != 16
36
976k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
976k
  register int y, cb, cr;
38
976k
  register _JSAMPROW outptr;
39
976k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
976k
  register JDIMENSION col;
41
976k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
976k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
976k
  register int *Crrtab = cconvert->Cr_r_tab;
45
976k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
976k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
976k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
976k
  SHIFT_TEMPS
49
50
2.96M
  while (--num_rows >= 0) {
51
1.99M
    inptr0 = input_buf[0][input_row];
52
1.99M
    inptr1 = input_buf[1][input_row];
53
1.99M
    inptr2 = input_buf[2][input_row];
54
1.99M
    input_row++;
55
1.99M
    outptr = *output_buf++;
56
107M
    for (col = 0; col < num_cols; col++) {
57
105M
      y  = inptr0[col];
58
105M
      cb = inptr1[col];
59
105M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
105M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
105M
      outptr[RGB_GREEN] = range_limit[y +
63
105M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
105M
                                                SCALEBITS))];
65
105M
      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.1M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
#endif
71
105M
      outptr += RGB_PIXELSIZE;
72
105M
    }
73
1.99M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
976k
}
jdcolor.c:ycc_extrgb_convert_internal
Line
Count
Source
34
935k
{
35
935k
#if BITS_IN_JSAMPLE != 16
36
935k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
935k
  register int y, cb, cr;
38
935k
  register _JSAMPROW outptr;
39
935k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
935k
  register JDIMENSION col;
41
935k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
935k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
935k
  register int *Crrtab = cconvert->Cr_r_tab;
45
935k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
935k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
935k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
935k
  SHIFT_TEMPS
49
50
2.81M
  while (--num_rows >= 0) {
51
1.88M
    inptr0 = input_buf[0][input_row];
52
1.88M
    inptr1 = input_buf[1][input_row];
53
1.88M
    inptr2 = input_buf[2][input_row];
54
1.88M
    input_row++;
55
1.88M
    outptr = *output_buf++;
56
92.7M
    for (col = 0; col < num_cols; col++) {
57
90.8M
      y  = inptr0[col];
58
90.8M
      cb = inptr1[col];
59
90.8M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
90.8M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
90.8M
      outptr[RGB_GREEN] = range_limit[y +
63
90.8M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
90.8M
                                                SCALEBITS))];
65
90.8M
      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
90.8M
      outptr += RGB_PIXELSIZE;
72
90.8M
    }
73
1.88M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
935k
}
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
40.6k
{
35
40.6k
#if BITS_IN_JSAMPLE != 16
36
40.6k
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
40.6k
  register int y, cb, cr;
38
40.6k
  register _JSAMPROW outptr;
39
40.6k
  register _JSAMPROW inptr0, inptr1, inptr2;
40
40.6k
  register JDIMENSION col;
41
40.6k
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
40.6k
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
40.6k
  register int *Crrtab = cconvert->Cr_r_tab;
45
40.6k
  register int *Cbbtab = cconvert->Cb_b_tab;
46
40.6k
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
40.6k
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
40.6k
  SHIFT_TEMPS
49
50
149k
  while (--num_rows >= 0) {
51
109k
    inptr0 = input_buf[0][input_row];
52
109k
    inptr1 = input_buf[1][input_row];
53
109k
    inptr2 = input_buf[2][input_row];
54
109k
    input_row++;
55
109k
    outptr = *output_buf++;
56
14.2M
    for (col = 0; col < num_cols; col++) {
57
14.1M
      y  = inptr0[col];
58
14.1M
      cb = inptr1[col];
59
14.1M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
14.1M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
14.1M
      outptr[RGB_GREEN] = range_limit[y +
63
14.1M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
14.1M
                                                SCALEBITS))];
65
14.1M
      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.1M
#ifdef RGB_ALPHA
69
14.1M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
14.1M
#endif
71
14.1M
      outptr += RGB_PIXELSIZE;
72
14.1M
    }
73
109k
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
40.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.30M
{
92
9.30M
  register _JSAMPROW inptr, outptr;
93
9.30M
  register JDIMENSION col;
94
9.30M
  JDIMENSION num_cols = cinfo->output_width;
95
96
26.1M
  while (--num_rows >= 0) {
97
16.8M
    inptr = input_buf[0][input_row++];
98
16.8M
    outptr = *output_buf++;
99
815M
    for (col = 0; col < num_cols; col++) {
100
799M
      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
53.7M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
#endif
106
799M
      outptr += RGB_PIXELSIZE;
107
799M
    }
108
16.8M
  }
109
9.30M
}
jdcolor.c:gray_extrgb_convert_internal
Line
Count
Source
91
5.70M
{
92
5.70M
  register _JSAMPROW inptr, outptr;
93
5.70M
  register JDIMENSION col;
94
5.70M
  JDIMENSION num_cols = cinfo->output_width;
95
96
18.5M
  while (--num_rows >= 0) {
97
12.8M
    inptr = input_buf[0][input_row++];
98
12.8M
    outptr = *output_buf++;
99
718M
    for (col = 0; col < num_cols; col++) {
100
705M
      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
705M
      outptr += RGB_PIXELSIZE;
107
705M
    }
108
12.8M
  }
109
5.70M
}
Unexecuted instantiation: jdcolor.c:gray_extrgbx_convert_internal
jdcolor.c:gray_extbgr_convert_internal
Line
Count
Source
91
1.90M
{
92
1.90M
  register _JSAMPROW inptr, outptr;
93
1.90M
  register JDIMENSION col;
94
1.90M
  JDIMENSION num_cols = cinfo->output_width;
95
96
3.80M
  while (--num_rows >= 0) {
97
1.90M
    inptr = input_buf[0][input_row++];
98
1.90M
    outptr = *output_buf++;
99
41.9M
    for (col = 0; col < num_cols; col++) {
100
40.0M
      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
40.0M
      outptr += RGB_PIXELSIZE;
107
40.0M
    }
108
1.90M
  }
109
1.90M
}
jdcolor.c:gray_extbgrx_convert_internal
Line
Count
Source
91
272k
{
92
272k
  register _JSAMPROW inptr, outptr;
93
272k
  register JDIMENSION col;
94
272k
  JDIMENSION num_cols = cinfo->output_width;
95
96
889k
  while (--num_rows >= 0) {
97
616k
    inptr = input_buf[0][input_row++];
98
616k
    outptr = *output_buf++;
99
30.7M
    for (col = 0; col < num_cols; col++) {
100
30.1M
      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.1M
#ifdef RGB_ALPHA
104
30.1M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
30.1M
#endif
106
30.1M
      outptr += RGB_PIXELSIZE;
107
30.1M
    }
108
616k
  }
109
272k
}
Unexecuted instantiation: jdcolor.c:gray_extxbgr_convert_internal
jdcolor.c:gray_extxrgb_convert_internal
Line
Count
Source
91
1.42M
{
92
1.42M
  register _JSAMPROW inptr, outptr;
93
1.42M
  register JDIMENSION col;
94
1.42M
  JDIMENSION num_cols = cinfo->output_width;
95
96
2.85M
  while (--num_rows >= 0) {
97
1.42M
    inptr = input_buf[0][input_row++];
98
1.42M
    outptr = *output_buf++;
99
24.9M
    for (col = 0; col < num_cols; col++) {
100
23.5M
      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
23.5M
#ifdef RGB_ALPHA
104
23.5M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
23.5M
#endif
106
23.5M
      outptr += RGB_PIXELSIZE;
107
23.5M
    }
108
1.42M
  }
109
1.42M
}
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
209k
{
122
209k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
209k
  register _JSAMPROW outptr;
124
209k
  register JDIMENSION col;
125
209k
  JDIMENSION num_cols = cinfo->output_width;
126
127
504k
  while (--num_rows >= 0) {
128
295k
    inptr0 = input_buf[0][input_row];
129
295k
    inptr1 = input_buf[1][input_row];
130
295k
    inptr2 = input_buf[2][input_row];
131
295k
    input_row++;
132
295k
    outptr = *output_buf++;
133
18.1M
    for (col = 0; col < num_cols; col++) {
134
17.8M
      outptr[RGB_RED] = inptr0[col];
135
17.8M
      outptr[RGB_GREEN] = inptr1[col];
136
17.8M
      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.86M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
#endif
142
17.8M
      outptr += RGB_PIXELSIZE;
143
17.8M
    }
144
295k
  }
145
209k
}
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
70.9k
{
122
70.9k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
70.9k
  register _JSAMPROW outptr;
124
70.9k
  register JDIMENSION col;
125
70.9k
  JDIMENSION num_cols = cinfo->output_width;
126
127
147k
  while (--num_rows >= 0) {
128
76.1k
    inptr0 = input_buf[0][input_row];
129
76.1k
    inptr1 = input_buf[1][input_row];
130
76.1k
    inptr2 = input_buf[2][input_row];
131
76.1k
    input_row++;
132
76.1k
    outptr = *output_buf++;
133
9.05M
    for (col = 0; col < num_cols; col++) {
134
8.97M
      outptr[RGB_RED] = inptr0[col];
135
8.97M
      outptr[RGB_GREEN] = inptr1[col];
136
8.97M
      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
8.97M
      outptr += RGB_PIXELSIZE;
143
8.97M
    }
144
76.1k
  }
145
70.9k
}
jdcolor.c:rgb_extbgrx_convert_internal
Line
Count
Source
121
85.3k
{
122
85.3k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
85.3k
  register _JSAMPROW outptr;
124
85.3k
  register JDIMENSION col;
125
85.3k
  JDIMENSION num_cols = cinfo->output_width;
126
127
247k
  while (--num_rows >= 0) {
128
162k
    inptr0 = input_buf[0][input_row];
129
162k
    inptr1 = input_buf[1][input_row];
130
162k
    inptr2 = input_buf[2][input_row];
131
162k
    input_row++;
132
162k
    outptr = *output_buf++;
133
3.79M
    for (col = 0; col < num_cols; col++) {
134
3.63M
      outptr[RGB_RED] = inptr0[col];
135
3.63M
      outptr[RGB_GREEN] = inptr1[col];
136
3.63M
      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.63M
#ifdef RGB_ALPHA
140
3.63M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
3.63M
#endif
142
3.63M
      outptr += RGB_PIXELSIZE;
143
3.63M
    }
144
162k
  }
145
85.3k
}
Unexecuted instantiation: jdcolor.c:rgb_extxbgr_convert_internal
jdcolor.c:rgb_extxrgb_convert_internal
Line
Count
Source
121
53.2k
{
122
53.2k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
53.2k
  register _JSAMPROW outptr;
124
53.2k
  register JDIMENSION col;
125
53.2k
  JDIMENSION num_cols = cinfo->output_width;
126
127
110k
  while (--num_rows >= 0) {
128
57.1k
    inptr0 = input_buf[0][input_row];
129
57.1k
    inptr1 = input_buf[1][input_row];
130
57.1k
    inptr2 = input_buf[2][input_row];
131
57.1k
    input_row++;
132
57.1k
    outptr = *output_buf++;
133
5.28M
    for (col = 0; col < num_cols; col++) {
134
5.22M
      outptr[RGB_RED] = inptr0[col];
135
5.22M
      outptr[RGB_GREEN] = inptr1[col];
136
5.22M
      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.22M
#ifdef RGB_ALPHA
140
5.22M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
5.22M
#endif
142
5.22M
      outptr += RGB_PIXELSIZE;
143
5.22M
    }
144
57.1k
  }
145
53.2k
}
Unexecuted instantiation: jdcolor.c:rgb_rgb_convert_internal