Coverage Report

Created: 2024-01-23 06:26

/src/libjpeg-turbo.main/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
7.36M
{
35
7.36M
#if BITS_IN_JSAMPLE != 16
36
7.36M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
7.36M
  register int y, cb, cr;
38
7.36M
  register _JSAMPROW outptr;
39
7.36M
  register _JSAMPROW inptr0, inptr1, inptr2;
40
7.36M
  register JDIMENSION col;
41
7.36M
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
7.36M
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
7.36M
  register int *Crrtab = cconvert->Cr_r_tab;
45
7.36M
  register int *Cbbtab = cconvert->Cb_b_tab;
46
7.36M
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
7.36M
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
7.36M
  SHIFT_TEMPS
49
50
24.1M
  while (--num_rows >= 0) {
51
16.7M
    inptr0 = input_buf[0][input_row];
52
16.7M
    inptr1 = input_buf[1][input_row];
53
16.7M
    inptr2 = input_buf[2][input_row];
54
16.7M
    input_row++;
55
16.7M
    outptr = *output_buf++;
56
559M
    for (col = 0; col < num_cols; col++) {
57
542M
      y  = inptr0[col];
58
542M
      cb = inptr1[col];
59
542M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
542M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
542M
      outptr[RGB_GREEN] = range_limit[y +
63
542M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
542M
                                                SCALEBITS))];
65
542M
      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
83.2M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
#endif
71
542M
      outptr += RGB_PIXELSIZE;
72
542M
    }
73
16.7M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
7.36M
}
jdcolor.c:ycc_extrgb_convert_internal
Line
Count
Source
34
5.35M
{
35
5.35M
#if BITS_IN_JSAMPLE != 16
36
5.35M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
5.35M
  register int y, cb, cr;
38
5.35M
  register _JSAMPROW outptr;
39
5.35M
  register _JSAMPROW inptr0, inptr1, inptr2;
40
5.35M
  register JDIMENSION col;
41
5.35M
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
5.35M
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
5.35M
  register int *Crrtab = cconvert->Cr_r_tab;
45
5.35M
  register int *Cbbtab = cconvert->Cb_b_tab;
46
5.35M
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
5.35M
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
5.35M
  SHIFT_TEMPS
49
50
18.1M
  while (--num_rows >= 0) {
51
12.8M
    inptr0 = input_buf[0][input_row];
52
12.8M
    inptr1 = input_buf[1][input_row];
53
12.8M
    inptr2 = input_buf[2][input_row];
54
12.8M
    input_row++;
55
12.8M
    outptr = *output_buf++;
56
472M
    for (col = 0; col < num_cols; col++) {
57
459M
      y  = inptr0[col];
58
459M
      cb = inptr1[col];
59
459M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
459M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
459M
      outptr[RGB_GREEN] = range_limit[y +
63
459M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
459M
                                                SCALEBITS))];
65
459M
      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
459M
      outptr += RGB_PIXELSIZE;
72
459M
    }
73
12.8M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
5.35M
}
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
2.01M
{
35
2.01M
#if BITS_IN_JSAMPLE != 16
36
2.01M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
37
2.01M
  register int y, cb, cr;
38
2.01M
  register _JSAMPROW outptr;
39
2.01M
  register _JSAMPROW inptr0, inptr1, inptr2;
40
2.01M
  register JDIMENSION col;
41
2.01M
  JDIMENSION num_cols = cinfo->output_width;
42
  /* copy these pointers into registers if possible */
43
2.01M
  register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
44
2.01M
  register int *Crrtab = cconvert->Cr_r_tab;
45
2.01M
  register int *Cbbtab = cconvert->Cb_b_tab;
46
2.01M
  register JLONG *Crgtab = cconvert->Cr_g_tab;
47
2.01M
  register JLONG *Cbgtab = cconvert->Cb_g_tab;
48
2.01M
  SHIFT_TEMPS
49
50
5.94M
  while (--num_rows >= 0) {
51
3.93M
    inptr0 = input_buf[0][input_row];
52
3.93M
    inptr1 = input_buf[1][input_row];
53
3.93M
    inptr2 = input_buf[2][input_row];
54
3.93M
    input_row++;
55
3.93M
    outptr = *output_buf++;
56
87.2M
    for (col = 0; col < num_cols; col++) {
57
83.2M
      y  = inptr0[col];
58
83.2M
      cb = inptr1[col];
59
83.2M
      cr = inptr2[col];
60
      /* Range-limiting is essential due to noise introduced by DCT losses. */
61
83.2M
      outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
62
83.2M
      outptr[RGB_GREEN] = range_limit[y +
63
83.2M
                              ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
64
83.2M
                                                SCALEBITS))];
65
83.2M
      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
83.2M
#ifdef RGB_ALPHA
69
83.2M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
70
83.2M
#endif
71
83.2M
      outptr += RGB_PIXELSIZE;
72
83.2M
    }
73
3.93M
  }
74
#else
75
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
76
#endif
77
2.01M
}
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
3.32M
{
92
3.32M
  register _JSAMPROW inptr, outptr;
93
3.32M
  register JDIMENSION col;
94
3.32M
  JDIMENSION num_cols = cinfo->output_width;
95
96
8.44M
  while (--num_rows >= 0) {
97
5.11M
    inptr = input_buf[0][input_row++];
98
5.11M
    outptr = *output_buf++;
99
192M
    for (col = 0; col < num_cols; col++) {
100
186M
      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
13.9M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
#endif
106
186M
      outptr += RGB_PIXELSIZE;
107
186M
    }
108
5.11M
  }
109
3.32M
}
jdcolor.c:gray_extrgb_convert_internal
Line
Count
Source
91
2.93M
{
92
2.93M
  register _JSAMPROW inptr, outptr;
93
2.93M
  register JDIMENSION col;
94
2.93M
  JDIMENSION num_cols = cinfo->output_width;
95
96
7.37M
  while (--num_rows >= 0) {
97
4.44M
    inptr = input_buf[0][input_row++];
98
4.44M
    outptr = *output_buf++;
99
177M
    for (col = 0; col < num_cols; col++) {
100
173M
      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
173M
      outptr += RGB_PIXELSIZE;
107
173M
    }
108
4.44M
  }
109
2.93M
}
Unexecuted instantiation: jdcolor.c:gray_extrgbx_convert_internal
Unexecuted instantiation: jdcolor.c:gray_extbgr_convert_internal
jdcolor.c:gray_extbgrx_convert_internal
Line
Count
Source
91
390k
{
92
390k
  register _JSAMPROW inptr, outptr;
93
390k
  register JDIMENSION col;
94
390k
  JDIMENSION num_cols = cinfo->output_width;
95
96
1.06M
  while (--num_rows >= 0) {
97
672k
    inptr = input_buf[0][input_row++];
98
672k
    outptr = *output_buf++;
99
14.6M
    for (col = 0; col < num_cols; col++) {
100
13.9M
      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
13.9M
#ifdef RGB_ALPHA
104
13.9M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
105
13.9M
#endif
106
13.9M
      outptr += RGB_PIXELSIZE;
107
13.9M
    }
108
672k
  }
109
390k
}
Unexecuted instantiation: jdcolor.c:gray_extxbgr_convert_internal
Unexecuted instantiation: jdcolor.c:gray_extxrgb_convert_internal
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
428k
{
122
428k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
428k
  register _JSAMPROW outptr;
124
428k
  register JDIMENSION col;
125
428k
  JDIMENSION num_cols = cinfo->output_width;
126
127
1.29M
  while (--num_rows >= 0) {
128
867k
    inptr0 = input_buf[0][input_row];
129
867k
    inptr1 = input_buf[1][input_row];
130
867k
    inptr2 = input_buf[2][input_row];
131
867k
    input_row++;
132
867k
    outptr = *output_buf++;
133
33.1M
    for (col = 0; col < num_cols; col++) {
134
32.2M
      outptr[RGB_RED] = inptr0[col];
135
32.2M
      outptr[RGB_GREEN] = inptr1[col];
136
32.2M
      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
32.2M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
#endif
142
32.2M
      outptr += RGB_PIXELSIZE;
143
32.2M
    }
144
867k
  }
145
428k
}
Unexecuted instantiation: jdcolor.c:rgb_extrgb_convert_internal
Unexecuted instantiation: jdcolor.c:rgb_extrgbx_convert_internal
Unexecuted instantiation: jdcolor.c:rgb_extbgr_convert_internal
jdcolor.c:rgb_extbgrx_convert_internal
Line
Count
Source
121
428k
{
122
428k
  register _JSAMPROW inptr0, inptr1, inptr2;
123
428k
  register _JSAMPROW outptr;
124
428k
  register JDIMENSION col;
125
428k
  JDIMENSION num_cols = cinfo->output_width;
126
127
1.29M
  while (--num_rows >= 0) {
128
867k
    inptr0 = input_buf[0][input_row];
129
867k
    inptr1 = input_buf[1][input_row];
130
867k
    inptr2 = input_buf[2][input_row];
131
867k
    input_row++;
132
867k
    outptr = *output_buf++;
133
33.1M
    for (col = 0; col < num_cols; col++) {
134
32.2M
      outptr[RGB_RED] = inptr0[col];
135
32.2M
      outptr[RGB_GREEN] = inptr1[col];
136
32.2M
      outptr[RGB_BLUE] = inptr2[col];
137
      /* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
138
      /* opaque alpha channel value */
139
32.2M
#ifdef RGB_ALPHA
140
32.2M
      outptr[RGB_ALPHA] = _MAXJSAMPLE;
141
32.2M
#endif
142
32.2M
      outptr += RGB_PIXELSIZE;
143
32.2M
    }
144
867k
  }
145
428k
}
Unexecuted instantiation: jdcolor.c:rgb_extxbgr_convert_internal
Unexecuted instantiation: jdcolor.c:rgb_extxrgb_convert_internal
Unexecuted instantiation: jdcolor.c:rgb_rgb_convert_internal