Coverage Report

Created: 2025-07-01 06:27

/src/libjpeg-turbo.3.0.x/jccolext.c
Line
Count
Source
1
/*
2
 * jccolext.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1996, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.
8
 * For conditions of distribution and use, see the accompanying README.ijg
9
 * file.
10
 *
11
 * This file contains input colorspace conversion routines.
12
 */
13
14
15
/* This file is included by jccolor.c */
16
17
18
/*
19
 * Convert some rows of samples to the JPEG colorspace.
20
 *
21
 * Note that we change from the application's interleaved-pixel format
22
 * to our internal noninterleaved, one-plane-per-component format.
23
 * The input buffer is therefore three times as wide as the output buffer.
24
 *
25
 * A starting row offset is provided only for the output buffer.  The caller
26
 * can easily adjust the passed input_buf value to accommodate any row
27
 * offset required on that side.
28
 */
29
30
INLINE
31
LOCAL(void)
32
rgb_ycc_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
33
                         _JSAMPIMAGE output_buf, JDIMENSION output_row,
34
                         int num_rows)
35
47.8M
{
36
47.8M
#if BITS_IN_JSAMPLE != 16
37
47.8M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
38
47.8M
  register int r, g, b;
39
47.8M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
40
47.8M
  register _JSAMPROW inptr;
41
47.8M
  register _JSAMPROW outptr0, outptr1, outptr2;
42
47.8M
  register JDIMENSION col;
43
47.8M
  JDIMENSION num_cols = cinfo->image_width;
44
45
102M
  while (--num_rows >= 0) {
46
54.7M
    inptr = *input_buf++;
47
54.7M
    outptr0 = output_buf[0][output_row];
48
54.7M
    outptr1 = output_buf[1][output_row];
49
54.7M
    outptr2 = output_buf[2][output_row];
50
54.7M
    output_row++;
51
189M
    for (col = 0; col < num_cols; col++) {
52
135M
      r = RANGE_LIMIT(inptr[RGB_RED]);
53
135M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
54
135M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
55
135M
      inptr += RGB_PIXELSIZE;
56
      /* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
57
       * must be too; we do not need an explicit range-limiting operation.
58
       * Hence the value being shifted is never negative, and we don't
59
       * need the general RIGHT_SHIFT macro.
60
       */
61
      /* Y */
62
135M
      outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
63
135M
                                 ctab[b + B_Y_OFF]) >> SCALEBITS);
64
      /* Cb */
65
135M
      outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
66
135M
                                 ctab[b + B_CB_OFF]) >> SCALEBITS);
67
      /* Cr */
68
135M
      outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
69
135M
                                 ctab[b + B_CR_OFF]) >> SCALEBITS);
70
135M
    }
71
54.7M
  }
72
#else
73
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
74
#endif
75
47.8M
}
jccolor.c:extrgb_ycc_convert_internal
Line
Count
Source
35
13.6M
{
36
13.6M
#if BITS_IN_JSAMPLE != 16
37
13.6M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
38
13.6M
  register int r, g, b;
39
13.6M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
40
13.6M
  register _JSAMPROW inptr;
41
13.6M
  register _JSAMPROW outptr0, outptr1, outptr2;
42
13.6M
  register JDIMENSION col;
43
13.6M
  JDIMENSION num_cols = cinfo->image_width;
44
45
27.3M
  while (--num_rows >= 0) {
46
13.6M
    inptr = *input_buf++;
47
13.6M
    outptr0 = output_buf[0][output_row];
48
13.6M
    outptr1 = output_buf[1][output_row];
49
13.6M
    outptr2 = output_buf[2][output_row];
50
13.6M
    output_row++;
51
47.4M
    for (col = 0; col < num_cols; col++) {
52
33.7M
      r = RANGE_LIMIT(inptr[RGB_RED]);
53
33.7M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
54
33.7M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
55
33.7M
      inptr += RGB_PIXELSIZE;
56
      /* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
57
       * must be too; we do not need an explicit range-limiting operation.
58
       * Hence the value being shifted is never negative, and we don't
59
       * need the general RIGHT_SHIFT macro.
60
       */
61
      /* Y */
62
33.7M
      outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
63
33.7M
                                 ctab[b + B_Y_OFF]) >> SCALEBITS);
64
      /* Cb */
65
33.7M
      outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
66
33.7M
                                 ctab[b + B_CB_OFF]) >> SCALEBITS);
67
      /* Cr */
68
33.7M
      outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
69
33.7M
                                 ctab[b + B_CR_OFF]) >> SCALEBITS);
70
33.7M
    }
71
13.6M
  }
72
#else
73
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
74
#endif
75
13.6M
}
jccolor.c:extrgbx_ycc_convert_internal
Line
Count
Source
35
6.84M
{
36
6.84M
#if BITS_IN_JSAMPLE != 16
37
6.84M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
38
6.84M
  register int r, g, b;
39
6.84M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
40
6.84M
  register _JSAMPROW inptr;
41
6.84M
  register _JSAMPROW outptr0, outptr1, outptr2;
42
6.84M
  register JDIMENSION col;
43
6.84M
  JDIMENSION num_cols = cinfo->image_width;
44
45
20.5M
  while (--num_rows >= 0) {
46
13.6M
    inptr = *input_buf++;
47
13.6M
    outptr0 = output_buf[0][output_row];
48
13.6M
    outptr1 = output_buf[1][output_row];
49
13.6M
    outptr2 = output_buf[2][output_row];
50
13.6M
    output_row++;
51
47.4M
    for (col = 0; col < num_cols; col++) {
52
33.7M
      r = RANGE_LIMIT(inptr[RGB_RED]);
53
33.7M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
54
33.7M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
55
33.7M
      inptr += RGB_PIXELSIZE;
56
      /* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
57
       * must be too; we do not need an explicit range-limiting operation.
58
       * Hence the value being shifted is never negative, and we don't
59
       * need the general RIGHT_SHIFT macro.
60
       */
61
      /* Y */
62
33.7M
      outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
63
33.7M
                                 ctab[b + B_Y_OFF]) >> SCALEBITS);
64
      /* Cb */
65
33.7M
      outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
66
33.7M
                                 ctab[b + B_CB_OFF]) >> SCALEBITS);
67
      /* Cr */
68
33.7M
      outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
69
33.7M
                                 ctab[b + B_CR_OFF]) >> SCALEBITS);
70
33.7M
    }
71
13.6M
  }
72
#else
73
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
74
#endif
75
6.84M
}
jccolor.c:extbgr_ycc_convert_internal
Line
Count
Source
35
13.6M
{
36
13.6M
#if BITS_IN_JSAMPLE != 16
37
13.6M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
38
13.6M
  register int r, g, b;
39
13.6M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
40
13.6M
  register _JSAMPROW inptr;
41
13.6M
  register _JSAMPROW outptr0, outptr1, outptr2;
42
13.6M
  register JDIMENSION col;
43
13.6M
  JDIMENSION num_cols = cinfo->image_width;
44
45
27.3M
  while (--num_rows >= 0) {
46
13.6M
    inptr = *input_buf++;
47
13.6M
    outptr0 = output_buf[0][output_row];
48
13.6M
    outptr1 = output_buf[1][output_row];
49
13.6M
    outptr2 = output_buf[2][output_row];
50
13.6M
    output_row++;
51
47.4M
    for (col = 0; col < num_cols; col++) {
52
33.7M
      r = RANGE_LIMIT(inptr[RGB_RED]);
53
33.7M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
54
33.7M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
55
33.7M
      inptr += RGB_PIXELSIZE;
56
      /* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
57
       * must be too; we do not need an explicit range-limiting operation.
58
       * Hence the value being shifted is never negative, and we don't
59
       * need the general RIGHT_SHIFT macro.
60
       */
61
      /* Y */
62
33.7M
      outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
63
33.7M
                                 ctab[b + B_Y_OFF]) >> SCALEBITS);
64
      /* Cb */
65
33.7M
      outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
66
33.7M
                                 ctab[b + B_CB_OFF]) >> SCALEBITS);
67
      /* Cr */
68
33.7M
      outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
69
33.7M
                                 ctab[b + B_CR_OFF]) >> SCALEBITS);
70
33.7M
    }
71
13.6M
  }
72
#else
73
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
74
#endif
75
13.6M
}
jccolor.c:extbgrx_ycc_convert_internal
Line
Count
Source
35
13.6M
{
36
13.6M
#if BITS_IN_JSAMPLE != 16
37
13.6M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
38
13.6M
  register int r, g, b;
39
13.6M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
40
13.6M
  register _JSAMPROW inptr;
41
13.6M
  register _JSAMPROW outptr0, outptr1, outptr2;
42
13.6M
  register JDIMENSION col;
43
13.6M
  JDIMENSION num_cols = cinfo->image_width;
44
45
27.3M
  while (--num_rows >= 0) {
46
13.6M
    inptr = *input_buf++;
47
13.6M
    outptr0 = output_buf[0][output_row];
48
13.6M
    outptr1 = output_buf[1][output_row];
49
13.6M
    outptr2 = output_buf[2][output_row];
50
13.6M
    output_row++;
51
47.4M
    for (col = 0; col < num_cols; col++) {
52
33.7M
      r = RANGE_LIMIT(inptr[RGB_RED]);
53
33.7M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
54
33.7M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
55
33.7M
      inptr += RGB_PIXELSIZE;
56
      /* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
57
       * must be too; we do not need an explicit range-limiting operation.
58
       * Hence the value being shifted is never negative, and we don't
59
       * need the general RIGHT_SHIFT macro.
60
       */
61
      /* Y */
62
33.7M
      outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
63
33.7M
                                 ctab[b + B_Y_OFF]) >> SCALEBITS);
64
      /* Cb */
65
33.7M
      outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
66
33.7M
                                 ctab[b + B_CB_OFF]) >> SCALEBITS);
67
      /* Cr */
68
33.7M
      outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
69
33.7M
                                 ctab[b + B_CR_OFF]) >> SCALEBITS);
70
33.7M
    }
71
13.6M
  }
72
#else
73
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
74
#endif
75
13.6M
}
Unexecuted instantiation: jccolor.c:extxbgr_ycc_convert_internal
Unexecuted instantiation: jccolor.c:extxrgb_ycc_convert_internal
Unexecuted instantiation: jccolor.c:rgb_ycc_convert_internal
76
77
78
/**************** Cases other than RGB -> YCbCr **************/
79
80
81
/*
82
 * Convert some rows of samples to the JPEG colorspace.
83
 * This version handles RGB->grayscale conversion, which is the same
84
 * as the RGB->Y portion of RGB->YCbCr.
85
 * We assume rgb_ycc_start has been called (we only use the Y tables).
86
 */
87
88
INLINE
89
LOCAL(void)
90
rgb_gray_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
91
                          _JSAMPIMAGE output_buf, JDIMENSION output_row,
92
                          int num_rows)
93
13.6M
{
94
13.6M
#if BITS_IN_JSAMPLE != 16
95
13.6M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
96
13.6M
  register int r, g, b;
97
13.6M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
98
13.6M
  register _JSAMPROW inptr;
99
13.6M
  register _JSAMPROW outptr;
100
13.6M
  register JDIMENSION col;
101
13.6M
  JDIMENSION num_cols = cinfo->image_width;
102
103
27.3M
  while (--num_rows >= 0) {
104
13.6M
    inptr = *input_buf++;
105
13.6M
    outptr = output_buf[0][output_row];
106
13.6M
    output_row++;
107
47.4M
    for (col = 0; col < num_cols; col++) {
108
33.7M
      r = RANGE_LIMIT(inptr[RGB_RED]);
109
33.7M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
110
33.7M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
111
33.7M
      inptr += RGB_PIXELSIZE;
112
      /* Y */
113
33.7M
      outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
114
33.7M
                                ctab[b + B_Y_OFF]) >> SCALEBITS);
115
33.7M
    }
116
13.6M
  }
117
#else
118
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
119
#endif
120
13.6M
}
Unexecuted instantiation: jccolor.c:extrgb_gray_convert_internal
Unexecuted instantiation: jccolor.c:extrgbx_gray_convert_internal
Unexecuted instantiation: jccolor.c:extbgr_gray_convert_internal
Unexecuted instantiation: jccolor.c:extbgrx_gray_convert_internal
Unexecuted instantiation: jccolor.c:extxbgr_gray_convert_internal
jccolor.c:extxrgb_gray_convert_internal
Line
Count
Source
93
13.6M
{
94
13.6M
#if BITS_IN_JSAMPLE != 16
95
13.6M
  my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
96
13.6M
  register int r, g, b;
97
13.6M
  register JLONG *ctab = cconvert->rgb_ycc_tab;
98
13.6M
  register _JSAMPROW inptr;
99
13.6M
  register _JSAMPROW outptr;
100
13.6M
  register JDIMENSION col;
101
13.6M
  JDIMENSION num_cols = cinfo->image_width;
102
103
27.3M
  while (--num_rows >= 0) {
104
13.6M
    inptr = *input_buf++;
105
13.6M
    outptr = output_buf[0][output_row];
106
13.6M
    output_row++;
107
47.4M
    for (col = 0; col < num_cols; col++) {
108
33.7M
      r = RANGE_LIMIT(inptr[RGB_RED]);
109
33.7M
      g = RANGE_LIMIT(inptr[RGB_GREEN]);
110
33.7M
      b = RANGE_LIMIT(inptr[RGB_BLUE]);
111
33.7M
      inptr += RGB_PIXELSIZE;
112
      /* Y */
113
33.7M
      outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
114
33.7M
                                ctab[b + B_Y_OFF]) >> SCALEBITS);
115
33.7M
    }
116
13.6M
  }
117
#else
118
  ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
119
#endif
120
13.6M
}
Unexecuted instantiation: jccolor.c:rgb_gray_convert_internal
121
122
123
/*
124
 * Convert some rows of samples to the JPEG colorspace.
125
 * This version handles extended RGB->plain RGB conversion
126
 */
127
128
INLINE
129
LOCAL(void)
130
rgb_rgb_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
131
                         _JSAMPIMAGE output_buf, JDIMENSION output_row,
132
                         int num_rows)
133
15.1M
{
134
15.1M
  register _JSAMPROW inptr;
135
15.1M
  register _JSAMPROW outptr0, outptr1, outptr2;
136
15.1M
  register JDIMENSION col;
137
15.1M
  JDIMENSION num_cols = cinfo->image_width;
138
139
30.3M
  while (--num_rows >= 0) {
140
15.1M
    inptr = *input_buf++;
141
15.1M
    outptr0 = output_buf[0][output_row];
142
15.1M
    outptr1 = output_buf[1][output_row];
143
15.1M
    outptr2 = output_buf[2][output_row];
144
15.1M
    output_row++;
145
93.4M
    for (col = 0; col < num_cols; col++) {
146
78.3M
      outptr0[col] = inptr[RGB_RED];
147
78.3M
      outptr1[col] = inptr[RGB_GREEN];
148
78.3M
      outptr2[col] = inptr[RGB_BLUE];
149
78.3M
      inptr += RGB_PIXELSIZE;
150
78.3M
    }
151
15.1M
  }
152
15.1M
}
Unexecuted instantiation: jccolor.c:extrgb_rgb_convert_internal
jccolor.c:extrgbx_rgb_convert_internal
Line
Count
Source
133
3.79M
{
134
3.79M
  register _JSAMPROW inptr;
135
3.79M
  register _JSAMPROW outptr0, outptr1, outptr2;
136
3.79M
  register JDIMENSION col;
137
3.79M
  JDIMENSION num_cols = cinfo->image_width;
138
139
7.58M
  while (--num_rows >= 0) {
140
3.79M
    inptr = *input_buf++;
141
3.79M
    outptr0 = output_buf[0][output_row];
142
3.79M
    outptr1 = output_buf[1][output_row];
143
3.79M
    outptr2 = output_buf[2][output_row];
144
3.79M
    output_row++;
145
23.3M
    for (col = 0; col < num_cols; col++) {
146
19.5M
      outptr0[col] = inptr[RGB_RED];
147
19.5M
      outptr1[col] = inptr[RGB_GREEN];
148
19.5M
      outptr2[col] = inptr[RGB_BLUE];
149
19.5M
      inptr += RGB_PIXELSIZE;
150
19.5M
    }
151
3.79M
  }
152
3.79M
}
jccolor.c:extbgr_rgb_convert_internal
Line
Count
Source
133
3.79M
{
134
3.79M
  register _JSAMPROW inptr;
135
3.79M
  register _JSAMPROW outptr0, outptr1, outptr2;
136
3.79M
  register JDIMENSION col;
137
3.79M
  JDIMENSION num_cols = cinfo->image_width;
138
139
7.58M
  while (--num_rows >= 0) {
140
3.79M
    inptr = *input_buf++;
141
3.79M
    outptr0 = output_buf[0][output_row];
142
3.79M
    outptr1 = output_buf[1][output_row];
143
3.79M
    outptr2 = output_buf[2][output_row];
144
3.79M
    output_row++;
145
23.3M
    for (col = 0; col < num_cols; col++) {
146
19.5M
      outptr0[col] = inptr[RGB_RED];
147
19.5M
      outptr1[col] = inptr[RGB_GREEN];
148
19.5M
      outptr2[col] = inptr[RGB_BLUE];
149
19.5M
      inptr += RGB_PIXELSIZE;
150
19.5M
    }
151
3.79M
  }
152
3.79M
}
jccolor.c:extbgrx_rgb_convert_internal
Line
Count
Source
133
3.79M
{
134
3.79M
  register _JSAMPROW inptr;
135
3.79M
  register _JSAMPROW outptr0, outptr1, outptr2;
136
3.79M
  register JDIMENSION col;
137
3.79M
  JDIMENSION num_cols = cinfo->image_width;
138
139
7.58M
  while (--num_rows >= 0) {
140
3.79M
    inptr = *input_buf++;
141
3.79M
    outptr0 = output_buf[0][output_row];
142
3.79M
    outptr1 = output_buf[1][output_row];
143
3.79M
    outptr2 = output_buf[2][output_row];
144
3.79M
    output_row++;
145
23.3M
    for (col = 0; col < num_cols; col++) {
146
19.5M
      outptr0[col] = inptr[RGB_RED];
147
19.5M
      outptr1[col] = inptr[RGB_GREEN];
148
19.5M
      outptr2[col] = inptr[RGB_BLUE];
149
19.5M
      inptr += RGB_PIXELSIZE;
150
19.5M
    }
151
3.79M
  }
152
3.79M
}
Unexecuted instantiation: jccolor.c:extxbgr_rgb_convert_internal
jccolor.c:extxrgb_rgb_convert_internal
Line
Count
Source
133
3.79M
{
134
3.79M
  register _JSAMPROW inptr;
135
3.79M
  register _JSAMPROW outptr0, outptr1, outptr2;
136
3.79M
  register JDIMENSION col;
137
3.79M
  JDIMENSION num_cols = cinfo->image_width;
138
139
7.58M
  while (--num_rows >= 0) {
140
3.79M
    inptr = *input_buf++;
141
3.79M
    outptr0 = output_buf[0][output_row];
142
3.79M
    outptr1 = output_buf[1][output_row];
143
3.79M
    outptr2 = output_buf[2][output_row];
144
3.79M
    output_row++;
145
23.3M
    for (col = 0; col < num_cols; col++) {
146
19.5M
      outptr0[col] = inptr[RGB_RED];
147
19.5M
      outptr1[col] = inptr[RGB_GREEN];
148
19.5M
      outptr2[col] = inptr[RGB_BLUE];
149
19.5M
      inptr += RGB_PIXELSIZE;
150
19.5M
    }
151
3.79M
  }
152
3.79M
}
Unexecuted instantiation: jccolor.c:rgb_rgb_convert_internal