Coverage Report

Created: 2026-01-25 06:04

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
158M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
184M
  (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.72M
{
80
1.72M
  register int ch;
81
82
1.72M
  ch = getc(infile);
83
1.72M
  if (ch == '#') {
84
490k
    do {
85
490k
      ch = getc(infile);
86
490k
    } while (ch != '\n' && ch != EOF);
87
23.0k
  }
88
1.72M
  return ch;
89
1.72M
}
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
707k
{
99
707k
  register int ch;
100
707k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
759k
  do {
104
759k
    ch = pbm_getc(infile);
105
759k
    if (ch == EOF)
106
14.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
759k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
707k
  if (ch < '0' || ch > '9')
110
1.32k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
707k
  val = ch - '0';
113
979k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
272k
    val *= 10;
115
272k
    val += ch - '0';
116
272k
    if (val > maxval)
117
769
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
272k
  }
119
120
707k
  return val;
121
707k
}
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.0k
{
139
10.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
140
10.0k
  FILE *infile = source->pub.input_file;
141
10.0k
  register _JSAMPROW ptr;
142
10.0k
  register _JSAMPLE *rescale = source->rescale;
143
10.0k
  JDIMENSION col;
144
10.0k
  unsigned int maxval = source->maxval;
145
146
10.0k
  ptr = source->pub._buffer[0];
147
25.8k
  for (col = cinfo->image_width; col > 0; col--) {
148
15.7k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
149
15.7k
  }
150
10.0k
  return 1;
151
10.0k
}
152
153
154
134M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
155
536M
  for (col = cinfo->image_width; col > 0; col--) { \
156
402M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
157
402M
    alpha_set_op \
158
402M
    ptr += ps; \
159
402M
  } \
160
134M
}
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.1k
{
167
50.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
168
50.1k
  FILE *infile = source->pub.input_file;
169
50.1k
  register _JSAMPROW ptr;
170
50.1k
  register _JSAMPLE *rescale = source->rescale;
171
50.1k
  JDIMENSION col;
172
50.1k
  unsigned int maxval = source->maxval;
173
50.1k
  register int rindex = rgb_red[cinfo->in_color_space];
174
50.1k
  register int gindex = rgb_green[cinfo->in_color_space];
175
50.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
176
50.1k
  register int aindex = alpha_index[cinfo->in_color_space];
177
50.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
178
179
50.1k
  ptr = source->pub._buffer[0];
180
50.1k
  if (maxval == _MAXJSAMPLE) {
181
11.6k
    if (aindex >= 0)
182
1.80k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
183
11.6k
                         ptr[aindex] = _MAXJSAMPLE;)
184
9.87k
    else
185
9.87k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
186
38.5k
  } else {
187
38.5k
    if (aindex >= 0)
188
6.36k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
189
38.5k
                         ptr[aindex] = _MAXJSAMPLE;)
190
32.1k
    else
191
32.1k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
192
38.5k
  }
193
50.1k
  return 1;
194
50.1k
}
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.16k
{
202
8.16k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
203
8.16k
  FILE *infile = source->pub.input_file;
204
8.16k
  register _JSAMPROW ptr;
205
8.16k
  register _JSAMPLE *rescale = source->rescale;
206
8.16k
  JDIMENSION col;
207
8.16k
  unsigned int maxval = source->maxval;
208
209
8.16k
  ptr = source->pub._buffer[0];
210
8.16k
  if (maxval == _MAXJSAMPLE) {
211
5.08k
    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.36k
  } else {
217
15.6k
    for (col = cinfo->image_width; col > 0; col--) {
218
9.26k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
219
9.26k
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
220
9.26k
      ptr += 4;
221
9.26k
    }
222
6.36k
  }
223
8.16k
  return 1;
224
8.16k
}
225
226
227
1.27M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
228
19.2M
  for (col = cinfo->image_width; col > 0; col--) { \
229
17.9M
    ptr[rindex] = read_op; \
230
17.9M
    ptr[gindex] = read_op; \
231
17.9M
    ptr[bindex] = read_op; \
232
17.9M
    alpha_set_op \
233
17.9M
    ptr += ps; \
234
17.9M
  } \
235
1.27M
}
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
51.4k
{
241
51.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
242
51.4k
  FILE *infile = source->pub.input_file;
243
51.4k
  register _JSAMPROW ptr;
244
51.4k
  register _JSAMPLE *rescale = source->rescale;
245
51.4k
  JDIMENSION col;
246
51.4k
  unsigned int maxval = source->maxval;
247
51.4k
  register int rindex = rgb_red[cinfo->in_color_space];
248
51.4k
  register int gindex = rgb_green[cinfo->in_color_space];
249
51.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
250
51.4k
  register int aindex = alpha_index[cinfo->in_color_space];
251
51.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
252
253
51.4k
  ptr = source->pub._buffer[0];
254
51.4k
  if (maxval == _MAXJSAMPLE) {
255
13.2k
    if (aindex >= 0)
256
2.10k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
257
13.2k
                    ptr[aindex] = _MAXJSAMPLE;)
258
11.1k
    else
259
11.1k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
260
38.2k
  } else {
261
38.2k
    if (aindex >= 0)
262
6.52k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
263
38.2k
                    ptr[aindex] = _MAXJSAMPLE;)
264
31.7k
    else
265
31.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
266
38.2k
  }
267
51.4k
  return 1;
268
51.4k
}
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.84k
    for (col = cinfo->image_width; col > 0; col--) {
286
6.73k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
287
6.73k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
6.73k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
6.73k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
290
6.73k
      ptr += 4;
291
6.73k
    }
292
6.52k
  } else {
293
16.9k
    for (col = cinfo->image_width; col > 0; col--) {
294
10.4k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
295
10.4k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
10.4k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.4k
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
298
10.4k
      ptr += 4;
299
10.4k
    }
300
6.52k
  }
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.2M
{
309
23.2M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
310
23.2M
  register _JSAMPROW ptr;
311
23.2M
  register U_CHAR *bufferptr;
312
23.2M
  register _JSAMPLE *rescale = source->rescale;
313
23.2M
  JDIMENSION col;
314
315
23.2M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
316
362
    ERREXIT(cinfo, JERR_INPUT_EOF);
317
23.2M
  ptr = source->pub._buffer[0];
318
23.2M
  bufferptr = source->iobuffer;
319
99.0M
  for (col = cinfo->image_width; col > 0; col--) {
320
75.7M
    *ptr++ = rescale[UCH(*bufferptr++)];
321
75.7M
  }
322
23.2M
  return 1;
323
23.2M
}
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
134M
{
331
134M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
332
134M
  register _JSAMPROW ptr;
333
134M
  register U_CHAR *bufferptr;
334
134M
  register _JSAMPLE *rescale = source->rescale;
335
134M
  JDIMENSION col;
336
134M
  unsigned int maxval = source->maxval;
337
134M
  register int rindex = rgb_red[cinfo->in_color_space];
338
134M
  register int gindex = rgb_green[cinfo->in_color_space];
339
134M
  register int bindex = rgb_blue[cinfo->in_color_space];
340
134M
  register int aindex = alpha_index[cinfo->in_color_space];
341
134M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
342
343
134M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
344
2.24k
    ERREXIT(cinfo, JERR_INPUT_EOF);
345
134M
  ptr = source->pub._buffer[0];
346
134M
  bufferptr = source->iobuffer;
347
134M
  if (maxval == _MAXJSAMPLE) {
348
17.8M
    if (aindex >= 0)
349
1.84M
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
350
15.9M
    else
351
15.9M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
352
116M
  } else {
353
116M
    if (aindex >= 0)
354
19.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
355
116M
                         ptr[aindex] = _MAXJSAMPLE;)
356
97.3M
    else
357
97.3M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
358
116M
  }
359
134M
  return 1;
360
134M
}
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.9M
{
368
20.9M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
369
20.9M
  register _JSAMPROW ptr;
370
20.9M
  register U_CHAR *bufferptr;
371
20.9M
  register _JSAMPLE *rescale = source->rescale;
372
20.9M
  JDIMENSION col;
373
20.9M
  unsigned int maxval = source->maxval;
374
375
20.9M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
376
365
    ERREXIT(cinfo, JERR_INPUT_EOF);
377
20.9M
  ptr = source->pub._buffer[0];
378
20.9M
  bufferptr = source->iobuffer;
379
20.9M
  if (maxval == _MAXJSAMPLE) {
380
4.29M
    for (col = cinfo->image_width; col > 0; col--) {
381
2.45M
      _JSAMPLE gray = *bufferptr++;
382
2.45M
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
383
2.45M
      ptr += 4;
384
2.45M
    }
385
19.0M
  } else {
386
81.6M
    for (col = cinfo->image_width; col > 0; col--) {
387
62.5M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
388
62.5M
      rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
389
62.5M
      ptr += 4;
390
62.5M
    }
391
19.0M
  }
392
20.9M
  return 1;
393
20.9M
}
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.38k
    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.79k
    if (aindex >= 0)
418
1.78k
      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
199k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = _MAXJSAMPLE;)
424
1.01M
    else
425
1.01M
      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
201k
{
436
201k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
437
201k
  register _JSAMPROW ptr;
438
201k
  register U_CHAR *bufferptr;
439
201k
  register _JSAMPLE *rescale = source->rescale;
440
201k
  JDIMENSION col;
441
201k
  unsigned int maxval = source->maxval;
442
443
201k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
444
600
    ERREXIT(cinfo, JERR_INPUT_EOF);
445
201k
  ptr = source->pub._buffer[0];
446
201k
  bufferptr = source->iobuffer;
447
201k
  if (maxval == _MAXJSAMPLE) {
448
500k
    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
199k
  } else {
456
2.78M
    for (col = cinfo->image_width; col > 0; col--) {
457
2.58M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
458
2.58M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
459
2.58M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
460
2.58M
      rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
461
2.58M
      ptr += 4;
462
2.58M
    }
463
199k
  }
464
201k
  return 1;
465
201k
}
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.56M
{
475
3.56M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
476
477
3.56M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
478
241
    ERREXIT(cinfo, JERR_INPUT_EOF);
479
3.56M
  return 1;
480
3.56M
}
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
201k
{
487
201k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
488
201k
  register _JSAMPROW ptr;
489
201k
  register U_CHAR *bufferptr;
490
201k
  register _JSAMPLE *rescale = source->rescale;
491
201k
  JDIMENSION col;
492
201k
  unsigned int maxval = source->maxval;
493
494
201k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
495
357
    ERREXIT(cinfo, JERR_INPUT_EOF);
496
201k
  ptr = source->pub._buffer[0];
497
201k
  bufferptr = source->iobuffer;
498
1.05M
  for (col = cinfo->image_width; col > 0; col--) {
499
850k
    register unsigned int temp;
500
850k
    temp  = UCH(*bufferptr++) << 8;
501
850k
    temp |= UCH(*bufferptr++);
502
850k
    if (temp > maxval)
503
216
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
504
850k
    *ptr++ = rescale[temp];
505
850k
  }
506
201k
  return 1;
507
201k
}
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
1.00M
{
514
1.00M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
515
1.00M
  register _JSAMPROW ptr;
516
1.00M
  register U_CHAR *bufferptr;
517
1.00M
  register _JSAMPLE *rescale = source->rescale;
518
1.00M
  JDIMENSION col;
519
1.00M
  unsigned int maxval = source->maxval;
520
1.00M
  register int rindex = rgb_red[cinfo->in_color_space];
521
1.00M
  register int gindex = rgb_green[cinfo->in_color_space];
522
1.00M
  register int bindex = rgb_blue[cinfo->in_color_space];
523
1.00M
  register int aindex = alpha_index[cinfo->in_color_space];
524
1.00M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
525
526
1.00M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
527
1.78k
    ERREXIT(cinfo, JERR_INPUT_EOF);
528
1.00M
  ptr = source->pub._buffer[0];
529
1.00M
  bufferptr = source->iobuffer;
530
5.25M
  for (col = cinfo->image_width; col > 0; col--) {
531
4.25M
    register unsigned int temp;
532
4.25M
    temp  = UCH(*bufferptr++) << 8;
533
4.25M
    temp |= UCH(*bufferptr++);
534
4.25M
    if (temp > maxval)
535
1.08k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
536
4.25M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
537
4.25M
    if (aindex >= 0)
538
744k
      ptr[aindex] = _MAXJSAMPLE;
539
4.25M
    ptr += ps;
540
4.25M
  }
541
1.00M
  return 1;
542
1.00M
}
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
300
    ERREXIT(cinfo, JERR_INPUT_EOF);
558
129k
  ptr = source->pub._buffer[0];
559
129k
  bufferptr = source->iobuffer;
560
874k
  for (col = cinfo->image_width; col > 0; col--) {
561
745k
    register unsigned int gray;
562
745k
    gray  = UCH(*bufferptr++) << 8;
563
745k
    gray |= UCH(*bufferptr++);
564
745k
    if (gray > maxval)
565
180
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
566
745k
    rgb_to_cmyk(rescale[gray], rescale[gray], rescale[gray], ptr, ptr + 1,
567
745k
                ptr + 2, ptr + 3);
568
745k
    ptr += 4;
569
745k
  }
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
60.9k
{
578
60.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
579
60.9k
  register _JSAMPROW ptr;
580
60.9k
  register U_CHAR *bufferptr;
581
60.9k
  register _JSAMPLE *rescale = source->rescale;
582
60.9k
  JDIMENSION col;
583
60.9k
  unsigned int maxval = source->maxval;
584
60.9k
  register int rindex = rgb_red[cinfo->in_color_space];
585
60.9k
  register int gindex = rgb_green[cinfo->in_color_space];
586
60.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
587
60.9k
  register int aindex = alpha_index[cinfo->in_color_space];
588
60.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
589
590
60.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
591
2.25k
    ERREXIT(cinfo, JERR_INPUT_EOF);
592
60.9k
  ptr = source->pub._buffer[0];
593
60.9k
  bufferptr = source->iobuffer;
594
157k
  for (col = cinfo->image_width; col > 0; col--) {
595
96.5k
    register unsigned int temp;
596
96.5k
    temp  = UCH(*bufferptr++) << 8;
597
96.5k
    temp |= UCH(*bufferptr++);
598
96.5k
    if (temp > maxval)
599
915
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
600
96.5k
    ptr[rindex] = rescale[temp];
601
96.5k
    temp  = UCH(*bufferptr++) << 8;
602
96.5k
    temp |= UCH(*bufferptr++);
603
96.5k
    if (temp > maxval)
604
660
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
605
96.5k
    ptr[gindex] = rescale[temp];
606
96.5k
    temp  = UCH(*bufferptr++) << 8;
607
96.5k
    temp |= UCH(*bufferptr++);
608
96.5k
    if (temp > maxval)
609
635
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
610
96.5k
    ptr[bindex] = rescale[temp];
611
96.5k
    if (aindex >= 0)
612
17.1k
      ptr[aindex] = _MAXJSAMPLE;
613
96.5k
    ptr += ps;
614
96.5k
  }
615
60.9k
  return 1;
616
60.9k
}
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
401
    ERREXIT(cinfo, JERR_INPUT_EOF);
632
11.0k
  ptr = source->pub._buffer[0];
633
11.0k
  bufferptr = source->iobuffer;
634
28.5k
  for (col = cinfo->image_width; col > 0; col--) {
635
17.5k
    register unsigned int r, g, b;
636
17.5k
    r  = UCH(*bufferptr++) << 8;
637
17.5k
    r |= UCH(*bufferptr++);
638
17.5k
    if (r > maxval)
639
158
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
640
17.5k
    g  = UCH(*bufferptr++) << 8;
641
17.5k
    g |= UCH(*bufferptr++);
642
17.5k
    if (g > maxval)
643
109
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
644
17.5k
    b  = UCH(*bufferptr++) << 8;
645
17.5k
    b |= UCH(*bufferptr++);
646
17.5k
    if (b > maxval)
647
106
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
648
17.5k
    rgb_to_cmyk(rescale[r], rescale[g], rescale[b], ptr, ptr + 1, ptr + 2,
649
17.5k
                ptr + 3);
650
17.5k
    ptr += 4;
651
17.5k
  }
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
89.1k
{
663
89.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
664
89.1k
  int c;
665
89.1k
  unsigned int w, h, maxval;
666
89.1k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
667
668
89.1k
  if (getc(source->pub.input_file) != 'P')
669
0
    ERREXIT(cinfo, JERR_PPM_NOT);
670
671
89.1k
  c = getc(source->pub.input_file); /* subformat discriminator character */
672
673
  /* detect unsupported variants (ie, PBM) before trying to read header */
674
89.1k
  switch (c) {
675
7.81k
  case '2':                     /* it's a text-format PGM file */
676
16.3k
  case '3':                     /* it's a text-format PPM file */
677
69.7k
  case '5':                     /* it's a raw-format PGM file */
678
89.0k
  case '6':                     /* it's a raw-format PPM file */
679
89.0k
    break;
680
41
  default:
681
41
    ERREXIT(cinfo, JERR_PPM_NOT);
682
41
    break;
683
89.1k
  }
684
685
  /* fetch the remaining header info */
686
89.0k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
687
89.0k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
688
89.0k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
689
690
89.0k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
691
199
    ERREXIT(cinfo, JERR_PPM_NOT);
692
89.0k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
693
1.39k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
694
695
89.0k
  cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
696
89.0k
  cinfo->image_width = (JDIMENSION)w;
697
89.0k
  cinfo->image_height = (JDIMENSION)h;
698
89.0k
  source->maxval = maxval;
699
700
  /* initialize flags to most common settings */
701
89.0k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
702
89.0k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
703
89.0k
  need_rescale = TRUE;          /* do we need a rescale array? */
704
705
89.0k
  switch (c) {
706
5.45k
  case '2':                     /* it's a text-format PGM file */
707
5.45k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
708
5.45k
        cinfo->in_color_space == JCS_RGB)
709
0
      cinfo->in_color_space = JCS_GRAYSCALE;
710
5.45k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
711
5.45k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
712
797
      source->pub.get_pixel_rows = get_text_gray_row;
713
4.66k
    else if (IsExtRGB(cinfo->in_color_space))
714
3.98k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
715
677
    else if (cinfo->in_color_space == JCS_CMYK)
716
677
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
717
0
    else
718
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
719
5.45k
    need_iobuffer = FALSE;
720
5.45k
    break;
721
722
6.75k
  case '3':                     /* it's a text-format PPM file */
723
6.75k
    if (cinfo->in_color_space == JCS_UNKNOWN)
724
0
      cinfo->in_color_space = JCS_EXT_RGB;
725
6.75k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
726
6.75k
    if (IsExtRGB(cinfo->in_color_space))
727
4.91k
      source->pub.get_pixel_rows = get_text_rgb_row;
728
1.83k
    else if (cinfo->in_color_space == JCS_CMYK)
729
856
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
730
983
    else
731
983
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
732
6.75k
    need_iobuffer = FALSE;
733
6.75k
    break;
734
735
51.0k
  case '5':                     /* it's a raw-format PGM file */
736
51.0k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
737
51.0k
        cinfo->in_color_space == JCS_RGB)
738
0
      cinfo->in_color_space = JCS_GRAYSCALE;
739
51.0k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
740
51.0k
    if (maxval > 255) {
741
4.41k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
742
645
        source->pub.get_pixel_rows = get_word_gray_row;
743
3.77k
      else if (IsExtRGB(cinfo->in_color_space))
744
3.22k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
745
546
      else if (cinfo->in_color_space == JCS_CMYK)
746
546
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
747
0
      else
748
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
749
46.6k
    } else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
750
3.12k
               cinfo->in_color_space == JCS_GRAYSCALE) {
751
475
      source->pub.get_pixel_rows = get_raw_row;
752
475
      use_raw_buffer = TRUE;
753
475
      need_rescale = FALSE;
754
46.1k
    } else {
755
46.1k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
756
6.42k
        source->pub.get_pixel_rows = get_scaled_gray_row;
757
39.7k
      else if (IsExtRGB(cinfo->in_color_space))
758
34.5k
        source->pub.get_pixel_rows = get_gray_rgb_row;
759
5.20k
      else if (cinfo->in_color_space == JCS_CMYK)
760
5.20k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
761
0
      else
762
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
763
46.1k
    }
764
51.0k
    break;
765
766
17.6k
  case '6':                     /* it's a raw-format PPM file */
767
17.6k
    if (cinfo->in_color_space == JCS_UNKNOWN)
768
0
      cinfo->in_color_space = JCS_EXT_RGB;
769
17.6k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
770
17.6k
    if (maxval > 255) {
771
6.40k
      if (IsExtRGB(cinfo->in_color_space))
772
4.66k
        source->pub.get_pixel_rows = get_word_rgb_row;
773
1.74k
      else if (cinfo->in_color_space == JCS_CMYK)
774
813
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
775
932
      else
776
932
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
777
11.2k
    } else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
778
1.45k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
779
1.45k
               (cinfo->in_color_space == JCS_EXT_RGB ||
780
1.23k
                cinfo->in_color_space == JCS_RGB)) {
781
#else
782
               cinfo->in_color_space == JCS_EXT_RGB) {
783
#endif
784
215
      source->pub.get_pixel_rows = get_raw_row;
785
215
      use_raw_buffer = TRUE;
786
215
      need_rescale = FALSE;
787
11.0k
    } else {
788
11.0k
      if (IsExtRGB(cinfo->in_color_space))
789
8.07k
        source->pub.get_pixel_rows = get_rgb_row;
790
2.99k
      else if (cinfo->in_color_space == JCS_CMYK)
791
1.34k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
792
1.65k
      else
793
1.65k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
794
11.0k
    }
795
17.6k
    break;
796
89.0k
  }
797
798
77.3k
  if (IsExtRGB(cinfo->in_color_space))
799
59.5k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
800
17.7k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
801
8.34k
    cinfo->input_components = 1;
802
9.44k
  else if (cinfo->in_color_space == JCS_CMYK)
803
9.44k
    cinfo->input_components = 4;
804
805
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
806
77.3k
  if (need_iobuffer) {
807
66.1k
    if (c == '6')
808
15.0k
      source->buffer_width = (size_t)w * 3 *
809
15.0k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
810
51.0k
    else
811
51.0k
      source->buffer_width = (size_t)w *
812
51.0k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
813
66.1k
    source->iobuffer = (U_CHAR *)
814
66.1k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
815
66.1k
                                  source->buffer_width);
816
66.1k
  }
817
818
  /* Create compressor input buffer. */
819
77.3k
  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
690
    source->pixrow = (_JSAMPROW)source->iobuffer;
823
690
    source->pub._buffer = &source->pixrow;
824
690
    source->pub.buffer_height = 1;
825
76.6k
  } else {
826
    /* Need to translate anyway, so make a separate sample buffer. */
827
76.6k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
828
76.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
829
76.6k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
830
76.6k
    source->pub.buffer_height = 1;
831
76.6k
  }
832
833
  /* Compute the rescaling array if required. */
834
77.3k
  if (need_rescale) {
835
76.6k
    long val, half_maxval;
836
837
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
838
76.6k
    source->rescale = (_JSAMPLE *)
839
76.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
840
76.6k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
841
76.6k
                                           sizeof(_JSAMPLE)));
842
76.6k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
843
76.6k
                                        sizeof(_JSAMPLE)));
844
76.6k
    half_maxval = maxval / 2;
845
214M
    for (val = 0; val <= (long)maxval; val++) {
846
      /* The multiplication here must be done in 32 bits to avoid overflow */
847
214M
      source->rescale[val] = (_JSAMPLE)((val * _MAXJSAMPLE + half_maxval) /
848
214M
                                        maxval);
849
214M
    }
850
76.6k
  }
851
77.3k
}
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
50.6k
{
861
  /* no work */
862
50.6k
}
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
89.1k
{
872
89.1k
  ppm_source_ptr source;
873
874
89.1k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
875
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
876
877
  /* Create module interface object */
878
89.1k
  source = (ppm_source_ptr)
879
89.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
89.1k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
89.1k
  source->pub.start_input = start_input_ppm;
883
89.1k
  source->pub.finish_input = finish_input_ppm;
884
89.1k
  source->pub.max_pixels = 0;
885
886
89.1k
  return (cjpeg_source_ptr)source;
887
89.1k
}
jinit_read_ppm
Line
Count
Source
871
47.7k
{
872
47.7k
  ppm_source_ptr source;
873
874
47.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
47.7k
  source = (ppm_source_ptr)
879
47.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
47.7k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
47.7k
  source->pub.start_input = start_input_ppm;
883
47.7k
  source->pub.finish_input = finish_input_ppm;
884
47.7k
  source->pub.max_pixels = 0;
885
886
47.7k
  return (cjpeg_source_ptr)source;
887
47.7k
}
j12init_read_ppm
Line
Count
Source
871
30.7k
{
872
30.7k
  ppm_source_ptr source;
873
874
30.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
30.7k
  source = (ppm_source_ptr)
879
30.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
30.7k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
30.7k
  source->pub.start_input = start_input_ppm;
883
30.7k
  source->pub.finish_input = finish_input_ppm;
884
30.7k
  source->pub.max_pixels = 0;
885
886
30.7k
  return (cjpeg_source_ptr)source;
887
30.7k
}
j16init_read_ppm
Line
Count
Source
871
10.6k
{
872
10.6k
  ppm_source_ptr source;
873
874
10.6k
  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.6k
  source = (ppm_source_ptr)
879
10.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
880
10.6k
                                sizeof(ppm_source_struct));
881
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
882
10.6k
  source->pub.start_input = start_input_ppm;
883
10.6k
  source->pub.finish_input = finish_input_ppm;
884
10.6k
  source->pub.max_pixels = 0;
885
886
10.6k
  return (cjpeg_source_ptr)source;
887
10.6k
}
888
889
#endif /* defined(PPM_SUPPORTED) &&
890
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */