Coverage Report

Created: 2026-05-11 07:55

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