Coverage Report

Created: 2026-02-26 07:10

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, 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
168M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
185M
  (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
1.74M
{
80
1.74M
  register int ch;
81
82
1.74M
  ch = getc(infile);
83
1.74M
  if (ch == '#') {
84
440k
    do {
85
440k
      ch = getc(infile);
86
440k
    } while (ch != '\n' && ch != EOF);
87
23.4k
  }
88
1.74M
  return ch;
89
1.74M
}
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
717k
{
99
717k
  register int ch;
100
717k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
770k
  do {
104
770k
    ch = pbm_getc(infile);
105
770k
    if (ch == EOF)
106
15.4k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
770k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
717k
  if (ch < '0' || ch > '9')
110
1.36k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
717k
  val = ch - '0';
113
994k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
276k
    val *= 10;
115
276k
    val += ch - '0';
116
276k
    if (val > maxval)
117
810
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
276k
  }
119
120
717k
  return val;
121
717k
}
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
10.5k
{
139
10.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
140
10.5k
  FILE *infile = source->pub.input_file;
141
10.5k
  register _JSAMPROW ptr;
142
10.5k
  register _JSAMPLE *rescale = source->rescale;
143
10.5k
  JDIMENSION col;
144
10.5k
  unsigned int maxval = source->maxval;
145
146
10.5k
  ptr = source->pub._buffer[0];
147
28.5k
  for (col = cinfo->image_width; col > 0; col--) {
148
17.9k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
149
17.9k
  }
150
10.5k
  return 1;
151
10.5k
}
152
153
154
135M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
155
562M
  for (col = cinfo->image_width; col > 0; col--) { \
156
427M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
157
427M
    alpha_set_op \
158
427M
    ptr += ps; \
159
427M
  } \
160
135M
}
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
50.8k
{
167
50.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
168
50.8k
  FILE *infile = source->pub.input_file;
169
50.8k
  register _JSAMPROW ptr;
170
50.8k
  register _JSAMPLE *rescale = source->rescale;
171
50.8k
  JDIMENSION col;
172
50.8k
  unsigned int maxval = source->maxval;
173
50.8k
  register int rindex = rgb_red[cinfo->in_color_space];
174
50.8k
  register int gindex = rgb_green[cinfo->in_color_space];
175
50.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
176
50.8k
  register int aindex = alpha_index[cinfo->in_color_space];
177
50.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
178
179
50.8k
  ptr = source->pub._buffer[0];
180
50.8k
  if (maxval == _MAXJSAMPLE) {
181
11.7k
    if (aindex >= 0)
182
1.81k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
183
11.7k
                         ptr[aindex] = _MAXJSAMPLE;)
184
9.91k
    else
185
9.91k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
186
39.0k
  } else {
187
39.0k
    if (aindex >= 0)
188
6.47k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
189
39.0k
                         ptr[aindex] = _MAXJSAMPLE;)
190
32.6k
    else
191
32.6k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
192
39.0k
  }
193
50.8k
  return 1;
194
50.8k
}
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
8.28k
{
202
8.28k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
203
8.28k
  FILE *infile = source->pub.input_file;
204
8.28k
  register _JSAMPROW ptr;
205
8.28k
  register _JSAMPLE *rescale = source->rescale;
206
8.28k
  JDIMENSION col;
207
8.28k
  unsigned int maxval = source->maxval;
208
209
8.28k
  ptr = source->pub._buffer[0];
210
8.28k
  if (maxval == _MAXJSAMPLE) {
211
5.10k
    for (col = cinfo->image_width; col > 0; col--) {
212
3.28k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
213
3.28k
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
214
3.28k
      ptr += 4;
215
3.28k
    }
216
6.47k
  } else {
217
15.8k
    for (col = cinfo->image_width; col > 0; col--) {
218
9.37k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
219
9.37k
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
220
9.37k
      ptr += 4;
221
9.37k
    }
222
6.47k
  }
223
8.28k
  return 1;
224
8.28k
}
225
226
227
1.26M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
228
18.7M
  for (col = cinfo->image_width; col > 0; col--) { \
229
17.5M
    ptr[rindex] = read_op; \
230
17.5M
    ptr[gindex] = read_op; \
231
17.5M
    ptr[bindex] = read_op; \
232
17.5M
    alpha_set_op \
233
17.5M
    ptr += ps; \
234
17.5M
  } \
235
1.26M
}
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
52.0k
{
241
52.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
242
52.0k
  FILE *infile = source->pub.input_file;
243
52.0k
  register _JSAMPROW ptr;
244
52.0k
  register _JSAMPLE *rescale = source->rescale;
245
52.0k
  JDIMENSION col;
246
52.0k
  unsigned int maxval = source->maxval;
247
52.0k
  register int rindex = rgb_red[cinfo->in_color_space];
248
52.0k
  register int gindex = rgb_green[cinfo->in_color_space];
249
52.0k
  register int bindex = rgb_blue[cinfo->in_color_space];
250
52.0k
  register int aindex = alpha_index[cinfo->in_color_space];
251
52.0k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
252
253
52.0k
  ptr = source->pub._buffer[0];
254
52.0k
  if (maxval == _MAXJSAMPLE) {
255
13.5k
    if (aindex >= 0)
256
2.12k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
257
13.5k
                    ptr[aindex] = _MAXJSAMPLE;)
258
11.4k
    else
259
11.4k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
260
38.5k
  } else {
261
38.5k
    if (aindex >= 0)
262
6.51k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
263
38.5k
                    ptr[aindex] = _MAXJSAMPLE;)
264
32.0k
    else
265
32.0k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
266
38.5k
  }
267
52.0k
  return 1;
268
52.0k
}
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
8.63k
{
276
8.63k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
277
8.63k
  FILE *infile = source->pub.input_file;
278
8.63k
  register _JSAMPROW ptr;
279
8.63k
  register _JSAMPLE *rescale = source->rescale;
280
8.63k
  JDIMENSION col;
281
8.63k
  unsigned int maxval = source->maxval;
282
283
8.63k
  ptr = source->pub._buffer[0];
284
8.63k
  if (maxval == _MAXJSAMPLE) {
285
8.82k
    for (col = cinfo->image_width; col > 0; col--) {
286
6.70k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
287
6.70k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
6.70k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
6.70k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
290
6.70k
      ptr += 4;
291
6.70k
    }
292
6.51k
  } else {
293
16.9k
    for (col = cinfo->image_width; col > 0; col--) {
294
10.3k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
295
10.3k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
10.3k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.3k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
298
10.3k
      ptr += 4;
299
10.3k
    }
300
6.51k
  }
301
8.63k
  return 1;
302
8.63k
}
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
23.4M
{
309
23.4M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
310
23.4M
  register _JSAMPROW ptr;
311
23.4M
  register U_CHAR *bufferptr;
312
23.4M
  register _JSAMPLE *rescale = source->rescale;
313
23.4M
  JDIMENSION col;
314
315
23.4M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
316
435
    ERREXIT(cinfo, JERR_INPUT_EOF);
317
23.4M
  ptr = source->pub._buffer[0];
318
23.4M
  bufferptr = source->iobuffer;
319
104M
  for (col = cinfo->image_width; col > 0; col--) {
320
80.8M
    *ptr++ = rescale[UCH(*bufferptr++)];
321
80.8M
  }
322
23.4M
  return 1;
323
23.4M
}
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
135M
{
331
135M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
332
135M
  register _JSAMPROW ptr;
333
135M
  register U_CHAR *bufferptr;
334
135M
  register _JSAMPLE *rescale = source->rescale;
335
135M
  JDIMENSION col;
336
135M
  unsigned int maxval = source->maxval;
337
135M
  register int rindex = rgb_red[cinfo->in_color_space];
338
135M
  register int gindex = rgb_green[cinfo->in_color_space];
339
135M
  register int bindex = rgb_blue[cinfo->in_color_space];
340
135M
  register int aindex = alpha_index[cinfo->in_color_space];
341
135M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
342
343
135M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
344
2.29k
    ERREXIT(cinfo, JERR_INPUT_EOF);
345
135M
  ptr = source->pub._buffer[0];
346
135M
  bufferptr = source->iobuffer;
347
135M
  if (maxval == _MAXJSAMPLE) {
348
18.1M
    if (aindex >= 0)
349
1.81M
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
350
16.3M
    else
351
16.3M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
352
117M
  } else {
353
117M
    if (aindex >= 0)
354
19.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
355
117M
                         ptr[aindex] = _MAXJSAMPLE;)
356
98.1M
    else
357
98.1M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
358
117M
  }
359
135M
  return 1;
360
135M
}
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
20.8M
{
368
20.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
369
20.8M
  register _JSAMPROW ptr;
370
20.8M
  register U_CHAR *bufferptr;
371
20.8M
  register _JSAMPLE *rescale = source->rescale;
372
20.8M
  JDIMENSION col;
373
20.8M
  unsigned int maxval = source->maxval;
374
375
20.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
376
377
    ERREXIT(cinfo, JERR_INPUT_EOF);
377
20.8M
  ptr = source->pub._buffer[0];
378
20.8M
  bufferptr = source->iobuffer;
379
20.8M
  if (maxval == _MAXJSAMPLE) {
380
4.22M
    for (col = cinfo->image_width; col > 0; col--) {
381
2.41M
      _JSAMPLE gray = *bufferptr++;
382
2.41M
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
383
2.41M
      ptr += 4;
384
2.41M
    }
385
19.0M
  } else {
386
86.8M
    for (col = cinfo->image_width; col > 0; col--) {
387
67.8M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
388
67.8M
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
389
67.8M
      ptr += 4;
390
67.8M
    }
391
19.0M
  }
392
20.8M
  return 1;
393
20.8M
}
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
1.21M
{
400
1.21M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
401
1.21M
  register _JSAMPROW ptr;
402
1.21M
  register U_CHAR *bufferptr;
403
1.21M
  register _JSAMPLE *rescale = source->rescale;
404
1.21M
  JDIMENSION col;
405
1.21M
  unsigned int maxval = source->maxval;
406
1.21M
  register int rindex = rgb_red[cinfo->in_color_space];
407
1.21M
  register int gindex = rgb_green[cinfo->in_color_space];
408
1.21M
  register int bindex = rgb_blue[cinfo->in_color_space];
409
1.21M
  register int aindex = alpha_index[cinfo->in_color_space];
410
1.21M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
411
412
1.21M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
413
3.52k
    ERREXIT(cinfo, JERR_INPUT_EOF);
414
1.21M
  ptr = source->pub._buffer[0];
415
1.21M
  bufferptr = source->iobuffer;
416
1.21M
  if (maxval == _MAXJSAMPLE) {
417
9.80k
    if (aindex >= 0)
418
1.79k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
419
8.00k
    else
420
8.00k
      RGB_READ_LOOP(*bufferptr++, {})
421
1.20M
  } else {
422
1.20M
    if (aindex >= 0)
423
197k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = _MAXJSAMPLE;)
424
1.00M
    else
425
1.00M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
426
1.20M
  }
427
1.21M
  return 1;
428
1.21M
}
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
200k
{
436
200k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
437
200k
  register _JSAMPROW ptr;
438
200k
  register U_CHAR *bufferptr;
439
200k
  register _JSAMPLE *rescale = source->rescale;
440
200k
  JDIMENSION col;
441
200k
  unsigned int maxval = source->maxval;
442
443
200k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
444
600
    ERREXIT(cinfo, JERR_INPUT_EOF);
445
200k
  ptr = source->pub._buffer[0];
446
200k
  bufferptr = source->iobuffer;
447
200k
  if (maxval == _MAXJSAMPLE) {
448
501k
    for (col = cinfo->image_width; col > 0; col--) {
449
499k
      _JSAMPLE r = *bufferptr++;
450
499k
      _JSAMPLE g = *bufferptr++;
451
499k
      _JSAMPLE b = *bufferptr++;
452
499k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
453
499k
      ptr += 4;
454
499k
    }
455
198k
  } else {
456
2.73M
    for (col = cinfo->image_width; col > 0; col--) {
457
2.53M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
458
2.53M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
459
2.53M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
460
2.53M
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
461
2.53M
      ptr += 4;
462
2.53M
    }
463
198k
  }
464
200k
  return 1;
465
200k
}
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
3.63M
{
475
3.63M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
476
477
3.63M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
478
275
    ERREXIT(cinfo, JERR_INPUT_EOF);
479
3.63M
  return 1;
480
3.63M
}
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
139k
{
487
139k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
488
139k
  register _JSAMPROW ptr;
489
139k
  register U_CHAR *bufferptr;
490
139k
  register _JSAMPLE *rescale = source->rescale;
491
139k
  JDIMENSION col;
492
139k
  unsigned int maxval = source->maxval;
493
494
139k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
495
385
    ERREXIT(cinfo, JERR_INPUT_EOF);
496
139k
  ptr = source->pub._buffer[0];
497
139k
  bufferptr = source->iobuffer;
498
895k
  for (col = cinfo->image_width; col > 0; col--) {
499
756k
    register unsigned int temp;
500
756k
    temp  = UCH(*bufferptr++) << 8;
501
756k
    temp |= UCH(*bufferptr++);
502
756k
    if (temp > maxval)
503
247
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
504
756k
    *ptr++ = rescale[temp];
505
756k
  }
506
139k
  return 1;
507
139k
}
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
693k
{
514
693k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
515
693k
  register _JSAMPROW ptr;
516
693k
  register U_CHAR *bufferptr;
517
693k
  register _JSAMPLE *rescale = source->rescale;
518
693k
  JDIMENSION col;
519
693k
  unsigned int maxval = source->maxval;
520
693k
  register int rindex = rgb_red[cinfo->in_color_space];
521
693k
  register int gindex = rgb_green[cinfo->in_color_space];
522
693k
  register int bindex = rgb_blue[cinfo->in_color_space];
523
693k
  register int aindex = alpha_index[cinfo->in_color_space];
524
693k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
525
526
693k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
527
1.74k
    ERREXIT(cinfo, JERR_INPUT_EOF);
528
693k
  ptr = source->pub._buffer[0];
529
693k
  bufferptr = source->iobuffer;
530
4.47M
  for (col = cinfo->image_width; col > 0; col--) {
531
3.77M
    register unsigned int temp;
532
3.77M
    temp  = UCH(*bufferptr++) << 8;
533
3.77M
    temp |= UCH(*bufferptr++);
534
3.77M
    if (temp > maxval)
535
1.08k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
536
3.77M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
537
3.77M
    if (aindex >= 0)
538
712k
      ptr[aindex] = _MAXJSAMPLE;
539
3.77M
    ptr += ps;
540
3.77M
  }
541
693k
  return 1;
542
693k
}
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
129k
{
549
129k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
550
129k
  register _JSAMPROW ptr;
551
129k
  register U_CHAR *bufferptr;
552
129k
  register _JSAMPLE *rescale = source->rescale;
553
129k
  JDIMENSION col;
554
129k
  unsigned int maxval = source->maxval;
555
556
129k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
557
294
    ERREXIT(cinfo, JERR_INPUT_EOF);
558
129k
  ptr = source->pub._buffer[0];
559
129k
  bufferptr = source->iobuffer;
560
841k
  for (col = cinfo->image_width; col > 0; col--) {
561
712k
    register unsigned int gray;
562
712k
    gray  = UCH(*bufferptr++) << 8;
563
712k
    gray |= UCH(*bufferptr++);
564
712k
    if (gray > maxval)
565
180
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
566
712k
    rgb_to_cmyk(rescale[gray], rescale[gray], rescale[gray], ptr, ptr + 1,
567
712k
                ptr + 2, ptr + 3);
568
712k
    ptr += 4;
569
712k
  }
570
129k
  return 1;
571
129k
}
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
63.7k
{
578
63.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
579
63.7k
  register _JSAMPROW ptr;
580
63.7k
  register U_CHAR *bufferptr;
581
63.7k
  register _JSAMPLE *rescale = source->rescale;
582
63.7k
  JDIMENSION col;
583
63.7k
  unsigned int maxval = source->maxval;
584
63.7k
  register int rindex = rgb_red[cinfo->in_color_space];
585
63.7k
  register int gindex = rgb_green[cinfo->in_color_space];
586
63.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
587
63.7k
  register int aindex = alpha_index[cinfo->in_color_space];
588
63.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
589
590
63.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
591
2.32k
    ERREXIT(cinfo, JERR_INPUT_EOF);
592
63.7k
  ptr = source->pub._buffer[0];
593
63.7k
  bufferptr = source->iobuffer;
594
344k
  for (col = cinfo->image_width; col > 0; col--) {
595
281k
    register unsigned int temp;
596
281k
    temp  = UCH(*bufferptr++) << 8;
597
281k
    temp |= UCH(*bufferptr++);
598
281k
    if (temp > maxval)
599
1.01k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
600
281k
    ptr[rindex] = rescale[temp];
601
281k
    temp  = UCH(*bufferptr++) << 8;
602
281k
    temp |= UCH(*bufferptr++);
603
281k
    if (temp > maxval)
604
699
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
605
281k
    ptr[gindex] = rescale[temp];
606
281k
    temp  = UCH(*bufferptr++) << 8;
607
281k
    temp |= UCH(*bufferptr++);
608
281k
    if (temp > maxval)
609
690
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
610
281k
    ptr[bindex] = rescale[temp];
611
281k
    if (aindex >= 0)
612
17.3k
      ptr[aindex] = _MAXJSAMPLE;
613
281k
    ptr += ps;
614
281k
  }
615
63.7k
  return 1;
616
63.7k
}
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
402
    ERREXIT(cinfo, JERR_INPUT_EOF);
632
11.0k
  ptr = source->pub._buffer[0];
633
11.0k
  bufferptr = source->iobuffer;
634
28.7k
  for (col = cinfo->image_width; col > 0; col--) {
635
17.7k
    register unsigned int r, g, b;
636
17.7k
    r  = UCH(*bufferptr++) << 8;
637
17.7k
    r |= UCH(*bufferptr++);
638
17.7k
    if (r > maxval)
639
162
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
640
17.7k
    g  = UCH(*bufferptr++) << 8;
641
17.7k
    g |= UCH(*bufferptr++);
642
17.7k
    if (g > maxval)
643
109
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
644
17.7k
    b  = UCH(*bufferptr++) << 8;
645
17.7k
    b |= UCH(*bufferptr++);
646
17.7k
    if (b > maxval)
647
107
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
648
17.7k
    rgb_to_cmyk(rescale[r], rescale[g], rescale[b], ptr, ptr + 1, ptr + 2,
649
17.7k
                ptr + 3);
650
17.7k
    ptr += 4;
651
17.7k
  }
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
91.3k
{
663
91.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
664
91.3k
  int c;
665
91.3k
  unsigned int w, h, maxval;
666
91.3k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
667
668
91.3k
  if (getc(source->pub.input_file) != 'P')
669
0
    ERREXIT(cinfo, JERR_PPM_NOT);
670
671
91.3k
  c = getc(source->pub.input_file); /* subformat discriminator character */
672
673
  /* detect unsupported variants (ie, PBM) before trying to read header */
674
91.3k
  switch (c) {
675
8.17k
  case '2':                     /* it's a text-format PGM file */
676
17.1k
  case '3':                     /* it's a text-format PPM file */
677
71.1k
  case '5':                     /* it's a raw-format PGM file */
678
91.3k
  case '6':                     /* it's a raw-format PPM file */
679
91.3k
    break;
680
43
  default:
681
43
    ERREXIT(cinfo, JERR_PPM_NOT);
682
43
    break;
683
91.3k
  }
684
685
  /* fetch the remaining header info */
686
91.3k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
687
91.3k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
688
91.3k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
689
690
91.3k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
691
207
    ERREXIT(cinfo, JERR_PPM_NOT);
692
91.3k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
693
1.45k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
694
695
91.3k
  cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
696
91.3k
  cinfo->image_width = (JDIMENSION)w;
697
91.3k
  cinfo->image_height = (JDIMENSION)h;
698
91.3k
  source->maxval = maxval;
699
700
  /* initialize flags to most common settings */
701
91.3k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
702
91.3k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
703
91.3k
  need_rescale = TRUE;          /* do we need a rescale array? */
704
705
91.3k
  switch (c) {
706
5.71k
  case '2':                     /* it's a text-format PGM file */
707
5.71k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
708
5.71k
        cinfo->in_color_space == JCS_RGB)
709
206
      cinfo->in_color_space = JCS_GRAYSCALE;
710
5.71k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
711
5.71k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
712
1.01k
      source->pub.get_pixel_rows = get_text_gray_row;
713
4.70k
    else if (IsExtRGB(cinfo->in_color_space))
714
4.02k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
715
681
    else if (cinfo->in_color_space == JCS_CMYK)
716
681
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
717
0
    else
718
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
719
5.71k
    need_iobuffer = FALSE;
720
5.71k
    break;
721
722
6.99k
  case '3':                     /* it's a text-format PPM file */
723
6.99k
    if (cinfo->in_color_space == JCS_UNKNOWN)
724
0
      cinfo->in_color_space = JCS_EXT_RGB;
725
6.99k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
726
6.99k
    if (IsExtRGB(cinfo->in_color_space))
727
5.13k
      source->pub.get_pixel_rows = get_text_rgb_row;
728
1.86k
    else if (cinfo->in_color_space == JCS_CMYK)
729
867
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
730
994
    else
731
994
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
732
6.99k
    need_iobuffer = FALSE;
733
6.99k
    break;
734
735
51.5k
  case '5':                     /* it's a raw-format PGM file */
736
51.5k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
737
51.5k
        cinfo->in_color_space == JCS_RGB)
738
336
      cinfo->in_color_space = JCS_GRAYSCALE;
739
51.5k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
740
51.5k
    if (maxval > 255) {
741
4.53k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
742
778
        source->pub.get_pixel_rows = get_word_gray_row;
743
3.75k
      else if (IsExtRGB(cinfo->in_color_space))
744
3.21k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
745
545
      else if (cinfo->in_color_space == JCS_CMYK)
746
545
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
747
0
      else
748
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
749
47.0k
    } else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
750
3.18k
               cinfo->in_color_space == JCS_GRAYSCALE) {
751
496
      source->pub.get_pixel_rows = get_raw_row;
752
496
      use_raw_buffer = TRUE;
753
496
      need_rescale = FALSE;
754
46.5k
    } else {
755
46.5k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
756
6.63k
        source->pub.get_pixel_rows = get_scaled_gray_row;
757
39.8k
      else if (IsExtRGB(cinfo->in_color_space))
758
34.6k
        source->pub.get_pixel_rows = get_gray_rgb_row;
759
5.22k
      else if (cinfo->in_color_space == JCS_CMYK)
760
5.22k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
761
0
      else
762
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
763
46.5k
    }
764
51.5k
    break;
765
766
18.4k
  case '6':                     /* it's a raw-format PPM file */
767
18.4k
    if (cinfo->in_color_space == JCS_UNKNOWN)
768
0
      cinfo->in_color_space = JCS_EXT_RGB;
769
18.4k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
770
18.4k
    if (maxval > 255) {
771
6.72k
      if (IsExtRGB(cinfo->in_color_space))
772
4.96k
        source->pub.get_pixel_rows = get_word_rgb_row;
773
1.76k
      else if (cinfo->in_color_space == JCS_CMYK)
774
820
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
775
944
      else
776
944
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
777
11.7k
    } else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
778
1.46k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
779
1.46k
               (cinfo->in_color_space == JCS_EXT_RGB ||
780
1.25k
                cinfo->in_color_space == JCS_RGB)) {
781
#else
782
               cinfo->in_color_space == JCS_EXT_RGB) {
783
#endif
784
262
      source->pub.get_pixel_rows = get_raw_row;
785
262
      use_raw_buffer = TRUE;
786
262
      need_rescale = FALSE;
787
11.4k
    } else {
788
11.4k
      if (IsExtRGB(cinfo->in_color_space))
789
8.50k
        source->pub.get_pixel_rows = get_rgb_row;
790
2.97k
      else if (cinfo->in_color_space == JCS_CMYK)
791
1.33k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
792
1.64k
      else
793
1.64k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
794
11.4k
    }
795
18.4k
    break;
796
91.3k
  }
797
798
79.1k
  if (IsExtRGB(cinfo->in_color_space))
799
60.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
800
18.3k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
801
8.92k
    cinfo->input_components = 1;
802
9.47k
  else if (cinfo->in_color_space == JCS_CMYK)
803
9.47k
    cinfo->input_components = 4;
804
805
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
806
79.1k
  if (need_iobuffer) {
807
67.4k
    if (c == '6')
808
15.8k
      source->buffer_width = (size_t)w * 3 *
809
15.8k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
810
51.5k
    else
811
51.5k
      source->buffer_width = (size_t)w *
812
51.5k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
813
67.4k
    source->iobuffer = (U_CHAR *)
814
67.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
815
67.4k
                                  source->buffer_width);
816
67.4k
  }
817
818
  /* Create compressor input buffer. */
819
79.1k
  if (use_raw_buffer) {
820
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
821
    /* Synthesize a _JSAMPARRAY pointer structure */
822
758
    source->pixrow = (_JSAMPROW)source->iobuffer;
823
758
    source->pub._buffer = &source->pixrow;
824
758
    source->pub.buffer_height = 1;
825
78.3k
  } else {
826
    /* Need to translate anyway, so make a separate sample buffer. */
827
78.3k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
828
78.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
829
78.3k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
830
78.3k
    source->pub.buffer_height = 1;
831
78.3k
  }
832
833
  /* Compute the rescaling array if required. */
834
79.1k
  if (need_rescale) {
835
78.3k
    long val, half_maxval;
836
837
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
838
78.3k
    source->rescale = (_JSAMPLE *)
839
78.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
840
78.3k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
841
78.3k
                                           sizeof(_JSAMPLE)));
842
78.3k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
843
78.3k
                                        sizeof(_JSAMPLE)));
844
78.3k
    half_maxval = maxval / 2;
845
226M
    for (val = 0; val <= (long)maxval; val++) {
846
      /* The multiplication here must be done in 32 bits to avoid overflow */
847
226M
      source->rescale[val] = (_JSAMPLE)((val * _MAXJSAMPLE + half_maxval) /
848
226M
                                        maxval);
849
226M
    }
850
78.3k
  }
851
79.1k
}
852
853
854
/*
855
 * Finish up at the end of the file.
856
 */
857
858
METHODDEF(void)
859
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
860
51.2k
{
861
  /* no work */
862
51.2k
}
863
864
865
/*
866
 * The module selection routine for PPM format input.
867
 */
868
869
GLOBAL(cjpeg_source_ptr)
870
_jinit_read_ppm(j_compress_ptr cinfo)
871
91.3k
{
872
91.3k
  ppm_source_ptr source;
873
874
91.3k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
875
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
876
877
  /* Create module interface object */
878
91.3k
  source = (ppm_source_ptr)
879
91.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
91.3k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
91.3k
  source->pub.start_input = start_input_ppm;
883
91.3k
  source->pub.finish_input = finish_input_ppm;
884
91.3k
  source->pub.max_pixels = 0;
885
886
91.3k
  return (cjpeg_source_ptr)source;
887
91.3k
}
jinit_read_ppm
Line
Count
Source
871
49.7k
{
872
49.7k
  ppm_source_ptr source;
873
874
49.7k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
875
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
876
877
  /* Create module interface object */
878
49.7k
  source = (ppm_source_ptr)
879
49.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
49.7k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
49.7k
  source->pub.start_input = start_input_ppm;
883
49.7k
  source->pub.finish_input = finish_input_ppm;
884
49.7k
  source->pub.max_pixels = 0;
885
886
49.7k
  return (cjpeg_source_ptr)source;
887
49.7k
}
j12init_read_ppm
Line
Count
Source
871
31.0k
{
872
31.0k
  ppm_source_ptr source;
873
874
31.0k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
875
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
876
877
  /* Create module interface object */
878
31.0k
  source = (ppm_source_ptr)
879
31.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
31.0k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
31.0k
  source->pub.start_input = start_input_ppm;
883
31.0k
  source->pub.finish_input = finish_input_ppm;
884
31.0k
  source->pub.max_pixels = 0;
885
886
31.0k
  return (cjpeg_source_ptr)source;
887
31.0k
}
j16init_read_ppm
Line
Count
Source
871
10.5k
{
872
10.5k
  ppm_source_ptr source;
873
874
10.5k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
875
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
876
877
  /* Create module interface object */
878
10.5k
  source = (ppm_source_ptr)
879
10.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
10.5k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
10.5k
  source->pub.start_input = start_input_ppm;
883
10.5k
  source->pub.finish_input = finish_input_ppm;
884
10.5k
  source->pub.max_pixels = 0;
885
886
10.5k
  return (cjpeg_source_ptr)source;
887
10.5k
}
888
889
#endif /* defined(PPM_SUPPORTED) &&
890
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */