Coverage Report

Created: 2025-11-09 06:50

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-2024, 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
17.8M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
16.3M
  (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
304k
{
80
304k
  register int ch;
81
82
304k
  ch = getc(infile);
83
304k
  if (ch == '#') {
84
65.9k
    do {
85
65.9k
      ch = getc(infile);
86
65.9k
    } while (ch != '\n' && ch != EOF);
87
3.24k
  }
88
304k
  return ch;
89
304k
}
Unexecuted instantiation: rdppm-8.c:pbm_getc
rdppm-12.c:pbm_getc
Line
Count
Source
79
304k
{
80
304k
  register int ch;
81
82
304k
  ch = getc(infile);
83
304k
  if (ch == '#') {
84
65.9k
    do {
85
65.9k
      ch = getc(infile);
86
65.9k
    } while (ch != '\n' && ch != EOF);
87
3.24k
  }
88
304k
  return ch;
89
304k
}
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
128k
{
99
128k
  register int ch;
100
128k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
136k
  do {
104
136k
    ch = pbm_getc(infile);
105
136k
    if (ch == EOF)
106
3.09k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
136k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
128k
  if (ch < '0' || ch > '9')
110
290
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
128k
  val = ch - '0';
113
171k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
43.1k
    val *= 10;
115
43.1k
    val += ch - '0';
116
43.1k
    if (val > maxval)
117
126
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
43.1k
  }
119
120
128k
  return val;
121
128k
}
Unexecuted instantiation: rdppm-8.c:read_pbm_integer
rdppm-12.c:read_pbm_integer
Line
Count
Source
98
128k
{
99
128k
  register int ch;
100
128k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
136k
  do {
104
136k
    ch = pbm_getc(infile);
105
136k
    if (ch == EOF)
106
3.09k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
136k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
128k
  if (ch < '0' || ch > '9')
110
290
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
128k
  val = ch - '0';
113
171k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
43.1k
    val *= 10;
115
43.1k
    val += ch - '0';
116
43.1k
    if (val > maxval)
117
126
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
43.1k
  }
119
120
128k
  return val;
121
128k
}
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.97k
{
140
1.97k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
1.97k
  FILE *infile = source->pub.input_file;
142
1.97k
  register _JSAMPROW ptr;
143
1.97k
  register _JSAMPLE *rescale = source->rescale;
144
1.97k
  JDIMENSION col;
145
1.97k
  unsigned int maxval = source->maxval;
146
147
1.97k
  ptr = source->pub._buffer[0];
148
5.02k
  for (col = cinfo->image_width; col > 0; col--) {
149
3.04k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
3.04k
  }
151
1.97k
  return 1;
152
1.97k
}
Unexecuted instantiation: rdppm-8.c:get_text_gray_row
rdppm-12.c:get_text_gray_row
Line
Count
Source
139
1.97k
{
140
1.97k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
1.97k
  FILE *infile = source->pub.input_file;
142
1.97k
  register _JSAMPROW ptr;
143
1.97k
  register _JSAMPLE *rescale = source->rescale;
144
1.97k
  JDIMENSION col;
145
1.97k
  unsigned int maxval = source->maxval;
146
147
1.97k
  ptr = source->pub._buffer[0];
148
5.02k
  for (col = cinfo->image_width; col > 0; col--) {
149
3.04k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
3.04k
  }
151
1.97k
  return 1;
152
1.97k
}
Unexecuted instantiation: rdppm-16.c:get_text_gray_row
153
154
155
11.5M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
156
47.3M
  for (col = cinfo->image_width; col > 0; col--) { \
157
35.7M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
158
35.7M
    alpha_set_op \
159
35.7M
    ptr += ps; \
160
35.7M
  } \
161
11.5M
}
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
9.89k
{
168
9.89k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
9.89k
  FILE *infile = source->pub.input_file;
170
9.89k
  register _JSAMPROW ptr;
171
9.89k
  register _JSAMPLE *rescale = source->rescale;
172
9.89k
  JDIMENSION col;
173
9.89k
  unsigned int maxval = source->maxval;
174
9.89k
  register int rindex = rgb_red[cinfo->in_color_space];
175
9.89k
  register int gindex = rgb_green[cinfo->in_color_space];
176
9.89k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
9.89k
  register int aindex = alpha_index[cinfo->in_color_space];
178
9.89k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
9.89k
  ptr = source->pub._buffer[0];
181
9.89k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
868
    if (aindex >= 0)
183
225
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
868
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
643
    else
186
643
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
9.02k
  } else {
188
9.02k
    if (aindex >= 0)
189
1.75k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
9.02k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
7.26k
    else
192
7.26k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
9.02k
  }
194
9.89k
  return 1;
195
9.89k
}
Unexecuted instantiation: rdppm-8.c:get_text_gray_rgb_row
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
167
9.89k
{
168
9.89k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
9.89k
  FILE *infile = source->pub.input_file;
170
9.89k
  register _JSAMPROW ptr;
171
9.89k
  register _JSAMPLE *rescale = source->rescale;
172
9.89k
  JDIMENSION col;
173
9.89k
  unsigned int maxval = source->maxval;
174
9.89k
  register int rindex = rgb_red[cinfo->in_color_space];
175
9.89k
  register int gindex = rgb_green[cinfo->in_color_space];
176
9.89k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
9.89k
  register int aindex = alpha_index[cinfo->in_color_space];
178
9.89k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
9.89k
  ptr = source->pub._buffer[0];
181
9.89k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
868
    if (aindex >= 0)
183
225
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
868
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
643
    else
186
643
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
9.02k
  } else {
188
9.02k
    if (aindex >= 0)
189
1.75k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
9.02k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
7.26k
    else
192
7.26k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
9.02k
  }
194
9.89k
  return 1;
195
9.89k
}
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.97k
{
203
1.97k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
1.97k
  FILE *infile = source->pub.input_file;
205
1.97k
  register _JSAMPROW ptr;
206
1.97k
  register _JSAMPLE *rescale = source->rescale;
207
1.97k
  JDIMENSION col;
208
1.97k
  unsigned int maxval = source->maxval;
209
210
1.97k
  ptr = source->pub._buffer[0];
211
1.97k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
1.04k
    for (col = cinfo->image_width; col > 0; col--) {
213
726
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
726
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
726
      ptr += 4;
216
726
    }
217
1.66k
  } else {
218
3.98k
    for (col = cinfo->image_width; col > 0; col--) {
219
2.32k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
2.32k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
221
2.32k
      ptr += 4;
222
2.32k
    }
223
1.66k
  }
224
1.97k
  return 1;
225
1.97k
}
Unexecuted instantiation: rdppm-8.c:get_text_gray_cmyk_row
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
202
1.97k
{
203
1.97k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
1.97k
  FILE *infile = source->pub.input_file;
205
1.97k
  register _JSAMPROW ptr;
206
1.97k
  register _JSAMPLE *rescale = source->rescale;
207
1.97k
  JDIMENSION col;
208
1.97k
  unsigned int maxval = source->maxval;
209
210
1.97k
  ptr = source->pub._buffer[0];
211
1.97k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
1.04k
    for (col = cinfo->image_width; col > 0; col--) {
213
726
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
726
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
726
      ptr += 4;
216
726
    }
217
1.66k
  } else {
218
3.98k
    for (col = cinfo->image_width; col > 0; col--) {
219
2.32k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
2.32k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
221
2.32k
      ptr += 4;
222
2.32k
    }
223
1.66k
  }
224
1.97k
  return 1;
225
1.97k
}
Unexecuted instantiation: rdppm-16.c:get_text_gray_cmyk_row
226
227
228
25.2k
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
229
1.06M
  for (col = cinfo->image_width; col > 0; col--) { \
230
1.04M
    ptr[rindex] = read_op; \
231
1.04M
    ptr[gindex] = read_op; \
232
1.04M
    ptr[bindex] = read_op; \
233
1.04M
    alpha_set_op \
234
1.04M
    ptr += ps; \
235
1.04M
  } \
236
25.2k
}
237
238
METHODDEF(JDIMENSION)
239
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
240
/* This version is for reading text-format PPM files with any maxval */
241
11.1k
{
242
11.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
243
11.1k
  FILE *infile = source->pub.input_file;
244
11.1k
  register _JSAMPROW ptr;
245
11.1k
  register _JSAMPLE *rescale = source->rescale;
246
11.1k
  JDIMENSION col;
247
11.1k
  unsigned int maxval = source->maxval;
248
11.1k
  register int rindex = rgb_red[cinfo->in_color_space];
249
11.1k
  register int gindex = rgb_green[cinfo->in_color_space];
250
11.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
251
11.1k
  register int aindex = alpha_index[cinfo->in_color_space];
252
11.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
253
254
11.1k
  ptr = source->pub._buffer[0];
255
11.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
256
1.56k
    if (aindex >= 0)
257
224
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
258
1.56k
                    ptr[aindex] = (_JSAMPLE)maxval;)
259
1.33k
    else
260
1.33k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
261
9.53k
  } else {
262
9.53k
    if (aindex >= 0)
263
1.99k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
264
9.53k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
265
7.54k
    else
266
7.54k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
267
9.53k
  }
268
11.1k
  return 1;
269
11.1k
}
Unexecuted instantiation: rdppm-8.c:get_text_rgb_row
rdppm-12.c:get_text_rgb_row
Line
Count
Source
241
11.1k
{
242
11.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
243
11.1k
  FILE *infile = source->pub.input_file;
244
11.1k
  register _JSAMPROW ptr;
245
11.1k
  register _JSAMPLE *rescale = source->rescale;
246
11.1k
  JDIMENSION col;
247
11.1k
  unsigned int maxval = source->maxval;
248
11.1k
  register int rindex = rgb_red[cinfo->in_color_space];
249
11.1k
  register int gindex = rgb_green[cinfo->in_color_space];
250
11.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
251
11.1k
  register int aindex = alpha_index[cinfo->in_color_space];
252
11.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
253
254
11.1k
  ptr = source->pub._buffer[0];
255
11.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
256
1.56k
    if (aindex >= 0)
257
224
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
258
1.56k
                    ptr[aindex] = (_JSAMPLE)maxval;)
259
1.33k
    else
260
1.33k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
261
9.53k
  } else {
262
9.53k
    if (aindex >= 0)
263
1.99k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
264
9.53k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
265
7.54k
    else
266
7.54k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
267
9.53k
  }
268
11.1k
  return 1;
269
11.1k
}
Unexecuted instantiation: rdppm-16.c:get_text_rgb_row
270
271
272
METHODDEF(JDIMENSION)
273
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
274
/* This version is for reading text-format PPM files with any maxval and
275
   converting to CMYK */
276
2.22k
{
277
2.22k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
278
2.22k
  FILE *infile = source->pub.input_file;
279
2.22k
  register _JSAMPROW ptr;
280
2.22k
  register _JSAMPLE *rescale = source->rescale;
281
2.22k
  JDIMENSION col;
282
2.22k
  unsigned int maxval = source->maxval;
283
284
2.22k
  ptr = source->pub._buffer[0];
285
2.22k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
286
2.11k
    for (col = cinfo->image_width; col > 0; col--) {
287
1.44k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
1.44k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
1.44k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
1.44k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
291
1.44k
      ptr += 4;
292
1.44k
    }
293
1.55k
  } else {
294
4.43k
    for (col = cinfo->image_width; col > 0; col--) {
295
2.88k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
2.88k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
2.88k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
2.88k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
299
2.88k
      ptr += 4;
300
2.88k
    }
301
1.55k
  }
302
2.22k
  return 1;
303
2.22k
}
Unexecuted instantiation: rdppm-8.c:get_text_rgb_cmyk_row
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
276
2.22k
{
277
2.22k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
278
2.22k
  FILE *infile = source->pub.input_file;
279
2.22k
  register _JSAMPROW ptr;
280
2.22k
  register _JSAMPLE *rescale = source->rescale;
281
2.22k
  JDIMENSION col;
282
2.22k
  unsigned int maxval = source->maxval;
283
284
2.22k
  ptr = source->pub._buffer[0];
285
2.22k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
286
2.11k
    for (col = cinfo->image_width; col > 0; col--) {
287
1.44k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
1.44k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
1.44k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
1.44k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
291
1.44k
      ptr += 4;
292
1.44k
    }
293
1.55k
  } else {
294
4.43k
    for (col = cinfo->image_width; col > 0; col--) {
295
2.88k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
2.88k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
2.88k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
2.88k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
299
2.88k
      ptr += 4;
300
2.88k
    }
301
1.55k
  }
302
2.22k
  return 1;
303
2.22k
}
Unexecuted instantiation: rdppm-16.c:get_text_rgb_cmyk_row
304
305
306
METHODDEF(JDIMENSION)
307
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
308
/* This version is for reading raw-byte-format PGM files with any maxval */
309
2.31M
{
310
2.31M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
311
2.31M
  register _JSAMPROW ptr;
312
2.31M
  register U_CHAR *bufferptr;
313
2.31M
  register _JSAMPLE *rescale = source->rescale;
314
2.31M
  JDIMENSION col;
315
316
2.31M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
317
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
318
2.31M
  ptr = source->pub._buffer[0];
319
2.31M
  bufferptr = source->iobuffer;
320
9.46M
  for (col = cinfo->image_width; col > 0; col--) {
321
7.15M
    *ptr++ = rescale[UCH(*bufferptr++)];
322
7.15M
  }
323
2.31M
  return 1;
324
2.31M
}
Unexecuted instantiation: rdppm-8.c:get_scaled_gray_row
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
309
2.31M
{
310
2.31M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
311
2.31M
  register _JSAMPROW ptr;
312
2.31M
  register U_CHAR *bufferptr;
313
2.31M
  register _JSAMPLE *rescale = source->rescale;
314
2.31M
  JDIMENSION col;
315
316
2.31M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
317
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
318
2.31M
  ptr = source->pub._buffer[0];
319
2.31M
  bufferptr = source->iobuffer;
320
9.46M
  for (col = cinfo->image_width; col > 0; col--) {
321
7.15M
    *ptr++ = rescale[UCH(*bufferptr++)];
322
7.15M
  }
323
2.31M
  return 1;
324
2.31M
}
Unexecuted instantiation: rdppm-16.c:get_scaled_gray_row
325
326
327
METHODDEF(JDIMENSION)
328
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
329
/* This version is for reading raw-byte-format PGM files with any maxval
330
   and converting to extended RGB */
331
11.5M
{
332
11.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
333
11.5M
  register _JSAMPROW ptr;
334
11.5M
  register U_CHAR *bufferptr;
335
11.5M
  register _JSAMPLE *rescale = source->rescale;
336
11.5M
  JDIMENSION col;
337
11.5M
  unsigned int maxval = source->maxval;
338
11.5M
  register int rindex = rgb_red[cinfo->in_color_space];
339
11.5M
  register int gindex = rgb_green[cinfo->in_color_space];
340
11.5M
  register int bindex = rgb_blue[cinfo->in_color_space];
341
11.5M
  register int aindex = alpha_index[cinfo->in_color_space];
342
11.5M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
343
344
11.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
345
315
    ERREXIT(cinfo, JERR_INPUT_EOF);
346
11.5M
  ptr = source->pub._buffer[0];
347
11.5M
  bufferptr = source->iobuffer;
348
11.5M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
349
0
    if (aindex >= 0)
350
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
351
0
    else
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
353
11.5M
  } else {
354
11.5M
    if (aindex >= 0)
355
2.31M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
356
11.5M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
357
9.25M
    else
358
9.25M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
359
11.5M
  }
360
11.5M
  return 1;
361
11.5M
}
Unexecuted instantiation: rdppm-8.c:get_gray_rgb_row
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
331
11.5M
{
332
11.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
333
11.5M
  register _JSAMPROW ptr;
334
11.5M
  register U_CHAR *bufferptr;
335
11.5M
  register _JSAMPLE *rescale = source->rescale;
336
11.5M
  JDIMENSION col;
337
11.5M
  unsigned int maxval = source->maxval;
338
11.5M
  register int rindex = rgb_red[cinfo->in_color_space];
339
11.5M
  register int gindex = rgb_green[cinfo->in_color_space];
340
11.5M
  register int bindex = rgb_blue[cinfo->in_color_space];
341
11.5M
  register int aindex = alpha_index[cinfo->in_color_space];
342
11.5M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
343
344
11.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
345
315
    ERREXIT(cinfo, JERR_INPUT_EOF);
346
11.5M
  ptr = source->pub._buffer[0];
347
11.5M
  bufferptr = source->iobuffer;
348
11.5M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
349
0
    if (aindex >= 0)
350
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
351
0
    else
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
353
11.5M
  } else {
354
11.5M
    if (aindex >= 0)
355
2.31M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
356
11.5M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
357
9.25M
    else
358
9.25M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
359
11.5M
  }
360
11.5M
  return 1;
361
11.5M
}
Unexecuted instantiation: rdppm-16.c:get_gray_rgb_row
362
363
364
METHODDEF(JDIMENSION)
365
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
366
/* This version is for reading raw-byte-format PGM files with any maxval
367
   and converting to CMYK */
368
2.31M
{
369
2.31M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
370
2.31M
  register _JSAMPROW ptr;
371
2.31M
  register U_CHAR *bufferptr;
372
2.31M
  register _JSAMPLE *rescale = source->rescale;
373
2.31M
  JDIMENSION col;
374
2.31M
  unsigned int maxval = source->maxval;
375
376
2.31M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
377
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
378
2.31M
  ptr = source->pub._buffer[0];
379
2.31M
  bufferptr = source->iobuffer;
380
2.31M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
381
0
    for (col = cinfo->image_width; col > 0; col--) {
382
0
      _JSAMPLE gray = *bufferptr++;
383
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
384
0
      ptr += 4;
385
0
    }
386
2.31M
  } else {
387
9.46M
    for (col = cinfo->image_width; col > 0; col--) {
388
7.15M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
389
7.15M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
390
7.15M
      ptr += 4;
391
7.15M
    }
392
2.31M
  }
393
2.31M
  return 1;
394
2.31M
}
Unexecuted instantiation: rdppm-8.c:get_gray_cmyk_row
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
368
2.31M
{
369
2.31M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
370
2.31M
  register _JSAMPROW ptr;
371
2.31M
  register U_CHAR *bufferptr;
372
2.31M
  register _JSAMPLE *rescale = source->rescale;
373
2.31M
  JDIMENSION col;
374
2.31M
  unsigned int maxval = source->maxval;
375
376
2.31M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
377
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
378
2.31M
  ptr = source->pub._buffer[0];
379
2.31M
  bufferptr = source->iobuffer;
380
2.31M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
381
0
    for (col = cinfo->image_width; col > 0; col--) {
382
0
      _JSAMPLE gray = *bufferptr++;
383
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
384
0
      ptr += 4;
385
0
    }
386
2.31M
  } else {
387
9.46M
    for (col = cinfo->image_width; col > 0; col--) {
388
7.15M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
389
7.15M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
390
7.15M
      ptr += 4;
391
7.15M
    }
392
2.31M
  }
393
2.31M
  return 1;
394
2.31M
}
Unexecuted instantiation: rdppm-16.c:get_gray_cmyk_row
395
396
397
METHODDEF(JDIMENSION)
398
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
399
/* This version is for reading raw-byte-format PPM files with any maxval */
400
14.1k
{
401
14.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
402
14.1k
  register _JSAMPROW ptr;
403
14.1k
  register U_CHAR *bufferptr;
404
14.1k
  register _JSAMPLE *rescale = source->rescale;
405
14.1k
  JDIMENSION col;
406
14.1k
  unsigned int maxval = source->maxval;
407
14.1k
  register int rindex = rgb_red[cinfo->in_color_space];
408
14.1k
  register int gindex = rgb_green[cinfo->in_color_space];
409
14.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
410
14.1k
  register int aindex = alpha_index[cinfo->in_color_space];
411
14.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
412
413
14.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
414
460
    ERREXIT(cinfo, JERR_INPUT_EOF);
415
14.1k
  ptr = source->pub._buffer[0];
416
14.1k
  bufferptr = source->iobuffer;
417
14.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
418
0
    if (aindex >= 0)
419
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
420
0
    else
421
0
      RGB_READ_LOOP(*bufferptr++, {})
422
14.1k
  } else {
423
14.1k
    if (aindex >= 0)
424
2.73k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
425
14.1k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
426
11.3k
    else
427
11.3k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
428
14.1k
  }
429
14.1k
  return 1;
430
14.1k
}
Unexecuted instantiation: rdppm-8.c:get_rgb_row
rdppm-12.c:get_rgb_row
Line
Count
Source
400
14.1k
{
401
14.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
402
14.1k
  register _JSAMPROW ptr;
403
14.1k
  register U_CHAR *bufferptr;
404
14.1k
  register _JSAMPLE *rescale = source->rescale;
405
14.1k
  JDIMENSION col;
406
14.1k
  unsigned int maxval = source->maxval;
407
14.1k
  register int rindex = rgb_red[cinfo->in_color_space];
408
14.1k
  register int gindex = rgb_green[cinfo->in_color_space];
409
14.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
410
14.1k
  register int aindex = alpha_index[cinfo->in_color_space];
411
14.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
412
413
14.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
414
460
    ERREXIT(cinfo, JERR_INPUT_EOF);
415
14.1k
  ptr = source->pub._buffer[0];
416
14.1k
  bufferptr = source->iobuffer;
417
14.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
418
0
    if (aindex >= 0)
419
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
420
0
    else
421
0
      RGB_READ_LOOP(*bufferptr++, {})
422
14.1k
  } else {
423
14.1k
    if (aindex >= 0)
424
2.73k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
425
14.1k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
426
11.3k
    else
427
11.3k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
428
14.1k
  }
429
14.1k
  return 1;
430
14.1k
}
Unexecuted instantiation: rdppm-16.c:get_rgb_row
431
432
433
METHODDEF(JDIMENSION)
434
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
435
/* This version is for reading raw-byte-format PPM files with any maxval and
436
   converting to CMYK */
437
2.82k
{
438
2.82k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
439
2.82k
  register _JSAMPROW ptr;
440
2.82k
  register U_CHAR *bufferptr;
441
2.82k
  register _JSAMPLE *rescale = source->rescale;
442
2.82k
  JDIMENSION col;
443
2.82k
  unsigned int maxval = source->maxval;
444
445
2.82k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
446
92
    ERREXIT(cinfo, JERR_INPUT_EOF);
447
2.82k
  ptr = source->pub._buffer[0];
448
2.82k
  bufferptr = source->iobuffer;
449
2.82k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
450
0
    for (col = cinfo->image_width; col > 0; col--) {
451
0
      _JSAMPLE r = *bufferptr++;
452
0
      _JSAMPLE g = *bufferptr++;
453
0
      _JSAMPLE b = *bufferptr++;
454
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
455
0
      ptr += 4;
456
0
    }
457
2.82k
  } else {
458
206k
    for (col = cinfo->image_width; col > 0; col--) {
459
203k
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
460
203k
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
461
203k
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
462
203k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
463
203k
      ptr += 4;
464
203k
    }
465
2.82k
  }
466
2.82k
  return 1;
467
2.82k
}
Unexecuted instantiation: rdppm-8.c:get_rgb_cmyk_row
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
437
2.82k
{
438
2.82k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
439
2.82k
  register _JSAMPROW ptr;
440
2.82k
  register U_CHAR *bufferptr;
441
2.82k
  register _JSAMPLE *rescale = source->rescale;
442
2.82k
  JDIMENSION col;
443
2.82k
  unsigned int maxval = source->maxval;
444
445
2.82k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
446
92
    ERREXIT(cinfo, JERR_INPUT_EOF);
447
2.82k
  ptr = source->pub._buffer[0];
448
2.82k
  bufferptr = source->iobuffer;
449
2.82k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
450
0
    for (col = cinfo->image_width; col > 0; col--) {
451
0
      _JSAMPLE r = *bufferptr++;
452
0
      _JSAMPLE g = *bufferptr++;
453
0
      _JSAMPLE b = *bufferptr++;
454
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
455
0
      ptr += 4;
456
0
    }
457
2.82k
  } else {
458
206k
    for (col = cinfo->image_width; col > 0; col--) {
459
203k
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
460
203k
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
461
203k
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
462
203k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
463
203k
      ptr += 4;
464
203k
    }
465
2.82k
  }
466
2.82k
  return 1;
467
2.82k
}
Unexecuted instantiation: rdppm-16.c:get_rgb_cmyk_row
468
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
}
Unexecuted instantiation: rdppm-8.c:get_raw_row
Unexecuted instantiation: rdppm-12.c:get_raw_row
Unexecuted instantiation: rdppm-16.c:get_raw_row
484
485
486
METHODDEF(JDIMENSION)
487
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
488
/* This version is for reading raw-word-format PGM files with any maxval */
489
14.7k
{
490
14.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
491
14.7k
  register _JSAMPROW ptr;
492
14.7k
  register U_CHAR *bufferptr;
493
14.7k
  register _JSAMPLE *rescale = source->rescale;
494
14.7k
  JDIMENSION col;
495
14.7k
  unsigned int maxval = source->maxval;
496
497
14.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
498
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
499
14.7k
  ptr = source->pub._buffer[0];
500
14.7k
  bufferptr = source->iobuffer;
501
31.3k
  for (col = cinfo->image_width; col > 0; col--) {
502
16.5k
    register unsigned int temp;
503
16.5k
    temp  = UCH(*bufferptr++) << 8;
504
16.5k
    temp |= UCH(*bufferptr++);
505
16.5k
    if (temp > maxval)
506
37
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
507
16.5k
    *ptr++ = rescale[temp];
508
16.5k
  }
509
14.7k
  return 1;
510
14.7k
}
Unexecuted instantiation: rdppm-8.c:get_word_gray_row
rdppm-12.c:get_word_gray_row
Line
Count
Source
489
14.7k
{
490
14.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
491
14.7k
  register _JSAMPROW ptr;
492
14.7k
  register U_CHAR *bufferptr;
493
14.7k
  register _JSAMPLE *rescale = source->rescale;
494
14.7k
  JDIMENSION col;
495
14.7k
  unsigned int maxval = source->maxval;
496
497
14.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
498
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
499
14.7k
  ptr = source->pub._buffer[0];
500
14.7k
  bufferptr = source->iobuffer;
501
31.3k
  for (col = cinfo->image_width; col > 0; col--) {
502
16.5k
    register unsigned int temp;
503
16.5k
    temp  = UCH(*bufferptr++) << 8;
504
16.5k
    temp |= UCH(*bufferptr++);
505
16.5k
    if (temp > maxval)
506
37
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
507
16.5k
    *ptr++ = rescale[temp];
508
16.5k
  }
509
14.7k
  return 1;
510
14.7k
}
Unexecuted instantiation: rdppm-16.c:get_word_gray_row
511
512
513
METHODDEF(JDIMENSION)
514
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
515
/* This version is for reading raw-word-format PGM files with any maxval */
516
73.9k
{
517
73.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
518
73.9k
  register _JSAMPROW ptr;
519
73.9k
  register U_CHAR *bufferptr;
520
73.9k
  register _JSAMPLE *rescale = source->rescale;
521
73.9k
  JDIMENSION col;
522
73.9k
  unsigned int maxval = source->maxval;
523
73.9k
  register int rindex = rgb_red[cinfo->in_color_space];
524
73.9k
  register int gindex = rgb_green[cinfo->in_color_space];
525
73.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
526
73.9k
  register int aindex = alpha_index[cinfo->in_color_space];
527
73.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
528
529
73.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
530
315
    ERREXIT(cinfo, JERR_INPUT_EOF);
531
73.9k
  ptr = source->pub._buffer[0];
532
73.9k
  bufferptr = source->iobuffer;
533
156k
  for (col = cinfo->image_width; col > 0; col--) {
534
82.9k
    register unsigned int temp;
535
82.9k
    temp  = UCH(*bufferptr++) << 8;
536
82.9k
    temp |= UCH(*bufferptr++);
537
82.9k
    if (temp > maxval)
538
185
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
82.9k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
540
82.9k
    if (aindex >= 0)
541
16.5k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
542
82.9k
    ptr += ps;
543
82.9k
  }
544
73.9k
  return 1;
545
73.9k
}
Unexecuted instantiation: rdppm-8.c:get_word_gray_rgb_row
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
516
73.9k
{
517
73.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
518
73.9k
  register _JSAMPROW ptr;
519
73.9k
  register U_CHAR *bufferptr;
520
73.9k
  register _JSAMPLE *rescale = source->rescale;
521
73.9k
  JDIMENSION col;
522
73.9k
  unsigned int maxval = source->maxval;
523
73.9k
  register int rindex = rgb_red[cinfo->in_color_space];
524
73.9k
  register int gindex = rgb_green[cinfo->in_color_space];
525
73.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
526
73.9k
  register int aindex = alpha_index[cinfo->in_color_space];
527
73.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
528
529
73.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
530
315
    ERREXIT(cinfo, JERR_INPUT_EOF);
531
73.9k
  ptr = source->pub._buffer[0];
532
73.9k
  bufferptr = source->iobuffer;
533
156k
  for (col = cinfo->image_width; col > 0; col--) {
534
82.9k
    register unsigned int temp;
535
82.9k
    temp  = UCH(*bufferptr++) << 8;
536
82.9k
    temp |= UCH(*bufferptr++);
537
82.9k
    if (temp > maxval)
538
185
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
82.9k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
540
82.9k
    if (aindex >= 0)
541
16.5k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
542
82.9k
    ptr += ps;
543
82.9k
  }
544
73.9k
  return 1;
545
73.9k
}
Unexecuted instantiation: rdppm-16.c:get_word_gray_rgb_row
546
547
548
METHODDEF(JDIMENSION)
549
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
550
/* This version is for reading raw-word-format PGM files with any maxval */
551
14.7k
{
552
14.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
553
14.7k
  register _JSAMPROW ptr;
554
14.7k
  register U_CHAR *bufferptr;
555
14.7k
  register _JSAMPLE *rescale = source->rescale;
556
14.7k
  JDIMENSION col;
557
14.7k
  unsigned int maxval = source->maxval;
558
559
14.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
560
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
561
14.7k
  ptr = source->pub._buffer[0];
562
14.7k
  bufferptr = source->iobuffer;
563
31.3k
  for (col = cinfo->image_width; col > 0; col--) {
564
16.5k
    register unsigned int gray;
565
16.5k
    gray  = UCH(*bufferptr++) << 8;
566
16.5k
    gray |= UCH(*bufferptr++);
567
16.5k
    if (gray > maxval)
568
37
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
569
16.5k
    rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
570
16.5k
                ptr + 1, ptr + 2, ptr + 3);
571
16.5k
    ptr += 4;
572
16.5k
  }
573
14.7k
  return 1;
574
14.7k
}
Unexecuted instantiation: rdppm-8.c:get_word_gray_cmyk_row
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
551
14.7k
{
552
14.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
553
14.7k
  register _JSAMPROW ptr;
554
14.7k
  register U_CHAR *bufferptr;
555
14.7k
  register _JSAMPLE *rescale = source->rescale;
556
14.7k
  JDIMENSION col;
557
14.7k
  unsigned int maxval = source->maxval;
558
559
14.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
560
63
    ERREXIT(cinfo, JERR_INPUT_EOF);
561
14.7k
  ptr = source->pub._buffer[0];
562
14.7k
  bufferptr = source->iobuffer;
563
31.3k
  for (col = cinfo->image_width; col > 0; col--) {
564
16.5k
    register unsigned int gray;
565
16.5k
    gray  = UCH(*bufferptr++) << 8;
566
16.5k
    gray |= UCH(*bufferptr++);
567
16.5k
    if (gray > maxval)
568
37
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
569
16.5k
    rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
570
16.5k
                ptr + 1, ptr + 2, ptr + 3);
571
16.5k
    ptr += 4;
572
16.5k
  }
573
14.7k
  return 1;
574
14.7k
}
Unexecuted instantiation: rdppm-16.c:get_word_gray_cmyk_row
575
576
577
METHODDEF(JDIMENSION)
578
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
579
/* This version is for reading raw-word-format PPM files with any maxval */
580
15.8k
{
581
15.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
582
15.8k
  register _JSAMPROW ptr;
583
15.8k
  register U_CHAR *bufferptr;
584
15.8k
  register _JSAMPLE *rescale = source->rescale;
585
15.8k
  JDIMENSION col;
586
15.8k
  unsigned int maxval = source->maxval;
587
15.8k
  register int rindex = rgb_red[cinfo->in_color_space];
588
15.8k
  register int gindex = rgb_green[cinfo->in_color_space];
589
15.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
590
15.8k
  register int aindex = alpha_index[cinfo->in_color_space];
591
15.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
592
593
15.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
594
365
    ERREXIT(cinfo, JERR_INPUT_EOF);
595
15.8k
  ptr = source->pub._buffer[0];
596
15.8k
  bufferptr = source->iobuffer;
597
389k
  for (col = cinfo->image_width; col > 0; col--) {
598
374k
    register unsigned int temp;
599
374k
    temp  = UCH(*bufferptr++) << 8;
600
374k
    temp |= UCH(*bufferptr++);
601
374k
    if (temp > maxval)
602
145
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
603
374k
    ptr[rindex] = rescale[temp];
604
374k
    temp  = UCH(*bufferptr++) << 8;
605
374k
    temp |= UCH(*bufferptr++);
606
374k
    if (temp > maxval)
607
115
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
608
374k
    ptr[gindex] = rescale[temp];
609
374k
    temp  = UCH(*bufferptr++) << 8;
610
374k
    temp |= UCH(*bufferptr++);
611
374k
    if (temp > maxval)
612
105
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
613
374k
    ptr[bindex] = rescale[temp];
614
374k
    if (aindex >= 0)
615
74.7k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
616
374k
    ptr += ps;
617
374k
  }
618
15.8k
  return 1;
619
15.8k
}
Unexecuted instantiation: rdppm-8.c:get_word_rgb_row
rdppm-12.c:get_word_rgb_row
Line
Count
Source
580
15.8k
{
581
15.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
582
15.8k
  register _JSAMPROW ptr;
583
15.8k
  register U_CHAR *bufferptr;
584
15.8k
  register _JSAMPLE *rescale = source->rescale;
585
15.8k
  JDIMENSION col;
586
15.8k
  unsigned int maxval = source->maxval;
587
15.8k
  register int rindex = rgb_red[cinfo->in_color_space];
588
15.8k
  register int gindex = rgb_green[cinfo->in_color_space];
589
15.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
590
15.8k
  register int aindex = alpha_index[cinfo->in_color_space];
591
15.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
592
593
15.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
594
365
    ERREXIT(cinfo, JERR_INPUT_EOF);
595
15.8k
  ptr = source->pub._buffer[0];
596
15.8k
  bufferptr = source->iobuffer;
597
389k
  for (col = cinfo->image_width; col > 0; col--) {
598
374k
    register unsigned int temp;
599
374k
    temp  = UCH(*bufferptr++) << 8;
600
374k
    temp |= UCH(*bufferptr++);
601
374k
    if (temp > maxval)
602
145
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
603
374k
    ptr[rindex] = rescale[temp];
604
374k
    temp  = UCH(*bufferptr++) << 8;
605
374k
    temp |= UCH(*bufferptr++);
606
374k
    if (temp > maxval)
607
115
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
608
374k
    ptr[gindex] = rescale[temp];
609
374k
    temp  = UCH(*bufferptr++) << 8;
610
374k
    temp |= UCH(*bufferptr++);
611
374k
    if (temp > maxval)
612
105
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
613
374k
    ptr[bindex] = rescale[temp];
614
374k
    if (aindex >= 0)
615
74.7k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
616
374k
    ptr += ps;
617
374k
  }
618
15.8k
  return 1;
619
15.8k
}
Unexecuted instantiation: rdppm-16.c:get_word_rgb_row
620
621
622
METHODDEF(JDIMENSION)
623
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
624
/* This version is for reading raw-word-format PPM files with any maxval */
625
3.17k
{
626
3.17k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
627
3.17k
  register _JSAMPROW ptr;
628
3.17k
  register U_CHAR *bufferptr;
629
3.17k
  register _JSAMPLE *rescale = source->rescale;
630
3.17k
  JDIMENSION col;
631
3.17k
  unsigned int maxval = source->maxval;
632
633
3.17k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
634
73
    ERREXIT(cinfo, JERR_INPUT_EOF);
635
3.17k
  ptr = source->pub._buffer[0];
636
3.17k
  bufferptr = source->iobuffer;
637
77.9k
  for (col = cinfo->image_width; col > 0; col--) {
638
74.8k
    register unsigned int r, g, b;
639
74.8k
    r  = UCH(*bufferptr++) << 8;
640
74.8k
    r |= UCH(*bufferptr++);
641
74.8k
    if (r > maxval)
642
29
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
643
74.8k
    g  = UCH(*bufferptr++) << 8;
644
74.8k
    g |= UCH(*bufferptr++);
645
74.8k
    if (g > maxval)
646
23
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
647
74.8k
    b  = UCH(*bufferptr++) << 8;
648
74.8k
    b |= UCH(*bufferptr++);
649
74.8k
    if (b > maxval)
650
21
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
651
74.8k
    rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
652
74.8k
                ptr + 2, ptr + 3);
653
74.8k
    ptr += 4;
654
74.8k
  }
655
3.17k
  return 1;
656
3.17k
}
Unexecuted instantiation: rdppm-8.c:get_word_rgb_cmyk_row
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
625
3.17k
{
626
3.17k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
627
3.17k
  register _JSAMPROW ptr;
628
3.17k
  register U_CHAR *bufferptr;
629
3.17k
  register _JSAMPLE *rescale = source->rescale;
630
3.17k
  JDIMENSION col;
631
3.17k
  unsigned int maxval = source->maxval;
632
633
3.17k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
634
73
    ERREXIT(cinfo, JERR_INPUT_EOF);
635
3.17k
  ptr = source->pub._buffer[0];
636
3.17k
  bufferptr = source->iobuffer;
637
77.9k
  for (col = cinfo->image_width; col > 0; col--) {
638
74.8k
    register unsigned int r, g, b;
639
74.8k
    r  = UCH(*bufferptr++) << 8;
640
74.8k
    r |= UCH(*bufferptr++);
641
74.8k
    if (r > maxval)
642
29
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
643
74.8k
    g  = UCH(*bufferptr++) << 8;
644
74.8k
    g |= UCH(*bufferptr++);
645
74.8k
    if (g > maxval)
646
23
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
647
74.8k
    b  = UCH(*bufferptr++) << 8;
648
74.8k
    b |= UCH(*bufferptr++);
649
74.8k
    if (b > maxval)
650
21
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
651
74.8k
    rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
652
74.8k
                ptr + 2, ptr + 3);
653
74.8k
    ptr += 4;
654
74.8k
  }
655
3.17k
  return 1;
656
3.17k
}
Unexecuted instantiation: rdppm-16.c:get_word_rgb_cmyk_row
657
658
659
/*
660
 * Read the file header; return image size and component count.
661
 */
662
663
METHODDEF(void)
664
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
665
11.1k
{
666
11.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
667
11.1k
  int c;
668
11.1k
  unsigned int w, h, maxval;
669
11.1k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
670
671
11.1k
  if (getc(source->pub.input_file) != 'P')
672
0
    ERREXIT(cinfo, JERR_PPM_NOT);
673
674
11.1k
  c = getc(source->pub.input_file); /* subformat discriminator character */
675
676
  /* detect unsupported variants (ie, PBM) before trying to read header */
677
11.1k
  switch (c) {
678
1.71k
  case '2':                     /* it's a text-format PGM file */
679
3.59k
  case '3':                     /* it's a text-format PPM file */
680
8.68k
  case '5':                     /* it's a raw-format PGM file */
681
11.0k
  case '6':                     /* it's a raw-format PPM file */
682
11.0k
    break;
683
21
  default:
684
21
    ERREXIT(cinfo, JERR_PPM_NOT);
685
21
    break;
686
11.1k
  }
687
688
  /* fetch the remaining header info */
689
11.0k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
690
11.0k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
691
11.0k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
692
693
11.0k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
694
28
    ERREXIT(cinfo, JERR_PPM_NOT);
695
11.0k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
696
231
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
697
698
11.0k
  cinfo->image_width = (JDIMENSION)w;
699
11.0k
  cinfo->image_height = (JDIMENSION)h;
700
11.0k
  source->maxval = maxval;
701
702
  /* initialize flags to most common settings */
703
11.0k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
704
11.0k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
705
11.0k
  need_rescale = TRUE;          /* do we need a rescale array? */
706
707
11.0k
  switch (c) {
708
1.25k
  case '2':                     /* it's a text-format PGM file */
709
1.25k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
710
1.25k
        cinfo->in_color_space == JCS_RGB)
711
0
      cinfo->in_color_space = JCS_GRAYSCALE;
712
1.25k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
713
1.25k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
714
179
      source->pub.get_pixel_rows = get_text_gray_row;
715
1.07k
    else if (IsExtRGB(cinfo->in_color_space))
716
895
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
717
179
    else if (cinfo->in_color_space == JCS_CMYK)
718
179
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
719
0
    else
720
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
721
1.25k
    need_iobuffer = FALSE;
722
1.25k
    break;
723
724
1.51k
  case '3':                     /* it's a text-format PPM file */
725
1.51k
    if (cinfo->in_color_space == JCS_UNKNOWN)
726
0
      cinfo->in_color_space = JCS_EXT_RGB;
727
1.51k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
728
1.51k
    if (IsExtRGB(cinfo->in_color_space))
729
1.08k
      source->pub.get_pixel_rows = get_text_rgb_row;
730
434
    else if (cinfo->in_color_space == JCS_CMYK)
731
217
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
732
217
    else
733
217
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
734
1.51k
    need_iobuffer = FALSE;
735
1.51k
    break;
736
737
4.67k
  case '5':                     /* it's a raw-format PGM file */
738
4.67k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
739
4.67k
        cinfo->in_color_space == JCS_RGB)
740
0
      cinfo->in_color_space = JCS_GRAYSCALE;
741
4.67k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
742
4.67k
    if (maxval > 255) {
743
847
      if (cinfo->in_color_space == JCS_GRAYSCALE)
744
121
        source->pub.get_pixel_rows = get_word_gray_row;
745
726
      else if (IsExtRGB(cinfo->in_color_space))
746
605
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
747
121
      else if (cinfo->in_color_space == JCS_CMYK)
748
121
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
749
0
      else
750
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
751
3.82k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
752
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
753
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
754
0
      source->pub.get_pixel_rows = get_raw_row;
755
0
      use_raw_buffer = TRUE;
756
0
      need_rescale = FALSE;
757
3.82k
    } else {
758
3.82k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
759
547
        source->pub.get_pixel_rows = get_scaled_gray_row;
760
3.28k
      else if (IsExtRGB(cinfo->in_color_space))
761
2.73k
        source->pub.get_pixel_rows = get_gray_rgb_row;
762
547
      else if (cinfo->in_color_space == JCS_CMYK)
763
547
        source->pub.get_pixel_rows = get_gray_cmyk_row;
764
0
      else
765
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
766
3.82k
    }
767
4.67k
    break;
768
769
2.25k
  case '6':                     /* it's a raw-format PPM file */
770
2.25k
    if (cinfo->in_color_space == JCS_UNKNOWN)
771
0
      cinfo->in_color_space = JCS_EXT_RGB;
772
2.25k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
773
2.25k
    if (maxval > 255) {
774
1.22k
      if (IsExtRGB(cinfo->in_color_space))
775
875
        source->pub.get_pixel_rows = get_word_rgb_row;
776
350
      else if (cinfo->in_color_space == JCS_CMYK)
777
175
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
778
175
      else
779
175
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
780
1.22k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
781
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
782
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
783
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
784
0
                cinfo->in_color_space == JCS_RGB)) {
785
#else
786
               cinfo->in_color_space == JCS_EXT_RGB) {
787
#endif
788
0
      source->pub.get_pixel_rows = get_raw_row;
789
0
      use_raw_buffer = TRUE;
790
0
      need_rescale = FALSE;
791
1.02k
    } else {
792
1.02k
      if (IsExtRGB(cinfo->in_color_space))
793
735
        source->pub.get_pixel_rows = get_rgb_row;
794
294
      else if (cinfo->in_color_space == JCS_CMYK)
795
147
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
796
147
      else
797
147
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
798
1.02k
    }
799
2.25k
    break;
800
11.0k
  }
801
802
9.16k
  if (IsExtRGB(cinfo->in_color_space))
803
6.93k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
804
2.23k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
805
847
    cinfo->input_components = 1;
806
1.38k
  else if (cinfo->in_color_space == JCS_CMYK)
807
1.38k
    cinfo->input_components = 4;
808
809
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
810
9.16k
  if (need_iobuffer) {
811
6.60k
    if (c == '6')
812
1.93k
      source->buffer_width = (size_t)w * 3 *
813
1.93k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
814
4.67k
    else
815
4.67k
      source->buffer_width = (size_t)w *
816
4.67k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
817
6.60k
    source->iobuffer = (U_CHAR *)
818
6.60k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
819
6.60k
                                  source->buffer_width);
820
6.60k
  }
821
822
  /* Create compressor input buffer. */
823
9.16k
  if (use_raw_buffer) {
824
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
825
    /* Synthesize a _JSAMPARRAY pointer structure */
826
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
827
0
    source->pub._buffer = &source->pixrow;
828
0
    source->pub.buffer_height = 1;
829
9.16k
  } else {
830
    /* Need to translate anyway, so make a separate sample buffer. */
831
9.16k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
832
9.16k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
833
9.16k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
834
9.16k
    source->pub.buffer_height = 1;
835
9.16k
  }
836
837
  /* Compute the rescaling array if required. */
838
9.16k
  if (need_rescale) {
839
9.16k
    long val, half_maxval;
840
841
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
842
9.16k
    source->rescale = (_JSAMPLE *)
843
9.16k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
844
9.16k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
845
9.16k
                                           sizeof(_JSAMPLE)));
846
9.16k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
847
9.16k
                                        sizeof(_JSAMPLE)));
848
9.16k
    half_maxval = maxval / 2;
849
40.0M
    for (val = 0; val <= (long)maxval; val++) {
850
      /* The multiplication here must be done in 32 bits to avoid overflow */
851
40.0M
      source->rescale[val] =
852
40.0M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
853
40.0M
                   maxval);
854
40.0M
    }
855
9.16k
  }
856
9.16k
}
Unexecuted instantiation: rdppm-8.c:start_input_ppm
rdppm-12.c:start_input_ppm
Line
Count
Source
665
11.1k
{
666
11.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
667
11.1k
  int c;
668
11.1k
  unsigned int w, h, maxval;
669
11.1k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
670
671
11.1k
  if (getc(source->pub.input_file) != 'P')
672
0
    ERREXIT(cinfo, JERR_PPM_NOT);
673
674
11.1k
  c = getc(source->pub.input_file); /* subformat discriminator character */
675
676
  /* detect unsupported variants (ie, PBM) before trying to read header */
677
11.1k
  switch (c) {
678
1.71k
  case '2':                     /* it's a text-format PGM file */
679
3.59k
  case '3':                     /* it's a text-format PPM file */
680
8.68k
  case '5':                     /* it's a raw-format PGM file */
681
11.0k
  case '6':                     /* it's a raw-format PPM file */
682
11.0k
    break;
683
21
  default:
684
21
    ERREXIT(cinfo, JERR_PPM_NOT);
685
21
    break;
686
11.1k
  }
687
688
  /* fetch the remaining header info */
689
11.0k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
690
11.0k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
691
11.0k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
692
693
11.0k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
694
28
    ERREXIT(cinfo, JERR_PPM_NOT);
695
11.0k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
696
231
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
697
698
11.0k
  cinfo->image_width = (JDIMENSION)w;
699
11.0k
  cinfo->image_height = (JDIMENSION)h;
700
11.0k
  source->maxval = maxval;
701
702
  /* initialize flags to most common settings */
703
11.0k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
704
11.0k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
705
11.0k
  need_rescale = TRUE;          /* do we need a rescale array? */
706
707
11.0k
  switch (c) {
708
1.25k
  case '2':                     /* it's a text-format PGM file */
709
1.25k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
710
1.25k
        cinfo->in_color_space == JCS_RGB)
711
0
      cinfo->in_color_space = JCS_GRAYSCALE;
712
1.25k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
713
1.25k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
714
179
      source->pub.get_pixel_rows = get_text_gray_row;
715
1.07k
    else if (IsExtRGB(cinfo->in_color_space))
716
895
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
717
179
    else if (cinfo->in_color_space == JCS_CMYK)
718
179
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
719
0
    else
720
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
721
1.25k
    need_iobuffer = FALSE;
722
1.25k
    break;
723
724
1.51k
  case '3':                     /* it's a text-format PPM file */
725
1.51k
    if (cinfo->in_color_space == JCS_UNKNOWN)
726
0
      cinfo->in_color_space = JCS_EXT_RGB;
727
1.51k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
728
1.51k
    if (IsExtRGB(cinfo->in_color_space))
729
1.08k
      source->pub.get_pixel_rows = get_text_rgb_row;
730
434
    else if (cinfo->in_color_space == JCS_CMYK)
731
217
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
732
217
    else
733
217
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
734
1.51k
    need_iobuffer = FALSE;
735
1.51k
    break;
736
737
4.67k
  case '5':                     /* it's a raw-format PGM file */
738
4.67k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
739
4.67k
        cinfo->in_color_space == JCS_RGB)
740
0
      cinfo->in_color_space = JCS_GRAYSCALE;
741
4.67k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
742
4.67k
    if (maxval > 255) {
743
847
      if (cinfo->in_color_space == JCS_GRAYSCALE)
744
121
        source->pub.get_pixel_rows = get_word_gray_row;
745
726
      else if (IsExtRGB(cinfo->in_color_space))
746
605
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
747
121
      else if (cinfo->in_color_space == JCS_CMYK)
748
121
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
749
0
      else
750
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
751
3.82k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
752
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
753
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
754
0
      source->pub.get_pixel_rows = get_raw_row;
755
0
      use_raw_buffer = TRUE;
756
0
      need_rescale = FALSE;
757
3.82k
    } else {
758
3.82k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
759
547
        source->pub.get_pixel_rows = get_scaled_gray_row;
760
3.28k
      else if (IsExtRGB(cinfo->in_color_space))
761
2.73k
        source->pub.get_pixel_rows = get_gray_rgb_row;
762
547
      else if (cinfo->in_color_space == JCS_CMYK)
763
547
        source->pub.get_pixel_rows = get_gray_cmyk_row;
764
0
      else
765
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
766
3.82k
    }
767
4.67k
    break;
768
769
2.25k
  case '6':                     /* it's a raw-format PPM file */
770
2.25k
    if (cinfo->in_color_space == JCS_UNKNOWN)
771
0
      cinfo->in_color_space = JCS_EXT_RGB;
772
2.25k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
773
2.25k
    if (maxval > 255) {
774
1.22k
      if (IsExtRGB(cinfo->in_color_space))
775
875
        source->pub.get_pixel_rows = get_word_rgb_row;
776
350
      else if (cinfo->in_color_space == JCS_CMYK)
777
175
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
778
175
      else
779
175
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
780
1.22k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
781
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
782
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
783
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
784
0
                cinfo->in_color_space == JCS_RGB)) {
785
#else
786
               cinfo->in_color_space == JCS_EXT_RGB) {
787
#endif
788
0
      source->pub.get_pixel_rows = get_raw_row;
789
0
      use_raw_buffer = TRUE;
790
0
      need_rescale = FALSE;
791
1.02k
    } else {
792
1.02k
      if (IsExtRGB(cinfo->in_color_space))
793
735
        source->pub.get_pixel_rows = get_rgb_row;
794
294
      else if (cinfo->in_color_space == JCS_CMYK)
795
147
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
796
147
      else
797
147
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
798
1.02k
    }
799
2.25k
    break;
800
11.0k
  }
801
802
9.16k
  if (IsExtRGB(cinfo->in_color_space))
803
6.93k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
804
2.23k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
805
847
    cinfo->input_components = 1;
806
1.38k
  else if (cinfo->in_color_space == JCS_CMYK)
807
1.38k
    cinfo->input_components = 4;
808
809
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
810
9.16k
  if (need_iobuffer) {
811
6.60k
    if (c == '6')
812
1.93k
      source->buffer_width = (size_t)w * 3 *
813
1.93k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
814
4.67k
    else
815
4.67k
      source->buffer_width = (size_t)w *
816
4.67k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
817
6.60k
    source->iobuffer = (U_CHAR *)
818
6.60k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
819
6.60k
                                  source->buffer_width);
820
6.60k
  }
821
822
  /* Create compressor input buffer. */
823
9.16k
  if (use_raw_buffer) {
824
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
825
    /* Synthesize a _JSAMPARRAY pointer structure */
826
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
827
0
    source->pub._buffer = &source->pixrow;
828
0
    source->pub.buffer_height = 1;
829
9.16k
  } else {
830
    /* Need to translate anyway, so make a separate sample buffer. */
831
9.16k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
832
9.16k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
833
9.16k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
834
9.16k
    source->pub.buffer_height = 1;
835
9.16k
  }
836
837
  /* Compute the rescaling array if required. */
838
9.16k
  if (need_rescale) {
839
9.16k
    long val, half_maxval;
840
841
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
842
9.16k
    source->rescale = (_JSAMPLE *)
843
9.16k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
844
9.16k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
845
9.16k
                                           sizeof(_JSAMPLE)));
846
9.16k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
847
9.16k
                                        sizeof(_JSAMPLE)));
848
9.16k
    half_maxval = maxval / 2;
849
40.0M
    for (val = 0; val <= (long)maxval; val++) {
850
      /* The multiplication here must be done in 32 bits to avoid overflow */
851
40.0M
      source->rescale[val] =
852
40.0M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
853
40.0M
                   maxval);
854
40.0M
    }
855
9.16k
  }
856
9.16k
}
Unexecuted instantiation: rdppm-16.c:start_input_ppm
857
858
859
/*
860
 * Finish up at the end of the file.
861
 */
862
863
METHODDEF(void)
864
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
865
4.20k
{
866
  /* no work */
867
4.20k
}
Unexecuted instantiation: rdppm-8.c:finish_input_ppm
rdppm-12.c:finish_input_ppm
Line
Count
Source
865
4.20k
{
866
  /* no work */
867
4.20k
}
Unexecuted instantiation: rdppm-16.c:finish_input_ppm
868
869
870
/*
871
 * The module selection routine for PPM format input.
872
 */
873
874
GLOBAL(cjpeg_source_ptr)
875
_jinit_read_ppm(j_compress_ptr cinfo)
876
11.1k
{
877
11.1k
  ppm_source_ptr source;
878
879
#if BITS_IN_JSAMPLE == 8
880
0
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
881
#else
882
11.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
883
11.1k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
884
0
#endif
885
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
886
887
  /* Create module interface object */
888
11.1k
  source = (ppm_source_ptr)
889
11.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
890
11.1k
                                sizeof(ppm_source_struct));
891
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
892
11.1k
  source->pub.start_input = start_input_ppm;
893
11.1k
  source->pub.finish_input = finish_input_ppm;
894
11.1k
  source->pub.max_pixels = 0;
895
896
11.1k
  return (cjpeg_source_ptr)source;
897
11.1k
}
Unexecuted instantiation: jinit_read_ppm
j12init_read_ppm
Line
Count
Source
876
11.1k
{
877
11.1k
  ppm_source_ptr source;
878
879
#if BITS_IN_JSAMPLE == 8
880
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
881
#else
882
11.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
883
11.1k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
884
0
#endif
885
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
886
887
  /* Create module interface object */
888
11.1k
  source = (ppm_source_ptr)
889
11.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
890
11.1k
                                sizeof(ppm_source_struct));
891
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
892
11.1k
  source->pub.start_input = start_input_ppm;
893
11.1k
  source->pub.finish_input = finish_input_ppm;
894
11.1k
  source->pub.max_pixels = 0;
895
896
11.1k
  return (cjpeg_source_ptr)source;
897
11.1k
}
Unexecuted instantiation: j16init_read_ppm
898
899
#endif /* defined(PPM_SUPPORTED) &&
900
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */