Coverage Report

Created: 2023-06-07 06:03

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