Coverage Report

Created: 2026-05-11 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/rdppm.c
Line
Count
Source
1
/*
2
 * rdppm.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * Modified 2009 by Bill Allombert, Guido Vollbeding.
7
 * libjpeg-turbo Modifications:
8
 * Copyright (C) 2015-2017, 2020-2026, D. R. Commander.
9
 * For conditions of distribution and use, see the accompanying README.ijg
10
 * file.
11
 *
12
 * This file contains routines to read input images in PPM/PGM format.
13
 * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
14
 * The PBMPLUS library is NOT required to compile this software
15
 * (but it is highly useful as a set of PPM image manipulation programs).
16
 *
17
 * These routines may need modification for non-Unix environments or
18
 * specialized applications.  As they stand, they assume input from
19
 * an ordinary stdio stream.  They further assume that reading begins
20
 * at the start of the file; start_input may need work if the
21
 * user interface has already read some data (e.g., to determine that
22
 * the file is indeed PPM format).
23
 */
24
25
#include "cmyk.h"
26
#include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
27
28
#if defined(PPM_SUPPORTED) && \
29
    (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
30
31
32
/* Portions of this code are based on the PBMPLUS library, which is:
33
**
34
** Copyright (C) 1988 by Jef Poskanzer.
35
**
36
** Permission to use, copy, modify, and distribute this software and its
37
** documentation for any purpose and without fee is hereby granted, provided
38
** that the above copyright notice appear in all copies and that both that
39
** copyright notice and this permission notice appear in supporting
40
** documentation.  This software is provided "as is" without express or
41
** implied warranty.
42
*/
43
44
45
#define ReadOK(file, buffer, len) \
46
12.8M
  (fread(buffer, 1, len, file) == ((size_t)(len)))
47
48
static int alpha_index[JPEG_NUMCS] = {
49
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
50
};
51
52
53
/* Private version of data source object */
54
55
typedef struct {
56
  struct cjpeg_source_struct pub; /* public fields */
57
58
  /* Usually these two pointers point to the same place: */
59
  unsigned char *iobuffer;      /* fread's I/O buffer */
60
  _JSAMPROW pixrow;             /* compressor input buffer */
61
  size_t buffer_width;          /* width of I/O buffer */
62
  _JSAMPLE *rescale;            /* => maxval-remapping array, or NULL */
63
  unsigned int maxval;
64
} ppm_source_struct;
65
66
typedef ppm_source_struct *ppm_source_ptr;
67
68
69
LOCAL(int)
70
pbm_getc(FILE *infile)
71
/* Read next char, skipping over any comments */
72
/* A comment/newline sequence is returned as a newline */
73
322k
{
74
322k
  register int ch;
75
76
322k
  ch = getc(infile);
77
322k
  if (ch == '#') {
78
55.1k
    do {
79
55.1k
      ch = getc(infile);
80
55.1k
    } while (ch != '\n' && ch != EOF);
81
3.40k
  }
82
322k
  return ch;
83
322k
}
Unexecuted instantiation: rdppm-8.c:pbm_getc
rdppm-12.c:pbm_getc
Line
Count
Source
73
322k
{
74
322k
  register int ch;
75
76
322k
  ch = getc(infile);
77
322k
  if (ch == '#') {
78
55.1k
    do {
79
55.1k
      ch = getc(infile);
80
55.1k
    } while (ch != '\n' && ch != EOF);
81
3.40k
  }
82
322k
  return ch;
83
322k
}
Unexecuted instantiation: rdppm-16.c:pbm_getc
84
85
86
LOCAL(unsigned int)
87
read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
88
/* Read an unsigned decimal integer from the PPM file */
89
/* Swallows one trailing character after the integer */
90
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
91
/* This should not be a problem in practice. */
92
140k
{
93
140k
  register int ch;
94
140k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
147k
  do {
98
147k
    ch = pbm_getc(infile);
99
147k
    if (ch == EOF)
100
3.34k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
147k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
140k
  if (ch < '0' || ch > '9')
104
288
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
140k
  val = ch - '0';
107
178k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
38.0k
    val *= 10;
109
38.0k
    val += ch - '0';
110
38.0k
    if (val > maxval)
111
146
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
38.0k
  }
113
114
140k
  return val;
115
140k
}
Unexecuted instantiation: rdppm-8.c:read_pbm_integer
rdppm-12.c:read_pbm_integer
Line
Count
Source
92
140k
{
93
140k
  register int ch;
94
140k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
147k
  do {
98
147k
    ch = pbm_getc(infile);
99
147k
    if (ch == EOF)
100
3.34k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
147k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
140k
  if (ch < '0' || ch > '9')
104
288
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
140k
  val = ch - '0';
107
178k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
38.0k
    val *= 10;
109
38.0k
    val += ch - '0';
110
38.0k
    if (val > maxval)
111
146
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
38.0k
  }
113
114
140k
  return val;
115
140k
}
Unexecuted instantiation: rdppm-16.c:read_pbm_integer
116
117
118
/*
119
 * Read one row of pixels.
120
 *
121
 * We provide several different versions depending on input file format.
122
 * In all cases, input is scaled to cinfo->data_precision.
123
 *
124
 * A really fast path is provided for reading byte/sample raw files with
125
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U,
126
 * which is the normal case for 8-bit data.
127
 */
128
129
130
METHODDEF(JDIMENSION)
131
get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
132
/* This version is for reading text-format PGM files with any maxval */
133
2.30k
{
134
2.30k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
2.30k
  FILE *infile = source->pub.input_file;
136
2.30k
  register _JSAMPROW ptr;
137
2.30k
  register _JSAMPLE *rescale = source->rescale;
138
2.30k
  JDIMENSION col;
139
2.30k
  unsigned int maxval = source->maxval;
140
141
2.30k
  ptr = source->pub._buffer[0];
142
5.84k
  for (col = cinfo->image_width; col > 0; col--) {
143
3.54k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
3.54k
  }
145
2.30k
  return 1;
146
2.30k
}
Unexecuted instantiation: rdppm-8.c:get_text_gray_row
rdppm-12.c:get_text_gray_row
Line
Count
Source
133
2.30k
{
134
2.30k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
2.30k
  FILE *infile = source->pub.input_file;
136
2.30k
  register _JSAMPROW ptr;
137
2.30k
  register _JSAMPLE *rescale = source->rescale;
138
2.30k
  JDIMENSION col;
139
2.30k
  unsigned int maxval = source->maxval;
140
141
2.30k
  ptr = source->pub._buffer[0];
142
5.84k
  for (col = cinfo->image_width; col > 0; col--) {
143
3.54k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
3.54k
  }
145
2.30k
  return 1;
146
2.30k
}
Unexecuted instantiation: rdppm-16.c:get_text_gray_row
147
148
149
9.16M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
150
52.5M
  for (col = cinfo->image_width; col > 0; col--) { \
151
43.4M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
152
43.4M
    alpha_set_op \
153
43.4M
    ptr += ps; \
154
43.4M
  } \
155
9.16M
}
156
157
METHODDEF(JDIMENSION)
158
get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
159
/* This version is for reading text-format PGM files with any maxval and
160
   converting to extended RGB */
161
11.5k
{
162
11.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
11.5k
  FILE *infile = source->pub.input_file;
164
11.5k
  register _JSAMPROW ptr;
165
11.5k
  register _JSAMPLE *rescale = source->rescale;
166
11.5k
  JDIMENSION col;
167
11.5k
  unsigned int maxval = source->maxval;
168
11.5k
  register int rindex = rgb_red[cinfo->in_color_space];
169
11.5k
  register int gindex = rgb_green[cinfo->in_color_space];
170
11.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
11.5k
  register int aindex = alpha_index[cinfo->in_color_space];
172
11.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
11.5k
  ptr = source->pub._buffer[0];
175
11.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
1.30k
    if (aindex >= 0)
177
222
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
1.30k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
1.08k
    else
180
1.08k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
10.2k
  } else {
182
10.2k
    if (aindex >= 0)
183
2.08k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
10.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
8.12k
    else
186
8.12k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
10.2k
  }
188
11.5k
  return 1;
189
11.5k
}
Unexecuted instantiation: rdppm-8.c:get_text_gray_rgb_row
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
161
11.5k
{
162
11.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
11.5k
  FILE *infile = source->pub.input_file;
164
11.5k
  register _JSAMPROW ptr;
165
11.5k
  register _JSAMPLE *rescale = source->rescale;
166
11.5k
  JDIMENSION col;
167
11.5k
  unsigned int maxval = source->maxval;
168
11.5k
  register int rindex = rgb_red[cinfo->in_color_space];
169
11.5k
  register int gindex = rgb_green[cinfo->in_color_space];
170
11.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
11.5k
  register int aindex = alpha_index[cinfo->in_color_space];
172
11.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
11.5k
  ptr = source->pub._buffer[0];
175
11.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
1.30k
    if (aindex >= 0)
177
222
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
1.30k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
1.08k
    else
180
1.08k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
10.2k
  } else {
182
10.2k
    if (aindex >= 0)
183
2.08k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
10.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
8.12k
    else
186
8.12k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
10.2k
  }
188
11.5k
  return 1;
189
11.5k
}
Unexecuted instantiation: rdppm-16.c:get_text_gray_rgb_row
190
191
192
METHODDEF(JDIMENSION)
193
get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
194
/* This version is for reading text-format PGM files with any maxval and
195
   converting to CMYK */
196
2.30k
{
197
2.30k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
2.30k
  FILE *infile = source->pub.input_file;
199
2.30k
  register _JSAMPROW ptr;
200
2.30k
  register _JSAMPLE *rescale = source->rescale;
201
2.30k
  JDIMENSION col;
202
2.30k
  unsigned int maxval = source->maxval;
203
204
2.30k
  ptr = source->pub._buffer[0];
205
2.30k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
1.31k
    for (col = cinfo->image_width; col > 0; col--) {
207
859
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
859
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
859
      ptr += 4;
210
859
    }
211
1.85k
  } else {
212
4.53k
    for (col = cinfo->image_width; col > 0; col--) {
213
2.68k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
2.68k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
2.68k
                  ptr + 1, ptr + 2, ptr + 3);
216
2.68k
      ptr += 4;
217
2.68k
    }
218
1.85k
  }
219
2.30k
  return 1;
220
2.30k
}
Unexecuted instantiation: rdppm-8.c:get_text_gray_cmyk_row
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
196
2.30k
{
197
2.30k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
2.30k
  FILE *infile = source->pub.input_file;
199
2.30k
  register _JSAMPROW ptr;
200
2.30k
  register _JSAMPLE *rescale = source->rescale;
201
2.30k
  JDIMENSION col;
202
2.30k
  unsigned int maxval = source->maxval;
203
204
2.30k
  ptr = source->pub._buffer[0];
205
2.30k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
1.31k
    for (col = cinfo->image_width; col > 0; col--) {
207
859
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
859
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
859
      ptr += 4;
210
859
    }
211
1.85k
  } else {
212
4.53k
    for (col = cinfo->image_width; col > 0; col--) {
213
2.68k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
2.68k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
2.68k
                  ptr + 1, ptr + 2, ptr + 3);
216
2.68k
      ptr += 4;
217
2.68k
    }
218
1.85k
  }
219
2.30k
  return 1;
220
2.30k
}
Unexecuted instantiation: rdppm-16.c:get_text_gray_cmyk_row
221
222
223
40.6k
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
224
4.60M
  for (col = cinfo->image_width; col > 0; col--) { \
225
4.56M
    ptr[rindex] = read_op; \
226
4.56M
    ptr[gindex] = read_op; \
227
4.56M
    ptr[bindex] = read_op; \
228
4.56M
    alpha_set_op \
229
4.56M
    ptr += ps; \
230
4.56M
  } \
231
40.6k
}
232
233
METHODDEF(JDIMENSION)
234
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
235
/* This version is for reading text-format PPM files with any maxval */
236
10.8k
{
237
10.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
10.8k
  FILE *infile = source->pub.input_file;
239
10.8k
  register _JSAMPROW ptr;
240
10.8k
  register _JSAMPLE *rescale = source->rescale;
241
10.8k
  JDIMENSION col;
242
10.8k
  unsigned int maxval = source->maxval;
243
10.8k
  register int rindex = rgb_red[cinfo->in_color_space];
244
10.8k
  register int gindex = rgb_green[cinfo->in_color_space];
245
10.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
10.8k
  register int aindex = alpha_index[cinfo->in_color_space];
247
10.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
10.8k
  ptr = source->pub._buffer[0];
250
10.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
1.42k
    if (aindex >= 0)
252
327
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
1.42k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
1.10k
    else
255
1.10k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
9.44k
  } else {
257
9.44k
    if (aindex >= 0)
258
1.84k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
9.44k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
7.59k
    else
261
7.59k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
9.44k
  }
263
10.8k
  return 1;
264
10.8k
}
Unexecuted instantiation: rdppm-8.c:get_text_rgb_row
rdppm-12.c:get_text_rgb_row
Line
Count
Source
236
10.8k
{
237
10.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
10.8k
  FILE *infile = source->pub.input_file;
239
10.8k
  register _JSAMPROW ptr;
240
10.8k
  register _JSAMPLE *rescale = source->rescale;
241
10.8k
  JDIMENSION col;
242
10.8k
  unsigned int maxval = source->maxval;
243
10.8k
  register int rindex = rgb_red[cinfo->in_color_space];
244
10.8k
  register int gindex = rgb_green[cinfo->in_color_space];
245
10.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
10.8k
  register int aindex = alpha_index[cinfo->in_color_space];
247
10.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
10.8k
  ptr = source->pub._buffer[0];
250
10.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
1.42k
    if (aindex >= 0)
252
327
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
1.42k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
1.10k
    else
255
1.10k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
9.44k
  } else {
257
9.44k
    if (aindex >= 0)
258
1.84k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
9.44k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
7.59k
    else
261
7.59k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
9.44k
  }
263
10.8k
  return 1;
264
10.8k
}
Unexecuted instantiation: rdppm-16.c:get_text_rgb_row
265
266
267
METHODDEF(JDIMENSION)
268
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
269
/* This version is for reading text-format PPM files with any maxval and
270
   converting to CMYK */
271
2.17k
{
272
2.17k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
2.17k
  FILE *infile = source->pub.input_file;
274
2.17k
  register _JSAMPROW ptr;
275
2.17k
  register _JSAMPLE *rescale = source->rescale;
276
2.17k
  JDIMENSION col;
277
2.17k
  unsigned int maxval = source->maxval;
278
279
2.17k
  ptr = source->pub._buffer[0];
280
2.17k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
1.76k
    for (col = cinfo->image_width; col > 0; col--) {
282
1.30k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
1.30k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
1.30k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
1.30k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
1.30k
      ptr += 4;
287
1.30k
    }
288
1.71k
  } else {
289
4.93k
    for (col = cinfo->image_width; col > 0; col--) {
290
3.22k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
3.22k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
3.22k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
3.22k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
3.22k
                  ptr + 2, ptr + 3);
295
3.22k
      ptr += 4;
296
3.22k
    }
297
1.71k
  }
298
2.17k
  return 1;
299
2.17k
}
Unexecuted instantiation: rdppm-8.c:get_text_rgb_cmyk_row
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
271
2.17k
{
272
2.17k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
2.17k
  FILE *infile = source->pub.input_file;
274
2.17k
  register _JSAMPROW ptr;
275
2.17k
  register _JSAMPLE *rescale = source->rescale;
276
2.17k
  JDIMENSION col;
277
2.17k
  unsigned int maxval = source->maxval;
278
279
2.17k
  ptr = source->pub._buffer[0];
280
2.17k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
1.76k
    for (col = cinfo->image_width; col > 0; col--) {
282
1.30k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
1.30k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
1.30k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
1.30k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
1.30k
      ptr += 4;
287
1.30k
    }
288
1.71k
  } else {
289
4.93k
    for (col = cinfo->image_width; col > 0; col--) {
290
3.22k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
3.22k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
3.22k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
3.22k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
3.22k
                  ptr + 2, ptr + 3);
295
3.22k
      ptr += 4;
296
3.22k
    }
297
1.71k
  }
298
2.17k
  return 1;
299
2.17k
}
Unexecuted instantiation: rdppm-16.c:get_text_rgb_cmyk_row
300
301
302
METHODDEF(JDIMENSION)
303
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
304
/* This version is for reading raw-byte-format PGM files with any maxval */
305
1.83M
{
306
1.83M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
1.83M
  register _JSAMPROW ptr;
308
1.83M
  register unsigned char *bufferptr;
309
1.83M
  register _JSAMPLE *rescale = source->rescale;
310
1.83M
  JDIMENSION col;
311
312
1.83M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
66
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
1.83M
  ptr = source->pub._buffer[0];
315
1.83M
  bufferptr = source->iobuffer;
316
10.5M
  for (col = cinfo->image_width; col > 0; col--) {
317
8.67M
    *ptr++ = rescale[*bufferptr++];
318
8.67M
  }
319
1.83M
  return 1;
320
1.83M
}
Unexecuted instantiation: rdppm-8.c:get_scaled_gray_row
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
305
1.83M
{
306
1.83M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
1.83M
  register _JSAMPROW ptr;
308
1.83M
  register unsigned char *bufferptr;
309
1.83M
  register _JSAMPLE *rescale = source->rescale;
310
1.83M
  JDIMENSION col;
311
312
1.83M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
66
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
1.83M
  ptr = source->pub._buffer[0];
315
1.83M
  bufferptr = source->iobuffer;
316
10.5M
  for (col = cinfo->image_width; col > 0; col--) {
317
8.67M
    *ptr++ = rescale[*bufferptr++];
318
8.67M
  }
319
1.83M
  return 1;
320
1.83M
}
Unexecuted instantiation: rdppm-16.c:get_scaled_gray_row
321
322
323
METHODDEF(JDIMENSION)
324
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
325
/* This version is for reading raw-byte-format PGM files with any maxval
326
   and converting to extended RGB */
327
9.15M
{
328
9.15M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
9.15M
  register _JSAMPROW ptr;
330
9.15M
  register unsigned char *bufferptr;
331
9.15M
  register _JSAMPLE *rescale = source->rescale;
332
9.15M
  JDIMENSION col;
333
9.15M
  unsigned int maxval = source->maxval;
334
9.15M
  register int rindex = rgb_red[cinfo->in_color_space];
335
9.15M
  register int gindex = rgb_green[cinfo->in_color_space];
336
9.15M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
9.15M
  register int aindex = alpha_index[cinfo->in_color_space];
338
9.15M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
9.15M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
330
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
9.15M
  ptr = source->pub._buffer[0];
343
9.15M
  bufferptr = source->iobuffer;
344
9.15M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
0
    if (aindex >= 0)
346
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
0
    else
348
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
9.15M
  } else {
350
9.15M
    if (aindex >= 0)
351
1.83M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
9.15M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
7.32M
    else
354
7.32M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
9.15M
  }
356
9.15M
  return 1;
357
9.15M
}
Unexecuted instantiation: rdppm-8.c:get_gray_rgb_row
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
327
9.15M
{
328
9.15M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
9.15M
  register _JSAMPROW ptr;
330
9.15M
  register unsigned char *bufferptr;
331
9.15M
  register _JSAMPLE *rescale = source->rescale;
332
9.15M
  JDIMENSION col;
333
9.15M
  unsigned int maxval = source->maxval;
334
9.15M
  register int rindex = rgb_red[cinfo->in_color_space];
335
9.15M
  register int gindex = rgb_green[cinfo->in_color_space];
336
9.15M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
9.15M
  register int aindex = alpha_index[cinfo->in_color_space];
338
9.15M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
9.15M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
330
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
9.15M
  ptr = source->pub._buffer[0];
343
9.15M
  bufferptr = source->iobuffer;
344
9.15M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
0
    if (aindex >= 0)
346
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
0
    else
348
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
9.15M
  } else {
350
9.15M
    if (aindex >= 0)
351
1.83M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
9.15M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
7.32M
    else
354
7.32M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
9.15M
  }
356
9.15M
  return 1;
357
9.15M
}
Unexecuted instantiation: rdppm-16.c:get_gray_rgb_row
358
359
360
METHODDEF(JDIMENSION)
361
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
362
/* This version is for reading raw-byte-format PGM files with any maxval
363
   and converting to CMYK */
364
1.83M
{
365
1.83M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
1.83M
  register _JSAMPROW ptr;
367
1.83M
  register unsigned char *bufferptr;
368
1.83M
  register _JSAMPLE *rescale = source->rescale;
369
1.83M
  JDIMENSION col;
370
1.83M
  unsigned int maxval = source->maxval;
371
372
1.83M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
66
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
1.83M
  ptr = source->pub._buffer[0];
375
1.83M
  bufferptr = source->iobuffer;
376
1.83M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
0
    for (col = cinfo->image_width; col > 0; col--) {
378
0
      _JSAMPLE gray = *bufferptr++;
379
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
0
      ptr += 4;
381
0
    }
382
1.83M
  } else {
383
10.5M
    for (col = cinfo->image_width; col > 0; col--) {
384
8.67M
      _JSAMPLE gray = rescale[*bufferptr++];
385
8.67M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
8.67M
                  ptr + 1, ptr + 2, ptr + 3);
387
8.67M
      ptr += 4;
388
8.67M
    }
389
1.83M
  }
390
1.83M
  return 1;
391
1.83M
}
Unexecuted instantiation: rdppm-8.c:get_gray_cmyk_row
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
364
1.83M
{
365
1.83M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
1.83M
  register _JSAMPROW ptr;
367
1.83M
  register unsigned char *bufferptr;
368
1.83M
  register _JSAMPLE *rescale = source->rescale;
369
1.83M
  JDIMENSION col;
370
1.83M
  unsigned int maxval = source->maxval;
371
372
1.83M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
66
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
1.83M
  ptr = source->pub._buffer[0];
375
1.83M
  bufferptr = source->iobuffer;
376
1.83M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
0
    for (col = cinfo->image_width; col > 0; col--) {
378
0
      _JSAMPLE gray = *bufferptr++;
379
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
0
      ptr += 4;
381
0
    }
382
1.83M
  } else {
383
10.5M
    for (col = cinfo->image_width; col > 0; col--) {
384
8.67M
      _JSAMPLE gray = rescale[*bufferptr++];
385
8.67M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
8.67M
                  ptr + 1, ptr + 2, ptr + 3);
387
8.67M
      ptr += 4;
388
8.67M
    }
389
1.83M
  }
390
1.83M
  return 1;
391
1.83M
}
Unexecuted instantiation: rdppm-16.c:get_gray_cmyk_row
392
393
394
METHODDEF(JDIMENSION)
395
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
396
/* This version is for reading raw-byte-format PPM files with any maxval */
397
29.7k
{
398
29.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
29.7k
  register _JSAMPROW ptr;
400
29.7k
  register unsigned char *bufferptr;
401
29.7k
  register _JSAMPLE *rescale = source->rescale;
402
29.7k
  JDIMENSION col;
403
29.7k
  unsigned int maxval = source->maxval;
404
29.7k
  register int rindex = rgb_red[cinfo->in_color_space];
405
29.7k
  register int gindex = rgb_green[cinfo->in_color_space];
406
29.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
407
29.7k
  register int aindex = alpha_index[cinfo->in_color_space];
408
29.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
29.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
505
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
29.7k
  ptr = source->pub._buffer[0];
413
29.7k
  bufferptr = source->iobuffer;
414
29.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
0
    if (aindex >= 0)
416
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
0
    else
418
0
      RGB_READ_LOOP(*bufferptr++, {})
419
29.7k
  } else {
420
29.7k
    if (aindex >= 0)
421
5.84k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
29.7k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
23.8k
    else
424
23.8k
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
29.7k
  }
426
29.7k
  return 1;
427
29.7k
}
Unexecuted instantiation: rdppm-8.c:get_rgb_row
rdppm-12.c:get_rgb_row
Line
Count
Source
397
29.7k
{
398
29.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
29.7k
  register _JSAMPROW ptr;
400
29.7k
  register unsigned char *bufferptr;
401
29.7k
  register _JSAMPLE *rescale = source->rescale;
402
29.7k
  JDIMENSION col;
403
29.7k
  unsigned int maxval = source->maxval;
404
29.7k
  register int rindex = rgb_red[cinfo->in_color_space];
405
29.7k
  register int gindex = rgb_green[cinfo->in_color_space];
406
29.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
407
29.7k
  register int aindex = alpha_index[cinfo->in_color_space];
408
29.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
29.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
505
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
29.7k
  ptr = source->pub._buffer[0];
413
29.7k
  bufferptr = source->iobuffer;
414
29.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
0
    if (aindex >= 0)
416
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
0
    else
418
0
      RGB_READ_LOOP(*bufferptr++, {})
419
29.7k
  } else {
420
29.7k
    if (aindex >= 0)
421
5.84k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
29.7k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
23.8k
    else
424
23.8k
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
29.7k
  }
426
29.7k
  return 1;
427
29.7k
}
Unexecuted instantiation: rdppm-16.c:get_rgb_row
428
429
430
METHODDEF(JDIMENSION)
431
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
432
/* This version is for reading raw-byte-format PPM files with any maxval and
433
   converting to CMYK */
434
5.94k
{
435
5.94k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
5.94k
  register _JSAMPROW ptr;
437
5.94k
  register unsigned char *bufferptr;
438
5.94k
  register _JSAMPLE *rescale = source->rescale;
439
5.94k
  JDIMENSION col;
440
5.94k
  unsigned int maxval = source->maxval;
441
442
5.94k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
101
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
5.94k
  ptr = source->pub._buffer[0];
445
5.94k
  bufferptr = source->iobuffer;
446
5.94k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
0
    for (col = cinfo->image_width; col > 0; col--) {
448
0
      _JSAMPLE r = *bufferptr++;
449
0
      _JSAMPLE g = *bufferptr++;
450
0
      _JSAMPLE b = *bufferptr++;
451
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
0
      ptr += 4;
453
0
    }
454
5.94k
  } else {
455
914k
    for (col = cinfo->image_width; col > 0; col--) {
456
908k
      _JSAMPLE r = rescale[*bufferptr++];
457
908k
      _JSAMPLE g = rescale[*bufferptr++];
458
908k
      _JSAMPLE b = rescale[*bufferptr++];
459
908k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
908k
                  ptr + 2, ptr + 3);
461
908k
      ptr += 4;
462
908k
    }
463
5.94k
  }
464
5.94k
  return 1;
465
5.94k
}
Unexecuted instantiation: rdppm-8.c:get_rgb_cmyk_row
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
434
5.94k
{
435
5.94k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
5.94k
  register _JSAMPROW ptr;
437
5.94k
  register unsigned char *bufferptr;
438
5.94k
  register _JSAMPLE *rescale = source->rescale;
439
5.94k
  JDIMENSION col;
440
5.94k
  unsigned int maxval = source->maxval;
441
442
5.94k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
101
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
5.94k
  ptr = source->pub._buffer[0];
445
5.94k
  bufferptr = source->iobuffer;
446
5.94k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
0
    for (col = cinfo->image_width; col > 0; col--) {
448
0
      _JSAMPLE r = *bufferptr++;
449
0
      _JSAMPLE g = *bufferptr++;
450
0
      _JSAMPLE b = *bufferptr++;
451
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
0
      ptr += 4;
453
0
    }
454
5.94k
  } else {
455
914k
    for (col = cinfo->image_width; col > 0; col--) {
456
908k
      _JSAMPLE r = rescale[*bufferptr++];
457
908k
      _JSAMPLE g = rescale[*bufferptr++];
458
908k
      _JSAMPLE b = rescale[*bufferptr++];
459
908k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
908k
                  ptr + 2, ptr + 3);
461
908k
      ptr += 4;
462
908k
    }
463
5.94k
  }
464
5.94k
  return 1;
465
5.94k
}
Unexecuted instantiation: rdppm-16.c:get_rgb_cmyk_row
466
467
468
#if BITS_IN_JSAMPLE == 8
469
470
METHODDEF(JDIMENSION)
471
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
472
/* This version is for reading raw-byte-format files with
473
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
474
 * In this case we just read right into the _JSAMPLE buffer!
475
 * Note that same code works for PPM and PGM files.
476
 */
477
0
{
478
0
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
479
480
0
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
481
0
    ERREXIT(cinfo, JERR_INPUT_EOF);
482
0
  return 1;
483
0
}
484
485
#endif
486
487
488
METHODDEF(JDIMENSION)
489
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
490
/* This version is for reading raw-word-format PGM files with any maxval */
491
4.37k
{
492
4.37k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
4.37k
  register _JSAMPROW ptr;
494
4.37k
  register unsigned char *bufferptr;
495
4.37k
  register _JSAMPLE *rescale = source->rescale;
496
4.37k
  JDIMENSION col;
497
4.37k
  unsigned int maxval = source->maxval;
498
499
4.37k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
86
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
4.37k
  ptr = source->pub._buffer[0];
502
4.37k
  bufferptr = source->iobuffer;
503
11.7k
  for (col = cinfo->image_width; col > 0; col--) {
504
7.34k
    register unsigned int temp;
505
7.34k
    temp  = (*bufferptr++) << 8;
506
7.34k
    temp |= (*bufferptr++);
507
7.34k
    if (temp > maxval)
508
78
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
7.34k
    *ptr++ = rescale[temp];
510
7.34k
  }
511
4.37k
  return 1;
512
4.37k
}
Unexecuted instantiation: rdppm-8.c:get_word_gray_row
rdppm-12.c:get_word_gray_row
Line
Count
Source
491
4.37k
{
492
4.37k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
4.37k
  register _JSAMPROW ptr;
494
4.37k
  register unsigned char *bufferptr;
495
4.37k
  register _JSAMPLE *rescale = source->rescale;
496
4.37k
  JDIMENSION col;
497
4.37k
  unsigned int maxval = source->maxval;
498
499
4.37k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
86
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
4.37k
  ptr = source->pub._buffer[0];
502
4.37k
  bufferptr = source->iobuffer;
503
11.7k
  for (col = cinfo->image_width; col > 0; col--) {
504
7.34k
    register unsigned int temp;
505
7.34k
    temp  = (*bufferptr++) << 8;
506
7.34k
    temp |= (*bufferptr++);
507
7.34k
    if (temp > maxval)
508
78
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
7.34k
    *ptr++ = rescale[temp];
510
7.34k
  }
511
4.37k
  return 1;
512
4.37k
}
Unexecuted instantiation: rdppm-16.c:get_word_gray_row
513
514
515
METHODDEF(JDIMENSION)
516
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
517
/* This version is for reading raw-word-format PGM files with any maxval */
518
21.8k
{
519
21.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
21.8k
  register _JSAMPROW ptr;
521
21.8k
  register unsigned char *bufferptr;
522
21.8k
  register _JSAMPLE *rescale = source->rescale;
523
21.8k
  JDIMENSION col;
524
21.8k
  unsigned int maxval = source->maxval;
525
21.8k
  register int rindex = rgb_red[cinfo->in_color_space];
526
21.8k
  register int gindex = rgb_green[cinfo->in_color_space];
527
21.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
21.8k
  register int aindex = alpha_index[cinfo->in_color_space];
529
21.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
21.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
430
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
21.8k
  ptr = source->pub._buffer[0];
534
21.8k
  bufferptr = source->iobuffer;
535
58.6k
  for (col = cinfo->image_width; col > 0; col--) {
536
36.7k
    register unsigned int temp;
537
36.7k
    temp  = (*bufferptr++) << 8;
538
36.7k
    temp |= (*bufferptr++);
539
36.7k
    if (temp > maxval)
540
390
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
36.7k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
36.7k
    if (aindex >= 0)
543
7.26k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
36.7k
    ptr += ps;
545
36.7k
  }
546
21.8k
  return 1;
547
21.8k
}
Unexecuted instantiation: rdppm-8.c:get_word_gray_rgb_row
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
518
21.8k
{
519
21.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
21.8k
  register _JSAMPROW ptr;
521
21.8k
  register unsigned char *bufferptr;
522
21.8k
  register _JSAMPLE *rescale = source->rescale;
523
21.8k
  JDIMENSION col;
524
21.8k
  unsigned int maxval = source->maxval;
525
21.8k
  register int rindex = rgb_red[cinfo->in_color_space];
526
21.8k
  register int gindex = rgb_green[cinfo->in_color_space];
527
21.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
21.8k
  register int aindex = alpha_index[cinfo->in_color_space];
529
21.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
21.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
430
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
21.8k
  ptr = source->pub._buffer[0];
534
21.8k
  bufferptr = source->iobuffer;
535
58.6k
  for (col = cinfo->image_width; col > 0; col--) {
536
36.7k
    register unsigned int temp;
537
36.7k
    temp  = (*bufferptr++) << 8;
538
36.7k
    temp |= (*bufferptr++);
539
36.7k
    if (temp > maxval)
540
390
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
36.7k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
36.7k
    if (aindex >= 0)
543
7.26k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
36.7k
    ptr += ps;
545
36.7k
  }
546
21.8k
  return 1;
547
21.8k
}
Unexecuted instantiation: rdppm-16.c:get_word_gray_rgb_row
548
549
550
METHODDEF(JDIMENSION)
551
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
552
/* This version is for reading raw-word-format PGM files with any maxval */
553
4.37k
{
554
4.37k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
4.37k
  register _JSAMPROW ptr;
556
4.37k
  register unsigned char *bufferptr;
557
4.37k
  register _JSAMPLE *rescale = source->rescale;
558
4.37k
  JDIMENSION col;
559
4.37k
  unsigned int maxval = source->maxval;
560
561
4.37k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
86
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
4.37k
  ptr = source->pub._buffer[0];
564
4.37k
  bufferptr = source->iobuffer;
565
4.37k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
1.37k
    for (col = cinfo->image_width; col > 0; col--) {
567
922
      register unsigned int gray;
568
922
      gray  = (*bufferptr++) << 8;
569
922
      gray |= (*bufferptr++);
570
922
      if (gray > maxval)
571
23
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
922
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
922
                  ptr + 1, ptr + 2, ptr + 3);
574
922
      ptr += 4;
575
922
    }
576
3.92k
  } else {
577
10.3k
    for (col = cinfo->image_width; col > 0; col--) {
578
6.42k
      register unsigned int temp;
579
6.42k
      _JSAMPLE gray;
580
6.42k
      temp  = (*bufferptr++) << 8;
581
6.42k
      temp |= (*bufferptr++);
582
6.42k
      if (temp > maxval)
583
55
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
6.42k
      gray = rescale[temp];
585
6.42k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
6.42k
                  ptr + 1, ptr + 2, ptr + 3);
587
6.42k
      ptr += 4;
588
6.42k
    }
589
3.92k
  }
590
4.37k
  return 1;
591
4.37k
}
Unexecuted instantiation: rdppm-8.c:get_word_gray_cmyk_row
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
553
4.37k
{
554
4.37k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
4.37k
  register _JSAMPROW ptr;
556
4.37k
  register unsigned char *bufferptr;
557
4.37k
  register _JSAMPLE *rescale = source->rescale;
558
4.37k
  JDIMENSION col;
559
4.37k
  unsigned int maxval = source->maxval;
560
561
4.37k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
86
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
4.37k
  ptr = source->pub._buffer[0];
564
4.37k
  bufferptr = source->iobuffer;
565
4.37k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
1.37k
    for (col = cinfo->image_width; col > 0; col--) {
567
922
      register unsigned int gray;
568
922
      gray  = (*bufferptr++) << 8;
569
922
      gray |= (*bufferptr++);
570
922
      if (gray > maxval)
571
23
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
922
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
922
                  ptr + 1, ptr + 2, ptr + 3);
574
922
      ptr += 4;
575
922
    }
576
3.92k
  } else {
577
10.3k
    for (col = cinfo->image_width; col > 0; col--) {
578
6.42k
      register unsigned int temp;
579
6.42k
      _JSAMPLE gray;
580
6.42k
      temp  = (*bufferptr++) << 8;
581
6.42k
      temp |= (*bufferptr++);
582
6.42k
      if (temp > maxval)
583
55
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
6.42k
      gray = rescale[temp];
585
6.42k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
6.42k
                  ptr + 1, ptr + 2, ptr + 3);
587
6.42k
      ptr += 4;
588
6.42k
    }
589
3.92k
  }
590
4.37k
  return 1;
591
4.37k
}
Unexecuted instantiation: rdppm-16.c:get_word_gray_cmyk_row
592
593
594
METHODDEF(JDIMENSION)
595
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
596
/* This version is for reading raw-word-format PPM files with any maxval */
597
14.8k
{
598
14.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
14.8k
  register _JSAMPROW ptr;
600
14.8k
  register unsigned char *bufferptr;
601
14.8k
  register _JSAMPLE *rescale = source->rescale;
602
14.8k
  JDIMENSION col;
603
14.8k
  unsigned int maxval = source->maxval;
604
14.8k
  register int rindex = rgb_red[cinfo->in_color_space];
605
14.8k
  register int gindex = rgb_green[cinfo->in_color_space];
606
14.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
14.8k
  register int aindex = alpha_index[cinfo->in_color_space];
608
14.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
14.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
570
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
14.8k
  ptr = source->pub._buffer[0];
613
14.8k
  bufferptr = source->iobuffer;
614
45.6k
  for (col = cinfo->image_width; col > 0; col--) {
615
30.7k
    register unsigned int temp;
616
30.7k
    temp  = (*bufferptr++) << 8;
617
30.7k
    temp |= (*bufferptr++);
618
30.7k
    if (temp > maxval)
619
280
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
30.7k
    ptr[rindex] = rescale[temp];
621
30.7k
    temp  = (*bufferptr++) << 8;
622
30.7k
    temp |= (*bufferptr++);
623
30.7k
    if (temp > maxval)
624
255
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
30.7k
    ptr[gindex] = rescale[temp];
626
30.7k
    temp  = (*bufferptr++) << 8;
627
30.7k
    temp |= (*bufferptr++);
628
30.7k
    if (temp > maxval)
629
230
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
30.7k
    ptr[bindex] = rescale[temp];
631
30.7k
    if (aindex >= 0)
632
5.99k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
30.7k
    ptr += ps;
634
30.7k
  }
635
14.8k
  return 1;
636
14.8k
}
Unexecuted instantiation: rdppm-8.c:get_word_rgb_row
rdppm-12.c:get_word_rgb_row
Line
Count
Source
597
14.8k
{
598
14.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
14.8k
  register _JSAMPROW ptr;
600
14.8k
  register unsigned char *bufferptr;
601
14.8k
  register _JSAMPLE *rescale = source->rescale;
602
14.8k
  JDIMENSION col;
603
14.8k
  unsigned int maxval = source->maxval;
604
14.8k
  register int rindex = rgb_red[cinfo->in_color_space];
605
14.8k
  register int gindex = rgb_green[cinfo->in_color_space];
606
14.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
14.8k
  register int aindex = alpha_index[cinfo->in_color_space];
608
14.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
14.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
570
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
14.8k
  ptr = source->pub._buffer[0];
613
14.8k
  bufferptr = source->iobuffer;
614
45.6k
  for (col = cinfo->image_width; col > 0; col--) {
615
30.7k
    register unsigned int temp;
616
30.7k
    temp  = (*bufferptr++) << 8;
617
30.7k
    temp |= (*bufferptr++);
618
30.7k
    if (temp > maxval)
619
280
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
30.7k
    ptr[rindex] = rescale[temp];
621
30.7k
    temp  = (*bufferptr++) << 8;
622
30.7k
    temp |= (*bufferptr++);
623
30.7k
    if (temp > maxval)
624
255
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
30.7k
    ptr[gindex] = rescale[temp];
626
30.7k
    temp  = (*bufferptr++) << 8;
627
30.7k
    temp |= (*bufferptr++);
628
30.7k
    if (temp > maxval)
629
230
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
30.7k
    ptr[bindex] = rescale[temp];
631
30.7k
    if (aindex >= 0)
632
5.99k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
30.7k
    ptr += ps;
634
30.7k
  }
635
14.8k
  return 1;
636
14.8k
}
Unexecuted instantiation: rdppm-16.c:get_word_rgb_row
637
638
639
METHODDEF(JDIMENSION)
640
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
641
/* This version is for reading raw-word-format PPM files with any maxval */
642
2.97k
{
643
2.97k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
2.97k
  register _JSAMPROW ptr;
645
2.97k
  register unsigned char *bufferptr;
646
2.97k
  register _JSAMPLE *rescale = source->rescale;
647
2.97k
  JDIMENSION col;
648
2.97k
  unsigned int maxval = source->maxval;
649
650
2.97k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
114
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
2.97k
  ptr = source->pub._buffer[0];
653
2.97k
  bufferptr = source->iobuffer;
654
2.97k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
3.65k
    for (col = cinfo->image_width; col > 0; col--) {
656
2.79k
      register unsigned int r, g, b;
657
2.79k
      r  = (*bufferptr++) << 8;
658
2.79k
      r |= (*bufferptr++);
659
2.79k
      if (r > maxval)
660
20
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
2.79k
      g  = (*bufferptr++) << 8;
662
2.79k
      g |= (*bufferptr++);
663
2.79k
      if (g > maxval)
664
20
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
2.79k
      b  = (*bufferptr++) << 8;
666
2.79k
      b |= (*bufferptr++);
667
2.79k
      if (b > maxval)
668
20
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
2.79k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
2.79k
                  ptr + 2, ptr + 3);
671
2.79k
      ptr += 4;
672
2.79k
    }
673
2.11k
  } else {
674
5.46k
    for (col = cinfo->image_width; col > 0; col--) {
675
3.35k
      register unsigned int r, g, b;
676
3.35k
      r  = (*bufferptr++) << 8;
677
3.35k
      r |= (*bufferptr++);
678
3.35k
      if (r > maxval)
679
36
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
3.35k
      g  = (*bufferptr++) << 8;
681
3.35k
      g |= (*bufferptr++);
682
3.35k
      if (g > maxval)
683
31
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
3.35k
      b  = (*bufferptr++) << 8;
685
3.35k
      b |= (*bufferptr++);
686
3.35k
      if (b > maxval)
687
26
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
3.35k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
3.35k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
3.35k
      ptr += 4;
691
3.35k
    }
692
2.11k
  }
693
2.97k
  return 1;
694
2.97k
}
Unexecuted instantiation: rdppm-8.c:get_word_rgb_cmyk_row
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
642
2.97k
{
643
2.97k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
2.97k
  register _JSAMPROW ptr;
645
2.97k
  register unsigned char *bufferptr;
646
2.97k
  register _JSAMPLE *rescale = source->rescale;
647
2.97k
  JDIMENSION col;
648
2.97k
  unsigned int maxval = source->maxval;
649
650
2.97k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
114
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
2.97k
  ptr = source->pub._buffer[0];
653
2.97k
  bufferptr = source->iobuffer;
654
2.97k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
3.65k
    for (col = cinfo->image_width; col > 0; col--) {
656
2.79k
      register unsigned int r, g, b;
657
2.79k
      r  = (*bufferptr++) << 8;
658
2.79k
      r |= (*bufferptr++);
659
2.79k
      if (r > maxval)
660
20
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
2.79k
      g  = (*bufferptr++) << 8;
662
2.79k
      g |= (*bufferptr++);
663
2.79k
      if (g > maxval)
664
20
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
2.79k
      b  = (*bufferptr++) << 8;
666
2.79k
      b |= (*bufferptr++);
667
2.79k
      if (b > maxval)
668
20
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
2.79k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
2.79k
                  ptr + 2, ptr + 3);
671
2.79k
      ptr += 4;
672
2.79k
    }
673
2.11k
  } else {
674
5.46k
    for (col = cinfo->image_width; col > 0; col--) {
675
3.35k
      register unsigned int r, g, b;
676
3.35k
      r  = (*bufferptr++) << 8;
677
3.35k
      r |= (*bufferptr++);
678
3.35k
      if (r > maxval)
679
36
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
3.35k
      g  = (*bufferptr++) << 8;
681
3.35k
      g |= (*bufferptr++);
682
3.35k
      if (g > maxval)
683
31
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
3.35k
      b  = (*bufferptr++) << 8;
685
3.35k
      b |= (*bufferptr++);
686
3.35k
      if (b > maxval)
687
26
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
3.35k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
3.35k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
3.35k
      ptr += 4;
691
3.35k
    }
692
2.11k
  }
693
2.97k
  return 1;
694
2.97k
}
Unexecuted instantiation: rdppm-16.c:get_word_rgb_cmyk_row
695
696
697
/*
698
 * Read the file header; return image size and component count.
699
 */
700
701
METHODDEF(void)
702
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
703
12.7k
{
704
12.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
12.7k
  int c;
706
12.7k
  unsigned int w, h, maxval;
707
12.7k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
12.7k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
12.7k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
12.7k
  switch (c) {
716
1.68k
  case '2':                     /* it's a text-format PGM file */
717
3.70k
  case '3':                     /* it's a text-format PPM file */
718
9.24k
  case '5':                     /* it's a raw-format PGM file */
719
12.7k
  case '6':                     /* it's a raw-format PPM file */
720
12.7k
    break;
721
56
  default:
722
56
    ERREXIT(cinfo, JERR_PPM_NOT);
723
56
    break;
724
12.7k
  }
725
726
  /* fetch the remaining header info */
727
12.7k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
12.7k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
12.7k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
12.7k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
21
    ERREXIT(cinfo, JERR_PPM_NOT);
733
12.7k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
21
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
12.7k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
231
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
12.7k
  cinfo->image_width = (JDIMENSION)w;
739
12.7k
  cinfo->image_height = (JDIMENSION)h;
740
12.7k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
12.7k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
12.7k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
12.7k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
12.7k
  switch (c) {
748
1.37k
  case '2':                     /* it's a text-format PGM file */
749
1.37k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
1.37k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
1.37k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
1.37k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
197
      source->pub.get_pixel_rows = get_text_gray_row;
755
1.18k
    else if (IsExtRGB(cinfo->in_color_space))
756
985
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
197
    else if (cinfo->in_color_space == JCS_CMYK)
758
197
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
1.37k
    need_iobuffer = FALSE;
762
1.37k
    break;
763
764
1.58k
  case '3':                     /* it's a text-format PPM file */
765
1.58k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
1.58k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
1.58k
    if (IsExtRGB(cinfo->in_color_space))
769
1.13k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
452
    else if (cinfo->in_color_space == JCS_CMYK)
771
226
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
226
    else
773
226
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
1.58k
    need_iobuffer = FALSE;
775
1.58k
    break;
776
777
5.18k
  case '5':                     /* it's a raw-format PGM file */
778
5.18k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
5.18k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
5.18k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
5.18k
    if (maxval > 255) {
783
1.33k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
191
        source->pub.get_pixel_rows = get_word_gray_row;
785
1.14k
      else if (IsExtRGB(cinfo->in_color_space))
786
955
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
191
      else if (cinfo->in_color_space == JCS_CMYK)
788
191
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
0
    } else if (maxval <= _MAXJSAMPLE &&
793
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
0
      source->pub.get_pixel_rows = get_raw_row;
796
0
      use_raw_buffer = TRUE;
797
0
      need_rescale = FALSE;
798
#endif
799
3.84k
    } else {
800
3.84k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
549
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
3.29k
      else if (IsExtRGB(cinfo->in_color_space))
803
2.74k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
549
      else if (cinfo->in_color_space == JCS_CMYK)
805
549
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
3.84k
    }
809
5.18k
    break;
810
811
3.13k
  case '6':                     /* it's a raw-format PPM file */
812
3.13k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
3.13k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
3.13k
    if (maxval > 255) {
816
2.00k
      if (IsExtRGB(cinfo->in_color_space))
817
1.43k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
574
      else if (cinfo->in_color_space == JCS_CMYK)
819
287
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
287
      else
821
287
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
0
    } else if (maxval <= _MAXJSAMPLE &&
824
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
0
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
0
      source->pub.get_pixel_rows = get_raw_row;
832
0
      use_raw_buffer = TRUE;
833
0
      need_rescale = FALSE;
834
#endif
835
1.12k
    } else {
836
1.12k
      if (IsExtRGB(cinfo->in_color_space))
837
805
        source->pub.get_pixel_rows = get_rgb_row;
838
322
      else if (cinfo->in_color_space == JCS_CMYK)
839
161
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
161
      else
841
161
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
1.12k
    }
843
3.13k
    break;
844
12.7k
  }
845
846
10.6k
  if (IsExtRGB(cinfo->in_color_space))
847
8.05k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
2.54k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
937
    cinfo->input_components = 1;
850
1.61k
  else if (cinfo->in_color_space == JCS_CMYK)
851
1.61k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
10.6k
  if (need_iobuffer) {
855
7.86k
    if (c == '6')
856
2.68k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
5.18k
    else
858
5.18k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
7.86k
    source->iobuffer = (unsigned char *)
860
7.86k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
7.86k
                                  source->buffer_width);
862
7.86k
  }
863
864
  /* Create compressor input buffer. */
865
10.6k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
0
    source->pub._buffer = &source->pixrow;
870
0
    source->pub.buffer_height = 1;
871
10.6k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
10.6k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
10.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
10.6k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
10.6k
    source->pub.buffer_height = 1;
877
10.6k
  }
878
879
  /* Compute the rescaling array if required. */
880
10.6k
  if (need_rescale) {
881
10.6k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
10.6k
    source->rescale = (_JSAMPLE *)
885
10.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
10.6k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
10.6k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
10.6k
    half_maxval = (size_t)maxval / 2;
889
37.2M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
37.2M
      source->rescale[val] =
892
37.2M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
37.2M
                   maxval);
894
37.2M
    }
895
10.6k
  }
896
10.6k
}
Unexecuted instantiation: rdppm-8.c:start_input_ppm
rdppm-12.c:start_input_ppm
Line
Count
Source
703
12.7k
{
704
12.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
12.7k
  int c;
706
12.7k
  unsigned int w, h, maxval;
707
12.7k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
12.7k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
12.7k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
12.7k
  switch (c) {
716
1.68k
  case '2':                     /* it's a text-format PGM file */
717
3.70k
  case '3':                     /* it's a text-format PPM file */
718
9.24k
  case '5':                     /* it's a raw-format PGM file */
719
12.7k
  case '6':                     /* it's a raw-format PPM file */
720
12.7k
    break;
721
56
  default:
722
56
    ERREXIT(cinfo, JERR_PPM_NOT);
723
56
    break;
724
12.7k
  }
725
726
  /* fetch the remaining header info */
727
12.7k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
12.7k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
12.7k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
12.7k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
21
    ERREXIT(cinfo, JERR_PPM_NOT);
733
12.7k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
21
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
12.7k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
231
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
12.7k
  cinfo->image_width = (JDIMENSION)w;
739
12.7k
  cinfo->image_height = (JDIMENSION)h;
740
12.7k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
12.7k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
12.7k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
12.7k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
12.7k
  switch (c) {
748
1.37k
  case '2':                     /* it's a text-format PGM file */
749
1.37k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
1.37k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
1.37k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
1.37k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
197
      source->pub.get_pixel_rows = get_text_gray_row;
755
1.18k
    else if (IsExtRGB(cinfo->in_color_space))
756
985
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
197
    else if (cinfo->in_color_space == JCS_CMYK)
758
197
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
1.37k
    need_iobuffer = FALSE;
762
1.37k
    break;
763
764
1.58k
  case '3':                     /* it's a text-format PPM file */
765
1.58k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
1.58k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
1.58k
    if (IsExtRGB(cinfo->in_color_space))
769
1.13k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
452
    else if (cinfo->in_color_space == JCS_CMYK)
771
226
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
226
    else
773
226
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
1.58k
    need_iobuffer = FALSE;
775
1.58k
    break;
776
777
5.18k
  case '5':                     /* it's a raw-format PGM file */
778
5.18k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
5.18k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
5.18k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
5.18k
    if (maxval > 255) {
783
1.33k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
191
        source->pub.get_pixel_rows = get_word_gray_row;
785
1.14k
      else if (IsExtRGB(cinfo->in_color_space))
786
955
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
191
      else if (cinfo->in_color_space == JCS_CMYK)
788
191
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
    } else if (maxval <= _MAXJSAMPLE &&
793
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
      source->pub.get_pixel_rows = get_raw_row;
796
      use_raw_buffer = TRUE;
797
      need_rescale = FALSE;
798
#endif
799
3.84k
    } else {
800
3.84k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
549
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
3.29k
      else if (IsExtRGB(cinfo->in_color_space))
803
2.74k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
549
      else if (cinfo->in_color_space == JCS_CMYK)
805
549
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
3.84k
    }
809
5.18k
    break;
810
811
3.13k
  case '6':                     /* it's a raw-format PPM file */
812
3.13k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
3.13k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
3.13k
    if (maxval > 255) {
816
2.00k
      if (IsExtRGB(cinfo->in_color_space))
817
1.43k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
574
      else if (cinfo->in_color_space == JCS_CMYK)
819
287
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
287
      else
821
287
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
    } else if (maxval <= _MAXJSAMPLE &&
824
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
      source->pub.get_pixel_rows = get_raw_row;
832
      use_raw_buffer = TRUE;
833
      need_rescale = FALSE;
834
#endif
835
2.00k
    } else {
836
1.12k
      if (IsExtRGB(cinfo->in_color_space))
837
805
        source->pub.get_pixel_rows = get_rgb_row;
838
322
      else if (cinfo->in_color_space == JCS_CMYK)
839
161
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
161
      else
841
161
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
1.12k
    }
843
3.13k
    break;
844
12.7k
  }
845
846
10.6k
  if (IsExtRGB(cinfo->in_color_space))
847
8.05k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
2.54k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
937
    cinfo->input_components = 1;
850
1.61k
  else if (cinfo->in_color_space == JCS_CMYK)
851
1.61k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
10.6k
  if (need_iobuffer) {
855
7.86k
    if (c == '6')
856
2.68k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
5.18k
    else
858
5.18k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
7.86k
    source->iobuffer = (unsigned char *)
860
7.86k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
7.86k
                                  source->buffer_width);
862
7.86k
  }
863
864
  /* Create compressor input buffer. */
865
10.6k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
0
    source->pub._buffer = &source->pixrow;
870
0
    source->pub.buffer_height = 1;
871
10.6k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
10.6k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
10.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
10.6k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
10.6k
    source->pub.buffer_height = 1;
877
10.6k
  }
878
879
  /* Compute the rescaling array if required. */
880
10.6k
  if (need_rescale) {
881
10.6k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
10.6k
    source->rescale = (_JSAMPLE *)
885
10.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
10.6k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
10.6k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
10.6k
    half_maxval = (size_t)maxval / 2;
889
37.2M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
37.2M
      source->rescale[val] =
892
37.2M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
37.2M
                   maxval);
894
37.2M
    }
895
10.6k
  }
896
10.6k
}
Unexecuted instantiation: rdppm-16.c:start_input_ppm
897
898
899
METHODDEF(boolean)
900
read_icc_profile_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo,
901
                     JOCTET **icc_data_ptr, unsigned int *icc_data_len)
902
0
{
903
0
  return FALSE;
904
0
}
Unexecuted instantiation: rdppm-8.c:read_icc_profile_ppm
Unexecuted instantiation: rdppm-12.c:read_icc_profile_ppm
Unexecuted instantiation: rdppm-16.c:read_icc_profile_ppm
905
906
907
/*
908
 * Finish up at the end of the file.
909
 */
910
911
METHODDEF(void)
912
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
913
12.7k
{
914
  /* no work */
915
12.7k
}
Unexecuted instantiation: rdppm-8.c:finish_input_ppm
rdppm-12.c:finish_input_ppm
Line
Count
Source
913
12.7k
{
914
  /* no work */
915
12.7k
}
Unexecuted instantiation: rdppm-16.c:finish_input_ppm
916
917
918
/*
919
 * The module selection routine for PPM format input.
920
 */
921
922
GLOBAL(cjpeg_source_ptr)
923
_jinit_read_ppm(j_compress_ptr cinfo)
924
12.7k
{
925
12.7k
  ppm_source_ptr source;
926
927
#if BITS_IN_JSAMPLE == 8
928
0
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
929
#else
930
12.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
931
12.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
932
0
#endif
933
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
934
935
  /* Create module interface object */
936
12.7k
  source = (ppm_source_ptr)
937
12.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
938
12.7k
                                sizeof(ppm_source_struct));
939
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
940
12.7k
  source->pub.start_input = start_input_ppm;
941
12.7k
  source->pub.read_icc_profile = read_icc_profile_ppm;
942
12.7k
  source->pub.finish_input = finish_input_ppm;
943
12.7k
  source->pub.max_pixels = 0;
944
945
12.7k
  return (cjpeg_source_ptr)source;
946
12.7k
}
Unexecuted instantiation: jinit_read_ppm
j12init_read_ppm
Line
Count
Source
924
12.7k
{
925
12.7k
  ppm_source_ptr source;
926
927
#if BITS_IN_JSAMPLE == 8
928
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
929
#else
930
12.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
931
12.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
932
0
#endif
933
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
934
935
  /* Create module interface object */
936
12.7k
  source = (ppm_source_ptr)
937
12.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
938
12.7k
                                sizeof(ppm_source_struct));
939
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
940
12.7k
  source->pub.start_input = start_input_ppm;
941
12.7k
  source->pub.read_icc_profile = read_icc_profile_ppm;
942
12.7k
  source->pub.finish_input = finish_input_ppm;
943
12.7k
  source->pub.max_pixels = 0;
944
945
12.7k
  return (cjpeg_source_ptr)source;
946
12.7k
}
Unexecuted instantiation: j16init_read_ppm
947
948
#endif /* defined(PPM_SUPPORTED) &&
949
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */