Coverage Report

Created: 2026-03-12 07:02

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