Coverage Report

Created: 2026-05-11 07:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.1.x/src/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-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
243M
  (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
3.95M
{
74
3.95M
  register int ch;
75
76
3.95M
  ch = getc(infile);
77
3.95M
  if (ch == '#') {
78
669k
    do {
79
669k
      ch = getc(infile);
80
669k
    } while (ch != '\n' && ch != EOF);
81
59.5k
  }
82
3.95M
  return ch;
83
3.95M
}
rdppm-8.c:pbm_getc
Line
Count
Source
73
1.93M
{
74
1.93M
  register int ch;
75
76
1.93M
  ch = getc(infile);
77
1.93M
  if (ch == '#') {
78
356k
    do {
79
356k
      ch = getc(infile);
80
356k
    } while (ch != '\n' && ch != EOF);
81
30.5k
  }
82
1.93M
  return ch;
83
1.93M
}
rdppm-12.c:pbm_getc
Line
Count
Source
73
1.32M
{
74
1.32M
  register int ch;
75
76
1.32M
  ch = getc(infile);
77
1.32M
  if (ch == '#') {
78
216k
    do {
79
216k
      ch = getc(infile);
80
216k
    } while (ch != '\n' && ch != EOF);
81
19.5k
  }
82
1.32M
  return ch;
83
1.32M
}
rdppm-16.c:pbm_getc
Line
Count
Source
73
694k
{
74
694k
  register int ch;
75
76
694k
  ch = getc(infile);
77
694k
  if (ch == '#') {
78
96.3k
    do {
79
96.3k
      ch = getc(infile);
80
96.3k
    } while (ch != '\n' && ch != EOF);
81
9.47k
  }
82
694k
  return ch;
83
694k
}
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
1.60M
{
93
1.60M
  register int ch;
94
1.60M
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
1.79M
  do {
98
1.79M
    ch = pbm_getc(infile);
99
1.79M
    if (ch == EOF)
100
35.5k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
1.79M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
1.60M
  if (ch < '0' || ch > '9')
104
3.96k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
1.60M
  val = ch - '0';
107
2.19M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
588k
    val *= 10;
109
588k
    val += ch - '0';
110
588k
    if (val > maxval)
111
1.75k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
588k
  }
113
114
1.60M
  return val;
115
1.60M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
92
786k
{
93
786k
  register int ch;
94
786k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
877k
  do {
98
877k
    ch = pbm_getc(infile);
99
877k
    if (ch == EOF)
100
16.9k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
877k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
786k
  if (ch < '0' || ch > '9')
104
1.89k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
786k
  val = ch - '0';
107
1.07M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
290k
    val *= 10;
109
290k
    val += ch - '0';
110
290k
    if (val > maxval)
111
921
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
290k
  }
113
114
786k
  return val;
115
786k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
92
533k
{
93
533k
  register int ch;
94
533k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
596k
  do {
98
596k
    ch = pbm_getc(infile);
99
596k
    if (ch == EOF)
100
11.9k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
596k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
533k
  if (ch < '0' || ch > '9')
104
1.51k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
533k
  val = ch - '0';
107
737k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
204k
    val *= 10;
109
204k
    val += ch - '0';
110
204k
    if (val > maxval)
111
553
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
204k
  }
113
114
533k
  return val;
115
533k
}
rdppm-16.c:read_pbm_integer
Line
Count
Source
92
288k
{
93
288k
  register int ch;
94
288k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
320k
  do {
98
320k
    ch = pbm_getc(infile);
99
320k
    if (ch == EOF)
100
6.61k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
320k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
288k
  if (ch < '0' || ch > '9')
104
557
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
288k
  val = ch - '0';
107
381k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
93.0k
    val *= 10;
109
93.0k
    val += ch - '0';
110
93.0k
    if (val > maxval)
111
279
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
93.0k
  }
113
114
288k
  return val;
115
288k
}
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 cinfo->data_precision.
123
 *
124
 * A really fast path is provided for reading byte/sample raw files with
125
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U,
126
 * which is the normal case for 8-bit data.
127
 */
128
129
130
METHODDEF(JDIMENSION)
131
get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
132
/* This version is for reading text-format PGM files with any maxval */
133
22.2k
{
134
22.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
22.2k
  FILE *infile = source->pub.input_file;
136
22.2k
  register _JSAMPROW ptr;
137
22.2k
  register _JSAMPLE *rescale = source->rescale;
138
22.2k
  JDIMENSION col;
139
22.2k
  unsigned int maxval = source->maxval;
140
141
22.2k
  ptr = source->pub._buffer[0];
142
62.0k
  for (col = cinfo->image_width; col > 0; col--) {
143
39.8k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
39.8k
  }
145
22.2k
  return 1;
146
22.2k
}
rdppm-8.c:get_text_gray_row
Line
Count
Source
133
11.2k
{
134
11.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
11.2k
  FILE *infile = source->pub.input_file;
136
11.2k
  register _JSAMPROW ptr;
137
11.2k
  register _JSAMPLE *rescale = source->rescale;
138
11.2k
  JDIMENSION col;
139
11.2k
  unsigned int maxval = source->maxval;
140
141
11.2k
  ptr = source->pub._buffer[0];
142
32.4k
  for (col = cinfo->image_width; col > 0; col--) {
143
21.2k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
21.2k
  }
145
11.2k
  return 1;
146
11.2k
}
rdppm-12.c:get_text_gray_row
Line
Count
Source
133
7.29k
{
134
7.29k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
7.29k
  FILE *infile = source->pub.input_file;
136
7.29k
  register _JSAMPROW ptr;
137
7.29k
  register _JSAMPLE *rescale = source->rescale;
138
7.29k
  JDIMENSION col;
139
7.29k
  unsigned int maxval = source->maxval;
140
141
7.29k
  ptr = source->pub._buffer[0];
142
18.8k
  for (col = cinfo->image_width; col > 0; col--) {
143
11.5k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
11.5k
  }
145
7.29k
  return 1;
146
7.29k
}
rdppm-16.c:get_text_gray_row
Line
Count
Source
133
3.73k
{
134
3.73k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
3.73k
  FILE *infile = source->pub.input_file;
136
3.73k
  register _JSAMPROW ptr;
137
3.73k
  register _JSAMPLE *rescale = source->rescale;
138
3.73k
  JDIMENSION col;
139
3.73k
  unsigned int maxval = source->maxval;
140
141
3.73k
  ptr = source->pub._buffer[0];
142
10.7k
  for (col = cinfo->image_width; col > 0; col--) {
143
6.98k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
6.98k
  }
145
3.73k
  return 1;
146
3.73k
}
147
148
149
173M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
150
937M
  for (col = cinfo->image_width; col > 0; col--) { \
151
764M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
152
764M
    alpha_set_op \
153
764M
    ptr += ps; \
154
764M
  } \
155
173M
}
156
157
METHODDEF(JDIMENSION)
158
get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
159
/* This version is for reading text-format PGM files with any maxval and
160
   converting to extended RGB */
161
106k
{
162
106k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
106k
  FILE *infile = source->pub.input_file;
164
106k
  register _JSAMPROW ptr;
165
106k
  register _JSAMPLE *rescale = source->rescale;
166
106k
  JDIMENSION col;
167
106k
  unsigned int maxval = source->maxval;
168
106k
  register int rindex = rgb_red[cinfo->in_color_space];
169
106k
  register int gindex = rgb_green[cinfo->in_color_space];
170
106k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
106k
  register int aindex = alpha_index[cinfo->in_color_space];
172
106k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
106k
  ptr = source->pub._buffer[0];
175
106k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
19.4k
    if (aindex >= 0)
177
3.14k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
19.4k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
16.3k
    else
180
16.3k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
86.9k
  } else {
182
86.9k
    if (aindex >= 0)
183
14.6k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
86.9k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
72.3k
    else
186
72.3k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
86.9k
  }
188
106k
  return 1;
189
106k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
161
51.3k
{
162
51.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
51.3k
  FILE *infile = source->pub.input_file;
164
51.3k
  register _JSAMPROW ptr;
165
51.3k
  register _JSAMPLE *rescale = source->rescale;
166
51.3k
  JDIMENSION col;
167
51.3k
  unsigned int maxval = source->maxval;
168
51.3k
  register int rindex = rgb_red[cinfo->in_color_space];
169
51.3k
  register int gindex = rgb_green[cinfo->in_color_space];
170
51.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
51.3k
  register int aindex = alpha_index[cinfo->in_color_space];
172
51.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
51.3k
  ptr = source->pub._buffer[0];
175
51.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
10.4k
    if (aindex >= 0)
177
1.53k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
10.4k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
8.87k
    else
180
8.87k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
40.8k
  } else {
182
40.8k
    if (aindex >= 0)
183
5.21k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
40.8k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
35.6k
    else
186
35.6k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
40.8k
  }
188
51.3k
  return 1;
189
51.3k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
161
36.4k
{
162
36.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
36.4k
  FILE *infile = source->pub.input_file;
164
36.4k
  register _JSAMPROW ptr;
165
36.4k
  register _JSAMPLE *rescale = source->rescale;
166
36.4k
  JDIMENSION col;
167
36.4k
  unsigned int maxval = source->maxval;
168
36.4k
  register int rindex = rgb_red[cinfo->in_color_space];
169
36.4k
  register int gindex = rgb_green[cinfo->in_color_space];
170
36.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
36.4k
  register int aindex = alpha_index[cinfo->in_color_space];
172
36.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
36.4k
  ptr = source->pub._buffer[0];
175
36.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
6.40k
    if (aindex >= 0)
177
1.17k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
6.40k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
5.22k
    else
180
5.22k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
30.0k
  } else {
182
30.0k
    if (aindex >= 0)
183
6.11k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
30.0k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
23.9k
    else
186
23.9k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
30.0k
  }
188
36.4k
  return 1;
189
36.4k
}
rdppm-16.c:get_text_gray_rgb_row
Line
Count
Source
161
18.6k
{
162
18.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
18.6k
  FILE *infile = source->pub.input_file;
164
18.6k
  register _JSAMPROW ptr;
165
18.6k
  register _JSAMPLE *rescale = source->rescale;
166
18.6k
  JDIMENSION col;
167
18.6k
  unsigned int maxval = source->maxval;
168
18.6k
  register int rindex = rgb_red[cinfo->in_color_space];
169
18.6k
  register int gindex = rgb_green[cinfo->in_color_space];
170
18.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
18.6k
  register int aindex = alpha_index[cinfo->in_color_space];
172
18.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
18.6k
  ptr = source->pub._buffer[0];
175
18.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
2.66k
    if (aindex >= 0)
177
431
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
2.66k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
2.23k
    else
180
2.23k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
16.0k
  } else {
182
16.0k
    if (aindex >= 0)
183
3.30k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
16.0k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
12.7k
    else
186
12.7k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
16.0k
  }
188
18.6k
  return 1;
189
18.6k
}
190
191
192
METHODDEF(JDIMENSION)
193
get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
194
/* This version is for reading text-format PGM files with any maxval and
195
   converting to CMYK */
196
17.7k
{
197
17.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
17.7k
  FILE *infile = source->pub.input_file;
199
17.7k
  register _JSAMPROW ptr;
200
17.7k
  register _JSAMPLE *rescale = source->rescale;
201
17.7k
  JDIMENSION col;
202
17.7k
  unsigned int maxval = source->maxval;
203
204
17.7k
  ptr = source->pub._buffer[0];
205
17.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
14.1k
    for (col = cinfo->image_width; col > 0; col--) {
207
9.17k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
9.17k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
9.17k
      ptr += 4;
210
9.17k
    }
211
12.8k
  } else {
212
35.6k
    for (col = cinfo->image_width; col > 0; col--) {
213
22.8k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
22.8k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
22.8k
                  ptr + 1, ptr + 2, ptr + 3);
216
22.8k
      ptr += 4;
217
22.8k
    }
218
12.8k
  }
219
17.7k
  return 1;
220
17.7k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
196
6.75k
{
197
6.75k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
6.75k
  FILE *infile = source->pub.input_file;
199
6.75k
  register _JSAMPROW ptr;
200
6.75k
  register _JSAMPLE *rescale = source->rescale;
201
6.75k
  JDIMENSION col;
202
6.75k
  unsigned int maxval = source->maxval;
203
204
6.75k
  ptr = source->pub._buffer[0];
205
6.75k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
6.53k
    for (col = cinfo->image_width; col > 0; col--) {
207
4.22k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
4.22k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
4.22k
      ptr += 4;
210
4.22k
    }
211
4.44k
  } else {
212
13.6k
    for (col = cinfo->image_width; col > 0; col--) {
213
9.24k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
9.24k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
9.24k
                  ptr + 1, ptr + 2, ptr + 3);
216
9.24k
      ptr += 4;
217
9.24k
    }
218
4.44k
  }
219
6.75k
  return 1;
220
6.75k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
196
7.29k
{
197
7.29k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
7.29k
  FILE *infile = source->pub.input_file;
199
7.29k
  register _JSAMPROW ptr;
200
7.29k
  register _JSAMPLE *rescale = source->rescale;
201
7.29k
  JDIMENSION col;
202
7.29k
  unsigned int maxval = source->maxval;
203
204
7.29k
  ptr = source->pub._buffer[0];
205
7.29k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
4.84k
    for (col = cinfo->image_width; col > 0; col--) {
207
3.14k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
3.14k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
3.14k
      ptr += 4;
210
3.14k
    }
211
5.59k
  } else {
212
14.0k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.44k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
8.44k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
8.44k
                  ptr + 1, ptr + 2, ptr + 3);
216
8.44k
      ptr += 4;
217
8.44k
    }
218
5.59k
  }
219
7.29k
  return 1;
220
7.29k
}
rdppm-16.c:get_text_gray_cmyk_row
Line
Count
Source
196
3.73k
{
197
3.73k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
3.73k
  FILE *infile = source->pub.input_file;
199
3.73k
  register _JSAMPROW ptr;
200
3.73k
  register _JSAMPLE *rescale = source->rescale;
201
3.73k
  JDIMENSION col;
202
3.73k
  unsigned int maxval = source->maxval;
203
204
3.73k
  ptr = source->pub._buffer[0];
205
3.73k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
2.74k
    for (col = cinfo->image_width; col > 0; col--) {
207
1.81k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
1.81k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
1.81k
      ptr += 4;
210
1.81k
    }
211
2.80k
  } else {
212
7.97k
    for (col = cinfo->image_width; col > 0; col--) {
213
5.17k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
5.17k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
5.17k
                  ptr + 1, ptr + 2, ptr + 3);
216
5.17k
      ptr += 4;
217
5.17k
    }
218
2.80k
  }
219
3.73k
  return 1;
220
3.73k
}
221
222
223
8.24M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
224
72.7M
  for (col = cinfo->image_width; col > 0; col--) { \
225
64.4M
    ptr[rindex] = read_op; \
226
64.4M
    ptr[gindex] = read_op; \
227
64.4M
    ptr[bindex] = read_op; \
228
64.4M
    alpha_set_op \
229
64.4M
    ptr += ps; \
230
64.4M
  } \
231
8.24M
}
232
233
METHODDEF(JDIMENSION)
234
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
235
/* This version is for reading text-format PPM files with any maxval */
236
119k
{
237
119k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
119k
  FILE *infile = source->pub.input_file;
239
119k
  register _JSAMPROW ptr;
240
119k
  register _JSAMPLE *rescale = source->rescale;
241
119k
  JDIMENSION col;
242
119k
  unsigned int maxval = source->maxval;
243
119k
  register int rindex = rgb_red[cinfo->in_color_space];
244
119k
  register int gindex = rgb_green[cinfo->in_color_space];
245
119k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
119k
  register int aindex = alpha_index[cinfo->in_color_space];
247
119k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
119k
  ptr = source->pub._buffer[0];
250
119k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
25.4k
    if (aindex >= 0)
252
4.48k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
25.4k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
20.9k
    else
255
20.9k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
93.8k
  } else {
257
93.8k
    if (aindex >= 0)
258
15.6k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
93.8k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
78.2k
    else
261
78.2k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
93.8k
  }
263
119k
  return 1;
264
119k
}
rdppm-8.c:get_text_rgb_row
Line
Count
Source
236
57.2k
{
237
57.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
57.2k
  FILE *infile = source->pub.input_file;
239
57.2k
  register _JSAMPROW ptr;
240
57.2k
  register _JSAMPLE *rescale = source->rescale;
241
57.2k
  JDIMENSION col;
242
57.2k
  unsigned int maxval = source->maxval;
243
57.2k
  register int rindex = rgb_red[cinfo->in_color_space];
244
57.2k
  register int gindex = rgb_green[cinfo->in_color_space];
245
57.2k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
57.2k
  register int aindex = alpha_index[cinfo->in_color_space];
247
57.2k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
57.2k
  ptr = source->pub._buffer[0];
250
57.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
11.7k
    if (aindex >= 0)
252
1.53k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
11.7k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
10.1k
    else
255
10.1k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
45.5k
  } else {
257
45.5k
    if (aindex >= 0)
258
6.18k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
45.5k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
39.3k
    else
261
39.3k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
45.5k
  }
263
57.2k
  return 1;
264
57.2k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
236
36.8k
{
237
36.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
36.8k
  FILE *infile = source->pub.input_file;
239
36.8k
  register _JSAMPROW ptr;
240
36.8k
  register _JSAMPLE *rescale = source->rescale;
241
36.8k
  JDIMENSION col;
242
36.8k
  unsigned int maxval = source->maxval;
243
36.8k
  register int rindex = rgb_red[cinfo->in_color_space];
244
36.8k
  register int gindex = rgb_green[cinfo->in_color_space];
245
36.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
36.8k
  register int aindex = alpha_index[cinfo->in_color_space];
247
36.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
36.8k
  ptr = source->pub._buffer[0];
250
36.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
9.49k
    if (aindex >= 0)
252
1.90k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
9.49k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
7.59k
    else
255
7.59k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
27.3k
  } else {
257
27.3k
    if (aindex >= 0)
258
5.47k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
27.3k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
21.9k
    else
261
21.9k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
27.3k
  }
263
36.8k
  return 1;
264
36.8k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
236
25.1k
{
237
25.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
25.1k
  FILE *infile = source->pub.input_file;
239
25.1k
  register _JSAMPROW ptr;
240
25.1k
  register _JSAMPLE *rescale = source->rescale;
241
25.1k
  JDIMENSION col;
242
25.1k
  unsigned int maxval = source->maxval;
243
25.1k
  register int rindex = rgb_red[cinfo->in_color_space];
244
25.1k
  register int gindex = rgb_green[cinfo->in_color_space];
245
25.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
25.1k
  register int aindex = alpha_index[cinfo->in_color_space];
247
25.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
25.1k
  ptr = source->pub._buffer[0];
250
25.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
4.19k
    if (aindex >= 0)
252
1.03k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
4.19k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
3.15k
    else
255
3.15k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
20.9k
  } else {
257
20.9k
    if (aindex >= 0)
258
3.98k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
20.9k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
16.9k
    else
261
16.9k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
20.9k
  }
263
25.1k
  return 1;
264
25.1k
}
265
266
267
METHODDEF(JDIMENSION)
268
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
269
/* This version is for reading text-format PPM files with any maxval and
270
   converting to CMYK */
271
20.1k
{
272
20.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
20.1k
  FILE *infile = source->pub.input_file;
274
20.1k
  register _JSAMPROW ptr;
275
20.1k
  register _JSAMPLE *rescale = source->rescale;
276
20.1k
  JDIMENSION col;
277
20.1k
  unsigned int maxval = source->maxval;
278
279
20.1k
  ptr = source->pub._buffer[0];
280
20.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
21.3k
    for (col = cinfo->image_width; col > 0; col--) {
282
15.4k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
15.4k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
15.4k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
15.4k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
15.4k
      ptr += 4;
287
15.4k
    }
288
14.1k
  } else {
289
40.5k
    for (col = cinfo->image_width; col > 0; col--) {
290
26.4k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
26.4k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
26.4k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
26.4k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
26.4k
                  ptr + 2, ptr + 3);
295
26.4k
      ptr += 4;
296
26.4k
    }
297
14.1k
  }
298
20.1k
  return 1;
299
20.1k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
271
7.72k
{
272
7.72k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
7.72k
  FILE *infile = source->pub.input_file;
274
7.72k
  register _JSAMPROW ptr;
275
7.72k
  register _JSAMPLE *rescale = source->rescale;
276
7.72k
  JDIMENSION col;
277
7.72k
  unsigned int maxval = source->maxval;
278
279
7.72k
  ptr = source->pub._buffer[0];
280
7.72k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
8.25k
    for (col = cinfo->image_width; col > 0; col--) {
282
6.01k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
6.01k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
6.01k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
6.01k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
6.01k
      ptr += 4;
287
6.01k
    }
288
5.48k
  } else {
289
16.0k
    for (col = cinfo->image_width; col > 0; col--) {
290
10.6k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
10.6k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
10.6k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
10.6k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
10.6k
                  ptr + 2, ptr + 3);
295
10.6k
      ptr += 4;
296
10.6k
    }
297
5.48k
  }
298
7.72k
  return 1;
299
7.72k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
271
7.37k
{
272
7.37k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
7.37k
  FILE *infile = source->pub.input_file;
274
7.37k
  register _JSAMPROW ptr;
275
7.37k
  register _JSAMPLE *rescale = source->rescale;
276
7.37k
  JDIMENSION col;
277
7.37k
  unsigned int maxval = source->maxval;
278
279
7.37k
  ptr = source->pub._buffer[0];
280
7.37k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
8.47k
    for (col = cinfo->image_width; col > 0; col--) {
282
6.07k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
6.07k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
6.07k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
6.07k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
6.07k
      ptr += 4;
287
6.07k
    }
288
4.97k
  } else {
289
14.5k
    for (col = cinfo->image_width; col > 0; col--) {
290
9.59k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
9.59k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
9.59k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
9.59k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
9.59k
                  ptr + 2, ptr + 3);
295
9.59k
      ptr += 4;
296
9.59k
    }
297
4.97k
  }
298
7.37k
  return 1;
299
7.37k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
271
5.02k
{
272
5.02k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
5.02k
  FILE *infile = source->pub.input_file;
274
5.02k
  register _JSAMPROW ptr;
275
5.02k
  register _JSAMPLE *rescale = source->rescale;
276
5.02k
  JDIMENSION col;
277
5.02k
  unsigned int maxval = source->maxval;
278
279
5.02k
  ptr = source->pub._buffer[0];
280
5.02k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
4.64k
    for (col = cinfo->image_width; col > 0; col--) {
282
3.32k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
3.32k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
3.32k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
3.32k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
3.32k
      ptr += 4;
287
3.32k
    }
288
3.70k
  } else {
289
9.92k
    for (col = cinfo->image_width; col > 0; col--) {
290
6.21k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
6.21k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
6.21k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
6.21k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
6.21k
                  ptr + 2, ptr + 3);
295
6.21k
      ptr += 4;
296
6.21k
    }
297
3.70k
  }
298
5.02k
  return 1;
299
5.02k
}
300
301
302
METHODDEF(JDIMENSION)
303
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
304
/* This version is for reading raw-byte-format PGM files with any maxval */
305
32.3M
{
306
32.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
32.3M
  register _JSAMPROW ptr;
308
32.3M
  register unsigned char *bufferptr;
309
32.3M
  register _JSAMPLE *rescale = source->rescale;
310
32.3M
  JDIMENSION col;
311
312
32.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
1.45k
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
32.3M
  ptr = source->pub._buffer[0];
315
32.3M
  bufferptr = source->iobuffer;
316
175M
  for (col = cinfo->image_width; col > 0; col--) {
317
143M
    *ptr++ = rescale[*bufferptr++];
318
143M
  }
319
32.3M
  return 1;
320
32.3M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
305
16.8M
{
306
16.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
16.8M
  register _JSAMPROW ptr;
308
16.8M
  register unsigned char *bufferptr;
309
16.8M
  register _JSAMPLE *rescale = source->rescale;
310
16.8M
  JDIMENSION col;
311
312
16.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
983
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
16.8M
  ptr = source->pub._buffer[0];
315
16.8M
  bufferptr = source->iobuffer;
316
86.6M
  for (col = cinfo->image_width; col > 0; col--) {
317
69.8M
    *ptr++ = rescale[*bufferptr++];
318
69.8M
  }
319
16.8M
  return 1;
320
16.8M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
305
11.6M
{
306
11.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
11.6M
  register _JSAMPROW ptr;
308
11.6M
  register unsigned char *bufferptr;
309
11.6M
  register _JSAMPLE *rescale = source->rescale;
310
11.6M
  JDIMENSION col;
311
312
11.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
320
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
11.6M
  ptr = source->pub._buffer[0];
315
11.6M
  bufferptr = source->iobuffer;
316
64.5M
  for (col = cinfo->image_width; col > 0; col--) {
317
52.8M
    *ptr++ = rescale[*bufferptr++];
318
52.8M
  }
319
11.6M
  return 1;
320
11.6M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
305
3.87M
{
306
3.87M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
3.87M
  register _JSAMPROW ptr;
308
3.87M
  register unsigned char *bufferptr;
309
3.87M
  register _JSAMPLE *rescale = source->rescale;
310
3.87M
  JDIMENSION col;
311
312
3.87M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
150
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
3.87M
  ptr = source->pub._buffer[0];
315
3.87M
  bufferptr = source->iobuffer;
316
24.5M
  for (col = cinfo->image_width; col > 0; col--) {
317
20.6M
    *ptr++ = rescale[*bufferptr++];
318
20.6M
  }
319
3.87M
  return 1;
320
3.87M
}
321
322
323
METHODDEF(JDIMENSION)
324
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
325
/* This version is for reading raw-byte-format PGM files with any maxval
326
   and converting to extended RGB */
327
173M
{
328
173M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
173M
  register _JSAMPROW ptr;
330
173M
  register unsigned char *bufferptr;
331
173M
  register _JSAMPLE *rescale = source->rescale;
332
173M
  JDIMENSION col;
333
173M
  unsigned int maxval = source->maxval;
334
173M
  register int rindex = rgb_red[cinfo->in_color_space];
335
173M
  register int gindex = rgb_green[cinfo->in_color_space];
336
173M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
173M
  register int aindex = alpha_index[cinfo->in_color_space];
338
173M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
173M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
6.06k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
173M
  ptr = source->pub._buffer[0];
343
173M
  bufferptr = source->iobuffer;
344
173M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
11.5M
    if (aindex >= 0)
346
1.31M
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
10.2M
    else
348
10.2M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
161M
  } else {
350
161M
    if (aindex >= 0)
351
23.1M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
161M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
138M
    else
354
138M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
161M
  }
356
173M
  return 1;
357
173M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
327
95.6M
{
328
95.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
95.6M
  register _JSAMPROW ptr;
330
95.6M
  register unsigned char *bufferptr;
331
95.6M
  register _JSAMPLE *rescale = source->rescale;
332
95.6M
  JDIMENSION col;
333
95.6M
  unsigned int maxval = source->maxval;
334
95.6M
  register int rindex = rgb_red[cinfo->in_color_space];
335
95.6M
  register int gindex = rgb_green[cinfo->in_color_space];
336
95.6M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
95.6M
  register int aindex = alpha_index[cinfo->in_color_space];
338
95.6M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
95.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
3.71k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
95.6M
  ptr = source->pub._buffer[0];
343
95.6M
  bufferptr = source->iobuffer;
344
95.6M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
11.5M
    if (aindex >= 0)
346
1.31M
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
10.2M
    else
348
10.2M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
84.0M
  } else {
350
84.0M
    if (aindex >= 0)
351
7.59M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
84.0M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
76.4M
    else
354
76.4M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
84.0M
  }
356
95.6M
  return 1;
357
95.6M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
327
58.3M
{
328
58.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
58.3M
  register _JSAMPROW ptr;
330
58.3M
  register unsigned char *bufferptr;
331
58.3M
  register _JSAMPLE *rescale = source->rescale;
332
58.3M
  JDIMENSION col;
333
58.3M
  unsigned int maxval = source->maxval;
334
58.3M
  register int rindex = rgb_red[cinfo->in_color_space];
335
58.3M
  register int gindex = rgb_green[cinfo->in_color_space];
336
58.3M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
58.3M
  register int aindex = alpha_index[cinfo->in_color_space];
338
58.3M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
58.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
1.60k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
58.3M
  ptr = source->pub._buffer[0];
343
58.3M
  bufferptr = source->iobuffer;
344
58.3M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
0
    if (aindex >= 0)
346
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
0
    else
348
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
58.3M
  } else {
350
58.3M
    if (aindex >= 0)
351
11.6M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
58.3M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
46.6M
    else
354
46.6M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
58.3M
  }
356
58.3M
  return 1;
357
58.3M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
327
19.3M
{
328
19.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
19.3M
  register _JSAMPROW ptr;
330
19.3M
  register unsigned char *bufferptr;
331
19.3M
  register _JSAMPLE *rescale = source->rescale;
332
19.3M
  JDIMENSION col;
333
19.3M
  unsigned int maxval = source->maxval;
334
19.3M
  register int rindex = rgb_red[cinfo->in_color_space];
335
19.3M
  register int gindex = rgb_green[cinfo->in_color_space];
336
19.3M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
19.3M
  register int aindex = alpha_index[cinfo->in_color_space];
338
19.3M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
19.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
750
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
19.3M
  ptr = source->pub._buffer[0];
343
19.3M
  bufferptr = source->iobuffer;
344
19.3M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
0
    if (aindex >= 0)
346
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
0
    else
348
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
19.3M
  } else {
350
19.3M
    if (aindex >= 0)
351
3.87M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
19.3M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
15.5M
    else
354
15.5M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
19.3M
  }
356
19.3M
  return 1;
357
19.3M
}
358
359
360
METHODDEF(JDIMENSION)
361
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
362
/* This version is for reading raw-byte-format PGM files with any maxval
363
   and converting to CMYK */
364
24.4M
{
365
24.4M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
24.4M
  register _JSAMPROW ptr;
367
24.4M
  register unsigned char *bufferptr;
368
24.4M
  register _JSAMPLE *rescale = source->rescale;
369
24.4M
  JDIMENSION col;
370
24.4M
  unsigned int maxval = source->maxval;
371
372
24.4M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
1.00k
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
24.4M
  ptr = source->pub._buffer[0];
375
24.4M
  bufferptr = source->iobuffer;
376
24.4M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
10.4M
    for (col = cinfo->image_width; col > 0; col--) {
378
8.70M
      _JSAMPLE gray = *bufferptr++;
379
8.70M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
8.70M
      ptr += 4;
381
8.70M
    }
382
22.7M
  } else {
383
139M
    for (col = cinfo->image_width; col > 0; col--) {
384
116M
      _JSAMPLE gray = rescale[*bufferptr++];
385
116M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
116M
                  ptr + 1, ptr + 2, ptr + 3);
387
116M
      ptr += 4;
388
116M
    }
389
22.7M
  }
390
24.4M
  return 1;
391
24.4M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
364
8.90M
{
365
8.90M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
8.90M
  register _JSAMPROW ptr;
367
8.90M
  register unsigned char *bufferptr;
368
8.90M
  register _JSAMPLE *rescale = source->rescale;
369
8.90M
  JDIMENSION col;
370
8.90M
  unsigned int maxval = source->maxval;
371
372
8.90M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
532
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
8.90M
  ptr = source->pub._buffer[0];
375
8.90M
  bufferptr = source->iobuffer;
376
8.90M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
10.4M
    for (col = cinfo->image_width; col > 0; col--) {
378
8.70M
      _JSAMPLE gray = *bufferptr++;
379
8.70M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
8.70M
      ptr += 4;
381
8.70M
    }
382
7.17M
  } else {
383
50.2M
    for (col = cinfo->image_width; col > 0; col--) {
384
43.0M
      _JSAMPLE gray = rescale[*bufferptr++];
385
43.0M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
43.0M
                  ptr + 1, ptr + 2, ptr + 3);
387
43.0M
      ptr += 4;
388
43.0M
    }
389
7.17M
  }
390
8.90M
  return 1;
391
8.90M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
364
11.6M
{
365
11.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
11.6M
  register _JSAMPROW ptr;
367
11.6M
  register unsigned char *bufferptr;
368
11.6M
  register _JSAMPLE *rescale = source->rescale;
369
11.6M
  JDIMENSION col;
370
11.6M
  unsigned int maxval = source->maxval;
371
372
11.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
320
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
11.6M
  ptr = source->pub._buffer[0];
375
11.6M
  bufferptr = source->iobuffer;
376
11.6M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
0
    for (col = cinfo->image_width; col > 0; col--) {
378
0
      _JSAMPLE gray = *bufferptr++;
379
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
0
      ptr += 4;
381
0
    }
382
11.6M
  } else {
383
64.5M
    for (col = cinfo->image_width; col > 0; col--) {
384
52.8M
      _JSAMPLE gray = rescale[*bufferptr++];
385
52.8M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
52.8M
                  ptr + 1, ptr + 2, ptr + 3);
387
52.8M
      ptr += 4;
388
52.8M
    }
389
11.6M
  }
390
11.6M
  return 1;
391
11.6M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
364
3.87M
{
365
3.87M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
3.87M
  register _JSAMPROW ptr;
367
3.87M
  register unsigned char *bufferptr;
368
3.87M
  register _JSAMPLE *rescale = source->rescale;
369
3.87M
  JDIMENSION col;
370
3.87M
  unsigned int maxval = source->maxval;
371
372
3.87M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
150
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
3.87M
  ptr = source->pub._buffer[0];
375
3.87M
  bufferptr = source->iobuffer;
376
3.87M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
0
    for (col = cinfo->image_width; col > 0; col--) {
378
0
      _JSAMPLE gray = *bufferptr++;
379
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
0
      ptr += 4;
381
0
    }
382
3.87M
  } else {
383
24.5M
    for (col = cinfo->image_width; col > 0; col--) {
384
20.6M
      _JSAMPLE gray = rescale[*bufferptr++];
385
20.6M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
20.6M
                  ptr + 1, ptr + 2, ptr + 3);
387
20.6M
      ptr += 4;
388
20.6M
    }
389
3.87M
  }
390
3.87M
  return 1;
391
3.87M
}
392
393
394
METHODDEF(JDIMENSION)
395
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
396
/* This version is for reading raw-byte-format PPM files with any maxval */
397
8.12M
{
398
8.12M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
8.12M
  register _JSAMPROW ptr;
400
8.12M
  register unsigned char *bufferptr;
401
8.12M
  register _JSAMPLE *rescale = source->rescale;
402
8.12M
  JDIMENSION col;
403
8.12M
  unsigned int maxval = source->maxval;
404
8.12M
  register int rindex = rgb_red[cinfo->in_color_space];
405
8.12M
  register int gindex = rgb_green[cinfo->in_color_space];
406
8.12M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
8.12M
  register int aindex = alpha_index[cinfo->in_color_space];
408
8.12M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
8.12M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
7.37k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
8.12M
  ptr = source->pub._buffer[0];
413
8.12M
  bufferptr = source->iobuffer;
414
8.12M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
268k
    if (aindex >= 0)
416
59.3k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
209k
    else
418
209k
      RGB_READ_LOOP(*bufferptr++, {})
419
7.85M
  } else {
420
7.85M
    if (aindex >= 0)
421
1.53M
      RGB_READ_LOOP(rescale[*bufferptr++],
422
7.85M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
6.32M
    else
424
6.32M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
7.85M
  }
426
8.12M
  return 1;
427
8.12M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
397
2.65M
{
398
2.65M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
2.65M
  register _JSAMPROW ptr;
400
2.65M
  register unsigned char *bufferptr;
401
2.65M
  register _JSAMPLE *rescale = source->rescale;
402
2.65M
  JDIMENSION col;
403
2.65M
  unsigned int maxval = source->maxval;
404
2.65M
  register int rindex = rgb_red[cinfo->in_color_space];
405
2.65M
  register int gindex = rgb_green[cinfo->in_color_space];
406
2.65M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
2.65M
  register int aindex = alpha_index[cinfo->in_color_space];
408
2.65M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
2.65M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
4.31k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
2.65M
  ptr = source->pub._buffer[0];
413
2.65M
  bufferptr = source->iobuffer;
414
2.65M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
268k
    if (aindex >= 0)
416
59.3k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
209k
    else
418
209k
      RGB_READ_LOOP(*bufferptr++, {})
419
2.38M
  } else {
420
2.38M
    if (aindex >= 0)
421
438k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
2.38M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
1.94M
    else
424
1.94M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
2.38M
  }
426
2.65M
  return 1;
427
2.65M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
397
4.60M
{
398
4.60M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
4.60M
  register _JSAMPROW ptr;
400
4.60M
  register unsigned char *bufferptr;
401
4.60M
  register _JSAMPLE *rescale = source->rescale;
402
4.60M
  JDIMENSION col;
403
4.60M
  unsigned int maxval = source->maxval;
404
4.60M
  register int rindex = rgb_red[cinfo->in_color_space];
405
4.60M
  register int gindex = rgb_green[cinfo->in_color_space];
406
4.60M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
4.60M
  register int aindex = alpha_index[cinfo->in_color_space];
408
4.60M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
4.60M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
1.96k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
4.60M
  ptr = source->pub._buffer[0];
413
4.60M
  bufferptr = source->iobuffer;
414
4.60M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
0
    if (aindex >= 0)
416
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
0
    else
418
0
      RGB_READ_LOOP(*bufferptr++, {})
419
4.60M
  } else {
420
4.60M
    if (aindex >= 0)
421
920k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
4.60M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
3.68M
    else
424
3.68M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
4.60M
  }
426
4.60M
  return 1;
427
4.60M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
397
861k
{
398
861k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
861k
  register _JSAMPROW ptr;
400
861k
  register unsigned char *bufferptr;
401
861k
  register _JSAMPLE *rescale = source->rescale;
402
861k
  JDIMENSION col;
403
861k
  unsigned int maxval = source->maxval;
404
861k
  register int rindex = rgb_red[cinfo->in_color_space];
405
861k
  register int gindex = rgb_green[cinfo->in_color_space];
406
861k
  register int bindex = rgb_blue[cinfo->in_color_space];
407
861k
  register int aindex = alpha_index[cinfo->in_color_space];
408
861k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
861k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
1.10k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
861k
  ptr = source->pub._buffer[0];
413
861k
  bufferptr = source->iobuffer;
414
861k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
0
    if (aindex >= 0)
416
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
0
    else
418
0
      RGB_READ_LOOP(*bufferptr++, {})
419
861k
  } else {
420
861k
    if (aindex >= 0)
421
172k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
861k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
689k
    else
424
689k
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
861k
  }
426
861k
  return 1;
427
861k
}
428
429
430
METHODDEF(JDIMENSION)
431
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
432
/* This version is for reading raw-byte-format PPM files with any maxval and
433
   converting to CMYK */
434
1.59M
{
435
1.59M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
1.59M
  register _JSAMPROW ptr;
437
1.59M
  register unsigned char *bufferptr;
438
1.59M
  register _JSAMPLE *rescale = source->rescale;
439
1.59M
  JDIMENSION col;
440
1.59M
  unsigned int maxval = source->maxval;
441
442
1.59M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
1.26k
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
1.59M
  ptr = source->pub._buffer[0];
445
1.59M
  bufferptr = source->iobuffer;
446
1.59M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
447k
    for (col = cinfo->image_width; col > 0; col--) {
448
385k
      _JSAMPLE r = *bufferptr++;
449
385k
      _JSAMPLE g = *bufferptr++;
450
385k
      _JSAMPLE b = *bufferptr++;
451
385k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
385k
      ptr += 4;
453
385k
    }
454
1.52M
  } else {
455
13.6M
    for (col = cinfo->image_width; col > 0; col--) {
456
12.1M
      _JSAMPLE r = rescale[*bufferptr++];
457
12.1M
      _JSAMPLE g = rescale[*bufferptr++];
458
12.1M
      _JSAMPLE b = rescale[*bufferptr++];
459
12.1M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
12.1M
                  ptr + 2, ptr + 3);
461
12.1M
      ptr += 4;
462
12.1M
    }
463
1.52M
  }
464
1.59M
  return 1;
465
1.59M
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
434
498k
{
435
498k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
498k
  register _JSAMPROW ptr;
437
498k
  register unsigned char *bufferptr;
438
498k
  register _JSAMPLE *rescale = source->rescale;
439
498k
  JDIMENSION col;
440
498k
  unsigned int maxval = source->maxval;
441
442
498k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
652
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
498k
  ptr = source->pub._buffer[0];
445
498k
  bufferptr = source->iobuffer;
446
498k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
447k
    for (col = cinfo->image_width; col > 0; col--) {
448
385k
      _JSAMPLE r = *bufferptr++;
449
385k
      _JSAMPLE g = *bufferptr++;
450
385k
      _JSAMPLE b = *bufferptr++;
451
385k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
385k
      ptr += 4;
453
385k
    }
454
435k
  } else {
455
3.20M
    for (col = cinfo->image_width; col > 0; col--) {
456
2.76M
      _JSAMPLE r = rescale[*bufferptr++];
457
2.76M
      _JSAMPLE g = rescale[*bufferptr++];
458
2.76M
      _JSAMPLE b = rescale[*bufferptr++];
459
2.76M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
2.76M
                  ptr + 2, ptr + 3);
461
2.76M
      ptr += 4;
462
2.76M
    }
463
435k
  }
464
498k
  return 1;
465
498k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
434
921k
{
435
921k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
921k
  register _JSAMPROW ptr;
437
921k
  register unsigned char *bufferptr;
438
921k
  register _JSAMPLE *rescale = source->rescale;
439
921k
  JDIMENSION col;
440
921k
  unsigned int maxval = source->maxval;
441
442
921k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
392
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
921k
  ptr = source->pub._buffer[0];
445
921k
  bufferptr = source->iobuffer;
446
921k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
0
    for (col = cinfo->image_width; col > 0; col--) {
448
0
      _JSAMPLE r = *bufferptr++;
449
0
      _JSAMPLE g = *bufferptr++;
450
0
      _JSAMPLE b = *bufferptr++;
451
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
0
      ptr += 4;
453
0
    }
454
921k
  } else {
455
8.04M
    for (col = cinfo->image_width; col > 0; col--) {
456
7.12M
      _JSAMPLE r = rescale[*bufferptr++];
457
7.12M
      _JSAMPLE g = rescale[*bufferptr++];
458
7.12M
      _JSAMPLE b = rescale[*bufferptr++];
459
7.12M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
7.12M
                  ptr + 2, ptr + 3);
461
7.12M
      ptr += 4;
462
7.12M
    }
463
921k
  }
464
921k
  return 1;
465
921k
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
434
172k
{
435
172k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
172k
  register _JSAMPROW ptr;
437
172k
  register unsigned char *bufferptr;
438
172k
  register _JSAMPLE *rescale = source->rescale;
439
172k
  JDIMENSION col;
440
172k
  unsigned int maxval = source->maxval;
441
442
172k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
220
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
172k
  ptr = source->pub._buffer[0];
445
172k
  bufferptr = source->iobuffer;
446
172k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
0
    for (col = cinfo->image_width; col > 0; col--) {
448
0
      _JSAMPLE r = *bufferptr++;
449
0
      _JSAMPLE g = *bufferptr++;
450
0
      _JSAMPLE b = *bufferptr++;
451
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
0
      ptr += 4;
453
0
    }
454
172k
  } else {
455
2.44M
    for (col = cinfo->image_width; col > 0; col--) {
456
2.26M
      _JSAMPLE r = rescale[*bufferptr++];
457
2.26M
      _JSAMPLE g = rescale[*bufferptr++];
458
2.26M
      _JSAMPLE b = rescale[*bufferptr++];
459
2.26M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
2.26M
                  ptr + 2, ptr + 3);
461
2.26M
      ptr += 4;
462
2.26M
    }
463
172k
  }
464
172k
  return 1;
465
172k
}
466
467
468
#if BITS_IN_JSAMPLE == 8
469
470
METHODDEF(JDIMENSION)
471
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
472
/* This version is for reading raw-byte-format files with
473
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
474
 * In this case we just read right into the _JSAMPLE buffer!
475
 * Note that same code works for PPM and PGM files.
476
 */
477
2.39M
{
478
2.39M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
479
480
2.39M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
481
427
    ERREXIT(cinfo, JERR_INPUT_EOF);
482
2.39M
  return 1;
483
2.39M
}
484
485
#endif
486
487
488
METHODDEF(JDIMENSION)
489
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
490
/* This version is for reading raw-word-format PGM files with any maxval */
491
122k
{
492
122k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
122k
  register _JSAMPROW ptr;
494
122k
  register unsigned char *bufferptr;
495
122k
  register _JSAMPLE *rescale = source->rescale;
496
122k
  JDIMENSION col;
497
122k
  unsigned int maxval = source->maxval;
498
499
122k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
1.10k
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
122k
  ptr = source->pub._buffer[0];
502
122k
  bufferptr = source->iobuffer;
503
430k
  for (col = cinfo->image_width; col > 0; col--) {
504
307k
    register unsigned int temp;
505
307k
    temp  = (*bufferptr++) << 8;
506
307k
    temp |= (*bufferptr++);
507
307k
    if (temp > maxval)
508
694
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
307k
    *ptr++ = rescale[temp];
510
307k
  }
511
122k
  return 1;
512
122k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
491
15.0k
{
492
15.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
15.0k
  register _JSAMPROW ptr;
494
15.0k
  register unsigned char *bufferptr;
495
15.0k
  register _JSAMPLE *rescale = source->rescale;
496
15.0k
  JDIMENSION col;
497
15.0k
  unsigned int maxval = source->maxval;
498
499
15.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
533
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
15.0k
  ptr = source->pub._buffer[0];
502
15.0k
  bufferptr = source->iobuffer;
503
83.0k
  for (col = cinfo->image_width; col > 0; col--) {
504
68.0k
    register unsigned int temp;
505
68.0k
    temp  = (*bufferptr++) << 8;
506
68.0k
    temp |= (*bufferptr++);
507
68.0k
    if (temp > maxval)
508
346
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
68.0k
    *ptr++ = rescale[temp];
510
68.0k
  }
511
15.0k
  return 1;
512
15.0k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
491
74.6k
{
492
74.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
74.6k
  register _JSAMPROW ptr;
494
74.6k
  register unsigned char *bufferptr;
495
74.6k
  register _JSAMPLE *rescale = source->rescale;
496
74.6k
  JDIMENSION col;
497
74.6k
  unsigned int maxval = source->maxval;
498
499
74.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
357
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
74.6k
  ptr = source->pub._buffer[0];
502
74.6k
  bufferptr = source->iobuffer;
503
156k
  for (col = cinfo->image_width; col > 0; col--) {
504
82.1k
    register unsigned int temp;
505
82.1k
    temp  = (*bufferptr++) << 8;
506
82.1k
    temp |= (*bufferptr++);
507
82.1k
    if (temp > maxval)
508
278
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
82.1k
    *ptr++ = rescale[temp];
510
82.1k
  }
511
74.6k
  return 1;
512
74.6k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
491
32.9k
{
492
32.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
32.9k
  register _JSAMPROW ptr;
494
32.9k
  register unsigned char *bufferptr;
495
32.9k
  register _JSAMPLE *rescale = source->rescale;
496
32.9k
  JDIMENSION col;
497
32.9k
  unsigned int maxval = source->maxval;
498
499
32.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
215
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
32.9k
  ptr = source->pub._buffer[0];
502
32.9k
  bufferptr = source->iobuffer;
503
190k
  for (col = cinfo->image_width; col > 0; col--) {
504
157k
    register unsigned int temp;
505
157k
    temp  = (*bufferptr++) << 8;
506
157k
    temp |= (*bufferptr++);
507
157k
    if (temp > maxval)
508
70
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
157k
    *ptr++ = rescale[temp];
510
157k
  }
511
32.9k
  return 1;
512
32.9k
}
513
514
515
METHODDEF(JDIMENSION)
516
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
517
/* This version is for reading raw-word-format PGM files with any maxval */
518
608k
{
519
608k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
608k
  register _JSAMPROW ptr;
521
608k
  register unsigned char *bufferptr;
522
608k
  register _JSAMPLE *rescale = source->rescale;
523
608k
  JDIMENSION col;
524
608k
  unsigned int maxval = source->maxval;
525
608k
  register int rindex = rgb_red[cinfo->in_color_space];
526
608k
  register int gindex = rgb_green[cinfo->in_color_space];
527
608k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
608k
  register int aindex = alpha_index[cinfo->in_color_space];
529
608k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
608k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
4.71k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
608k
  ptr = source->pub._buffer[0];
534
608k
  bufferptr = source->iobuffer;
535
2.14M
  for (col = cinfo->image_width; col > 0; col--) {
536
1.53M
    register unsigned int temp;
537
1.53M
    temp  = (*bufferptr++) << 8;
538
1.53M
    temp |= (*bufferptr++);
539
1.53M
    if (temp > maxval)
540
2.93k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
1.53M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
1.53M
    if (aindex >= 0)
543
258k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
1.53M
    ptr += ps;
545
1.53M
  }
546
608k
  return 1;
547
608k
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
518
70.6k
{
519
70.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
70.6k
  register _JSAMPROW ptr;
521
70.6k
  register unsigned char *bufferptr;
522
70.6k
  register _JSAMPLE *rescale = source->rescale;
523
70.6k
  JDIMENSION col;
524
70.6k
  unsigned int maxval = source->maxval;
525
70.6k
  register int rindex = rgb_red[cinfo->in_color_space];
526
70.6k
  register int gindex = rgb_green[cinfo->in_color_space];
527
70.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
70.6k
  register int aindex = alpha_index[cinfo->in_color_space];
529
70.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
70.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.85k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
70.6k
  ptr = source->pub._buffer[0];
534
70.6k
  bufferptr = source->iobuffer;
535
405k
  for (col = cinfo->image_width; col > 0; col--) {
536
334k
    register unsigned int temp;
537
334k
    temp  = (*bufferptr++) << 8;
538
334k
    temp |= (*bufferptr++);
539
334k
    if (temp > maxval)
540
1.19k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
334k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
334k
    if (aindex >= 0)
543
19.6k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
334k
    ptr += ps;
545
334k
  }
546
70.6k
  return 1;
547
70.6k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
518
373k
{
519
373k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
373k
  register _JSAMPROW ptr;
521
373k
  register unsigned char *bufferptr;
522
373k
  register _JSAMPLE *rescale = source->rescale;
523
373k
  JDIMENSION col;
524
373k
  unsigned int maxval = source->maxval;
525
373k
  register int rindex = rgb_red[cinfo->in_color_space];
526
373k
  register int gindex = rgb_green[cinfo->in_color_space];
527
373k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
373k
  register int aindex = alpha_index[cinfo->in_color_space];
529
373k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
373k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.78k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
373k
  ptr = source->pub._buffer[0];
534
373k
  bufferptr = source->iobuffer;
535
783k
  for (col = cinfo->image_width; col > 0; col--) {
536
410k
    register unsigned int temp;
537
410k
    temp  = (*bufferptr++) << 8;
538
410k
    temp |= (*bufferptr++);
539
410k
    if (temp > maxval)
540
1.39k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
410k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
410k
    if (aindex >= 0)
543
81.8k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
410k
    ptr += ps;
545
410k
  }
546
373k
  return 1;
547
373k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
518
164k
{
519
164k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
164k
  register _JSAMPROW ptr;
521
164k
  register unsigned char *bufferptr;
522
164k
  register _JSAMPLE *rescale = source->rescale;
523
164k
  JDIMENSION col;
524
164k
  unsigned int maxval = source->maxval;
525
164k
  register int rindex = rgb_red[cinfo->in_color_space];
526
164k
  register int gindex = rgb_green[cinfo->in_color_space];
527
164k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
164k
  register int aindex = alpha_index[cinfo->in_color_space];
529
164k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
164k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.07k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
164k
  ptr = source->pub._buffer[0];
534
164k
  bufferptr = source->iobuffer;
535
951k
  for (col = cinfo->image_width; col > 0; col--) {
536
786k
    register unsigned int temp;
537
786k
    temp  = (*bufferptr++) << 8;
538
786k
    temp |= (*bufferptr++);
539
786k
    if (temp > maxval)
540
350
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
786k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
786k
    if (aindex >= 0)
543
157k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
786k
    ptr += ps;
545
786k
  }
546
164k
  return 1;
547
164k
}
548
549
550
METHODDEF(JDIMENSION)
551
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
552
/* This version is for reading raw-word-format PGM files with any maxval */
553
118k
{
554
118k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
118k
  register _JSAMPROW ptr;
556
118k
  register unsigned char *bufferptr;
557
118k
  register _JSAMPLE *rescale = source->rescale;
558
118k
  JDIMENSION col;
559
118k
  unsigned int maxval = source->maxval;
560
561
118k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
834
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
118k
  ptr = source->pub._buffer[0];
564
118k
  bufferptr = source->iobuffer;
565
118k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
161k
    for (col = cinfo->image_width; col > 0; col--) {
567
141k
      register unsigned int gray;
568
141k
      gray  = (*bufferptr++) << 8;
569
141k
      gray |= (*bufferptr++);
570
141k
      if (gray > maxval)
571
93
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
141k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
141k
                  ptr + 1, ptr + 2, ptr + 3);
574
141k
      ptr += 4;
575
141k
    }
576
98.0k
  } else {
577
215k
    for (col = cinfo->image_width; col > 0; col--) {
578
117k
      register unsigned int temp;
579
117k
      _JSAMPLE gray;
580
117k
      temp  = (*bufferptr++) << 8;
581
117k
      temp |= (*bufferptr++);
582
117k
      if (temp > maxval)
583
418
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
117k
      gray = rescale[temp];
585
117k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
117k
                  ptr + 1, ptr + 2, ptr + 3);
587
117k
      ptr += 4;
588
117k
    }
589
98.0k
  }
590
118k
  return 1;
591
118k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
553
10.5k
{
554
10.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
10.5k
  register _JSAMPROW ptr;
556
10.5k
  register unsigned char *bufferptr;
557
10.5k
  register _JSAMPLE *rescale = source->rescale;
558
10.5k
  JDIMENSION col;
559
10.5k
  unsigned int maxval = source->maxval;
560
561
10.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
262
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
10.5k
  ptr = source->pub._buffer[0];
564
10.5k
  bufferptr = source->iobuffer;
565
10.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
0
    for (col = cinfo->image_width; col > 0; col--) {
567
0
      register unsigned int gray;
568
0
      gray  = (*bufferptr++) << 8;
569
0
      gray |= (*bufferptr++);
570
0
      if (gray > maxval)
571
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
0
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
0
                  ptr + 1, ptr + 2, ptr + 3);
574
0
      ptr += 4;
575
0
    }
576
10.5k
  } else {
577
30.3k
    for (col = cinfo->image_width; col > 0; col--) {
578
19.7k
      register unsigned int temp;
579
19.7k
      _JSAMPLE gray;
580
19.7k
      temp  = (*bufferptr++) << 8;
581
19.7k
      temp |= (*bufferptr++);
582
19.7k
      if (temp > maxval)
583
163
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
19.7k
      gray = rescale[temp];
585
19.7k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
19.7k
                  ptr + 1, ptr + 2, ptr + 3);
587
19.7k
      ptr += 4;
588
19.7k
    }
589
10.5k
  }
590
10.5k
  return 1;
591
10.5k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
553
74.6k
{
554
74.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
74.6k
  register _JSAMPROW ptr;
556
74.6k
  register unsigned char *bufferptr;
557
74.6k
  register _JSAMPLE *rescale = source->rescale;
558
74.6k
  JDIMENSION col;
559
74.6k
  unsigned int maxval = source->maxval;
560
561
74.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
357
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
74.6k
  ptr = source->pub._buffer[0];
564
74.6k
  bufferptr = source->iobuffer;
565
74.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
7.89k
    for (col = cinfo->image_width; col > 0; col--) {
567
5.06k
      register unsigned int gray;
568
5.06k
      gray  = (*bufferptr++) << 8;
569
5.06k
      gray |= (*bufferptr++);
570
5.06k
      if (gray > maxval)
571
93
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
5.06k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
5.06k
                  ptr + 1, ptr + 2, ptr + 3);
574
5.06k
      ptr += 4;
575
5.06k
    }
576
71.7k
  } else {
577
148k
    for (col = cinfo->image_width; col > 0; col--) {
578
77.0k
      register unsigned int temp;
579
77.0k
      _JSAMPLE gray;
580
77.0k
      temp  = (*bufferptr++) << 8;
581
77.0k
      temp |= (*bufferptr++);
582
77.0k
      if (temp > maxval)
583
185
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
77.0k
      gray = rescale[temp];
585
77.0k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
77.0k
                  ptr + 1, ptr + 2, ptr + 3);
587
77.0k
      ptr += 4;
588
77.0k
    }
589
71.7k
  }
590
74.6k
  return 1;
591
74.6k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
553
32.9k
{
554
32.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
32.9k
  register _JSAMPROW ptr;
556
32.9k
  register unsigned char *bufferptr;
557
32.9k
  register _JSAMPLE *rescale = source->rescale;
558
32.9k
  JDIMENSION col;
559
32.9k
  unsigned int maxval = source->maxval;
560
561
32.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
215
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
32.9k
  ptr = source->pub._buffer[0];
564
32.9k
  bufferptr = source->iobuffer;
565
32.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
153k
    for (col = cinfo->image_width; col > 0; col--) {
567
136k
      register unsigned int gray;
568
136k
      gray  = (*bufferptr++) << 8;
569
136k
      gray |= (*bufferptr++);
570
136k
      if (gray > maxval)
571
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
136k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
136k
                  ptr + 1, ptr + 2, ptr + 3);
574
136k
      ptr += 4;
575
136k
    }
576
17.3k
  } else {
577
36.5k
    for (col = cinfo->image_width; col > 0; col--) {
578
20.9k
      register unsigned int temp;
579
20.9k
      _JSAMPLE gray;
580
20.9k
      temp  = (*bufferptr++) << 8;
581
20.9k
      temp |= (*bufferptr++);
582
20.9k
      if (temp > maxval)
583
70
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
20.9k
      gray = rescale[temp];
585
20.9k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
20.9k
                  ptr + 1, ptr + 2, ptr + 3);
587
20.9k
      ptr += 4;
588
20.9k
    }
589
15.6k
  }
590
32.9k
  return 1;
591
32.9k
}
592
593
594
METHODDEF(JDIMENSION)
595
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
596
/* This version is for reading raw-word-format PPM files with any maxval */
597
173k
{
598
173k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
173k
  register _JSAMPROW ptr;
600
173k
  register unsigned char *bufferptr;
601
173k
  register _JSAMPLE *rescale = source->rescale;
602
173k
  JDIMENSION col;
603
173k
  unsigned int maxval = source->maxval;
604
173k
  register int rindex = rgb_red[cinfo->in_color_space];
605
173k
  register int gindex = rgb_green[cinfo->in_color_space];
606
173k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
173k
  register int aindex = alpha_index[cinfo->in_color_space];
608
173k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
173k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
6.14k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
173k
  ptr = source->pub._buffer[0];
613
173k
  bufferptr = source->iobuffer;
614
746k
  for (col = cinfo->image_width; col > 0; col--) {
615
573k
    register unsigned int temp;
616
573k
    temp  = (*bufferptr++) << 8;
617
573k
    temp |= (*bufferptr++);
618
573k
    if (temp > maxval)
619
2.19k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
573k
    ptr[rindex] = rescale[temp];
621
573k
    temp  = (*bufferptr++) << 8;
622
573k
    temp |= (*bufferptr++);
623
573k
    if (temp > maxval)
624
1.87k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
573k
    ptr[gindex] = rescale[temp];
626
573k
    temp  = (*bufferptr++) << 8;
627
573k
    temp |= (*bufferptr++);
628
573k
    if (temp > maxval)
629
1.82k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
573k
    ptr[bindex] = rescale[temp];
631
573k
    if (aindex >= 0)
632
108k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
573k
    ptr += ps;
634
573k
  }
635
173k
  return 1;
636
173k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
597
59.5k
{
598
59.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
59.5k
  register _JSAMPROW ptr;
600
59.5k
  register unsigned char *bufferptr;
601
59.5k
  register _JSAMPLE *rescale = source->rescale;
602
59.5k
  JDIMENSION col;
603
59.5k
  unsigned int maxval = source->maxval;
604
59.5k
  register int rindex = rgb_red[cinfo->in_color_space];
605
59.5k
  register int gindex = rgb_green[cinfo->in_color_space];
606
59.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
59.5k
  register int aindex = alpha_index[cinfo->in_color_space];
608
59.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
59.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
2.34k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
59.5k
  ptr = source->pub._buffer[0];
613
59.5k
  bufferptr = source->iobuffer;
614
150k
  for (col = cinfo->image_width; col > 0; col--) {
615
90.8k
    register unsigned int temp;
616
90.8k
    temp  = (*bufferptr++) << 8;
617
90.8k
    temp |= (*bufferptr++);
618
90.8k
    if (temp > maxval)
619
715
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
90.8k
    ptr[rindex] = rescale[temp];
621
90.8k
    temp  = (*bufferptr++) << 8;
622
90.8k
    temp |= (*bufferptr++);
623
90.8k
    if (temp > maxval)
624
792
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
90.8k
    ptr[gindex] = rescale[temp];
626
90.8k
    temp  = (*bufferptr++) << 8;
627
90.8k
    temp |= (*bufferptr++);
628
90.8k
    if (temp > maxval)
629
741
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
90.8k
    ptr[bindex] = rescale[temp];
631
90.8k
    if (aindex >= 0)
632
13.1k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
90.8k
    ptr += ps;
634
90.8k
  }
635
59.5k
  return 1;
636
59.5k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
597
65.1k
{
598
65.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
65.1k
  register _JSAMPROW ptr;
600
65.1k
  register unsigned char *bufferptr;
601
65.1k
  register _JSAMPLE *rescale = source->rescale;
602
65.1k
  JDIMENSION col;
603
65.1k
  unsigned int maxval = source->maxval;
604
65.1k
  register int rindex = rgb_red[cinfo->in_color_space];
605
65.1k
  register int gindex = rgb_green[cinfo->in_color_space];
606
65.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
65.1k
  register int aindex = alpha_index[cinfo->in_color_space];
608
65.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
65.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
2.42k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
65.1k
  ptr = source->pub._buffer[0];
613
65.1k
  bufferptr = source->iobuffer;
614
263k
  for (col = cinfo->image_width; col > 0; col--) {
615
198k
    register unsigned int temp;
616
198k
    temp  = (*bufferptr++) << 8;
617
198k
    temp |= (*bufferptr++);
618
198k
    if (temp > maxval)
619
1.14k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
198k
    ptr[rindex] = rescale[temp];
621
198k
    temp  = (*bufferptr++) << 8;
622
198k
    temp |= (*bufferptr++);
623
198k
    if (temp > maxval)
624
820
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
198k
    ptr[gindex] = rescale[temp];
626
198k
    temp  = (*bufferptr++) << 8;
627
198k
    temp |= (*bufferptr++);
628
198k
    if (temp > maxval)
629
850
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
198k
    ptr[bindex] = rescale[temp];
631
198k
    if (aindex >= 0)
632
39.0k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
198k
    ptr += ps;
634
198k
  }
635
65.1k
  return 1;
636
65.1k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
597
48.8k
{
598
48.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
48.8k
  register _JSAMPROW ptr;
600
48.8k
  register unsigned char *bufferptr;
601
48.8k
  register _JSAMPLE *rescale = source->rescale;
602
48.8k
  JDIMENSION col;
603
48.8k
  unsigned int maxval = source->maxval;
604
48.8k
  register int rindex = rgb_red[cinfo->in_color_space];
605
48.8k
  register int gindex = rgb_green[cinfo->in_color_space];
606
48.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
48.8k
  register int aindex = alpha_index[cinfo->in_color_space];
608
48.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
48.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
1.37k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
48.8k
  ptr = source->pub._buffer[0];
613
48.8k
  bufferptr = source->iobuffer;
614
332k
  for (col = cinfo->image_width; col > 0; col--) {
615
283k
    register unsigned int temp;
616
283k
    temp  = (*bufferptr++) << 8;
617
283k
    temp |= (*bufferptr++);
618
283k
    if (temp > maxval)
619
335
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
283k
    ptr[rindex] = rescale[temp];
621
283k
    temp  = (*bufferptr++) << 8;
622
283k
    temp |= (*bufferptr++);
623
283k
    if (temp > maxval)
624
265
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
283k
    ptr[gindex] = rescale[temp];
626
283k
    temp  = (*bufferptr++) << 8;
627
283k
    temp |= (*bufferptr++);
628
283k
    if (temp > maxval)
629
230
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
283k
    ptr[bindex] = rescale[temp];
631
283k
    if (aindex >= 0)
632
56.6k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
283k
    ptr += ps;
634
283k
  }
635
48.8k
  return 1;
636
48.8k
}
637
638
639
METHODDEF(JDIMENSION)
640
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
641
/* This version is for reading raw-word-format PPM files with any maxval */
642
31.2k
{
643
31.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
31.2k
  register _JSAMPROW ptr;
645
31.2k
  register unsigned char *bufferptr;
646
31.2k
  register _JSAMPLE *rescale = source->rescale;
647
31.2k
  JDIMENSION col;
648
31.2k
  unsigned int maxval = source->maxval;
649
650
31.2k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
1.09k
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
31.2k
  ptr = source->pub._buffer[0];
653
31.2k
  bufferptr = source->iobuffer;
654
31.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
71.1k
    for (col = cinfo->image_width; col > 0; col--) {
656
60.4k
      register unsigned int r, g, b;
657
60.4k
      r  = (*bufferptr++) << 8;
658
60.4k
      r |= (*bufferptr++);
659
60.4k
      if (r > maxval)
660
89
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
60.4k
      g  = (*bufferptr++) << 8;
662
60.4k
      g |= (*bufferptr++);
663
60.4k
      if (g > maxval)
664
66
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
60.4k
      b  = (*bufferptr++) << 8;
666
60.4k
      b |= (*bufferptr++);
667
60.4k
      if (b > maxval)
668
80
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
60.4k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
60.4k
                  ptr + 2, ptr + 3);
671
60.4k
      ptr += 4;
672
60.4k
    }
673
20.5k
  } else {
674
70.0k
    for (col = cinfo->image_width; col > 0; col--) {
675
49.5k
      register unsigned int r, g, b;
676
49.5k
      r  = (*bufferptr++) << 8;
677
49.5k
      r |= (*bufferptr++);
678
49.5k
      if (r > maxval)
679
323
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
49.5k
      g  = (*bufferptr++) << 8;
681
49.5k
      g |= (*bufferptr++);
682
49.5k
      if (g > maxval)
683
254
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
49.5k
      b  = (*bufferptr++) << 8;
685
49.5k
      b |= (*bufferptr++);
686
49.5k
      if (b > maxval)
687
222
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
49.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
49.5k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
49.5k
      ptr += 4;
691
49.5k
    }
692
20.5k
  }
693
31.2k
  return 1;
694
31.2k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
642
8.49k
{
643
8.49k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
8.49k
  register _JSAMPROW ptr;
645
8.49k
  register unsigned char *bufferptr;
646
8.49k
  register _JSAMPLE *rescale = source->rescale;
647
8.49k
  JDIMENSION col;
648
8.49k
  unsigned int maxval = source->maxval;
649
650
8.49k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
334
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
8.49k
  ptr = source->pub._buffer[0];
653
8.49k
  bufferptr = source->iobuffer;
654
8.49k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
0
    for (col = cinfo->image_width; col > 0; col--) {
656
0
      register unsigned int r, g, b;
657
0
      r  = (*bufferptr++) << 8;
658
0
      r |= (*bufferptr++);
659
0
      if (r > maxval)
660
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
0
      g  = (*bufferptr++) << 8;
662
0
      g |= (*bufferptr++);
663
0
      if (g > maxval)
664
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
0
      b  = (*bufferptr++) << 8;
666
0
      b |= (*bufferptr++);
667
0
      if (b > maxval)
668
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
0
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
0
                  ptr + 2, ptr + 3);
671
0
      ptr += 4;
672
0
    }
673
8.49k
  } else {
674
21.9k
    for (col = cinfo->image_width; col > 0; col--) {
675
13.4k
      register unsigned int r, g, b;
676
13.4k
      r  = (*bufferptr++) << 8;
677
13.4k
      r |= (*bufferptr++);
678
13.4k
      if (r > maxval)
679
116
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
13.4k
      g  = (*bufferptr++) << 8;
681
13.4k
      g |= (*bufferptr++);
682
13.4k
      if (g > maxval)
683
103
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
13.4k
      b  = (*bufferptr++) << 8;
685
13.4k
      b |= (*bufferptr++);
686
13.4k
      if (b > maxval)
687
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
13.4k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
13.4k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
13.4k
      ptr += 4;
691
13.4k
    }
692
8.49k
  }
693
8.49k
  return 1;
694
8.49k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
642
13.0k
{
643
13.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
13.0k
  register _JSAMPROW ptr;
645
13.0k
  register unsigned char *bufferptr;
646
13.0k
  register _JSAMPLE *rescale = source->rescale;
647
13.0k
  JDIMENSION col;
648
13.0k
  unsigned int maxval = source->maxval;
649
650
13.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
485
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
13.0k
  ptr = source->pub._buffer[0];
653
13.0k
  bufferptr = source->iobuffer;
654
13.0k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
13.0k
    for (col = cinfo->image_width; col > 0; col--) {
656
8.82k
      register unsigned int r, g, b;
657
8.82k
      r  = (*bufferptr++) << 8;
658
8.82k
      r |= (*bufferptr++);
659
8.82k
      if (r > maxval)
660
89
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
8.82k
      g  = (*bufferptr++) << 8;
662
8.82k
      g |= (*bufferptr++);
663
8.82k
      if (g > maxval)
664
66
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
8.82k
      b  = (*bufferptr++) << 8;
666
8.82k
      b |= (*bufferptr++);
667
8.82k
      if (b > maxval)
668
80
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
8.82k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
8.82k
                  ptr + 2, ptr + 3);
671
8.82k
      ptr += 4;
672
8.82k
    }
673
8.75k
  } else {
674
39.5k
    for (col = cinfo->image_width; col > 0; col--) {
675
30.8k
      register unsigned int r, g, b;
676
30.8k
      r  = (*bufferptr++) << 8;
677
30.8k
      r |= (*bufferptr++);
678
30.8k
      if (r > maxval)
679
140
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
30.8k
      g  = (*bufferptr++) << 8;
681
30.8k
      g |= (*bufferptr++);
682
30.8k
      if (g > maxval)
683
98
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
30.8k
      b  = (*bufferptr++) << 8;
685
30.8k
      b |= (*bufferptr++);
686
30.8k
      if (b > maxval)
687
90
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
30.8k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
30.8k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
30.8k
      ptr += 4;
691
30.8k
    }
692
8.75k
  }
693
13.0k
  return 1;
694
13.0k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
642
9.76k
{
643
9.76k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
9.76k
  register _JSAMPROW ptr;
645
9.76k
  register unsigned char *bufferptr;
646
9.76k
  register _JSAMPLE *rescale = source->rescale;
647
9.76k
  JDIMENSION col;
648
9.76k
  unsigned int maxval = source->maxval;
649
650
9.76k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
274
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
9.76k
  ptr = source->pub._buffer[0];
653
9.76k
  bufferptr = source->iobuffer;
654
9.76k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
58.0k
    for (col = cinfo->image_width; col > 0; col--) {
656
51.5k
      register unsigned int r, g, b;
657
51.5k
      r  = (*bufferptr++) << 8;
658
51.5k
      r |= (*bufferptr++);
659
51.5k
      if (r > maxval)
660
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
51.5k
      g  = (*bufferptr++) << 8;
662
51.5k
      g |= (*bufferptr++);
663
51.5k
      if (g > maxval)
664
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
51.5k
      b  = (*bufferptr++) << 8;
666
51.5k
      b |= (*bufferptr++);
667
51.5k
      if (b > maxval)
668
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
51.5k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
51.5k
                  ptr + 2, ptr + 3);
671
51.5k
      ptr += 4;
672
51.5k
    }
673
6.50k
  } else {
674
8.47k
    for (col = cinfo->image_width; col > 0; col--) {
675
5.21k
      register unsigned int r, g, b;
676
5.21k
      r  = (*bufferptr++) << 8;
677
5.21k
      r |= (*bufferptr++);
678
5.21k
      if (r > maxval)
679
67
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
5.21k
      g  = (*bufferptr++) << 8;
681
5.21k
      g |= (*bufferptr++);
682
5.21k
      if (g > maxval)
683
53
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
5.21k
      b  = (*bufferptr++) << 8;
685
5.21k
      b |= (*bufferptr++);
686
5.21k
      if (b > maxval)
687
46
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
5.21k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
5.21k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
5.21k
      ptr += 4;
691
5.21k
    }
692
3.26k
  }
693
9.76k
  return 1;
694
9.76k
}
695
696
697
/*
698
 * Read the file header; return image size and component count.
699
 */
700
701
METHODDEF(void)
702
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
703
182k
{
704
182k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
182k
  int c;
706
182k
  unsigned int w, h, maxval;
707
182k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
182k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
182k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
182k
  switch (c) {
716
18.4k
  case '2':                     /* it's a text-format PGM file */
717
39.6k
  case '3':                     /* it's a text-format PPM file */
718
138k
  case '5':                     /* it's a raw-format PGM file */
719
182k
  case '6':                     /* it's a raw-format PPM file */
720
182k
    break;
721
646
  default:
722
646
    ERREXIT(cinfo, JERR_PPM_NOT);
723
646
    break;
724
182k
  }
725
726
  /* fetch the remaining header info */
727
182k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
182k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
182k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
182k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
412
    ERREXIT(cinfo, JERR_PPM_NOT);
733
182k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
256
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
182k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
2.59k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
182k
  cinfo->image_width = (JDIMENSION)w;
739
182k
  cinfo->image_height = (JDIMENSION)h;
740
182k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
182k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
182k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
182k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
182k
  switch (c) {
748
14.1k
  case '2':                     /* it's a text-format PGM file */
749
14.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
14.1k
        cinfo->in_color_space == JCS_RGB)
751
232
      cinfo->in_color_space = JCS_GRAYSCALE;
752
14.1k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
14.1k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
2.26k
      source->pub.get_pixel_rows = get_text_gray_row;
755
11.9k
    else if (IsExtRGB(cinfo->in_color_space))
756
10.1k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
1.77k
    else if (cinfo->in_color_space == JCS_CMYK)
758
1.77k
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
14.1k
    need_iobuffer = FALSE;
762
14.1k
    break;
763
764
16.5k
  case '3':                     /* it's a text-format PPM file */
765
16.5k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
16.5k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
16.5k
    if (IsExtRGB(cinfo->in_color_space))
769
12.1k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
4.44k
    else if (cinfo->in_color_space == JCS_CMYK)
771
2.09k
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
2.34k
    else
773
2.34k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
16.5k
    need_iobuffer = FALSE;
775
16.5k
    break;
776
777
93.5k
  case '5':                     /* it's a raw-format PGM file */
778
93.5k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
93.5k
        cinfo->in_color_space == JCS_RGB)
780
860
      cinfo->in_color_space = JCS_GRAYSCALE;
781
93.5k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
93.5k
    if (maxval > 255) {
783
12.5k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
2.05k
        source->pub.get_pixel_rows = get_word_gray_row;
785
10.4k
      else if (IsExtRGB(cinfo->in_color_space))
786
8.89k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
1.58k
      else if (cinfo->in_color_space == JCS_CMYK)
788
1.58k
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
46.8k
    } else if (maxval <= _MAXJSAMPLE &&
793
46.8k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
6.26k
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
1.03k
      source->pub.get_pixel_rows = get_raw_row;
796
1.03k
      use_raw_buffer = TRUE;
797
1.03k
      need_rescale = FALSE;
798
#endif
799
79.9k
    } else {
800
79.9k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
11.4k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
68.5k
      else if (IsExtRGB(cinfo->in_color_space))
803
59.5k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
8.98k
      else if (cinfo->in_color_space == JCS_CMYK)
805
8.98k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
79.9k
    }
809
93.5k
    break;
810
811
40.0k
  case '6':                     /* it's a raw-format PPM file */
812
40.0k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
40.0k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
40.0k
    if (maxval > 255) {
816
17.6k
      if (IsExtRGB(cinfo->in_color_space))
817
12.8k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
4.78k
      else if (cinfo->in_color_space == JCS_CMYK)
819
2.28k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
2.49k
      else
821
2.49k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
13.1k
    } else if (maxval <= _MAXJSAMPLE &&
824
13.1k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
2.40k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
2.40k
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
2.09k
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
367
      source->pub.get_pixel_rows = get_raw_row;
832
367
      use_raw_buffer = TRUE;
833
367
      need_rescale = FALSE;
834
#endif
835
22.0k
    } else {
836
22.0k
      if (IsExtRGB(cinfo->in_color_space))
837
16.1k
        source->pub.get_pixel_rows = get_rgb_row;
838
5.93k
      else if (cinfo->in_color_space == JCS_CMYK)
839
2.72k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
3.20k
      else
841
3.20k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
22.0k
    }
843
40.0k
    break;
844
182k
  }
845
846
156k
  if (IsExtRGB(cinfo->in_color_space))
847
120k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
36.2k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
16.8k
    cinfo->input_components = 1;
850
19.4k
  else if (cinfo->in_color_space == JCS_CMYK)
851
19.4k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
156k
  if (need_iobuffer) {
855
127k
    if (c == '6')
856
34.3k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
93.5k
    else
858
93.5k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
127k
    source->iobuffer = (unsigned char *)
860
127k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
127k
                                  source->buffer_width);
862
127k
  }
863
864
  /* Create compressor input buffer. */
865
156k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
1.40k
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
1.40k
    source->pub._buffer = &source->pixrow;
870
1.40k
    source->pub.buffer_height = 1;
871
154k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
154k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
154k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
154k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
154k
    source->pub.buffer_height = 1;
877
154k
  }
878
879
  /* Compute the rescaling array if required. */
880
156k
  if (need_rescale) {
881
154k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
154k
    source->rescale = (_JSAMPLE *)
885
154k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
154k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
154k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
154k
    half_maxval = (size_t)maxval / 2;
889
654M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
654M
      source->rescale[val] =
892
654M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
654M
                   maxval);
894
654M
    }
895
154k
  }
896
156k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
703
94.5k
{
704
94.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
94.5k
  int c;
706
94.5k
  unsigned int w, h, maxval;
707
94.5k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
94.5k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
94.5k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
94.5k
  switch (c) {
716
8.84k
  case '2':                     /* it's a text-format PGM file */
717
18.5k
  case '3':                     /* it's a text-format PPM file */
718
72.8k
  case '5':                     /* it's a raw-format PGM file */
719
94.2k
  case '6':                     /* it's a raw-format PPM file */
720
94.2k
    break;
721
261
  default:
722
261
    ERREXIT(cinfo, JERR_PPM_NOT);
723
261
    break;
724
94.5k
  }
725
726
  /* fetch the remaining header info */
727
94.2k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
94.2k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
94.2k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
94.2k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
195
    ERREXIT(cinfo, JERR_PPM_NOT);
733
94.2k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
130
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
94.2k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.14k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
94.2k
  cinfo->image_width = (JDIMENSION)w;
739
94.2k
  cinfo->image_height = (JDIMENSION)h;
740
94.2k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
94.2k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
94.2k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
94.2k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
94.2k
  switch (c) {
748
6.55k
  case '2':                     /* it's a text-format PGM file */
749
6.55k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
6.55k
        cinfo->in_color_space == JCS_RGB)
751
232
      cinfo->in_color_space = JCS_GRAYSCALE;
752
6.55k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
6.55k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
1.17k
      source->pub.get_pixel_rows = get_text_gray_row;
755
5.37k
    else if (IsExtRGB(cinfo->in_color_space))
756
4.69k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
684
    else if (cinfo->in_color_space == JCS_CMYK)
758
684
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
6.55k
    need_iobuffer = FALSE;
762
6.55k
    break;
763
764
7.69k
  case '3':                     /* it's a text-format PPM file */
765
7.69k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
7.69k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
7.69k
    if (IsExtRGB(cinfo->in_color_space))
769
5.79k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.90k
    else if (cinfo->in_color_space == JCS_CMYK)
771
825
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
1.07k
    else
773
1.07k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
7.69k
    need_iobuffer = FALSE;
775
7.69k
    break;
776
777
51.6k
  case '5':                     /* it's a raw-format PGM file */
778
51.6k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
51.6k
        cinfo->in_color_space == JCS_RGB)
780
860
      cinfo->in_color_space = JCS_GRAYSCALE;
781
51.6k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
51.6k
    if (maxval > 255) {
783
4.73k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
943
        source->pub.get_pixel_rows = get_word_gray_row;
785
3.79k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.32k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
468
      else if (cinfo->in_color_space == JCS_CMYK)
788
468
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
4.73k
#if BITS_IN_JSAMPLE == 8
792
46.8k
    } else if (maxval <= _MAXJSAMPLE &&
793
46.8k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
6.26k
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
1.03k
      source->pub.get_pixel_rows = get_raw_row;
796
1.03k
      use_raw_buffer = TRUE;
797
1.03k
      need_rescale = FALSE;
798
1.03k
#endif
799
45.8k
    } else {
800
45.8k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
6.57k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
39.2k
      else if (IsExtRGB(cinfo->in_color_space))
803
35.1k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
4.11k
      else if (cinfo->in_color_space == JCS_CMYK)
805
4.11k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
45.8k
    }
809
51.6k
    break;
810
811
19.5k
  case '6':                     /* it's a raw-format PPM file */
812
19.5k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
19.5k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
19.5k
    if (maxval > 255) {
816
6.40k
      if (IsExtRGB(cinfo->in_color_space))
817
4.83k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
1.56k
      else if (cinfo->in_color_space == JCS_CMYK)
819
676
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
892
      else
821
892
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
6.40k
#if BITS_IN_JSAMPLE == 8
823
13.1k
    } else if (maxval <= _MAXJSAMPLE &&
824
13.1k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
2.40k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
2.40k
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
2.09k
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
367
      source->pub.get_pixel_rows = get_raw_row;
832
367
      use_raw_buffer = TRUE;
833
367
      need_rescale = FALSE;
834
367
#endif
835
12.7k
    } else {
836
12.7k
      if (IsExtRGB(cinfo->in_color_space))
837
9.48k
        source->pub.get_pixel_rows = get_rgb_row;
838
3.28k
      else if (cinfo->in_color_space == JCS_CMYK)
839
1.39k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
1.88k
      else
841
1.88k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
12.7k
    }
843
19.5k
    break;
844
94.2k
  }
845
846
81.5k
  if (IsExtRGB(cinfo->in_color_space))
847
63.6k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
17.8k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
9.72k
    cinfo->input_components = 1;
850
8.16k
  else if (cinfo->in_color_space == JCS_CMYK)
851
8.16k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
81.5k
  if (need_iobuffer) {
855
68.3k
    if (c == '6')
856
16.7k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
51.6k
    else
858
51.6k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
68.3k
    source->iobuffer = (unsigned char *)
860
68.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
68.3k
                                  source->buffer_width);
862
68.3k
  }
863
864
  /* Create compressor input buffer. */
865
81.5k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
1.40k
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
1.40k
    source->pub._buffer = &source->pixrow;
870
1.40k
    source->pub.buffer_height = 1;
871
80.1k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
80.1k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
80.1k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
80.1k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
80.1k
    source->pub.buffer_height = 1;
877
80.1k
  }
878
879
  /* Compute the rescaling array if required. */
880
81.5k
  if (need_rescale) {
881
80.1k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
80.1k
    source->rescale = (_JSAMPLE *)
885
80.1k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
80.1k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
80.1k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
80.1k
    half_maxval = (size_t)maxval / 2;
889
183M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
183M
      source->rescale[val] =
892
183M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
183M
                   maxval);
894
183M
    }
895
80.1k
  }
896
81.5k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
703
62.6k
{
704
62.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
62.6k
  int c;
706
62.6k
  unsigned int w, h, maxval;
707
62.6k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
62.6k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
62.6k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
62.6k
  switch (c) {
716
6.35k
  case '2':                     /* it's a text-format PGM file */
717
13.6k
  case '3':                     /* it's a text-format PPM file */
718
46.4k
  case '5':                     /* it's a raw-format PGM file */
719
62.3k
  case '6':                     /* it's a raw-format PPM file */
720
62.3k
    break;
721
294
  default:
722
294
    ERREXIT(cinfo, JERR_PPM_NOT);
723
294
    break;
724
62.6k
  }
725
726
  /* fetch the remaining header info */
727
62.3k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
62.3k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
62.3k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
62.3k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
140
    ERREXIT(cinfo, JERR_PPM_NOT);
733
62.3k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
84
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
62.3k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
931
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
62.3k
  cinfo->image_width = (JDIMENSION)w;
739
62.3k
  cinfo->image_height = (JDIMENSION)h;
740
62.3k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
62.3k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
62.3k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
62.3k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
62.3k
  switch (c) {
748
5.02k
  case '2':                     /* it's a text-format PGM file */
749
5.02k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
5.02k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
5.02k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
5.02k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
718
      source->pub.get_pixel_rows = get_text_gray_row;
755
4.30k
    else if (IsExtRGB(cinfo->in_color_space))
756
3.59k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
718
    else if (cinfo->in_color_space == JCS_CMYK)
758
718
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
5.02k
    need_iobuffer = FALSE;
762
5.02k
    break;
763
764
5.68k
  case '3':                     /* it's a text-format PPM file */
765
5.68k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
5.68k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
5.68k
    if (IsExtRGB(cinfo->in_color_space))
769
4.06k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.62k
    else if (cinfo->in_color_space == JCS_CMYK)
771
812
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
812
    else
773
812
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
5.68k
    need_iobuffer = FALSE;
775
5.68k
    break;
776
777
31.1k
  case '5':                     /* it's a raw-format PGM file */
778
31.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
31.1k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
31.1k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
31.1k
    if (maxval > 255) {
783
5.13k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
734
        source->pub.get_pixel_rows = get_word_gray_row;
785
4.40k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.67k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
734
      else if (cinfo->in_color_space == JCS_CMYK)
788
734
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
    } else if (maxval <= _MAXJSAMPLE &&
793
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
      source->pub.get_pixel_rows = get_raw_row;
796
      use_raw_buffer = TRUE;
797
      need_rescale = FALSE;
798
#endif
799
26.0k
    } else {
800
26.0k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
3.71k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
22.2k
      else if (IsExtRGB(cinfo->in_color_space))
803
18.5k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
3.71k
      else if (cinfo->in_color_space == JCS_CMYK)
805
3.71k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
26.0k
    }
809
31.1k
    break;
810
811
14.4k
  case '6':                     /* it's a raw-format PPM file */
812
14.4k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
14.4k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
14.4k
    if (maxval > 255) {
816
7.74k
      if (IsExtRGB(cinfo->in_color_space))
817
5.53k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
2.21k
      else if (cinfo->in_color_space == JCS_CMYK)
819
1.10k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
1.10k
      else
821
1.10k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
    } else if (maxval <= _MAXJSAMPLE &&
824
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
      source->pub.get_pixel_rows = get_raw_row;
832
      use_raw_buffer = TRUE;
833
      need_rescale = FALSE;
834
#endif
835
7.74k
    } else {
836
6.67k
      if (IsExtRGB(cinfo->in_color_space))
837
4.76k
        source->pub.get_pixel_rows = get_rgb_row;
838
1.90k
      else if (cinfo->in_color_space == JCS_CMYK)
839
953
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
953
      else
841
953
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
6.67k
    }
843
14.4k
    break;
844
62.3k
  }
845
846
53.3k
  if (IsExtRGB(cinfo->in_color_space))
847
40.1k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
13.2k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
5.16k
    cinfo->input_components = 1;
850
8.03k
  else if (cinfo->in_color_space == JCS_CMYK)
851
8.03k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
53.3k
  if (need_iobuffer) {
855
43.4k
    if (c == '6')
856
12.3k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
31.1k
    else
858
31.1k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
43.4k
    source->iobuffer = (unsigned char *)
860
43.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
43.4k
                                  source->buffer_width);
862
43.4k
  }
863
864
  /* Create compressor input buffer. */
865
53.3k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
0
    source->pub._buffer = &source->pixrow;
870
0
    source->pub.buffer_height = 1;
871
53.3k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
53.3k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
53.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
53.3k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
53.3k
    source->pub.buffer_height = 1;
877
53.3k
  }
878
879
  /* Compute the rescaling array if required. */
880
53.3k
  if (need_rescale) {
881
53.3k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
53.3k
    source->rescale = (_JSAMPLE *)
885
53.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
53.3k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
53.3k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
53.3k
    half_maxval = (size_t)maxval / 2;
889
157M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
157M
      source->rescale[val] =
892
157M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
157M
                   maxval);
894
157M
    }
895
53.3k
  }
896
53.3k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
703
25.7k
{
704
25.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
25.7k
  int c;
706
25.7k
  unsigned int w, h, maxval;
707
25.7k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
25.7k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
25.7k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
25.7k
  switch (c) {
716
3.21k
  case '2':                     /* it's a text-format PGM file */
717
7.41k
  case '3':                     /* it's a text-format PPM file */
718
18.9k
  case '5':                     /* it's a raw-format PGM file */
719
25.6k
  case '6':                     /* it's a raw-format PPM file */
720
25.6k
    break;
721
91
  default:
722
91
    ERREXIT(cinfo, JERR_PPM_NOT);
723
91
    break;
724
25.7k
  }
725
726
  /* fetch the remaining header info */
727
25.6k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
25.6k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
25.6k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
25.6k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
77
    ERREXIT(cinfo, JERR_PPM_NOT);
733
25.6k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
42
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
25.6k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
511
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
25.6k
  cinfo->image_width = (JDIMENSION)w;
739
25.6k
  cinfo->image_height = (JDIMENSION)h;
740
25.6k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
25.6k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
25.6k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
25.6k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
25.6k
  switch (c) {
748
2.59k
  case '2':                     /* it's a text-format PGM file */
749
2.59k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
2.59k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
2.59k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
2.59k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
371
      source->pub.get_pixel_rows = get_text_gray_row;
755
2.22k
    else if (IsExtRGB(cinfo->in_color_space))
756
1.85k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
371
    else if (cinfo->in_color_space == JCS_CMYK)
758
371
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
2.59k
    need_iobuffer = FALSE;
762
2.59k
    break;
763
764
3.19k
  case '3':                     /* it's a text-format PPM file */
765
3.19k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
3.19k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
3.19k
    if (IsExtRGB(cinfo->in_color_space))
769
2.28k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
914
    else if (cinfo->in_color_space == JCS_CMYK)
771
457
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
457
    else
773
457
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
3.19k
    need_iobuffer = FALSE;
775
3.19k
    break;
776
777
10.7k
  case '5':                     /* it's a raw-format PGM file */
778
10.7k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
10.7k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
10.7k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
10.7k
    if (maxval > 255) {
783
2.66k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
380
        source->pub.get_pixel_rows = get_word_gray_row;
785
2.28k
      else if (IsExtRGB(cinfo->in_color_space))
786
1.90k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
380
      else if (cinfo->in_color_space == JCS_CMYK)
788
380
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
    } else if (maxval <= _MAXJSAMPLE &&
793
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
      source->pub.get_pixel_rows = get_raw_row;
796
      use_raw_buffer = TRUE;
797
      need_rescale = FALSE;
798
#endif
799
8.09k
    } else {
800
8.09k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
1.15k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
6.93k
      else if (IsExtRGB(cinfo->in_color_space))
803
5.78k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
1.15k
      else if (cinfo->in_color_space == JCS_CMYK)
805
1.15k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
8.09k
    }
809
10.7k
    break;
810
811
6.12k
  case '6':                     /* it's a raw-format PPM file */
812
6.12k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
6.12k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
6.12k
    if (maxval > 255) {
816
3.50k
      if (IsExtRGB(cinfo->in_color_space))
817
2.50k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
1.00k
      else if (cinfo->in_color_space == JCS_CMYK)
819
501
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
501
      else
821
501
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
    } else if (maxval <= _MAXJSAMPLE &&
824
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
      source->pub.get_pixel_rows = get_raw_row;
832
      use_raw_buffer = TRUE;
833
      need_rescale = FALSE;
834
#endif
835
3.50k
    } else {
836
2.61k
      if (IsExtRGB(cinfo->in_color_space))
837
1.87k
        source->pub.get_pixel_rows = get_rgb_row;
838
748
      else if (cinfo->in_color_space == JCS_CMYK)
839
374
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
374
      else
841
374
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
2.61k
    }
843
6.12k
    break;
844
25.6k
  }
845
846
21.3k
  if (IsExtRGB(cinfo->in_color_space))
847
16.1k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
5.14k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
1.90k
    cinfo->input_components = 1;
850
3.23k
  else if (cinfo->in_color_space == JCS_CMYK)
851
3.23k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
21.3k
  if (need_iobuffer) {
855
16.0k
    if (c == '6')
856
5.25k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
10.7k
    else
858
10.7k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
16.0k
    source->iobuffer = (unsigned char *)
860
16.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
16.0k
                                  source->buffer_width);
862
16.0k
  }
863
864
  /* Create compressor input buffer. */
865
21.3k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
0
    source->pub._buffer = &source->pixrow;
870
0
    source->pub.buffer_height = 1;
871
21.3k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
21.3k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
21.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
21.3k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
21.3k
    source->pub.buffer_height = 1;
877
21.3k
  }
878
879
  /* Compute the rescaling array if required. */
880
21.3k
  if (need_rescale) {
881
21.3k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
21.3k
    source->rescale = (_JSAMPLE *)
885
21.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
21.3k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
21.3k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
21.3k
    half_maxval = (size_t)maxval / 2;
889
313M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
313M
      source->rescale[val] =
892
313M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
313M
                   maxval);
894
313M
    }
895
21.3k
  }
896
21.3k
}
897
898
899
/*
900
 * Finish up at the end of the file.
901
 */
902
903
METHODDEF(void)
904
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
905
133k
{
906
  /* no work */
907
133k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
905
71.0k
{
906
  /* no work */
907
71.0k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
905
45.3k
{
906
  /* no work */
907
45.3k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
905
17.1k
{
906
  /* no work */
907
17.1k
}
908
909
910
/*
911
 * The module selection routine for PPM format input.
912
 */
913
914
GLOBAL(cjpeg_source_ptr)
915
_jinit_read_ppm(j_compress_ptr cinfo)
916
182k
{
917
182k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
94.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
88.3k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
88.3k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
182k
  source = (ppm_source_ptr)
929
182k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
182k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
182k
  source->pub.start_input = start_input_ppm;
933
182k
  source->pub.finish_input = finish_input_ppm;
934
182k
  source->pub.max_pixels = 0;
935
936
182k
  return (cjpeg_source_ptr)source;
937
182k
}
jinit_read_ppm
Line
Count
Source
916
94.5k
{
917
94.5k
  ppm_source_ptr source;
918
919
94.5k
#if BITS_IN_JSAMPLE == 8
920
94.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
94.5k
  source = (ppm_source_ptr)
929
94.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
94.5k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
94.5k
  source->pub.start_input = start_input_ppm;
933
94.5k
  source->pub.finish_input = finish_input_ppm;
934
94.5k
  source->pub.max_pixels = 0;
935
936
94.5k
  return (cjpeg_source_ptr)source;
937
94.5k
}
j12init_read_ppm
Line
Count
Source
916
62.6k
{
917
62.6k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
62.6k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
62.6k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
62.6k
  source = (ppm_source_ptr)
929
62.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
62.6k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
62.6k
  source->pub.start_input = start_input_ppm;
933
62.6k
  source->pub.finish_input = finish_input_ppm;
934
62.6k
  source->pub.max_pixels = 0;
935
936
62.6k
  return (cjpeg_source_ptr)source;
937
62.6k
}
j16init_read_ppm
Line
Count
Source
916
25.7k
{
917
25.7k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
25.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
25.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
25.7k
  source = (ppm_source_ptr)
929
25.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
25.7k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
25.7k
  source->pub.start_input = start_input_ppm;
933
25.7k
  source->pub.finish_input = finish_input_ppm;
934
25.7k
  source->pub.max_pixels = 0;
935
936
25.7k
  return (cjpeg_source_ptr)source;
937
25.7k
}
938
939
#endif /* defined(PPM_SUPPORTED) &&
940
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */