Coverage Report

Created: 2026-04-28 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/rdpng.c
Line
Count
Source
1
/*
2
 * rdpng.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) 2015-2017, 2020-2026, D. R. Commander.
8
 * For conditions of distribution and use, see the accompanying README.ijg
9
 * file.
10
 *
11
 * This file contains routines to read input images in 8-bit-per-channel or
12
 * 16-bit-per-channel PNG format.  libspng is required to compile this
13
 * software.
14
 */
15
16
#ifdef _MSC_VER
17
#define _CRT_SECURE_NO_DEPRECATE
18
#endif
19
20
#include "cmyk.h"
21
#include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
22
#include "spng/spng.h"
23
24
#if defined(PNG_SUPPORTED) && \
25
    (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
26
27
28
static int alpha_index[JPEG_NUMCS] = {
29
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
30
};
31
32
33
394k
#define TRY_SPNG(f) { \
34
394k
  int __spng_error = (f); \
35
394k
  if (__spng_error) \
36
394k
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(__spng_error)); \
37
394k
}
38
39
40
/* Private version of data source object */
41
42
typedef struct {
43
  struct cjpeg_source_struct pub; /* public fields */
44
45
  spng_ctx *ctx;
46
  uint8_t png_bit_depth, png_color_type;
47
  int png_alpha;
48
  struct spng_plte colormap;    /* PNG colormap */
49
50
  /* Usually these two pointers point to the same place: */
51
  unsigned char *iobuffer;      /* libspng's I/O buffer */
52
  _JSAMPROW pixrow;             /* compressor input buffer */
53
  size_t buffer_width;          /* width of I/O buffer */
54
  _JSAMPLE *rescale;            /* PNG bit depth => data precision remapping
55
                                   array, or NULL */
56
} png_source_struct;
57
58
typedef png_source_struct *png_source_ptr;
59
60
61
/*
62
 * Read one row of pixels.
63
 *
64
 * We provide several different versions depending on input file format.
65
 * In all cases, input is scaled to cinfo->data_precision.
66
 *
67
 * get_raw_row() is used when the pixel format is JCS_EXT_RGB/JCS_RGB or
68
 * JCS_GRAYSCALE, cinfo->data_precision is 8 or 16, and the PNG file doesn't
69
 * have an alpha channel.  Thus, we can read the pixels directly from the PNG
70
 * file.
71
 */
72
73
METHODDEF(JDIMENSION)
74
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
75
646k
{
76
646k
  png_source_ptr source = (png_source_ptr)sinfo;
77
646k
  int spng_error;
78
79
646k
  spng_error = spng_decode_row(source->ctx, source->iobuffer,
80
646k
                               source->buffer_width);
81
646k
  if (spng_error && spng_error != SPNG_EOI)
82
15.4k
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \
83
646k
  return 1;
84
646k
}
rdpng-8.c:get_raw_row
Line
Count
Source
75
318k
{
76
318k
  png_source_ptr source = (png_source_ptr)sinfo;
77
318k
  int spng_error;
78
79
318k
  spng_error = spng_decode_row(source->ctx, source->iobuffer,
80
318k
                               source->buffer_width);
81
318k
  if (spng_error && spng_error != SPNG_EOI)
82
7.63k
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \
83
318k
  return 1;
84
318k
}
rdpng-12.c:get_raw_row
Line
Count
Source
75
278k
{
76
278k
  png_source_ptr source = (png_source_ptr)sinfo;
77
278k
  int spng_error;
78
79
278k
  spng_error = spng_decode_row(source->ctx, source->iobuffer,
80
278k
                               source->buffer_width);
81
278k
  if (spng_error && spng_error != SPNG_EOI)
82
5.21k
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \
83
278k
  return 1;
84
278k
}
rdpng-16.c:get_raw_row
Line
Count
Source
75
48.8k
{
76
48.8k
  png_source_ptr source = (png_source_ptr)sinfo;
77
48.8k
  int spng_error;
78
79
48.8k
  spng_error = spng_decode_row(source->ctx, source->iobuffer,
80
48.8k
                               source->buffer_width);
81
48.8k
  if (spng_error && spng_error != SPNG_EOI)
82
2.56k
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \
83
48.8k
  return 1;
84
48.8k
}
85
86
87
156k
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \
88
10.9M
  for (col = cinfo->image_width; col > 0; col--) { \
89
10.7M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
90
10.7M
    alpha_set_op \
91
10.7M
    ptr += ps; \
92
10.7M
    pointer_op \
93
10.7M
  } \
94
156k
}
95
96
97
METHODDEF(JDIMENSION)
98
get_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
99
/* This version is for reading 8-bit-per-channel or 16-bit-per-channel
100
 * grayscale or grayscale + alpha PNG files.
101
 */
102
28.2k
{
103
28.2k
  png_source_ptr source = (png_source_ptr)sinfo;
104
28.2k
  register _JSAMPROW ptr;
105
28.2k
  register _JSAMPLE *rescale = source->rescale;
106
28.2k
  JDIMENSION col;
107
108
28.2k
  get_raw_row(cinfo, sinfo);
109
28.2k
  ptr = source->pub._buffer[0];
110
#if BITS_IN_JSAMPLE != 12
111
21.4k
  if (source->png_bit_depth == cinfo->data_precision) {
112
94
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
113
18.8k
    for (col = cinfo->image_width; col > 0; col--) {
114
18.8k
      *ptr++ = *bufferptr++;
115
18.8k
      bufferptr += source->png_alpha;
116
18.8k
    }
117
94
  } else
118
21.3k
#endif
119
28.1k
  if (source->png_bit_depth == 16) {
120
19.9k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
121
1.28M
    for (col = cinfo->image_width; col > 0; col--) {
122
1.26M
      *ptr++ = rescale[*bufferptr++];
123
1.26M
      bufferptr += source->png_alpha;
124
1.26M
    }
125
19.9k
  } else {
126
8.11k
    register unsigned char *bufferptr = source->iobuffer;
127
610k
    for (col = cinfo->image_width; col > 0; col--) {
128
602k
      *ptr++ = rescale[*bufferptr++];
129
602k
      bufferptr += source->png_alpha;
130
602k
    }
131
8.11k
  }
132
28.2k
  return 1;
133
28.2k
}
rdpng-8.c:get_gray_row
Line
Count
Source
102
19.4k
{
103
19.4k
  png_source_ptr source = (png_source_ptr)sinfo;
104
19.4k
  register _JSAMPROW ptr;
105
19.4k
  register _JSAMPLE *rescale = source->rescale;
106
19.4k
  JDIMENSION col;
107
108
19.4k
  get_raw_row(cinfo, sinfo);
109
19.4k
  ptr = source->pub._buffer[0];
110
19.4k
#if BITS_IN_JSAMPLE != 12
111
19.4k
  if (source->png_bit_depth == cinfo->data_precision) {
112
94
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
113
18.8k
    for (col = cinfo->image_width; col > 0; col--) {
114
18.8k
      *ptr++ = *bufferptr++;
115
18.8k
      bufferptr += source->png_alpha;
116
18.8k
    }
117
94
  } else
118
19.3k
#endif
119
19.3k
  if (source->png_bit_depth == 16) {
120
16.8k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
121
1.07M
    for (col = cinfo->image_width; col > 0; col--) {
122
1.06M
      *ptr++ = rescale[*bufferptr++];
123
1.06M
      bufferptr += source->png_alpha;
124
1.06M
    }
125
16.8k
  } else {
126
2.52k
    register unsigned char *bufferptr = source->iobuffer;
127
146k
    for (col = cinfo->image_width; col > 0; col--) {
128
144k
      *ptr++ = rescale[*bufferptr++];
129
144k
      bufferptr += source->png_alpha;
130
144k
    }
131
2.52k
  }
132
19.4k
  return 1;
133
19.4k
}
rdpng-12.c:get_gray_row
Line
Count
Source
102
6.72k
{
103
6.72k
  png_source_ptr source = (png_source_ptr)sinfo;
104
6.72k
  register _JSAMPROW ptr;
105
6.72k
  register _JSAMPLE *rescale = source->rescale;
106
6.72k
  JDIMENSION col;
107
108
6.72k
  get_raw_row(cinfo, sinfo);
109
6.72k
  ptr = source->pub._buffer[0];
110
#if BITS_IN_JSAMPLE != 12
111
  if (source->png_bit_depth == cinfo->data_precision) {
112
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
113
    for (col = cinfo->image_width; col > 0; col--) {
114
      *ptr++ = *bufferptr++;
115
      bufferptr += source->png_alpha;
116
    }
117
  } else
118
#endif
119
6.72k
  if (source->png_bit_depth == 16) {
120
3.13k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
121
204k
    for (col = cinfo->image_width; col > 0; col--) {
122
201k
      *ptr++ = rescale[*bufferptr++];
123
201k
      bufferptr += source->png_alpha;
124
201k
    }
125
3.58k
  } else {
126
3.58k
    register unsigned char *bufferptr = source->iobuffer;
127
292k
    for (col = cinfo->image_width; col > 0; col--) {
128
289k
      *ptr++ = rescale[*bufferptr++];
129
289k
      bufferptr += source->png_alpha;
130
289k
    }
131
3.58k
  }
132
6.72k
  return 1;
133
6.72k
}
rdpng-16.c:get_gray_row
Line
Count
Source
102
2.00k
{
103
2.00k
  png_source_ptr source = (png_source_ptr)sinfo;
104
2.00k
  register _JSAMPROW ptr;
105
2.00k
  register _JSAMPLE *rescale = source->rescale;
106
2.00k
  JDIMENSION col;
107
108
2.00k
  get_raw_row(cinfo, sinfo);
109
2.00k
  ptr = source->pub._buffer[0];
110
2.00k
#if BITS_IN_JSAMPLE != 12
111
2.00k
  if (source->png_bit_depth == cinfo->data_precision) {
112
0
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
113
0
    for (col = cinfo->image_width; col > 0; col--) {
114
0
      *ptr++ = *bufferptr++;
115
0
      bufferptr += source->png_alpha;
116
0
    }
117
0
  } else
118
2.00k
#endif
119
2.00k
  if (source->png_bit_depth == 16) {
120
0
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
121
0
    for (col = cinfo->image_width; col > 0; col--) {
122
0
      *ptr++ = rescale[*bufferptr++];
123
0
      bufferptr += source->png_alpha;
124
0
    }
125
2.00k
  } else {
126
2.00k
    register unsigned char *bufferptr = source->iobuffer;
127
170k
    for (col = cinfo->image_width; col > 0; col--) {
128
168k
      *ptr++ = rescale[*bufferptr++];
129
168k
      bufferptr += source->png_alpha;
130
168k
    }
131
2.00k
  }
132
2.00k
  return 1;
133
2.00k
}
134
135
136
METHODDEF(JDIMENSION)
137
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
138
/* This version is for reading 8-bit-per-channel or 16-bit-per-channel
139
 * grayscale or grayscale + alpha PNG files and converting to extended RGB.
140
 */
141
156k
{
142
156k
  png_source_ptr source = (png_source_ptr)sinfo;
143
156k
  register _JSAMPROW ptr;
144
156k
  register _JSAMPLE *rescale = source->rescale;
145
156k
  JDIMENSION col;
146
156k
  register int rindex = rgb_red[cinfo->in_color_space];
147
156k
  register int gindex = rgb_green[cinfo->in_color_space];
148
156k
  register int bindex = rgb_blue[cinfo->in_color_space];
149
156k
  register int aindex = alpha_index[cinfo->in_color_space];
150
156k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
151
152
156k
  get_raw_row(cinfo, sinfo);
153
156k
  ptr = source->pub._buffer[0];
154
#if BITS_IN_JSAMPLE != 12
155
123k
  if (source->png_bit_depth == cinfo->data_precision) {
156
19.6k
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
157
19.6k
    if (aindex >= 0)
158
1.45k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
159
19.6k
                         bufferptr += source->png_alpha;)
160
18.2k
    else
161
18.2k
      GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
162
19.6k
  } else
163
103k
#endif
164
137k
  if (source->png_bit_depth == 16) {
165
98.2k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
166
98.2k
    if (aindex >= 0)
167
7.37k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
168
98.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
169
98.2k
                         bufferptr += source->png_alpha;)
170
90.8k
    else
171
90.8k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
172
98.2k
                         bufferptr += source->png_alpha;)
173
98.2k
  } else {
174
38.8k
    register unsigned char *bufferptr = source->iobuffer;
175
38.8k
    if (aindex >= 0)
176
7.48k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
177
38.8k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
178
38.8k
                         bufferptr += source->png_alpha;)
179
31.3k
    else
180
31.3k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
181
38.8k
                         bufferptr += source->png_alpha;)
182
38.8k
  }
183
156k
  return 1;
184
156k
}
rdpng-8.c:get_gray_rgb_row
Line
Count
Source
141
104k
{
142
104k
  png_source_ptr source = (png_source_ptr)sinfo;
143
104k
  register _JSAMPROW ptr;
144
104k
  register _JSAMPLE *rescale = source->rescale;
145
104k
  JDIMENSION col;
146
104k
  register int rindex = rgb_red[cinfo->in_color_space];
147
104k
  register int gindex = rgb_green[cinfo->in_color_space];
148
104k
  register int bindex = rgb_blue[cinfo->in_color_space];
149
104k
  register int aindex = alpha_index[cinfo->in_color_space];
150
104k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
151
152
104k
  get_raw_row(cinfo, sinfo);
153
104k
  ptr = source->pub._buffer[0];
154
104k
#if BITS_IN_JSAMPLE != 12
155
104k
  if (source->png_bit_depth == cinfo->data_precision) {
156
16.1k
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
157
16.1k
    if (aindex >= 0)
158
1.45k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
159
16.1k
                         bufferptr += source->png_alpha;)
160
14.6k
    else
161
14.6k
      GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
162
16.1k
  } else
163
87.9k
#endif
164
87.9k
  if (source->png_bit_depth == 16) {
165
77.2k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
166
77.2k
    if (aindex >= 0)
167
2.47k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
168
77.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
169
77.2k
                         bufferptr += source->png_alpha;)
170
74.7k
    else
171
74.7k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
172
77.2k
                         bufferptr += source->png_alpha;)
173
77.2k
  } else {
174
10.6k
    register unsigned char *bufferptr = source->iobuffer;
175
10.6k
    if (aindex >= 0)
176
2.22k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
177
10.6k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
178
10.6k
                         bufferptr += source->png_alpha;)
179
8.44k
    else
180
8.44k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
181
10.6k
                         bufferptr += source->png_alpha;)
182
10.6k
  }
183
104k
  return 1;
184
104k
}
rdpng-12.c:get_gray_rgb_row
Line
Count
Source
141
33.6k
{
142
33.6k
  png_source_ptr source = (png_source_ptr)sinfo;
143
33.6k
  register _JSAMPROW ptr;
144
33.6k
  register _JSAMPLE *rescale = source->rescale;
145
33.6k
  JDIMENSION col;
146
33.6k
  register int rindex = rgb_red[cinfo->in_color_space];
147
33.6k
  register int gindex = rgb_green[cinfo->in_color_space];
148
33.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
149
33.6k
  register int aindex = alpha_index[cinfo->in_color_space];
150
33.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
151
152
33.6k
  get_raw_row(cinfo, sinfo);
153
33.6k
  ptr = source->pub._buffer[0];
154
#if BITS_IN_JSAMPLE != 12
155
  if (source->png_bit_depth == cinfo->data_precision) {
156
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
157
    if (aindex >= 0)
158
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
159
                         bufferptr += source->png_alpha;)
160
    else
161
      GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
162
  } else
163
#endif
164
33.6k
  if (source->png_bit_depth == 16) {
165
15.6k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
166
15.6k
    if (aindex >= 0)
167
3.13k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
168
15.6k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
169
15.6k
                         bufferptr += source->png_alpha;)
170
12.5k
    else
171
12.5k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
172
15.6k
                         bufferptr += source->png_alpha;)
173
17.9k
  } else {
174
17.9k
    register unsigned char *bufferptr = source->iobuffer;
175
17.9k
    if (aindex >= 0)
176
3.33k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
177
17.9k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
178
17.9k
                         bufferptr += source->png_alpha;)
179
14.6k
    else
180
14.6k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
181
17.9k
                         bufferptr += source->png_alpha;)
182
17.9k
  }
183
33.6k
  return 1;
184
33.6k
}
rdpng-16.c:get_gray_rgb_row
Line
Count
Source
141
19.0k
{
142
19.0k
  png_source_ptr source = (png_source_ptr)sinfo;
143
19.0k
  register _JSAMPROW ptr;
144
19.0k
  register _JSAMPLE *rescale = source->rescale;
145
19.0k
  JDIMENSION col;
146
19.0k
  register int rindex = rgb_red[cinfo->in_color_space];
147
19.0k
  register int gindex = rgb_green[cinfo->in_color_space];
148
19.0k
  register int bindex = rgb_blue[cinfo->in_color_space];
149
19.0k
  register int aindex = alpha_index[cinfo->in_color_space];
150
19.0k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
151
152
19.0k
  get_raw_row(cinfo, sinfo);
153
19.0k
  ptr = source->pub._buffer[0];
154
19.0k
#if BITS_IN_JSAMPLE != 12
155
19.0k
  if (source->png_bit_depth == cinfo->data_precision) {
156
3.53k
    _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
157
3.53k
    if (aindex >= 0)
158
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
159
3.53k
                         bufferptr += source->png_alpha;)
160
3.53k
    else
161
3.53k
      GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
162
3.53k
  } else
163
15.5k
#endif
164
15.5k
  if (source->png_bit_depth == 16) {
165
5.30k
    register unsigned short *bufferptr = (unsigned short *)source->iobuffer;
166
5.30k
    if (aindex >= 0)
167
1.76k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
168
5.30k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
169
5.30k
                         bufferptr += source->png_alpha;)
170
3.53k
    else
171
3.53k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
172
5.30k
                         bufferptr += source->png_alpha;)
173
10.2k
  } else {
174
10.2k
    register unsigned char *bufferptr = source->iobuffer;
175
10.2k
    if (aindex >= 0)
176
1.92k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
177
10.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;,
178
10.2k
                         bufferptr += source->png_alpha;)
179
8.31k
    else
180
8.31k
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {},
181
10.2k
                         bufferptr += source->png_alpha;)
182
10.2k
  }
183
19.0k
  return 1;
184
19.0k
}
185
186
187
METHODDEF(JDIMENSION)
188
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
189
/* This version is for reading 8-bit-per-channel or 16-bit-per-channel
190
 * grayscale or grayscale + alpha PNG files and converting to CMYK.
191
 */
192
16.9k
{
193
16.9k
  png_source_ptr source = (png_source_ptr)sinfo;
194
16.9k
  register _JSAMPROW ptr;
195
16.9k
  register _JSAMPLE *rescale = source->rescale;
196
16.9k
  JDIMENSION col;
197
198
16.9k
  get_raw_row(cinfo, sinfo);
199
16.9k
  ptr = source->pub._buffer[0];
200
#if BITS_IN_JSAMPLE != 12
201
10.1k
  if (source->png_bit_depth == cinfo->data_precision) {
202
3.22k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
203
306k
    for (col = cinfo->image_width; col > 0; col--) {
204
303k
      _JSAMPLE gray = *bufferptr++;
205
303k
      bufferptr += source->png_alpha;
206
303k
      rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2,
207
303k
                  ptr + 3);
208
303k
      ptr += 4;
209
303k
    }
210
3.22k
  } else
211
6.96k
#endif
212
13.6k
  if (source->png_bit_depth == 16) {
213
5.61k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
214
447k
    for (col = cinfo->image_width; col > 0; col--) {
215
441k
      _JSAMPLE gray = rescale[*bufferptr++];
216
441k
      bufferptr += source->png_alpha;
217
441k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
218
441k
                  ptr + 1, ptr + 2, ptr + 3);
219
441k
      ptr += 4;
220
441k
    }
221
8.07k
  } else {
222
8.07k
    register unsigned char *bufferptr = source->iobuffer;
223
610k
    for (col = cinfo->image_width; col > 0; col--) {
224
602k
      _JSAMPLE gray = rescale[*bufferptr++];
225
602k
      bufferptr += source->png_alpha;
226
602k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
227
602k
                  ptr + 1, ptr + 2, ptr + 3);
228
602k
      ptr += 4;
229
602k
    }
230
8.07k
  }
231
16.9k
  return 1;
232
16.9k
}
rdpng-8.c:get_gray_cmyk_row
Line
Count
Source
192
6.37k
{
193
6.37k
  png_source_ptr source = (png_source_ptr)sinfo;
194
6.37k
  register _JSAMPROW ptr;
195
6.37k
  register _JSAMPLE *rescale = source->rescale;
196
6.37k
  JDIMENSION col;
197
198
6.37k
  get_raw_row(cinfo, sinfo);
199
6.37k
  ptr = source->pub._buffer[0];
200
6.37k
#if BITS_IN_JSAMPLE != 12
201
6.37k
  if (source->png_bit_depth == cinfo->data_precision) {
202
1.45k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
203
133k
    for (col = cinfo->image_width; col > 0; col--) {
204
132k
      _JSAMPLE gray = *bufferptr++;
205
132k
      bufferptr += source->png_alpha;
206
132k
      rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2,
207
132k
                  ptr + 3);
208
132k
      ptr += 4;
209
132k
    }
210
1.45k
  } else
211
4.91k
#endif
212
4.91k
  if (source->png_bit_depth == 16) {
213
2.47k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
214
242k
    for (col = cinfo->image_width; col > 0; col--) {
215
239k
      _JSAMPLE gray = rescale[*bufferptr++];
216
239k
      bufferptr += source->png_alpha;
217
239k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
218
239k
                  ptr + 1, ptr + 2, ptr + 3);
219
239k
      ptr += 4;
220
239k
    }
221
2.47k
  } else {
222
2.43k
    register unsigned char *bufferptr = source->iobuffer;
223
146k
    for (col = cinfo->image_width; col > 0; col--) {
224
144k
      _JSAMPLE gray = rescale[*bufferptr++];
225
144k
      bufferptr += source->png_alpha;
226
144k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
227
144k
                  ptr + 1, ptr + 2, ptr + 3);
228
144k
      ptr += 4;
229
144k
    }
230
2.43k
  }
231
6.37k
  return 1;
232
6.37k
}
rdpng-12.c:get_gray_cmyk_row
Line
Count
Source
192
6.72k
{
193
6.72k
  png_source_ptr source = (png_source_ptr)sinfo;
194
6.72k
  register _JSAMPROW ptr;
195
6.72k
  register _JSAMPLE *rescale = source->rescale;
196
6.72k
  JDIMENSION col;
197
198
6.72k
  get_raw_row(cinfo, sinfo);
199
6.72k
  ptr = source->pub._buffer[0];
200
#if BITS_IN_JSAMPLE != 12
201
  if (source->png_bit_depth == cinfo->data_precision) {
202
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
203
    for (col = cinfo->image_width; col > 0; col--) {
204
      _JSAMPLE gray = *bufferptr++;
205
      bufferptr += source->png_alpha;
206
      rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2,
207
                  ptr + 3);
208
      ptr += 4;
209
    }
210
  } else
211
#endif
212
6.72k
  if (source->png_bit_depth == 16) {
213
3.13k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
214
204k
    for (col = cinfo->image_width; col > 0; col--) {
215
201k
      _JSAMPLE gray = rescale[*bufferptr++];
216
201k
      bufferptr += source->png_alpha;
217
201k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
218
201k
                  ptr + 1, ptr + 2, ptr + 3);
219
201k
      ptr += 4;
220
201k
    }
221
3.58k
  } else {
222
3.58k
    register unsigned char *bufferptr = source->iobuffer;
223
292k
    for (col = cinfo->image_width; col > 0; col--) {
224
289k
      _JSAMPLE gray = rescale[*bufferptr++];
225
289k
      bufferptr += source->png_alpha;
226
289k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
227
289k
                  ptr + 1, ptr + 2, ptr + 3);
228
289k
      ptr += 4;
229
289k
    }
230
3.58k
  }
231
6.72k
  return 1;
232
6.72k
}
rdpng-16.c:get_gray_cmyk_row
Line
Count
Source
192
3.81k
{
193
3.81k
  png_source_ptr source = (png_source_ptr)sinfo;
194
3.81k
  register _JSAMPROW ptr;
195
3.81k
  register _JSAMPLE *rescale = source->rescale;
196
3.81k
  JDIMENSION col;
197
198
3.81k
  get_raw_row(cinfo, sinfo);
199
3.81k
  ptr = source->pub._buffer[0];
200
3.81k
#if BITS_IN_JSAMPLE != 12
201
3.81k
  if (source->png_bit_depth == cinfo->data_precision) {
202
1.76k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
203
173k
    for (col = cinfo->image_width; col > 0; col--) {
204
171k
      _JSAMPLE gray = *bufferptr++;
205
171k
      bufferptr += source->png_alpha;
206
171k
      rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2,
207
171k
                  ptr + 3);
208
171k
      ptr += 4;
209
171k
    }
210
1.76k
  } else
211
2.04k
#endif
212
2.04k
  if (source->png_bit_depth == 16) {
213
0
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
214
0
    for (col = cinfo->image_width; col > 0; col--) {
215
0
      _JSAMPLE gray = rescale[*bufferptr++];
216
0
      bufferptr += source->png_alpha;
217
0
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
218
0
                  ptr + 1, ptr + 2, ptr + 3);
219
0
      ptr += 4;
220
0
    }
221
2.04k
  } else {
222
2.04k
    register unsigned char *bufferptr = source->iobuffer;
223
170k
    for (col = cinfo->image_width; col > 0; col--) {
224
168k
      _JSAMPLE gray = rescale[*bufferptr++];
225
168k
      bufferptr += source->png_alpha;
226
168k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
227
168k
                  ptr + 1, ptr + 2, ptr + 3);
228
168k
      ptr += 4;
229
168k
    }
230
2.04k
  }
231
3.81k
  return 1;
232
3.81k
}
233
234
235
361k
#define RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \
236
147M
  for (col = cinfo->image_width; col > 0; col--) { \
237
147M
    ptr[rindex] = read_op; \
238
147M
    ptr[gindex] = read_op; \
239
147M
    ptr[bindex] = read_op; \
240
147M
    alpha_set_op \
241
147M
    pointer_op \
242
147M
    ptr += ps; \
243
147M
  } \
244
361k
}
245
246
247
METHODDEF(JDIMENSION)
248
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
249
/* This version is for reading 8-bit-per-channel or 16-bit-per-channel
250
 * truecolor or truecolor + alpha PNG files and converting to extended RGB.
251
 */
252
361k
{
253
361k
  png_source_ptr source = (png_source_ptr)sinfo;
254
361k
  register _JSAMPROW ptr;
255
361k
  register _JSAMPLE *rescale = source->rescale;
256
361k
  JDIMENSION col;
257
361k
  register int rindex = rgb_red[cinfo->in_color_space];
258
361k
  register int gindex = rgb_green[cinfo->in_color_space];
259
361k
  register int bindex = rgb_blue[cinfo->in_color_space];
260
361k
  register int aindex = alpha_index[cinfo->in_color_space];
261
361k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
262
263
361k
  get_raw_row(cinfo, sinfo);
264
361k
  ptr = source->pub._buffer[0];
265
#if BITS_IN_JSAMPLE != 12
266
170k
  if (source->png_bit_depth == cinfo->data_precision) {
267
101k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
268
101k
    if (aindex >= 0)
269
1.59k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
270
101k
                    bufferptr += source->png_alpha;)
271
99.4k
    else
272
99.4k
      RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
273
101k
  } else
274
69.3k
#endif
275
260k
  if (source->png_bit_depth == 16) {
276
64.2k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
277
64.2k
    if (aindex >= 0)
278
11.8k
      RGB_READ_LOOP(rescale[*bufferptr++],
279
64.2k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
280
64.2k
                    bufferptr += source->png_alpha;)
281
52.3k
    else
282
52.3k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
283
64.2k
                    bufferptr += source->png_alpha;)
284
196k
  } else {
285
196k
    register unsigned char *bufferptr = source->iobuffer;
286
196k
    if (aindex >= 0)
287
38.2k
      RGB_READ_LOOP(rescale[*bufferptr++],
288
196k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
289
196k
                    bufferptr += source->png_alpha;)
290
158k
    else
291
158k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
292
196k
                    bufferptr += source->png_alpha;)
293
196k
  }
294
361k
  return 1;
295
361k
}
rdpng-8.c:get_rgb_row
Line
Count
Source
252
154k
{
253
154k
  png_source_ptr source = (png_source_ptr)sinfo;
254
154k
  register _JSAMPROW ptr;
255
154k
  register _JSAMPLE *rescale = source->rescale;
256
154k
  JDIMENSION col;
257
154k
  register int rindex = rgb_red[cinfo->in_color_space];
258
154k
  register int gindex = rgb_green[cinfo->in_color_space];
259
154k
  register int bindex = rgb_blue[cinfo->in_color_space];
260
154k
  register int aindex = alpha_index[cinfo->in_color_space];
261
154k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
262
263
154k
  get_raw_row(cinfo, sinfo);
264
154k
  ptr = source->pub._buffer[0];
265
154k
#if BITS_IN_JSAMPLE != 12
266
154k
  if (source->png_bit_depth == cinfo->data_precision) {
267
99.5k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
268
99.5k
    if (aindex >= 0)
269
1.59k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
270
99.5k
                    bufferptr += source->png_alpha;)
271
97.9k
    else
272
97.9k
      RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
273
99.5k
  } else
274
54.9k
#endif
275
54.9k
  if (source->png_bit_depth == 16) {
276
40.9k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
277
40.9k
    if (aindex >= 0)
278
6.57k
      RGB_READ_LOOP(rescale[*bufferptr++],
279
40.9k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
280
40.9k
                    bufferptr += source->png_alpha;)
281
34.3k
    else
282
34.3k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
283
40.9k
                    bufferptr += source->png_alpha;)
284
40.9k
  } else {
285
14.0k
    register unsigned char *bufferptr = source->iobuffer;
286
14.0k
    if (aindex >= 0)
287
2.50k
      RGB_READ_LOOP(rescale[*bufferptr++],
288
14.0k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
289
14.0k
                    bufferptr += source->png_alpha;)
290
11.5k
    else
291
11.5k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
292
14.0k
                    bufferptr += source->png_alpha;)
293
14.0k
  }
294
154k
  return 1;
295
154k
}
rdpng-12.c:get_rgb_row
Line
Count
Source
252
191k
{
253
191k
  png_source_ptr source = (png_source_ptr)sinfo;
254
191k
  register _JSAMPROW ptr;
255
191k
  register _JSAMPLE *rescale = source->rescale;
256
191k
  JDIMENSION col;
257
191k
  register int rindex = rgb_red[cinfo->in_color_space];
258
191k
  register int gindex = rgb_green[cinfo->in_color_space];
259
191k
  register int bindex = rgb_blue[cinfo->in_color_space];
260
191k
  register int aindex = alpha_index[cinfo->in_color_space];
261
191k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
262
263
191k
  get_raw_row(cinfo, sinfo);
264
191k
  ptr = source->pub._buffer[0];
265
#if BITS_IN_JSAMPLE != 12
266
  if (source->png_bit_depth == cinfo->data_precision) {
267
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
268
    if (aindex >= 0)
269
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
270
                    bufferptr += source->png_alpha;)
271
    else
272
      RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
273
  } else
274
#endif
275
191k
  if (source->png_bit_depth == 16) {
276
18.7k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
277
18.7k
    if (aindex >= 0)
278
3.75k
      RGB_READ_LOOP(rescale[*bufferptr++],
279
18.7k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
280
18.7k
                    bufferptr += source->png_alpha;)
281
15.0k
    else
282
15.0k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
283
18.7k
                    bufferptr += source->png_alpha;)
284
172k
  } else {
285
172k
    register unsigned char *bufferptr = source->iobuffer;
286
172k
    if (aindex >= 0)
287
33.9k
      RGB_READ_LOOP(rescale[*bufferptr++],
288
172k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
289
172k
                    bufferptr += source->png_alpha;)
290
138k
    else
291
138k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
292
172k
                    bufferptr += source->png_alpha;)
293
172k
  }
294
191k
  return 1;
295
191k
}
rdpng-16.c:get_rgb_row
Line
Count
Source
252
15.8k
{
253
15.8k
  png_source_ptr source = (png_source_ptr)sinfo;
254
15.8k
  register _JSAMPROW ptr;
255
15.8k
  register _JSAMPLE *rescale = source->rescale;
256
15.8k
  JDIMENSION col;
257
15.8k
  register int rindex = rgb_red[cinfo->in_color_space];
258
15.8k
  register int gindex = rgb_green[cinfo->in_color_space];
259
15.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
260
15.8k
  register int aindex = alpha_index[cinfo->in_color_space];
261
15.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
262
263
15.8k
  get_raw_row(cinfo, sinfo);
264
15.8k
  ptr = source->pub._buffer[0];
265
15.8k
#if BITS_IN_JSAMPLE != 12
266
15.8k
  if (source->png_bit_depth == cinfo->data_precision) {
267
1.49k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
268
1.49k
    if (aindex >= 0)
269
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;,
270
1.49k
                    bufferptr += source->png_alpha;)
271
1.49k
    else
272
1.49k
      RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;)
273
1.49k
  } else
274
14.3k
#endif
275
14.3k
  if (source->png_bit_depth == 16) {
276
4.47k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
277
4.47k
    if (aindex >= 0)
278
1.49k
      RGB_READ_LOOP(rescale[*bufferptr++],
279
4.47k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
280
4.47k
                    bufferptr += source->png_alpha;)
281
2.98k
    else
282
2.98k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
283
4.47k
                    bufferptr += source->png_alpha;)
284
9.85k
  } else {
285
9.85k
    register unsigned char *bufferptr = source->iobuffer;
286
9.85k
    if (aindex >= 0)
287
1.74k
      RGB_READ_LOOP(rescale[*bufferptr++],
288
9.85k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;,
289
9.85k
                    bufferptr += source->png_alpha;)
290
8.11k
    else
291
8.11k
      RGB_READ_LOOP(rescale[*bufferptr++], {},
292
9.85k
                    bufferptr += source->png_alpha;)
293
9.85k
  }
294
15.8k
  return 1;
295
15.8k
}
296
297
298
METHODDEF(JDIMENSION)
299
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
300
/* This version is for reading 8-bit-per-channel or 16-bit-per-channel
301
 * truecolor or truecolor + alpha PNG files and converting to CMYK.
302
 */
303
52.8k
{
304
52.8k
  png_source_ptr source = (png_source_ptr)sinfo;
305
52.8k
  register _JSAMPROW ptr;
306
52.8k
  register _JSAMPLE *rescale = source->rescale;
307
52.8k
  JDIMENSION col;
308
309
52.8k
  get_raw_row(cinfo, sinfo);
310
52.8k
  ptr = source->pub._buffer[0];
311
#if BITS_IN_JSAMPLE != 12
312
14.6k
  if (source->png_bit_depth == cinfo->data_precision) {
313
3.09k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
314
261k
    for (col = cinfo->image_width; col > 0; col--) {
315
258k
      _JSAMPLE r = *bufferptr++;
316
258k
      _JSAMPLE g = *bufferptr++;
317
258k
      _JSAMPLE b = *bufferptr++;
318
258k
      bufferptr += source->png_alpha;
319
258k
      rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
320
258k
      ptr += 4;
321
258k
    }
322
3.09k
  } else
323
11.5k
#endif
324
49.8k
  if (source->png_bit_depth == 16) {
325
10.3k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
326
900k
    for (col = cinfo->image_width; col > 0; col--) {
327
890k
      _JSAMPLE r = rescale[*bufferptr++];
328
890k
      _JSAMPLE g = rescale[*bufferptr++];
329
890k
      _JSAMPLE b = rescale[*bufferptr++];
330
890k
      bufferptr += source->png_alpha;
331
890k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
332
890k
                  ptr + 2, ptr + 3);
333
890k
      ptr += 4;
334
890k
    }
335
39.4k
  } else {
336
39.4k
    register unsigned char *bufferptr = source->iobuffer;
337
8.48M
    for (col = cinfo->image_width; col > 0; col--) {
338
8.44M
      _JSAMPLE r = rescale[*bufferptr++];
339
8.44M
      _JSAMPLE g = rescale[*bufferptr++];
340
8.44M
      _JSAMPLE b = rescale[*bufferptr++];
341
8.44M
      bufferptr += source->png_alpha;
342
8.44M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
343
8.44M
                  ptr + 2, ptr + 3);
344
8.44M
      ptr += 4;
345
8.44M
    }
346
39.4k
  }
347
52.8k
  return 1;
348
52.8k
}
rdpng-8.c:get_rgb_cmyk_row
Line
Count
Source
303
11.1k
{
304
11.1k
  png_source_ptr source = (png_source_ptr)sinfo;
305
11.1k
  register _JSAMPROW ptr;
306
11.1k
  register _JSAMPLE *rescale = source->rescale;
307
11.1k
  JDIMENSION col;
308
309
11.1k
  get_raw_row(cinfo, sinfo);
310
11.1k
  ptr = source->pub._buffer[0];
311
11.1k
#if BITS_IN_JSAMPLE != 12
312
11.1k
  if (source->png_bit_depth == cinfo->data_precision) {
313
1.59k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
314
118k
    for (col = cinfo->image_width; col > 0; col--) {
315
116k
      _JSAMPLE r = *bufferptr++;
316
116k
      _JSAMPLE g = *bufferptr++;
317
116k
      _JSAMPLE b = *bufferptr++;
318
116k
      bufferptr += source->png_alpha;
319
116k
      rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
320
116k
      ptr += 4;
321
116k
    }
322
1.59k
  } else
323
9.53k
#endif
324
9.53k
  if (source->png_bit_depth == 16) {
325
6.57k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
326
627k
    for (col = cinfo->image_width; col > 0; col--) {
327
620k
      _JSAMPLE r = rescale[*bufferptr++];
328
620k
      _JSAMPLE g = rescale[*bufferptr++];
329
620k
      _JSAMPLE b = rescale[*bufferptr++];
330
620k
      bufferptr += source->png_alpha;
331
620k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
332
620k
                  ptr + 2, ptr + 3);
333
620k
      ptr += 4;
334
620k
    }
335
6.57k
  } else {
336
2.95k
    register unsigned char *bufferptr = source->iobuffer;
337
1.36M
    for (col = cinfo->image_width; col > 0; col--) {
338
1.36M
      _JSAMPLE r = rescale[*bufferptr++];
339
1.36M
      _JSAMPLE g = rescale[*bufferptr++];
340
1.36M
      _JSAMPLE b = rescale[*bufferptr++];
341
1.36M
      bufferptr += source->png_alpha;
342
1.36M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
343
1.36M
                  ptr + 2, ptr + 3);
344
1.36M
      ptr += 4;
345
1.36M
    }
346
2.95k
  }
347
11.1k
  return 1;
348
11.1k
}
rdpng-12.c:get_rgb_cmyk_row
Line
Count
Source
303
38.2k
{
304
38.2k
  png_source_ptr source = (png_source_ptr)sinfo;
305
38.2k
  register _JSAMPROW ptr;
306
38.2k
  register _JSAMPLE *rescale = source->rescale;
307
38.2k
  JDIMENSION col;
308
309
38.2k
  get_raw_row(cinfo, sinfo);
310
38.2k
  ptr = source->pub._buffer[0];
311
#if BITS_IN_JSAMPLE != 12
312
  if (source->png_bit_depth == cinfo->data_precision) {
313
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
314
    for (col = cinfo->image_width; col > 0; col--) {
315
      _JSAMPLE r = *bufferptr++;
316
      _JSAMPLE g = *bufferptr++;
317
      _JSAMPLE b = *bufferptr++;
318
      bufferptr += source->png_alpha;
319
      rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
320
      ptr += 4;
321
    }
322
  } else
323
#endif
324
38.2k
  if (source->png_bit_depth == 16) {
325
3.75k
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
326
273k
    for (col = cinfo->image_width; col > 0; col--) {
327
270k
      _JSAMPLE r = rescale[*bufferptr++];
328
270k
      _JSAMPLE g = rescale[*bufferptr++];
329
270k
      _JSAMPLE b = rescale[*bufferptr++];
330
270k
      bufferptr += source->png_alpha;
331
270k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
332
270k
                  ptr + 2, ptr + 3);
333
270k
      ptr += 4;
334
270k
    }
335
34.5k
  } else {
336
34.5k
    register unsigned char *bufferptr = source->iobuffer;
337
6.96M
    for (col = cinfo->image_width; col > 0; col--) {
338
6.92M
      _JSAMPLE r = rescale[*bufferptr++];
339
6.92M
      _JSAMPLE g = rescale[*bufferptr++];
340
6.92M
      _JSAMPLE b = rescale[*bufferptr++];
341
6.92M
      bufferptr += source->png_alpha;
342
6.92M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
343
6.92M
                  ptr + 2, ptr + 3);
344
6.92M
      ptr += 4;
345
6.92M
    }
346
34.5k
  }
347
38.2k
  return 1;
348
38.2k
}
rdpng-16.c:get_rgb_cmyk_row
Line
Count
Source
303
3.50k
{
304
3.50k
  png_source_ptr source = (png_source_ptr)sinfo;
305
3.50k
  register _JSAMPROW ptr;
306
3.50k
  register _JSAMPLE *rescale = source->rescale;
307
3.50k
  JDIMENSION col;
308
309
3.50k
  get_raw_row(cinfo, sinfo);
310
3.50k
  ptr = source->pub._buffer[0];
311
3.50k
#if BITS_IN_JSAMPLE != 12
312
3.50k
  if (source->png_bit_depth == cinfo->data_precision) {
313
1.49k
    register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer;
314
143k
    for (col = cinfo->image_width; col > 0; col--) {
315
141k
      _JSAMPLE r = *bufferptr++;
316
141k
      _JSAMPLE g = *bufferptr++;
317
141k
      _JSAMPLE b = *bufferptr++;
318
141k
      bufferptr += source->png_alpha;
319
141k
      rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
320
141k
      ptr += 4;
321
141k
    }
322
1.49k
  } else
323
2.01k
#endif
324
2.01k
  if (source->png_bit_depth == 16) {
325
0
    unsigned short *bufferptr = (unsigned short *)source->iobuffer;
326
0
    for (col = cinfo->image_width; col > 0; col--) {
327
0
      _JSAMPLE r = rescale[*bufferptr++];
328
0
      _JSAMPLE g = rescale[*bufferptr++];
329
0
      _JSAMPLE b = rescale[*bufferptr++];
330
0
      bufferptr += source->png_alpha;
331
0
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
332
0
                  ptr + 2, ptr + 3);
333
0
      ptr += 4;
334
0
    }
335
2.01k
  } else {
336
2.01k
    register unsigned char *bufferptr = source->iobuffer;
337
155k
    for (col = cinfo->image_width; col > 0; col--) {
338
153k
      _JSAMPLE r = rescale[*bufferptr++];
339
153k
      _JSAMPLE g = rescale[*bufferptr++];
340
153k
      _JSAMPLE b = rescale[*bufferptr++];
341
153k
      bufferptr += source->png_alpha;
342
153k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
343
153k
                  ptr + 2, ptr + 3);
344
153k
      ptr += 4;
345
153k
    }
346
2.01k
  }
347
3.50k
  return 1;
348
3.50k
}
349
350
351
METHODDEF(JDIMENSION)
352
get_indexed_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
353
5.67k
{
354
/* This version is for reading 8-bit-per-channel indexed-color PNG files and
355
 * converting to extended RGB or CMYK.
356
 */
357
5.67k
  png_source_ptr source = (png_source_ptr)sinfo;
358
5.67k
  register _JSAMPROW ptr;
359
5.67k
  register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer;
360
5.67k
  register _JSAMPLE *rescale = source->rescale;
361
5.67k
  JDIMENSION col;
362
363
5.67k
  get_raw_row(cinfo, sinfo);
364
5.67k
  ptr = source->pub._buffer[0];
365
#if BITS_IN_JSAMPLE == 8
366
2.85k
  if (source->png_bit_depth == cinfo->data_precision) {
367
1.96k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
368
2.45k
      for (col = cinfo->image_width; col > 0; col--) {
369
2.16k
        JSAMPLE index = *bufferptr++;
370
371
2.16k
        if (index >= source->colormap.n_entries)
372
28
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
373
2.16k
        *ptr++ = source->colormap.entries[index].red;
374
2.16k
      }
375
1.67k
    } else if (cinfo->in_color_space == JCS_CMYK) {
376
837
      for (col = cinfo->image_width; col > 0; col--) {
377
740
        JSAMPLE index = *bufferptr++;
378
379
740
        if (index >= source->colormap.n_entries)
380
9
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
381
740
        rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red,
382
740
                    source->colormap.entries[index].green,
383
740
                    source->colormap.entries[index].blue, ptr, ptr + 1,
384
740
                    ptr + 2, ptr + 3);
385
740
        ptr += 4;
386
740
      }
387
1.57k
    } else {
388
1.57k
      register int rindex = rgb_red[cinfo->in_color_space];
389
1.57k
      register int gindex = rgb_green[cinfo->in_color_space];
390
1.57k
      register int bindex = rgb_blue[cinfo->in_color_space];
391
1.57k
      register int aindex = alpha_index[cinfo->in_color_space];
392
1.57k
      register int ps = rgb_pixelsize[cinfo->in_color_space];
393
394
23.9k
      for (col = cinfo->image_width; col > 0; col--) {
395
22.3k
        JSAMPLE index = *bufferptr++;
396
397
22.3k
        if (index >= source->colormap.n_entries)
398
135
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
399
22.3k
        ptr[rindex] = source->colormap.entries[index].red;
400
22.3k
        ptr[gindex] = source->colormap.entries[index].green;
401
22.3k
        ptr[bindex] = source->colormap.entries[index].blue;
402
22.3k
        if (aindex >= 0)
403
731
          ptr[aindex] = _MAXJSAMPLE;
404
22.3k
        ptr += ps;
405
22.3k
      }
406
1.57k
    }
407
1.96k
  } else
408
891
#endif
409
891
  {
410
3.71k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
411
2.08k
      for (col = cinfo->image_width; col > 0; col--) {
412
1.84k
        JSAMPLE index = *bufferptr++;
413
414
1.84k
        if (index >= source->colormap.n_entries)
415
28
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
416
1.84k
        *ptr++ = rescale[source->colormap.entries[index].red];
417
1.84k
      }
418
3.47k
    } else if (cinfo->in_color_space == JCS_CMYK) {
419
4.56k
      for (col = cinfo->image_width; col > 0; col--) {
420
4.06k
        JSAMPLE index = *bufferptr++;
421
422
4.06k
        if (index >= source->colormap.n_entries)
423
53
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
424
4.06k
        rgb_to_cmyk((1 << cinfo->data_precision) - 1,
425
4.06k
                    rescale[source->colormap.entries[index].red],
426
4.06k
                    rescale[source->colormap.entries[index].green],
427
4.06k
                    rescale[source->colormap.entries[index].blue], ptr,
428
4.06k
                    ptr + 1, ptr + 2, ptr + 3);
429
4.06k
        ptr += 4;
430
4.06k
      }
431
2.97k
    } else {
432
2.97k
      register int rindex = rgb_red[cinfo->in_color_space];
433
2.97k
      register int gindex = rgb_green[cinfo->in_color_space];
434
2.97k
      register int bindex = rgb_blue[cinfo->in_color_space];
435
2.97k
      register int aindex = alpha_index[cinfo->in_color_space];
436
2.97k
      register int ps = rgb_pixelsize[cinfo->in_color_space];
437
438
22.4k
      for (col = cinfo->image_width; col > 0; col--) {
439
19.4k
        JSAMPLE index = *bufferptr++;
440
441
19.4k
        if (index >= source->colormap.n_entries)
442
249
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
443
19.4k
        ptr[rindex] = rescale[source->colormap.entries[index].red];
444
19.4k
        ptr[gindex] = rescale[source->colormap.entries[index].green];
445
19.4k
        ptr[bindex] = rescale[source->colormap.entries[index].blue];
446
19.4k
        if (aindex >= 0)
447
4.01k
          ptr[aindex] = (1 << cinfo->data_precision) - 1;
448
19.4k
        ptr += ps;
449
19.4k
      }
450
2.97k
    }
451
891
  }
452
5.67k
  return 1;
453
5.67k
}
rdpng-8.c:get_indexed_row
Line
Count
Source
353
2.85k
{
354
/* This version is for reading 8-bit-per-channel indexed-color PNG files and
355
 * converting to extended RGB or CMYK.
356
 */
357
2.85k
  png_source_ptr source = (png_source_ptr)sinfo;
358
2.85k
  register _JSAMPROW ptr;
359
2.85k
  register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer;
360
2.85k
  register _JSAMPLE *rescale = source->rescale;
361
2.85k
  JDIMENSION col;
362
363
2.85k
  get_raw_row(cinfo, sinfo);
364
2.85k
  ptr = source->pub._buffer[0];
365
2.85k
#if BITS_IN_JSAMPLE == 8
366
2.85k
  if (source->png_bit_depth == cinfo->data_precision) {
367
1.96k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
368
2.45k
      for (col = cinfo->image_width; col > 0; col--) {
369
2.16k
        JSAMPLE index = *bufferptr++;
370
371
2.16k
        if (index >= source->colormap.n_entries)
372
28
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
373
2.16k
        *ptr++ = source->colormap.entries[index].red;
374
2.16k
      }
375
1.67k
    } else if (cinfo->in_color_space == JCS_CMYK) {
376
837
      for (col = cinfo->image_width; col > 0; col--) {
377
740
        JSAMPLE index = *bufferptr++;
378
379
740
        if (index >= source->colormap.n_entries)
380
9
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
381
740
        rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red,
382
740
                    source->colormap.entries[index].green,
383
740
                    source->colormap.entries[index].blue, ptr, ptr + 1,
384
740
                    ptr + 2, ptr + 3);
385
740
        ptr += 4;
386
740
      }
387
1.57k
    } else {
388
1.57k
      register int rindex = rgb_red[cinfo->in_color_space];
389
1.57k
      register int gindex = rgb_green[cinfo->in_color_space];
390
1.57k
      register int bindex = rgb_blue[cinfo->in_color_space];
391
1.57k
      register int aindex = alpha_index[cinfo->in_color_space];
392
1.57k
      register int ps = rgb_pixelsize[cinfo->in_color_space];
393
394
23.9k
      for (col = cinfo->image_width; col > 0; col--) {
395
22.3k
        JSAMPLE index = *bufferptr++;
396
397
22.3k
        if (index >= source->colormap.n_entries)
398
135
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
399
22.3k
        ptr[rindex] = source->colormap.entries[index].red;
400
22.3k
        ptr[gindex] = source->colormap.entries[index].green;
401
22.3k
        ptr[bindex] = source->colormap.entries[index].blue;
402
22.3k
        if (aindex >= 0)
403
731
          ptr[aindex] = _MAXJSAMPLE;
404
22.3k
        ptr += ps;
405
22.3k
      }
406
1.57k
    }
407
1.96k
  } else
408
891
#endif
409
891
  {
410
891
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
411
413
      for (col = cinfo->image_width; col > 0; col--) {
412
364
        JSAMPLE index = *bufferptr++;
413
414
364
        if (index >= source->colormap.n_entries)
415
7
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
416
364
        *ptr++ = rescale[source->colormap.entries[index].red];
417
364
      }
418
842
    } else if (cinfo->in_color_space == JCS_CMYK) {
419
1.00k
      for (col = cinfo->image_width; col > 0; col--) {
420
890
        JSAMPLE index = *bufferptr++;
421
422
890
        if (index >= source->colormap.n_entries)
423
16
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
424
890
        rgb_to_cmyk((1 << cinfo->data_precision) - 1,
425
890
                    rescale[source->colormap.entries[index].red],
426
890
                    rescale[source->colormap.entries[index].green],
427
890
                    rescale[source->colormap.entries[index].blue], ptr,
428
890
                    ptr + 1, ptr + 2, ptr + 3);
429
890
        ptr += 4;
430
890
      }
431
724
    } else {
432
724
      register int rindex = rgb_red[cinfo->in_color_space];
433
724
      register int gindex = rgb_green[cinfo->in_color_space];
434
724
      register int bindex = rgb_blue[cinfo->in_color_space];
435
724
      register int aindex = alpha_index[cinfo->in_color_space];
436
724
      register int ps = rgb_pixelsize[cinfo->in_color_space];
437
438
4.28k
      for (col = cinfo->image_width; col > 0; col--) {
439
3.56k
        JSAMPLE index = *bufferptr++;
440
441
3.56k
        if (index >= source->colormap.n_entries)
442
64
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
443
3.56k
        ptr[rindex] = rescale[source->colormap.entries[index].red];
444
3.56k
        ptr[gindex] = rescale[source->colormap.entries[index].green];
445
3.56k
        ptr[bindex] = rescale[source->colormap.entries[index].blue];
446
3.56k
        if (aindex >= 0)
447
874
          ptr[aindex] = (1 << cinfo->data_precision) - 1;
448
3.56k
        ptr += ps;
449
3.56k
      }
450
724
    }
451
891
  }
452
2.85k
  return 1;
453
2.85k
}
rdpng-12.c:get_indexed_row
Line
Count
Source
353
1.68k
{
354
/* This version is for reading 8-bit-per-channel indexed-color PNG files and
355
 * converting to extended RGB or CMYK.
356
 */
357
1.68k
  png_source_ptr source = (png_source_ptr)sinfo;
358
1.68k
  register _JSAMPROW ptr;
359
1.68k
  register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer;
360
1.68k
  register _JSAMPLE *rescale = source->rescale;
361
1.68k
  JDIMENSION col;
362
363
1.68k
  get_raw_row(cinfo, sinfo);
364
1.68k
  ptr = source->pub._buffer[0];
365
#if BITS_IN_JSAMPLE == 8
366
  if (source->png_bit_depth == cinfo->data_precision) {
367
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
368
      for (col = cinfo->image_width; col > 0; col--) {
369
        JSAMPLE index = *bufferptr++;
370
371
        if (index >= source->colormap.n_entries)
372
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
373
        *ptr++ = source->colormap.entries[index].red;
374
      }
375
    } else if (cinfo->in_color_space == JCS_CMYK) {
376
      for (col = cinfo->image_width; col > 0; col--) {
377
        JSAMPLE index = *bufferptr++;
378
379
        if (index >= source->colormap.n_entries)
380
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
381
        rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red,
382
                    source->colormap.entries[index].green,
383
                    source->colormap.entries[index].blue, ptr, ptr + 1,
384
                    ptr + 2, ptr + 3);
385
        ptr += 4;
386
      }
387
    } else {
388
      register int rindex = rgb_red[cinfo->in_color_space];
389
      register int gindex = rgb_green[cinfo->in_color_space];
390
      register int bindex = rgb_blue[cinfo->in_color_space];
391
      register int aindex = alpha_index[cinfo->in_color_space];
392
      register int ps = rgb_pixelsize[cinfo->in_color_space];
393
394
      for (col = cinfo->image_width; col > 0; col--) {
395
        JSAMPLE index = *bufferptr++;
396
397
        if (index >= source->colormap.n_entries)
398
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
399
        ptr[rindex] = source->colormap.entries[index].red;
400
        ptr[gindex] = source->colormap.entries[index].green;
401
        ptr[bindex] = source->colormap.entries[index].blue;
402
        if (aindex >= 0)
403
          ptr[aindex] = _MAXJSAMPLE;
404
        ptr += ps;
405
      }
406
    }
407
  } else
408
#endif
409
1.68k
  {
410
1.68k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
411
1.03k
      for (col = cinfo->image_width; col > 0; col--) {
412
911
        JSAMPLE index = *bufferptr++;
413
414
911
        if (index >= source->colormap.n_entries)
415
16
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
416
911
        *ptr++ = rescale[source->colormap.entries[index].red];
417
911
      }
418
1.56k
    } else if (cinfo->in_color_space == JCS_CMYK) {
419
2.20k
      for (col = cinfo->image_width; col > 0; col--) {
420
1.97k
        JSAMPLE index = *bufferptr++;
421
422
1.97k
        if (index >= source->colormap.n_entries)
423
27
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
424
1.97k
        rgb_to_cmyk((1 << cinfo->data_precision) - 1,
425
1.97k
                    rescale[source->colormap.entries[index].red],
426
1.97k
                    rescale[source->colormap.entries[index].green],
427
1.97k
                    rescale[source->colormap.entries[index].blue], ptr,
428
1.97k
                    ptr + 1, ptr + 2, ptr + 3);
429
1.97k
        ptr += 4;
430
1.97k
      }
431
1.33k
    } else {
432
1.33k
      register int rindex = rgb_red[cinfo->in_color_space];
433
1.33k
      register int gindex = rgb_green[cinfo->in_color_space];
434
1.33k
      register int bindex = rgb_blue[cinfo->in_color_space];
435
1.33k
      register int aindex = alpha_index[cinfo->in_color_space];
436
1.33k
      register int ps = rgb_pixelsize[cinfo->in_color_space];
437
438
11.2k
      for (col = cinfo->image_width; col > 0; col--) {
439
9.87k
        JSAMPLE index = *bufferptr++;
440
441
9.87k
        if (index >= source->colormap.n_entries)
442
135
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
443
9.87k
        ptr[rindex] = rescale[source->colormap.entries[index].red];
444
9.87k
        ptr[gindex] = rescale[source->colormap.entries[index].green];
445
9.87k
        ptr[bindex] = rescale[source->colormap.entries[index].blue];
446
9.87k
        if (aindex >= 0)
447
1.94k
          ptr[aindex] = (1 << cinfo->data_precision) - 1;
448
9.87k
        ptr += ps;
449
9.87k
      }
450
1.33k
    }
451
1.68k
  }
452
1.68k
  return 1;
453
1.68k
}
rdpng-16.c:get_indexed_row
Line
Count
Source
353
1.14k
{
354
/* This version is for reading 8-bit-per-channel indexed-color PNG files and
355
 * converting to extended RGB or CMYK.
356
 */
357
1.14k
  png_source_ptr source = (png_source_ptr)sinfo;
358
1.14k
  register _JSAMPROW ptr;
359
1.14k
  register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer;
360
1.14k
  register _JSAMPLE *rescale = source->rescale;
361
1.14k
  JDIMENSION col;
362
363
1.14k
  get_raw_row(cinfo, sinfo);
364
1.14k
  ptr = source->pub._buffer[0];
365
#if BITS_IN_JSAMPLE == 8
366
  if (source->png_bit_depth == cinfo->data_precision) {
367
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
368
      for (col = cinfo->image_width; col > 0; col--) {
369
        JSAMPLE index = *bufferptr++;
370
371
        if (index >= source->colormap.n_entries)
372
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
373
        *ptr++ = source->colormap.entries[index].red;
374
      }
375
    } else if (cinfo->in_color_space == JCS_CMYK) {
376
      for (col = cinfo->image_width; col > 0; col--) {
377
        JSAMPLE index = *bufferptr++;
378
379
        if (index >= source->colormap.n_entries)
380
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
381
        rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red,
382
                    source->colormap.entries[index].green,
383
                    source->colormap.entries[index].blue, ptr, ptr + 1,
384
                    ptr + 2, ptr + 3);
385
        ptr += 4;
386
      }
387
    } else {
388
      register int rindex = rgb_red[cinfo->in_color_space];
389
      register int gindex = rgb_green[cinfo->in_color_space];
390
      register int bindex = rgb_blue[cinfo->in_color_space];
391
      register int aindex = alpha_index[cinfo->in_color_space];
392
      register int ps = rgb_pixelsize[cinfo->in_color_space];
393
394
      for (col = cinfo->image_width; col > 0; col--) {
395
        JSAMPLE index = *bufferptr++;
396
397
        if (index >= source->colormap.n_entries)
398
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
399
        ptr[rindex] = source->colormap.entries[index].red;
400
        ptr[gindex] = source->colormap.entries[index].green;
401
        ptr[bindex] = source->colormap.entries[index].blue;
402
        if (aindex >= 0)
403
          ptr[aindex] = _MAXJSAMPLE;
404
        ptr += ps;
405
      }
406
    }
407
  } else
408
#endif
409
1.14k
  {
410
1.14k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
411
644
      for (col = cinfo->image_width; col > 0; col--) {
412
570
        JSAMPLE index = *bufferptr++;
413
414
570
        if (index >= source->colormap.n_entries)
415
5
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
416
570
        *ptr++ = rescale[source->colormap.entries[index].red];
417
570
      }
418
1.06k
    } else if (cinfo->in_color_space == JCS_CMYK) {
419
1.35k
      for (col = cinfo->image_width; col > 0; col--) {
420
1.20k
        JSAMPLE index = *bufferptr++;
421
422
1.20k
        if (index >= source->colormap.n_entries)
423
10
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
424
1.20k
        rgb_to_cmyk((1 << cinfo->data_precision) - 1,
425
1.20k
                    rescale[source->colormap.entries[index].red],
426
1.20k
                    rescale[source->colormap.entries[index].green],
427
1.20k
                    rescale[source->colormap.entries[index].blue], ptr,
428
1.20k
                    ptr + 1, ptr + 2, ptr + 3);
429
1.20k
        ptr += 4;
430
1.20k
      }
431
912
    } else {
432
912
      register int rindex = rgb_red[cinfo->in_color_space];
433
912
      register int gindex = rgb_green[cinfo->in_color_space];
434
912
      register int bindex = rgb_blue[cinfo->in_color_space];
435
912
      register int aindex = alpha_index[cinfo->in_color_space];
436
912
      register int ps = rgb_pixelsize[cinfo->in_color_space];
437
438
6.92k
      for (col = cinfo->image_width; col > 0; col--) {
439
6.01k
        JSAMPLE index = *bufferptr++;
440
441
6.01k
        if (index >= source->colormap.n_entries)
442
50
          ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
443
6.01k
        ptr[rindex] = rescale[source->colormap.entries[index].red];
444
6.01k
        ptr[gindex] = rescale[source->colormap.entries[index].green];
445
6.01k
        ptr[bindex] = rescale[source->colormap.entries[index].blue];
446
6.01k
        if (aindex >= 0)
447
1.19k
          ptr[aindex] = (1 << cinfo->data_precision) - 1;
448
6.01k
        ptr += ps;
449
6.01k
      }
450
912
    }
451
1.14k
  }
452
1.14k
  return 1;
453
1.14k
}
454
455
456
#ifdef ZERO_BUFFERS
457
458
static void *spng_malloc(size_t size)
459
{
460
  return calloc(1, size);
461
}
462
463
#endif
464
465
466
/*
467
 * Read the file header; return image size and component count.
468
 */
469
470
METHODDEF(void)
471
start_input_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
472
155k
{
473
155k
  png_source_ptr source = (png_source_ptr)sinfo;
474
155k
  struct spng_ihdr ihdr;
475
155k
  int png_components = 3;
476
155k
  boolean use_raw_buffer;
477
#ifdef ZERO_BUFFERS
478
  struct spng_alloc alloc;
479
480
  alloc.malloc_fn = spng_malloc;
481
  alloc.realloc_fn = realloc;
482
  alloc.calloc_fn = calloc;
483
  alloc.free_fn = free;
484
  source->ctx = spng_ctx_new2(&alloc, 0);
485
#else
486
155k
  source->ctx = spng_ctx_new(0);
487
155k
#endif
488
155k
  if (!source->ctx)
489
0
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context");
490
491
155k
  TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file));
492
493
155k
  TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr));
494
495
155k
  if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION)
496
22.8k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
497
155k
  if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16)
498
30.7k
    ERREXIT(cinfo, JERR_PNG_BADDEPTH);
499
155k
  if (sinfo->max_pixels &&
500
92.0k
      (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels)
501
1.67k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
502
503
155k
  cinfo->image_width = (JDIMENSION)ihdr.width;
504
155k
  cinfo->image_height = (JDIMENSION)ihdr.height;
505
155k
  source->png_bit_depth = ihdr.bit_depth;
506
155k
  source->png_color_type = ihdr.color_type;
507
508
  /* initialize flags to most common settings */
509
155k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
510
511
155k
  switch (ihdr.color_type) {
512
875
  case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA:
513
30.7k
  case SPNG_COLOR_TYPE_GRAYSCALE:
514
30.7k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
515
30.7k
        cinfo->in_color_space == JCS_RGB)
516
2.01k
      cinfo->in_color_space = JCS_GRAYSCALE;
517
30.7k
    TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height,
518
30.7k
             ihdr.bit_depth);
519
30.7k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
520
6.24k
      if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE &&
521
6.07k
          cinfo->data_precision == ihdr.bit_depth) {
522
2.71k
        source->pub.get_pixel_rows = get_raw_row;
523
2.71k
        use_raw_buffer = TRUE;
524
2.71k
      } else
525
3.52k
        source->pub.get_pixel_rows = get_gray_row;
526
24.5k
    } else if (IsExtRGB(cinfo->in_color_space))
527
21.1k
      source->pub.get_pixel_rows = get_gray_rgb_row;
528
3.39k
    else if (cinfo->in_color_space == JCS_CMYK)
529
3.39k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
530
0
    else
531
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
532
30.7k
    if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) {
533
875
      png_components = 2;
534
875
      source->png_alpha = 1;
535
29.8k
    } else {
536
29.8k
      png_components = 1;
537
29.8k
      source->png_alpha = 0;
538
29.8k
    }
539
30.7k
    break;
540
541
43.3k
  case SPNG_COLOR_TYPE_TRUECOLOR:
542
52.4k
  case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA:
543
52.4k
    if (cinfo->in_color_space == JCS_UNKNOWN)
544
0
      cinfo->in_color_space = JCS_EXT_RGB;
545
52.4k
    TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height,
546
52.4k
             ihdr.bit_depth);
547
52.4k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR &&
548
43.3k
        cinfo->data_precision == ihdr.bit_depth &&
549
15.1k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
550
15.1k
        (cinfo->in_color_space == JCS_EXT_RGB ||
551
12.2k
         cinfo->in_color_space == JCS_RGB)) {
552
#else
553
        cinfo->in_color_space == JCS_EXT_RGB) {
554
#endif
555
3.33k
      source->pub.get_pixel_rows = get_raw_row;
556
3.33k
      use_raw_buffer = TRUE;
557
49.1k
    } else if (IsExtRGB(cinfo->in_color_space))
558
35.5k
      source->pub.get_pixel_rows = get_rgb_row;
559
13.5k
    else if (cinfo->in_color_space == JCS_CMYK)
560
5.99k
      source->pub.get_pixel_rows = get_rgb_cmyk_row;
561
7.59k
    else
562
7.59k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
563
52.4k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) {
564
7.72k
      png_components = 4;
565
7.72k
      source->png_alpha = 1;
566
44.7k
    } else {
567
44.7k
      png_components = 3;
568
44.7k
      source->png_alpha = 0;
569
44.7k
    }
570
52.4k
    break;
571
572
7.14k
  case SPNG_COLOR_TYPE_INDEXED:
573
7.14k
  {
574
7.14k
    int i, gray = 1;
575
576
7.14k
    TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height,
577
7.14k
             ihdr.bit_depth);
578
7.14k
    TRY_SPNG(spng_get_plte(source->ctx, &source->colormap));
579
7.14k
    if (source->png_bit_depth != 8 || source->colormap.n_entries > 256)
580
0
      ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
581
582
98.1k
    for (i = 0; i < (int)source->colormap.n_entries; i++) {
583
91.0k
      if (source->colormap.entries[i].red !=
584
91.0k
          source->colormap.entries[i].green ||
585
46.2k
          source->colormap.entries[i].green !=
586
46.2k
          source->colormap.entries[i].blue)
587
45.8k
        gray = 0;
588
91.0k
    }
589
590
7.14k
    if ((cinfo->in_color_space == JCS_UNKNOWN ||
591
1.51k
         cinfo->in_color_space == JCS_RGB) && gray)
592
36
      cinfo->in_color_space = JCS_GRAYSCALE;
593
7.14k
    if (cinfo->in_color_space == JCS_GRAYSCALE && !gray)
594
106
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
595
596
7.14k
    source->pub.get_pixel_rows = get_indexed_row;
597
7.14k
    png_components = 1;
598
7.14k
    source->png_alpha = 0;
599
7.14k
    break;
600
43.3k
  }
601
602
0
  default:
603
0
    ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
604
155k
  }
605
606
77.0k
  if (IsExtRGB(cinfo->in_color_space))
607
61.1k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
608
15.9k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
609
6.38k
    cinfo->input_components = 1;
610
9.56k
  else if (cinfo->in_color_space == JCS_CMYK)
611
9.56k
    cinfo->input_components = 4;
612
613
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
614
77.0k
  source->buffer_width =
615
77.0k
    (size_t)ihdr.width * png_components * source->png_bit_depth / 8;
616
77.0k
  source->iobuffer = (unsigned char *)
617
77.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
618
77.0k
                                source->buffer_width);
619
620
  /* Create compressor input buffer. */
621
77.0k
  if (use_raw_buffer) {
622
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
623
    /* Synthesize a _JSAMPARRAY pointer structure */
624
6.05k
    source->pixrow = (_JSAMPROW)source->iobuffer;
625
6.05k
    source->pub._buffer = &source->pixrow;
626
6.05k
    source->pub.buffer_height = 1;
627
71.0k
  } else {
628
71.0k
    unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255;
629
71.0k
    size_t val, half_maxval;
630
631
    /* Need to translate anyway, so make a separate sample buffer. */
632
71.0k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
633
71.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
634
71.0k
       (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1);
635
71.0k
    source->pub.buffer_height = 1;
636
637
    /* Compute the rescaling array. */
638
71.0k
    source->rescale = (_JSAMPLE *)
639
71.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
640
71.0k
                                  (maxval + 1L) * sizeof(_JSAMPLE));
641
71.0k
    memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE));
642
71.0k
    half_maxval = maxval / 2;
643
1.29G
    for (val = 0; val <= maxval; val++) {
644
      /* The multiplication here must be done in 32 bits to avoid overflow */
645
1.29G
      source->rescale[val] =
646
1.29G
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
647
1.29G
                   maxval);
648
1.29G
    }
649
71.0k
  }
650
651
77.0k
  TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG,
652
77.0k
                             SPNG_DECODE_PROGRESSIVE));
653
77.0k
}
rdpng-8.c:start_input_png
Line
Count
Source
472
77.3k
{
473
77.3k
  png_source_ptr source = (png_source_ptr)sinfo;
474
77.3k
  struct spng_ihdr ihdr;
475
77.3k
  int png_components = 3;
476
77.3k
  boolean use_raw_buffer;
477
#ifdef ZERO_BUFFERS
478
  struct spng_alloc alloc;
479
480
  alloc.malloc_fn = spng_malloc;
481
  alloc.realloc_fn = realloc;
482
  alloc.calloc_fn = calloc;
483
  alloc.free_fn = free;
484
  source->ctx = spng_ctx_new2(&alloc, 0);
485
#else
486
77.3k
  source->ctx = spng_ctx_new(0);
487
77.3k
#endif
488
77.3k
  if (!source->ctx)
489
0
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context");
490
491
77.3k
  TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file));
492
493
77.3k
  TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr));
494
495
77.3k
  if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION)
496
17.5k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
497
77.3k
  if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16)
498
10.7k
    ERREXIT(cinfo, JERR_PNG_BADDEPTH);
499
77.3k
  if (sinfo->max_pixels &&
500
43.8k
      (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels)
501
737
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
502
503
77.3k
  cinfo->image_width = (JDIMENSION)ihdr.width;
504
77.3k
  cinfo->image_height = (JDIMENSION)ihdr.height;
505
77.3k
  source->png_bit_depth = ihdr.bit_depth;
506
77.3k
  source->png_color_type = ihdr.color_type;
507
508
  /* initialize flags to most common settings */
509
77.3k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
510
511
77.3k
  switch (ihdr.color_type) {
512
399
  case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA:
513
13.1k
  case SPNG_COLOR_TYPE_GRAYSCALE:
514
13.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
515
13.1k
        cinfo->in_color_space == JCS_RGB)
516
2.01k
      cinfo->in_color_space = JCS_GRAYSCALE;
517
13.1k
    TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height,
518
13.1k
             ihdr.bit_depth);
519
13.1k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
520
3.72k
      if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE &&
521
3.62k
          cinfo->data_precision == ihdr.bit_depth) {
522
2.60k
        source->pub.get_pixel_rows = get_raw_row;
523
2.60k
        use_raw_buffer = TRUE;
524
2.60k
      } else
525
1.12k
        source->pub.get_pixel_rows = get_gray_row;
526
9.43k
    } else if (IsExtRGB(cinfo->in_color_space))
527
8.55k
      source->pub.get_pixel_rows = get_gray_rgb_row;
528
876
    else if (cinfo->in_color_space == JCS_CMYK)
529
876
        source->pub.get_pixel_rows = get_gray_cmyk_row;
530
0
    else
531
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
532
13.1k
    if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) {
533
399
      png_components = 2;
534
399
      source->png_alpha = 1;
535
12.7k
    } else {
536
12.7k
      png_components = 1;
537
12.7k
      source->png_alpha = 0;
538
12.7k
    }
539
13.1k
    break;
540
541
20.0k
  case SPNG_COLOR_TYPE_TRUECOLOR:
542
25.9k
  case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA:
543
25.9k
    if (cinfo->in_color_space == JCS_UNKNOWN)
544
0
      cinfo->in_color_space = JCS_EXT_RGB;
545
25.9k
    TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height,
546
25.9k
             ihdr.bit_depth);
547
25.9k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR &&
548
20.0k
        cinfo->data_precision == ihdr.bit_depth &&
549
12.1k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
550
12.1k
        (cinfo->in_color_space == JCS_EXT_RGB ||
551
10.0k
         cinfo->in_color_space == JCS_RGB)) {
552
#else
553
        cinfo->in_color_space == JCS_EXT_RGB) {
554
#endif
555
2.59k
      source->pub.get_pixel_rows = get_raw_row;
556
2.59k
      use_raw_buffer = TRUE;
557
23.3k
    } else if (IsExtRGB(cinfo->in_color_space))
558
17.3k
      source->pub.get_pixel_rows = get_rgb_row;
559
6.00k
    else if (cinfo->in_color_space == JCS_CMYK)
560
2.19k
      source->pub.get_pixel_rows = get_rgb_cmyk_row;
561
3.80k
    else
562
3.80k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
563
25.9k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) {
564
4.95k
      png_components = 4;
565
4.95k
      source->png_alpha = 1;
566
20.9k
    } else {
567
20.9k
      png_components = 3;
568
20.9k
      source->png_alpha = 0;
569
20.9k
    }
570
25.9k
    break;
571
572
4.04k
  case SPNG_COLOR_TYPE_INDEXED:
573
4.04k
  {
574
4.04k
    int i, gray = 1;
575
576
4.04k
    TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height,
577
4.04k
             ihdr.bit_depth);
578
4.04k
    TRY_SPNG(spng_get_plte(source->ctx, &source->colormap));
579
4.04k
    if (source->png_bit_depth != 8 || source->colormap.n_entries > 256)
580
0
      ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
581
582
48.6k
    for (i = 0; i < (int)source->colormap.n_entries; i++) {
583
44.5k
      if (source->colormap.entries[i].red !=
584
44.5k
          source->colormap.entries[i].green ||
585
23.9k
          source->colormap.entries[i].green !=
586
23.9k
          source->colormap.entries[i].blue)
587
21.4k
        gray = 0;
588
44.5k
    }
589
590
4.04k
    if ((cinfo->in_color_space == JCS_UNKNOWN ||
591
741
         cinfo->in_color_space == JCS_RGB) && gray)
592
36
      cinfo->in_color_space = JCS_GRAYSCALE;
593
4.04k
    if (cinfo->in_color_space == JCS_GRAYSCALE && !gray)
594
48
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
595
596
4.04k
    source->pub.get_pixel_rows = get_indexed_row;
597
4.04k
    png_components = 1;
598
4.04k
    source->png_alpha = 0;
599
4.04k
    break;
600
20.0k
  }
601
602
0
  default:
603
0
    ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
604
77.3k
  }
605
606
35.9k
  if (IsExtRGB(cinfo->in_color_space))
607
29.0k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
608
6.96k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
609
3.81k
    cinfo->input_components = 1;
610
3.14k
  else if (cinfo->in_color_space == JCS_CMYK)
611
3.14k
    cinfo->input_components = 4;
612
613
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
614
35.9k
  source->buffer_width =
615
35.9k
    (size_t)ihdr.width * png_components * source->png_bit_depth / 8;
616
35.9k
  source->iobuffer = (unsigned char *)
617
35.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
618
35.9k
                                source->buffer_width);
619
620
  /* Create compressor input buffer. */
621
35.9k
  if (use_raw_buffer) {
622
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
623
    /* Synthesize a _JSAMPARRAY pointer structure */
624
5.20k
    source->pixrow = (_JSAMPROW)source->iobuffer;
625
5.20k
    source->pub._buffer = &source->pixrow;
626
5.20k
    source->pub.buffer_height = 1;
627
30.7k
  } else {
628
30.7k
    unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255;
629
30.7k
    size_t val, half_maxval;
630
631
    /* Need to translate anyway, so make a separate sample buffer. */
632
30.7k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
633
30.7k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
634
30.7k
       (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1);
635
30.7k
    source->pub.buffer_height = 1;
636
637
    /* Compute the rescaling array. */
638
30.7k
    source->rescale = (_JSAMPLE *)
639
30.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
640
30.7k
                                  (maxval + 1L) * sizeof(_JSAMPLE));
641
30.7k
    memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE));
642
30.7k
    half_maxval = maxval / 2;
643
611M
    for (val = 0; val <= maxval; val++) {
644
      /* The multiplication here must be done in 32 bits to avoid overflow */
645
611M
      source->rescale[val] =
646
611M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
647
611M
                   maxval);
648
611M
    }
649
30.7k
  }
650
651
35.9k
  TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG,
652
35.9k
                             SPNG_DECODE_PROGRESSIVE));
653
35.9k
}
rdpng-12.c:start_input_png
Line
Count
Source
472
52.9k
{
473
52.9k
  png_source_ptr source = (png_source_ptr)sinfo;
474
52.9k
  struct spng_ihdr ihdr;
475
52.9k
  int png_components = 3;
476
52.9k
  boolean use_raw_buffer;
477
#ifdef ZERO_BUFFERS
478
  struct spng_alloc alloc;
479
480
  alloc.malloc_fn = spng_malloc;
481
  alloc.realloc_fn = realloc;
482
  alloc.calloc_fn = calloc;
483
  alloc.free_fn = free;
484
  source->ctx = spng_ctx_new2(&alloc, 0);
485
#else
486
52.9k
  source->ctx = spng_ctx_new(0);
487
52.9k
#endif
488
52.9k
  if (!source->ctx)
489
0
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context");
490
491
52.9k
  TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file));
492
493
52.9k
  TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr));
494
495
52.9k
  if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION)
496
4.84k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
497
52.9k
  if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16)
498
14.2k
    ERREXIT(cinfo, JERR_PNG_BADDEPTH);
499
52.9k
  if (sinfo->max_pixels &&
500
30.8k
      (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels)
501
602
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
502
503
52.9k
  cinfo->image_width = (JDIMENSION)ihdr.width;
504
52.9k
  cinfo->image_height = (JDIMENSION)ihdr.height;
505
52.9k
  source->png_bit_depth = ihdr.bit_depth;
506
52.9k
  source->png_color_type = ihdr.color_type;
507
508
  /* initialize flags to most common settings */
509
52.9k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
510
511
52.9k
  switch (ihdr.color_type) {
512
469
  case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA:
513
12.4k
  case SPNG_COLOR_TYPE_GRAYSCALE:
514
12.4k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
515
12.4k
        cinfo->in_color_space == JCS_RGB)
516
0
      cinfo->in_color_space = JCS_GRAYSCALE;
517
12.4k
    TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height,
518
12.4k
             ihdr.bit_depth);
519
12.4k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
520
1.78k
      if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE &&
521
1.71k
          cinfo->data_precision == ihdr.bit_depth) {
522
0
        source->pub.get_pixel_rows = get_raw_row;
523
0
        use_raw_buffer = TRUE;
524
0
      } else
525
1.78k
        source->pub.get_pixel_rows = get_gray_row;
526
10.6k
    } else if (IsExtRGB(cinfo->in_color_space))
527
8.91k
      source->pub.get_pixel_rows = get_gray_rgb_row;
528
1.78k
    else if (cinfo->in_color_space == JCS_CMYK)
529
1.78k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
530
0
    else
531
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
532
12.4k
    if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) {
533
469
      png_components = 2;
534
469
      source->png_alpha = 1;
535
12.0k
    } else {
536
12.0k
      png_components = 1;
537
12.0k
      source->png_alpha = 0;
538
12.0k
    }
539
12.4k
    break;
540
541
12.1k
  case SPNG_COLOR_TYPE_TRUECOLOR:
542
15.3k
  case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA:
543
15.3k
    if (cinfo->in_color_space == JCS_UNKNOWN)
544
0
      cinfo->in_color_space = JCS_EXT_RGB;
545
15.3k
    TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height,
546
15.3k
             ihdr.bit_depth);
547
15.3k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR &&
548
12.1k
        cinfo->data_precision == ihdr.bit_depth &&
549
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
550
0
        (cinfo->in_color_space == JCS_EXT_RGB ||
551
0
         cinfo->in_color_space == JCS_RGB)) {
552
#else
553
        cinfo->in_color_space == JCS_EXT_RGB) {
554
#endif
555
0
      source->pub.get_pixel_rows = get_raw_row;
556
0
      use_raw_buffer = TRUE;
557
15.3k
    } else if (IsExtRGB(cinfo->in_color_space))
558
10.9k
      source->pub.get_pixel_rows = get_rgb_row;
559
4.38k
    else if (cinfo->in_color_space == JCS_CMYK)
560
2.19k
      source->pub.get_pixel_rows = get_rgb_cmyk_row;
561
2.19k
    else
562
2.19k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
563
15.3k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) {
564
2.74k
      png_components = 4;
565
2.74k
      source->png_alpha = 1;
566
12.6k
    } else {
567
12.6k
      png_components = 3;
568
12.6k
      source->png_alpha = 0;
569
12.6k
    }
570
15.3k
    break;
571
572
2.38k
  case SPNG_COLOR_TYPE_INDEXED:
573
2.38k
  {
574
2.38k
    int i, gray = 1;
575
576
2.38k
    TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height,
577
2.38k
             ihdr.bit_depth);
578
2.38k
    TRY_SPNG(spng_get_plte(source->ctx, &source->colormap));
579
2.38k
    if (source->png_bit_depth != 8 || source->colormap.n_entries > 256)
580
0
      ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
581
582
31.2k
    for (i = 0; i < (int)source->colormap.n_entries; i++) {
583
28.8k
      if (source->colormap.entries[i].red !=
584
28.8k
          source->colormap.entries[i].green ||
585
13.6k
          source->colormap.entries[i].green !=
586
13.6k
          source->colormap.entries[i].blue)
587
15.4k
        gray = 0;
588
28.8k
    }
589
590
2.38k
    if ((cinfo->in_color_space == JCS_UNKNOWN ||
591
490
         cinfo->in_color_space == JCS_RGB) && gray)
592
0
      cinfo->in_color_space = JCS_GRAYSCALE;
593
2.38k
    if (cinfo->in_color_space == JCS_GRAYSCALE && !gray)
594
38
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
595
596
2.38k
    source->pub.get_pixel_rows = get_indexed_row;
597
2.38k
    png_components = 1;
598
2.38k
    source->png_alpha = 0;
599
2.38k
    break;
600
12.1k
  }
601
602
0
  default:
603
0
    ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
604
52.9k
  }
605
606
26.0k
  if (IsExtRGB(cinfo->in_color_space))
607
20.2k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
608
5.86k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
609
1.81k
    cinfo->input_components = 1;
610
4.04k
  else if (cinfo->in_color_space == JCS_CMYK)
611
4.04k
    cinfo->input_components = 4;
612
613
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
614
26.0k
  source->buffer_width =
615
26.0k
    (size_t)ihdr.width * png_components * source->png_bit_depth / 8;
616
26.0k
  source->iobuffer = (unsigned char *)
617
26.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
618
26.0k
                                source->buffer_width);
619
620
  /* Create compressor input buffer. */
621
26.0k
  if (use_raw_buffer) {
622
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
623
    /* Synthesize a _JSAMPARRAY pointer structure */
624
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
625
0
    source->pub._buffer = &source->pixrow;
626
0
    source->pub.buffer_height = 1;
627
26.0k
  } else {
628
26.0k
    unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255;
629
26.0k
    size_t val, half_maxval;
630
631
    /* Need to translate anyway, so make a separate sample buffer. */
632
26.0k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
633
26.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
634
26.0k
       (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1);
635
26.0k
    source->pub.buffer_height = 1;
636
637
    /* Compute the rescaling array. */
638
26.0k
    source->rescale = (_JSAMPLE *)
639
26.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
640
26.0k
                                  (maxval + 1L) * sizeof(_JSAMPLE));
641
26.0k
    memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE));
642
26.0k
    half_maxval = maxval / 2;
643
393M
    for (val = 0; val <= maxval; val++) {
644
      /* The multiplication here must be done in 32 bits to avoid overflow */
645
393M
      source->rescale[val] =
646
393M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
647
393M
                   maxval);
648
393M
    }
649
26.0k
  }
650
651
26.0k
  TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG,
652
26.0k
                             SPNG_DECODE_PROGRESSIVE));
653
26.0k
}
rdpng-16.c:start_input_png
Line
Count
Source
472
25.1k
{
473
25.1k
  png_source_ptr source = (png_source_ptr)sinfo;
474
25.1k
  struct spng_ihdr ihdr;
475
25.1k
  int png_components = 3;
476
25.1k
  boolean use_raw_buffer;
477
#ifdef ZERO_BUFFERS
478
  struct spng_alloc alloc;
479
480
  alloc.malloc_fn = spng_malloc;
481
  alloc.realloc_fn = realloc;
482
  alloc.calloc_fn = calloc;
483
  alloc.free_fn = free;
484
  source->ctx = spng_ctx_new2(&alloc, 0);
485
#else
486
25.1k
  source->ctx = spng_ctx_new(0);
487
25.1k
#endif
488
25.1k
  if (!source->ctx)
489
0
    ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context");
490
491
25.1k
  TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file));
492
493
25.1k
  TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr));
494
495
25.1k
  if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION)
496
462
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
497
25.1k
  if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16)
498
5.66k
    ERREXIT(cinfo, JERR_PNG_BADDEPTH);
499
25.1k
  if (sinfo->max_pixels &&
500
17.3k
      (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels)
501
336
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
502
503
25.1k
  cinfo->image_width = (JDIMENSION)ihdr.width;
504
25.1k
  cinfo->image_height = (JDIMENSION)ihdr.height;
505
25.1k
  source->png_bit_depth = ihdr.bit_depth;
506
25.1k
  source->png_color_type = ihdr.color_type;
507
508
  /* initialize flags to most common settings */
509
25.1k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
510
511
25.1k
  switch (ihdr.color_type) {
512
7
  case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA:
513
5.11k
  case SPNG_COLOR_TYPE_GRAYSCALE:
514
5.11k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
515
5.11k
        cinfo->in_color_space == JCS_RGB)
516
0
      cinfo->in_color_space = JCS_GRAYSCALE;
517
5.11k
    TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height,
518
5.11k
             ihdr.bit_depth);
519
5.11k
    if (cinfo->in_color_space == JCS_GRAYSCALE) {
520
731
      if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE &&
521
730
          cinfo->data_precision == ihdr.bit_depth) {
522
106
        source->pub.get_pixel_rows = get_raw_row;
523
106
        use_raw_buffer = TRUE;
524
106
      } else
525
625
        source->pub.get_pixel_rows = get_gray_row;
526
4.38k
    } else if (IsExtRGB(cinfo->in_color_space))
527
3.65k
      source->pub.get_pixel_rows = get_gray_rgb_row;
528
731
    else if (cinfo->in_color_space == JCS_CMYK)
529
731
        source->pub.get_pixel_rows = get_gray_cmyk_row;
530
0
    else
531
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
532
5.11k
    if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) {
533
7
      png_components = 2;
534
7
      source->png_alpha = 1;
535
5.11k
    } else {
536
5.11k
      png_components = 1;
537
5.11k
      source->png_alpha = 0;
538
5.11k
    }
539
5.11k
    break;
540
541
11.1k
  case SPNG_COLOR_TYPE_TRUECOLOR:
542
11.2k
  case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA:
543
11.2k
    if (cinfo->in_color_space == JCS_UNKNOWN)
544
0
      cinfo->in_color_space = JCS_EXT_RGB;
545
11.2k
    TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height,
546
11.2k
             ihdr.bit_depth);
547
11.2k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR &&
548
11.1k
        cinfo->data_precision == ihdr.bit_depth &&
549
2.97k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
550
2.97k
        (cinfo->in_color_space == JCS_EXT_RGB ||
551
2.23k
         cinfo->in_color_space == JCS_RGB)) {
552
#else
553
        cinfo->in_color_space == JCS_EXT_RGB) {
554
#endif
555
744
      source->pub.get_pixel_rows = get_raw_row;
556
744
      use_raw_buffer = TRUE;
557
10.4k
    } else if (IsExtRGB(cinfo->in_color_space))
558
7.25k
      source->pub.get_pixel_rows = get_rgb_row;
559
3.20k
    else if (cinfo->in_color_space == JCS_CMYK)
560
1.60k
      source->pub.get_pixel_rows = get_rgb_cmyk_row;
561
1.60k
    else
562
1.60k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
563
11.2k
    if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) {
564
18
      png_components = 4;
565
18
      source->png_alpha = 1;
566
11.1k
    } else {
567
11.1k
      png_components = 3;
568
11.1k
      source->png_alpha = 0;
569
11.1k
    }
570
11.2k
    break;
571
572
721
  case SPNG_COLOR_TYPE_INDEXED:
573
721
  {
574
721
    int i, gray = 1;
575
576
721
    TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height,
577
721
             ihdr.bit_depth);
578
721
    TRY_SPNG(spng_get_plte(source->ctx, &source->colormap));
579
721
    if (source->png_bit_depth != 8 || source->colormap.n_entries > 256)
580
0
      ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
581
582
18.3k
    for (i = 0; i < (int)source->colormap.n_entries; i++) {
583
17.6k
      if (source->colormap.entries[i].red !=
584
17.6k
          source->colormap.entries[i].green ||
585
8.66k
          source->colormap.entries[i].green !=
586
8.66k
          source->colormap.entries[i].blue)
587
8.96k
        gray = 0;
588
17.6k
    }
589
590
721
    if ((cinfo->in_color_space == JCS_UNKNOWN ||
591
287
         cinfo->in_color_space == JCS_RGB) && gray)
592
0
      cinfo->in_color_space = JCS_GRAYSCALE;
593
721
    if (cinfo->in_color_space == JCS_GRAYSCALE && !gray)
594
20
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
595
596
721
    source->pub.get_pixel_rows = get_indexed_row;
597
721
    png_components = 1;
598
721
    source->png_alpha = 0;
599
721
    break;
600
11.1k
  }
601
602
0
  default:
603
0
    ERREXIT(cinfo, JERR_PNG_OUTOFRANGE);
604
25.1k
  }
605
606
14.9k
  if (IsExtRGB(cinfo->in_color_space))
607
11.8k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
608
3.12k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
609
752
    cinfo->input_components = 1;
610
2.37k
  else if (cinfo->in_color_space == JCS_CMYK)
611
2.37k
    cinfo->input_components = 4;
612
613
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
614
14.9k
  source->buffer_width =
615
14.9k
    (size_t)ihdr.width * png_components * source->png_bit_depth / 8;
616
14.9k
  source->iobuffer = (unsigned char *)
617
14.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
618
14.9k
                                source->buffer_width);
619
620
  /* Create compressor input buffer. */
621
14.9k
  if (use_raw_buffer) {
622
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
623
    /* Synthesize a _JSAMPARRAY pointer structure */
624
850
    source->pixrow = (_JSAMPROW)source->iobuffer;
625
850
    source->pub._buffer = &source->pixrow;
626
850
    source->pub.buffer_height = 1;
627
14.1k
  } else {
628
14.1k
    unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255;
629
14.1k
    size_t val, half_maxval;
630
631
    /* Need to translate anyway, so make a separate sample buffer. */
632
14.1k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
633
14.1k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
634
14.1k
       (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1);
635
14.1k
    source->pub.buffer_height = 1;
636
637
    /* Compute the rescaling array. */
638
14.1k
    source->rescale = (_JSAMPLE *)
639
14.1k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
640
14.1k
                                  (maxval + 1L) * sizeof(_JSAMPLE));
641
14.1k
    memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE));
642
14.1k
    half_maxval = maxval / 2;
643
288M
    for (val = 0; val <= maxval; val++) {
644
      /* The multiplication here must be done in 32 bits to avoid overflow */
645
288M
      source->rescale[val] =
646
288M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
647
288M
                   maxval);
648
288M
    }
649
14.1k
  }
650
651
14.9k
  TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG,
652
14.9k
                             SPNG_DECODE_PROGRESSIVE));
653
14.9k
}
654
655
656
/*
657
 * Return the ICC profile (if any) embedded in the PNG image.
658
 */
659
660
METHODDEF(boolean)
661
read_icc_profile_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo,
662
                     JOCTET **icc_data_ptr, unsigned int *icc_data_len)
663
24.2k
{
664
24.2k
  png_source_ptr source = (png_source_ptr)sinfo;
665
24.2k
  struct spng_iccp iccp;
666
667
24.2k
  if (!icc_data_ptr || !icc_data_len)
668
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
669
670
24.2k
  if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) {
671
200
    *icc_data_ptr = (JOCTET *)iccp.profile;
672
200
    *icc_data_len = (unsigned int)iccp.profile_len;
673
200
    return TRUE;
674
200
  }
675
676
24.0k
  return FALSE;
677
24.2k
}
rdpng-8.c:read_icc_profile_png
Line
Count
Source
663
11.8k
{
664
11.8k
  png_source_ptr source = (png_source_ptr)sinfo;
665
11.8k
  struct spng_iccp iccp;
666
667
11.8k
  if (!icc_data_ptr || !icc_data_len)
668
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
669
670
11.8k
  if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) {
671
121
    *icc_data_ptr = (JOCTET *)iccp.profile;
672
121
    *icc_data_len = (unsigned int)iccp.profile_len;
673
121
    return TRUE;
674
121
  }
675
676
11.7k
  return FALSE;
677
11.8k
}
rdpng-12.c:read_icc_profile_png
Line
Count
Source
663
8.44k
{
664
8.44k
  png_source_ptr source = (png_source_ptr)sinfo;
665
8.44k
  struct spng_iccp iccp;
666
667
8.44k
  if (!icc_data_ptr || !icc_data_len)
668
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
669
670
8.44k
  if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) {
671
31
    *icc_data_ptr = (JOCTET *)iccp.profile;
672
31
    *icc_data_len = (unsigned int)iccp.profile_len;
673
31
    return TRUE;
674
31
  }
675
676
8.41k
  return FALSE;
677
8.44k
}
rdpng-16.c:read_icc_profile_png
Line
Count
Source
663
3.92k
{
664
3.92k
  png_source_ptr source = (png_source_ptr)sinfo;
665
3.92k
  struct spng_iccp iccp;
666
667
3.92k
  if (!icc_data_ptr || !icc_data_len)
668
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
669
670
3.92k
  if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) {
671
48
    *icc_data_ptr = (JOCTET *)iccp.profile;
672
48
    *icc_data_len = (unsigned int)iccp.profile_len;
673
48
    return TRUE;
674
48
  }
675
676
3.87k
  return FALSE;
677
3.92k
}
678
679
680
/*
681
 * Finish up at the end of the file.
682
 */
683
684
METHODDEF(void)
685
finish_input_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
686
155k
{
687
155k
  png_source_ptr source = (png_source_ptr)sinfo;
688
689
155k
  if (source->ctx) {
690
155k
    spng_decode_chunks(source->ctx);
691
155k
    spng_ctx_free(source->ctx);
692
155k
    source->ctx = NULL;
693
155k
  }
694
155k
}
rdpng-8.c:finish_input_png
Line
Count
Source
686
77.3k
{
687
77.3k
  png_source_ptr source = (png_source_ptr)sinfo;
688
689
77.3k
  if (source->ctx) {
690
77.3k
    spng_decode_chunks(source->ctx);
691
77.3k
    spng_ctx_free(source->ctx);
692
    source->ctx = NULL;
693
77.3k
  }
694
77.3k
}
rdpng-12.c:finish_input_png
Line
Count
Source
686
52.9k
{
687
52.9k
  png_source_ptr source = (png_source_ptr)sinfo;
688
689
52.9k
  if (source->ctx) {
690
52.9k
    spng_decode_chunks(source->ctx);
691
52.9k
    spng_ctx_free(source->ctx);
692
    source->ctx = NULL;
693
52.9k
  }
694
52.9k
}
rdpng-16.c:finish_input_png
Line
Count
Source
686
25.1k
{
687
25.1k
  png_source_ptr source = (png_source_ptr)sinfo;
688
689
25.1k
  if (source->ctx) {
690
25.1k
    spng_decode_chunks(source->ctx);
691
25.1k
    spng_ctx_free(source->ctx);
692
    source->ctx = NULL;
693
25.1k
  }
694
25.1k
}
695
696
697
/*
698
 * The module selection routine for PNG format input.
699
 */
700
701
GLOBAL(cjpeg_source_ptr)
702
_jinit_read_png(j_compress_ptr cinfo)
703
155k
{
704
155k
  png_source_ptr source;
705
706
#if BITS_IN_JSAMPLE == 8
707
77.3k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
708
#else
709
78.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
710
78.0k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
711
0
#endif
712
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
713
714
  /* Create module interface object */
715
155k
  source = (png_source_ptr)
716
155k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
717
155k
                                sizeof(png_source_struct));
718
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
719
155k
  source->pub.start_input = start_input_png;
720
155k
  source->pub.read_icc_profile = read_icc_profile_png;
721
155k
  source->pub.finish_input = finish_input_png;
722
155k
  source->pub.max_pixels = 0;
723
724
155k
  return (cjpeg_source_ptr)source;
725
155k
}
jinit_read_png
Line
Count
Source
703
77.3k
{
704
77.3k
  png_source_ptr source;
705
706
77.3k
#if BITS_IN_JSAMPLE == 8
707
77.3k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
708
#else
709
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
710
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
711
#endif
712
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
713
714
  /* Create module interface object */
715
77.3k
  source = (png_source_ptr)
716
77.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
717
77.3k
                                sizeof(png_source_struct));
718
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
719
77.3k
  source->pub.start_input = start_input_png;
720
77.3k
  source->pub.read_icc_profile = read_icc_profile_png;
721
77.3k
  source->pub.finish_input = finish_input_png;
722
77.3k
  source->pub.max_pixels = 0;
723
724
77.3k
  return (cjpeg_source_ptr)source;
725
77.3k
}
j12init_read_png
Line
Count
Source
703
52.9k
{
704
52.9k
  png_source_ptr source;
705
706
#if BITS_IN_JSAMPLE == 8
707
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
708
#else
709
52.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
710
52.9k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
711
0
#endif
712
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
713
714
  /* Create module interface object */
715
52.9k
  source = (png_source_ptr)
716
52.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
717
52.9k
                                sizeof(png_source_struct));
718
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
719
52.9k
  source->pub.start_input = start_input_png;
720
52.9k
  source->pub.read_icc_profile = read_icc_profile_png;
721
52.9k
  source->pub.finish_input = finish_input_png;
722
52.9k
  source->pub.max_pixels = 0;
723
724
52.9k
  return (cjpeg_source_ptr)source;
725
52.9k
}
j16init_read_png
Line
Count
Source
703
25.1k
{
704
25.1k
  png_source_ptr source;
705
706
#if BITS_IN_JSAMPLE == 8
707
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
708
#else
709
25.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
710
25.1k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
711
0
#endif
712
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
713
714
  /* Create module interface object */
715
25.1k
  source = (png_source_ptr)
716
25.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
717
25.1k
                                sizeof(png_source_struct));
718
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
719
25.1k
  source->pub.start_input = start_input_png;
720
25.1k
  source->pub.read_icc_profile = read_icc_profile_png;
721
25.1k
  source->pub.finish_input = finish_input_png;
722
25.1k
  source->pub.max_pixels = 0;
723
724
25.1k
  return (cjpeg_source_ptr)source;
725
25.1k
}
726
727
#endif /* defined(PNG_SUPPORTED) &&
728
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */