Coverage Report

Created: 2026-06-10 06:18

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
177M
  (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.77M
{
74
1.77M
  register int ch;
75
76
1.77M
  ch = getc(infile);
77
1.77M
  if (ch == '#') {
78
403k
    do {
79
403k
      ch = getc(infile);
80
403k
    } while (ch != '\n' && ch != EOF);
81
24.3k
  }
82
1.77M
  return ch;
83
1.77M
}
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
734k
{
93
734k
  register int ch;
94
734k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
786k
  do {
98
786k
    ch = pbm_getc(infile);
99
786k
    if (ch == EOF)
100
16.7k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
786k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
734k
  if (ch < '0' || ch > '9')
104
1.44k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
734k
  val = ch - '0';
107
1.01M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
277k
    val *= 10;
109
277k
    val += ch - '0';
110
277k
    if (val > maxval)
111
818
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
277k
  }
113
114
734k
  return val;
115
734k
}
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
11.2k
{
133
11.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
134
11.2k
  FILE *infile = source->pub.input_file;
135
11.2k
  register _JSAMPROW ptr;
136
11.2k
  register _JSAMPLE *rescale = source->rescale;
137
11.2k
  JDIMENSION col;
138
11.2k
  unsigned int maxval = source->maxval;
139
140
11.2k
  ptr = source->pub._buffer[0];
141
29.8k
  for (col = cinfo->image_width; col > 0; col--) {
142
18.5k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
143
18.5k
  }
144
11.2k
  return 1;
145
11.2k
}
146
147
148
128M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
149
532M
  for (col = cinfo->image_width; col > 0; col--) { \
150
404M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
151
404M
    alpha_set_op \
152
404M
    ptr += ps; \
153
404M
  } \
154
128M
}
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
53.4k
{
161
53.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
162
53.4k
  FILE *infile = source->pub.input_file;
163
53.4k
  register _JSAMPROW ptr;
164
53.4k
  register _JSAMPLE *rescale = source->rescale;
165
53.4k
  JDIMENSION col;
166
53.4k
  unsigned int maxval = source->maxval;
167
53.4k
  register int rindex = rgb_red[cinfo->in_color_space];
168
53.4k
  register int gindex = rgb_green[cinfo->in_color_space];
169
53.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
170
53.4k
  register int aindex = alpha_index[cinfo->in_color_space];
171
53.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
172
173
53.4k
  ptr = source->pub._buffer[0];
174
53.4k
  if (maxval == _MAXJSAMPLE) {
175
11.7k
    if (aindex >= 0)
176
1.81k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
177
11.7k
                         ptr[aindex] = _MAXJSAMPLE;)
178
9.93k
    else
179
9.93k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
180
41.6k
  } else {
181
41.6k
    if (aindex >= 0)
182
6.98k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
183
41.6k
                         ptr[aindex] = _MAXJSAMPLE;)
184
34.6k
    else
185
34.6k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
186
41.6k
  }
187
53.4k
  return 1;
188
53.4k
}
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.80k
{
196
8.80k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
197
8.80k
  FILE *infile = source->pub.input_file;
198
8.80k
  register _JSAMPROW ptr;
199
8.80k
  register _JSAMPLE *rescale = source->rescale;
200
8.80k
  JDIMENSION col;
201
8.80k
  unsigned int maxval = source->maxval;
202
203
8.80k
  ptr = source->pub._buffer[0];
204
8.80k
  if (maxval == _MAXJSAMPLE) {
205
5.13k
    for (col = cinfo->image_width; col > 0; col--) {
206
3.31k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
207
3.31k
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
208
3.31k
      ptr += 4;
209
3.31k
    }
210
6.98k
  } else {
211
17.3k
    for (col = cinfo->image_width; col > 0; col--) {
212
10.3k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
213
10.3k
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
214
10.3k
      ptr += 4;
215
10.3k
    }
216
6.98k
  }
217
8.80k
  return 1;
218
8.80k
}
219
220
221
1.61M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
222
17.4M
  for (col = cinfo->image_width; col > 0; col--) { \
223
15.7M
    ptr[rindex] = read_op; \
224
15.7M
    ptr[gindex] = read_op; \
225
15.7M
    ptr[bindex] = read_op; \
226
15.7M
    alpha_set_op \
227
15.7M
    ptr += ps; \
228
15.7M
  } \
229
1.61M
}
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.2k
{
235
54.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
236
54.2k
  FILE *infile = source->pub.input_file;
237
54.2k
  register _JSAMPROW ptr;
238
54.2k
  register _JSAMPLE *rescale = source->rescale;
239
54.2k
  JDIMENSION col;
240
54.2k
  unsigned int maxval = source->maxval;
241
54.2k
  register int rindex = rgb_red[cinfo->in_color_space];
242
54.2k
  register int gindex = rgb_green[cinfo->in_color_space];
243
54.2k
  register int bindex = rgb_blue[cinfo->in_color_space];
244
54.2k
  register int aindex = alpha_index[cinfo->in_color_space];
245
54.2k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
246
247
54.2k
  ptr = source->pub._buffer[0];
248
54.2k
  if (maxval == _MAXJSAMPLE) {
249
17.4k
    if (aindex >= 0)
250
2.42k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
251
17.4k
                    ptr[aindex] = _MAXJSAMPLE;)
252
15.0k
    else
253
15.0k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
254
36.7k
  } else {
255
36.7k
    if (aindex >= 0)
256
6.42k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
257
36.7k
                    ptr[aindex] = _MAXJSAMPLE;)
258
30.3k
    else
259
30.3k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
260
36.7k
  }
261
54.2k
  return 1;
262
54.2k
}
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.85k
{
270
8.85k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
271
8.85k
  FILE *infile = source->pub.input_file;
272
8.85k
  register _JSAMPROW ptr;
273
8.85k
  register _JSAMPLE *rescale = source->rescale;
274
8.85k
  JDIMENSION col;
275
8.85k
  unsigned int maxval = source->maxval;
276
277
8.85k
  ptr = source->pub._buffer[0];
278
8.85k
  if (maxval == _MAXJSAMPLE) {
279
8.92k
    for (col = cinfo->image_width; col > 0; col--) {
280
6.49k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
281
6.49k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
282
6.49k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
6.49k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
284
6.49k
      ptr += 4;
285
6.49k
    }
286
6.42k
  } else {
287
16.7k
    for (col = cinfo->image_width; col > 0; col--) {
288
10.3k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
289
10.3k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
290
10.3k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
10.3k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
10.3k
      ptr += 4;
293
10.3k
    }
294
6.42k
  }
295
8.85k
  return 1;
296
8.85k
}
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
22.1M
{
303
22.1M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
304
22.1M
  register _JSAMPROW ptr;
305
22.1M
  register unsigned char *bufferptr;
306
22.1M
  register _JSAMPLE *rescale = source->rescale;
307
22.1M
  JDIMENSION col;
308
309
22.1M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
310
515
    ERREXIT(cinfo, JERR_INPUT_EOF);
311
22.1M
  ptr = source->pub._buffer[0];
312
22.1M
  bufferptr = source->iobuffer;
313
98.4M
  for (col = cinfo->image_width; col > 0; col--) {
314
76.3M
    *ptr++ = rescale[*bufferptr++];
315
76.3M
  }
316
22.1M
  return 1;
317
22.1M
}
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
128M
{
325
128M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
326
128M
  register _JSAMPROW ptr;
327
128M
  register unsigned char *bufferptr;
328
128M
  register _JSAMPLE *rescale = source->rescale;
329
128M
  JDIMENSION col;
330
128M
  unsigned int maxval = source->maxval;
331
128M
  register int rindex = rgb_red[cinfo->in_color_space];
332
128M
  register int gindex = rgb_green[cinfo->in_color_space];
333
128M
  register int bindex = rgb_blue[cinfo->in_color_space];
334
128M
  register int aindex = alpha_index[cinfo->in_color_space];
335
128M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
336
337
128M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
338
2.52k
    ERREXIT(cinfo, JERR_INPUT_EOF);
339
128M
  ptr = source->pub._buffer[0];
340
128M
  bufferptr = source->iobuffer;
341
128M
  if (maxval == _MAXJSAMPLE) {
342
18.0M
    if (aindex >= 0)
343
1.93M
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
344
16.0M
    else
345
16.0M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
346
110M
  } else {
347
110M
    if (aindex >= 0)
348
17.7M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], ptr[aindex] = _MAXJSAMPLE;)
349
92.9M
    else
350
92.9M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
351
110M
  }
352
128M
  return 1;
353
128M
}
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.6M
{
361
19.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
362
19.6M
  register _JSAMPROW ptr;
363
19.6M
  register unsigned char *bufferptr;
364
19.6M
  register _JSAMPLE *rescale = source->rescale;
365
19.6M
  JDIMENSION col;
366
19.6M
  unsigned int maxval = source->maxval;
367
368
19.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
369
416
    ERREXIT(cinfo, JERR_INPUT_EOF);
370
19.6M
  ptr = source->pub._buffer[0];
371
19.6M
  bufferptr = source->iobuffer;
372
19.6M
  if (maxval == _MAXJSAMPLE) {
373
4.57M
    for (col = cinfo->image_width; col > 0; col--) {
374
2.63M
      _JSAMPLE gray = *bufferptr++;
375
2.63M
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
376
2.63M
      ptr += 4;
377
2.63M
    }
378
17.7M
  } else {
379
81.1M
    for (col = cinfo->image_width; col > 0; col--) {
380
63.3M
      _JSAMPLE gray = rescale[*bufferptr++];
381
63.3M
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
382
63.3M
      ptr += 4;
383
63.3M
    }
384
17.7M
  }
385
19.6M
  return 1;
386
19.6M
}
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.55M
{
393
1.55M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
394
1.55M
  register _JSAMPROW ptr;
395
1.55M
  register unsigned char *bufferptr;
396
1.55M
  register _JSAMPLE *rescale = source->rescale;
397
1.55M
  JDIMENSION col;
398
1.55M
  unsigned int maxval = source->maxval;
399
1.55M
  register int rindex = rgb_red[cinfo->in_color_space];
400
1.55M
  register int gindex = rgb_green[cinfo->in_color_space];
401
1.55M
  register int bindex = rgb_blue[cinfo->in_color_space];
402
1.55M
  register int aindex = alpha_index[cinfo->in_color_space];
403
1.55M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
404
405
1.55M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
406
3.68k
    ERREXIT(cinfo, JERR_INPUT_EOF);
407
1.55M
  ptr = source->pub._buffer[0];
408
1.55M
  bufferptr = source->iobuffer;
409
1.55M
  if (maxval == _MAXJSAMPLE) {
410
10.1k
    if (aindex >= 0)
411
1.76k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
412
8.43k
    else
413
8.43k
      RGB_READ_LOOP(*bufferptr++, {})
414
1.54M
  } else {
415
1.54M
    if (aindex >= 0)
416
265k
      RGB_READ_LOOP(rescale[*bufferptr++], ptr[aindex] = _MAXJSAMPLE;)
417
1.28M
    else
418
1.28M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
419
1.54M
  }
420
1.55M
  return 1;
421
1.55M
}
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
267k
{
429
267k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
430
267k
  register _JSAMPROW ptr;
431
267k
  register unsigned char *bufferptr;
432
267k
  register _JSAMPLE *rescale = source->rescale;
433
267k
  JDIMENSION col;
434
267k
  unsigned int maxval = source->maxval;
435
436
267k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
437
621
    ERREXIT(cinfo, JERR_INPUT_EOF);
438
267k
  ptr = source->pub._buffer[0];
439
267k
  bufferptr = source->iobuffer;
440
267k
  if (maxval == _MAXJSAMPLE) {
441
303k
    for (col = cinfo->image_width; col > 0; col--) {
442
302k
      _JSAMPLE r = *bufferptr++;
443
302k
      _JSAMPLE g = *bufferptr++;
444
302k
      _JSAMPLE b = *bufferptr++;
445
302k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
446
302k
      ptr += 4;
447
302k
    }
448
265k
  } else {
449
2.78M
    for (col = cinfo->image_width; col > 0; col--) {
450
2.52M
      _JSAMPLE r = rescale[*bufferptr++];
451
2.52M
      _JSAMPLE g = rescale[*bufferptr++];
452
2.52M
      _JSAMPLE b = rescale[*bufferptr++];
453
2.52M
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
454
2.52M
      ptr += 4;
455
2.52M
    }
456
265k
  }
457
267k
  return 1;
458
267k
}
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.60M
{
470
3.60M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
471
472
3.60M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
473
200
    ERREXIT(cinfo, JERR_INPUT_EOF);
474
3.60M
  return 1;
475
3.60M
}
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
143k
{
484
143k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
485
143k
  register _JSAMPROW ptr;
486
143k
  register unsigned char *bufferptr;
487
143k
  register _JSAMPLE *rescale = source->rescale;
488
143k
  JDIMENSION col;
489
143k
  unsigned int maxval = source->maxval;
490
491
143k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
492
404
    ERREXIT(cinfo, JERR_INPUT_EOF);
493
143k
  ptr = source->pub._buffer[0];
494
143k
  bufferptr = source->iobuffer;
495
685k
  for (col = cinfo->image_width; col > 0; col--) {
496
541k
    register unsigned int temp;
497
541k
    temp  = (*bufferptr++) << 8;
498
541k
    temp |= (*bufferptr++);
499
541k
    if (temp > maxval)
500
265
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
501
541k
    *ptr++ = rescale[temp];
502
541k
  }
503
143k
  return 1;
504
143k
}
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
715k
{
511
715k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
512
715k
  register _JSAMPROW ptr;
513
715k
  register unsigned char *bufferptr;
514
715k
  register _JSAMPLE *rescale = source->rescale;
515
715k
  JDIMENSION col;
516
715k
  unsigned int maxval = source->maxval;
517
715k
  register int rindex = rgb_red[cinfo->in_color_space];
518
715k
  register int gindex = rgb_green[cinfo->in_color_space];
519
715k
  register int bindex = rgb_blue[cinfo->in_color_space];
520
715k
  register int aindex = alpha_index[cinfo->in_color_space];
521
715k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
522
523
715k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
524
1.80k
    ERREXIT(cinfo, JERR_INPUT_EOF);
525
715k
  ptr = source->pub._buffer[0];
526
715k
  bufferptr = source->iobuffer;
527
3.41M
  for (col = cinfo->image_width; col > 0; col--) {
528
2.70M
    register unsigned int temp;
529
2.70M
    temp  = (*bufferptr++) << 8;
530
2.70M
    temp |= (*bufferptr++);
531
2.70M
    if (temp > maxval)
532
1.16k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
533
2.70M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
534
2.70M
    if (aindex >= 0)
535
497k
      ptr[aindex] = _MAXJSAMPLE;
536
2.70M
    ptr += ps;
537
2.70M
  }
538
715k
  return 1;
539
715k
}
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
133k
{
546
133k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
547
133k
  register _JSAMPROW ptr;
548
133k
  register unsigned char *bufferptr;
549
133k
  register _JSAMPLE *rescale = source->rescale;
550
133k
  JDIMENSION col;
551
133k
  unsigned int maxval = source->maxval;
552
553
133k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
554
304
    ERREXIT(cinfo, JERR_INPUT_EOF);
555
133k
  ptr = source->pub._buffer[0];
556
133k
  bufferptr = source->iobuffer;
557
631k
  for (col = cinfo->image_width; col > 0; col--) {
558
498k
    register unsigned int gray;
559
498k
    gray  = (*bufferptr++) << 8;
560
498k
    gray |= (*bufferptr++);
561
498k
    if (gray > maxval)
562
193
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
563
498k
    rgb_to_cmyk(rescale[gray], rescale[gray], rescale[gray], ptr, ptr + 1,
564
498k
                ptr + 2, ptr + 3);
565
498k
    ptr += 4;
566
498k
  }
567
133k
  return 1;
568
133k
}
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
63.8k
{
575
63.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
576
63.8k
  register _JSAMPROW ptr;
577
63.8k
  register unsigned char *bufferptr;
578
63.8k
  register _JSAMPLE *rescale = source->rescale;
579
63.8k
  JDIMENSION col;
580
63.8k
  unsigned int maxval = source->maxval;
581
63.8k
  register int rindex = rgb_red[cinfo->in_color_space];
582
63.8k
  register int gindex = rgb_green[cinfo->in_color_space];
583
63.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
584
63.8k
  register int aindex = alpha_index[cinfo->in_color_space];
585
63.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
586
587
63.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
588
2.27k
    ERREXIT(cinfo, JERR_INPUT_EOF);
589
63.8k
  ptr = source->pub._buffer[0];
590
63.8k
  bufferptr = source->iobuffer;
591
219k
  for (col = cinfo->image_width; col > 0; col--) {
592
155k
    register unsigned int temp;
593
155k
    temp  = (*bufferptr++) << 8;
594
155k
    temp |= (*bufferptr++);
595
155k
    if (temp > maxval)
596
907
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
597
155k
    ptr[rindex] = rescale[temp];
598
155k
    temp  = (*bufferptr++) << 8;
599
155k
    temp |= (*bufferptr++);
600
155k
    if (temp > maxval)
601
798
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
602
155k
    ptr[gindex] = rescale[temp];
603
155k
    temp  = (*bufferptr++) << 8;
604
155k
    temp |= (*bufferptr++);
605
155k
    if (temp > maxval)
606
741
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
607
155k
    ptr[bindex] = rescale[temp];
608
155k
    if (aindex >= 0)
609
17.9k
      ptr[aindex] = _MAXJSAMPLE;
610
155k
    ptr += ps;
611
155k
  }
612
63.8k
  return 1;
613
63.8k
}
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.3k
{
620
11.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
621
11.3k
  register _JSAMPROW ptr;
622
11.3k
  register unsigned char *bufferptr;
623
11.3k
  register _JSAMPLE *rescale = source->rescale;
624
11.3k
  JDIMENSION col;
625
11.3k
  unsigned int maxval = source->maxval;
626
627
11.3k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
628
390
    ERREXIT(cinfo, JERR_INPUT_EOF);
629
11.3k
  ptr = source->pub._buffer[0];
630
11.3k
  bufferptr = source->iobuffer;
631
29.6k
  for (col = cinfo->image_width; col > 0; col--) {
632
18.3k
    register unsigned int r, g, b;
633
18.3k
    r  = (*bufferptr++) << 8;
634
18.3k
    r |= (*bufferptr++);
635
18.3k
    if (r > maxval)
636
148
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
637
18.3k
    g  = (*bufferptr++) << 8;
638
18.3k
    g |= (*bufferptr++);
639
18.3k
    if (g > maxval)
640
125
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
641
18.3k
    b  = (*bufferptr++) << 8;
642
18.3k
    b |= (*bufferptr++);
643
18.3k
    if (b > maxval)
644
116
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
645
18.3k
    rgb_to_cmyk(rescale[r], rescale[g], rescale[b], ptr, ptr + 1, ptr + 2,
646
18.3k
                ptr + 3);
647
18.3k
    ptr += 4;
648
18.3k
  }
649
11.3k
  return 1;
650
11.3k
}
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
52.1k
{
660
52.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
661
52.1k
  int c;
662
52.1k
  unsigned int w, h, maxval;
663
52.1k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
664
665
52.1k
  if (getc(source->pub.input_file) != 'P')
666
0
    ERREXIT(cinfo, JERR_PPM_NOT);
667
668
52.1k
  c = getc(source->pub.input_file); /* subformat discriminator character */
669
670
  /* detect unsupported variants (ie, PBM) before trying to read header */
671
52.1k
  switch (c) {
672
4.21k
  case '2':                     /* it's a text-format PGM file */
673
8.78k
  case '3':                     /* it's a text-format PPM file */
674
40.5k
  case '5':                     /* it's a raw-format PGM file */
675
52.0k
  case '6':                     /* it's a raw-format PPM file */
676
52.0k
    break;
677
24
  default:
678
24
    ERREXIT(cinfo, JERR_PPM_NOT);
679
24
    break;
680
52.1k
  }
681
682
  /* fetch the remaining header info */
683
52.0k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
684
52.0k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
685
52.0k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
686
687
52.0k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
688
120
    ERREXIT(cinfo, JERR_PPM_NOT);
689
52.0k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
690
74
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
691
52.0k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
692
794
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
693
694
52.0k
  cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
695
52.0k
  cinfo->image_width = (JDIMENSION)w;
696
52.0k
  cinfo->image_height = (JDIMENSION)h;
697
52.0k
  source->maxval = maxval;
698
699
  /* initialize flags to most common settings */
700
52.0k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
701
52.0k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
702
52.0k
  need_rescale = TRUE;          /* do we need a rescale array? */
703
704
52.0k
  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
228
      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
649
      source->pub.get_pixel_rows = get_text_gray_row;
712
2.39k
    else if (IsExtRGB(cinfo->in_color_space))
713
2.10k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
714
290
    else if (cinfo->in_color_space == JCS_CMYK)
715
290
      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.52k
  case '3':                     /* it's a text-format PPM file */
722
3.52k
    if (cinfo->in_color_space == JCS_UNKNOWN)
723
0
      cinfo->in_color_space = JCS_EXT_RGB;
724
3.52k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
725
3.52k
    if (IsExtRGB(cinfo->in_color_space))
726
2.66k
      source->pub.get_pixel_rows = get_text_rgb_row;
727
855
    else if (cinfo->in_color_space == JCS_CMYK)
728
364
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
729
491
    else
730
491
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
731
3.52k
    need_iobuffer = FALSE;
732
3.52k
    break;
733
734
30.4k
  case '5':                     /* it's a raw-format PGM file */
735
30.4k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
736
30.4k
        cinfo->in_color_space == JCS_RGB)
737
452
      cinfo->in_color_space = JCS_GRAYSCALE;
738
30.4k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
739
30.4k
    if (maxval > 255) {
740
2.31k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
741
480
        source->pub.get_pixel_rows = get_word_gray_row;
742
1.83k
      else if (IsExtRGB(cinfo->in_color_space))
743
1.61k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
744
220
      else if (cinfo->in_color_space == JCS_CMYK)
745
220
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
746
0
      else
747
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
748
2.31k
#if BITS_IN_JSAMPLE == 8
749
28.1k
    } else if (maxval == _MAXJSAMPLE &&
750
3.18k
               cinfo->in_color_space == JCS_GRAYSCALE) {
751
508
      source->pub.get_pixel_rows = get_raw_row;
752
508
      use_raw_buffer = TRUE;
753
508
      need_rescale = FALSE;
754
508
#endif
755
27.6k
    } else {
756
27.6k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
757
4.01k
        source->pub.get_pixel_rows = get_scaled_gray_row;
758
23.6k
      else if (IsExtRGB(cinfo->in_color_space))
759
21.1k
        source->pub.get_pixel_rows = get_gray_rgb_row;
760
2.48k
      else if (cinfo->in_color_space == JCS_CMYK)
761
2.48k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
762
0
      else
763
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
764
27.6k
    }
765
30.4k
    break;
766
767
10.3k
  case '6':                     /* it's a raw-format PPM file */
768
10.3k
    if (cinfo->in_color_space == JCS_UNKNOWN)
769
0
      cinfo->in_color_space = JCS_EXT_RGB;
770
10.3k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
771
10.3k
    if (maxval > 255) {
772
3.38k
      if (IsExtRGB(cinfo->in_color_space))
773
2.58k
        source->pub.get_pixel_rows = get_word_rgb_row;
774
808
      else if (cinfo->in_color_space == JCS_CMYK)
775
343
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
776
465
      else
777
465
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
778
3.38k
#if BITS_IN_JSAMPLE == 8
779
6.94k
    } else if (maxval == _MAXJSAMPLE &&
780
1.21k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
781
1.21k
               (cinfo->in_color_space == JCS_EXT_RGB ||
782
1.03k
                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.75k
    } else {
791
6.75k
      if (IsExtRGB(cinfo->in_color_space))
792
5.17k
        source->pub.get_pixel_rows = get_rgb_row;
793
1.57k
      else if (cinfo->in_color_space == JCS_CMYK)
794
639
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
795
940
      else
796
940
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
797
6.75k
    }
798
10.3k
    break;
799
52.0k
  }
800
801
45.4k
  if (IsExtRGB(cinfo->in_color_space))
802
35.4k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
803
9.99k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
804
5.65k
    cinfo->input_components = 1;
805
4.33k
  else if (cinfo->in_color_space == JCS_CMYK)
806
4.33k
    cinfo->input_components = 4;
807
808
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
809
45.4k
  if (need_iobuffer) {
810
39.3k
    if (c == '6')
811
8.93k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
812
30.4k
    else
813
30.4k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
814
39.3k
    source->iobuffer = (unsigned char *)
815
39.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
816
39.3k
                                  source->buffer_width);
817
39.3k
  }
818
819
  /* Create compressor input buffer. */
820
45.4k
  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
699
    source->pixrow = (_JSAMPROW)source->iobuffer;
824
699
    source->pub._buffer = &source->pixrow;
825
699
    source->pub.buffer_height = 1;
826
44.7k
  } else {
827
    /* Need to translate anyway, so make a separate sample buffer. */
828
44.7k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
829
44.7k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
830
44.7k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
831
44.7k
    source->pub.buffer_height = 1;
832
44.7k
  }
833
834
  /* Compute the rescaling array if required. */
835
45.4k
  if (need_rescale) {
836
44.7k
    size_t val, half_maxval;
837
838
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
839
44.7k
    source->rescale = (_JSAMPLE *)
840
44.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
841
44.7k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
842
44.7k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
843
44.7k
    half_maxval = (size_t)maxval / 2;
844
71.9M
    for (val = 0; val <= (size_t)maxval; val++) {
845
      /* The multiplication here must be done in 32 bits to avoid overflow */
846
71.9M
      source->rescale[val] = (_JSAMPLE)((val * _MAXJSAMPLE + half_maxval) /
847
71.9M
                                        maxval);
848
71.9M
    }
849
44.7k
  }
850
45.4k
}
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
53.9k
{
860
  /* no work */
861
53.9k
}
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
96.5k
{
871
96.5k
  ppm_source_ptr source;
872
873
96.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
96.5k
  source = (ppm_source_ptr)
878
96.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
879
96.5k
                                sizeof(ppm_source_struct));
880
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
881
96.5k
  source->pub.start_input = start_input_ppm;
882
96.5k
  source->pub.finish_input = finish_input_ppm;
883
96.5k
  source->pub.max_pixels = 0;
884
885
96.5k
  return (cjpeg_source_ptr)source;
886
96.5k
}
jinit_read_ppm
Line
Count
Source
870
52.1k
{
871
52.1k
  ppm_source_ptr source;
872
873
52.1k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
874
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
875
876
  /* Create module interface object */
877
52.1k
  source = (ppm_source_ptr)
878
52.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
879
52.1k
                                sizeof(ppm_source_struct));
880
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
881
52.1k
  source->pub.start_input = start_input_ppm;
882
52.1k
  source->pub.finish_input = finish_input_ppm;
883
52.1k
  source->pub.max_pixels = 0;
884
885
52.1k
  return (cjpeg_source_ptr)source;
886
52.1k
}
j12init_read_ppm
Line
Count
Source
870
32.5k
{
871
32.5k
  ppm_source_ptr source;
872
873
32.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
32.5k
  source = (ppm_source_ptr)
878
32.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
879
32.5k
                                sizeof(ppm_source_struct));
880
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
881
32.5k
  source->pub.start_input = start_input_ppm;
882
32.5k
  source->pub.finish_input = finish_input_ppm;
883
32.5k
  source->pub.max_pixels = 0;
884
885
32.5k
  return (cjpeg_source_ptr)source;
886
32.5k
}
j16init_read_ppm
Line
Count
Source
870
11.8k
{
871
11.8k
  ppm_source_ptr source;
872
873
11.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
11.8k
  source = (ppm_source_ptr)
878
11.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
879
11.8k
                                sizeof(ppm_source_struct));
880
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
881
11.8k
  source->pub.start_input = start_input_ppm;
882
11.8k
  source->pub.finish_input = finish_input_ppm;
883
11.8k
  source->pub.max_pixels = 0;
884
885
11.8k
  return (cjpeg_source_ptr)source;
886
11.8k
}
887
888
#endif /* defined(PPM_SUPPORTED) &&
889
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */