Coverage Report

Created: 2026-06-10 06:18

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
239M
  (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.83M
{
74
3.83M
  register int ch;
75
76
3.83M
  ch = getc(infile);
77
3.83M
  if (ch == '#') {
78
733k
    do {
79
733k
      ch = getc(infile);
80
733k
    } while (ch != '\n' && ch != EOF);
81
55.5k
  }
82
3.83M
  return ch;
83
3.83M
}
rdppm-8.c:pbm_getc
Line
Count
Source
73
1.83M
{
74
1.83M
  register int ch;
75
76
1.83M
  ch = getc(infile);
77
1.83M
  if (ch == '#') {
78
354k
    do {
79
354k
      ch = getc(infile);
80
354k
    } while (ch != '\n' && ch != EOF);
81
27.7k
  }
82
1.83M
  return ch;
83
1.83M
}
rdppm-12.c:pbm_getc
Line
Count
Source
73
1.31M
{
74
1.31M
  register int ch;
75
76
1.31M
  ch = getc(infile);
77
1.31M
  if (ch == '#') {
78
220k
    do {
79
220k
      ch = getc(infile);
80
220k
    } while (ch != '\n' && ch != EOF);
81
18.4k
  }
82
1.31M
  return ch;
83
1.31M
}
rdppm-16.c:pbm_getc
Line
Count
Source
73
682k
{
74
682k
  register int ch;
75
76
682k
  ch = getc(infile);
77
682k
  if (ch == '#') {
78
158k
    do {
79
158k
      ch = getc(infile);
80
158k
    } while (ch != '\n' && ch != EOF);
81
9.34k
  }
82
682k
  return ch;
83
682k
}
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.58M
{
93
1.58M
  register int ch;
94
1.58M
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
1.74M
  do {
98
1.74M
    ch = pbm_getc(infile);
99
1.74M
    if (ch == EOF)
100
36.5k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
1.74M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
1.58M
  if (ch < '0' || ch > '9')
104
3.66k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
1.58M
  val = ch - '0';
107
2.13M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
547k
    val *= 10;
109
547k
    val += ch - '0';
110
547k
    if (val > maxval)
111
1.71k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
547k
  }
113
114
1.58M
  return val;
115
1.58M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
92
759k
{
93
759k
  register int ch;
94
759k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
831k
  do {
98
831k
    ch = pbm_getc(infile);
99
831k
    if (ch == EOF)
100
17.3k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
831k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
759k
  if (ch < '0' || ch > '9')
104
1.75k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
759k
  val = ch - '0';
107
1.02M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
261k
    val *= 10;
109
261k
    val += ch - '0';
110
261k
    if (val > maxval)
111
886
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
261k
  }
113
114
759k
  return val;
115
759k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
92
536k
{
93
536k
  register int ch;
94
536k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
594k
  do {
98
594k
    ch = pbm_getc(infile);
99
594k
    if (ch == EOF)
100
12.3k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
594k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
536k
  if (ch < '0' || ch > '9')
104
1.36k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
536k
  val = ch - '0';
107
735k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
198k
    val *= 10;
109
198k
    val += ch - '0';
110
198k
    if (val > maxval)
111
549
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
198k
  }
113
114
536k
  return val;
115
536k
}
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
313k
  do {
98
313k
    ch = pbm_getc(infile);
99
313k
    if (ch == EOF)
100
6.81k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
313k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
288k
  if (ch < '0' || ch > '9')
104
552
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
288k
  val = ch - '0';
107
376k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
87.6k
    val *= 10;
109
87.6k
    val += ch - '0';
110
87.6k
    if (val > maxval)
111
278
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
87.6k
  }
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.8k
{
134
22.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
22.8k
  FILE *infile = source->pub.input_file;
136
22.8k
  register _JSAMPROW ptr;
137
22.8k
  register _JSAMPLE *rescale = source->rescale;
138
22.8k
  JDIMENSION col;
139
22.8k
  unsigned int maxval = source->maxval;
140
141
22.8k
  ptr = source->pub._buffer[0];
142
62.6k
  for (col = cinfo->image_width; col > 0; col--) {
143
39.7k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
39.7k
  }
145
22.8k
  return 1;
146
22.8k
}
rdppm-8.c:get_text_gray_row
Line
Count
Source
133
11.6k
{
134
11.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
11.6k
  FILE *infile = source->pub.input_file;
136
11.6k
  register _JSAMPROW ptr;
137
11.6k
  register _JSAMPLE *rescale = source->rescale;
138
11.6k
  JDIMENSION col;
139
11.6k
  unsigned int maxval = source->maxval;
140
141
11.6k
  ptr = source->pub._buffer[0];
142
32.6k
  for (col = cinfo->image_width; col > 0; col--) {
143
20.9k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
20.9k
  }
145
11.6k
  return 1;
146
11.6k
}
rdppm-12.c:get_text_gray_row
Line
Count
Source
133
7.48k
{
134
7.48k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
7.48k
  FILE *infile = source->pub.input_file;
136
7.48k
  register _JSAMPROW ptr;
137
7.48k
  register _JSAMPLE *rescale = source->rescale;
138
7.48k
  JDIMENSION col;
139
7.48k
  unsigned int maxval = source->maxval;
140
141
7.48k
  ptr = source->pub._buffer[0];
142
19.2k
  for (col = cinfo->image_width; col > 0; col--) {
143
11.7k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
11.7k
  }
145
7.48k
  return 1;
146
7.48k
}
rdppm-16.c:get_text_gray_row
Line
Count
Source
133
3.71k
{
134
3.71k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
3.71k
  FILE *infile = source->pub.input_file;
136
3.71k
  register _JSAMPROW ptr;
137
3.71k
  register _JSAMPLE *rescale = source->rescale;
138
3.71k
  JDIMENSION col;
139
3.71k
  unsigned int maxval = source->maxval;
140
141
3.71k
  ptr = source->pub._buffer[0];
142
10.6k
  for (col = cinfo->image_width; col > 0; col--) {
143
6.98k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
6.98k
  }
145
3.71k
  return 1;
146
3.71k
}
147
148
149
171M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
150
903M
  for (col = cinfo->image_width; col > 0; col--) { \
151
731M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
152
731M
    alpha_set_op \
153
731M
    ptr += ps; \
154
731M
  } \
155
171M
}
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
109k
{
162
109k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
109k
  FILE *infile = source->pub.input_file;
164
109k
  register _JSAMPROW ptr;
165
109k
  register _JSAMPLE *rescale = source->rescale;
166
109k
  JDIMENSION col;
167
109k
  unsigned int maxval = source->maxval;
168
109k
  register int rindex = rgb_red[cinfo->in_color_space];
169
109k
  register int gindex = rgb_green[cinfo->in_color_space];
170
109k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
109k
  register int aindex = alpha_index[cinfo->in_color_space];
172
109k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
109k
  ptr = source->pub._buffer[0];
175
109k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
22.8k
    if (aindex >= 0)
177
3.42k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
22.8k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
19.3k
    else
180
19.3k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
86.4k
  } else {
182
86.4k
    if (aindex >= 0)
183
14.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
86.4k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
71.9k
    else
186
71.9k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
86.4k
  }
188
109k
  return 1;
189
109k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
161
53.2k
{
162
53.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
53.2k
  FILE *infile = source->pub.input_file;
164
53.2k
  register _JSAMPROW ptr;
165
53.2k
  register _JSAMPLE *rescale = source->rescale;
166
53.2k
  JDIMENSION col;
167
53.2k
  unsigned int maxval = source->maxval;
168
53.2k
  register int rindex = rgb_red[cinfo->in_color_space];
169
53.2k
  register int gindex = rgb_green[cinfo->in_color_space];
170
53.2k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
53.2k
  register int aindex = alpha_index[cinfo->in_color_space];
172
53.2k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
53.2k
  ptr = source->pub._buffer[0];
175
53.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
14.0k
    if (aindex >= 0)
177
1.70k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
14.0k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
12.3k
    else
180
12.3k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
39.1k
  } else {
182
39.1k
    if (aindex >= 0)
183
5.02k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
39.1k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
34.1k
    else
186
34.1k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
39.1k
  }
188
53.2k
  return 1;
189
53.2k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
161
37.4k
{
162
37.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
37.4k
  FILE *infile = source->pub.input_file;
164
37.4k
  register _JSAMPROW ptr;
165
37.4k
  register _JSAMPLE *rescale = source->rescale;
166
37.4k
  JDIMENSION col;
167
37.4k
  unsigned int maxval = source->maxval;
168
37.4k
  register int rindex = rgb_red[cinfo->in_color_space];
169
37.4k
  register int gindex = rgb_green[cinfo->in_color_space];
170
37.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
37.4k
  register int aindex = alpha_index[cinfo->in_color_space];
172
37.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
37.4k
  ptr = source->pub._buffer[0];
175
37.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
6.54k
    if (aindex >= 0)
177
1.28k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
6.54k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
5.26k
    else
180
5.26k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
30.8k
  } else {
182
30.8k
    if (aindex >= 0)
183
6.20k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
30.8k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
24.6k
    else
186
24.6k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
30.8k
  }
188
37.4k
  return 1;
189
37.4k
}
rdppm-16.c:get_text_gray_rgb_row
Line
Count
Source
161
18.5k
{
162
18.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
18.5k
  FILE *infile = source->pub.input_file;
164
18.5k
  register _JSAMPROW ptr;
165
18.5k
  register _JSAMPLE *rescale = source->rescale;
166
18.5k
  JDIMENSION col;
167
18.5k
  unsigned int maxval = source->maxval;
168
18.5k
  register int rindex = rgb_red[cinfo->in_color_space];
169
18.5k
  register int gindex = rgb_green[cinfo->in_color_space];
170
18.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
18.5k
  register int aindex = alpha_index[cinfo->in_color_space];
172
18.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
18.5k
  ptr = source->pub._buffer[0];
175
18.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
2.16k
    if (aindex >= 0)
177
434
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
2.16k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
1.72k
    else
180
1.72k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
16.3k
  } else {
182
16.3k
    if (aindex >= 0)
183
3.27k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
16.3k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
13.1k
    else
186
13.1k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
16.3k
  }
188
18.5k
  return 1;
189
18.5k
}
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.9k
{
197
17.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
17.9k
  FILE *infile = source->pub.input_file;
199
17.9k
  register _JSAMPROW ptr;
200
17.9k
  register _JSAMPLE *rescale = source->rescale;
201
17.9k
  JDIMENSION col;
202
17.9k
  unsigned int maxval = source->maxval;
203
204
17.9k
  ptr = source->pub._buffer[0];
205
17.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
13.5k
    for (col = cinfo->image_width; col > 0; col--) {
207
8.94k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
8.94k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
8.94k
      ptr += 4;
210
8.94k
    }
211
13.3k
  } else {
212
35.7k
    for (col = cinfo->image_width; col > 0; col--) {
213
22.4k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
22.4k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
22.4k
                  ptr + 1, ptr + 2, ptr + 3);
216
22.4k
      ptr += 4;
217
22.4k
    }
218
13.3k
  }
219
17.9k
  return 1;
220
17.9k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
196
6.73k
{
197
6.73k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
6.73k
  FILE *infile = source->pub.input_file;
199
6.73k
  register _JSAMPROW ptr;
200
6.73k
  register _JSAMPLE *rescale = source->rescale;
201
6.73k
  JDIMENSION col;
202
6.73k
  unsigned int maxval = source->maxval;
203
204
6.73k
  ptr = source->pub._buffer[0];
205
6.73k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
6.34k
    for (col = cinfo->image_width; col > 0; col--) {
207
4.05k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
4.05k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
4.05k
      ptr += 4;
210
4.05k
    }
211
4.44k
  } else {
212
12.9k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.53k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
8.53k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
8.53k
                  ptr + 1, ptr + 2, ptr + 3);
216
8.53k
      ptr += 4;
217
8.53k
    }
218
4.44k
  }
219
6.73k
  return 1;
220
6.73k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
196
7.48k
{
197
7.48k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
7.48k
  FILE *infile = source->pub.input_file;
199
7.48k
  register _JSAMPROW ptr;
200
7.48k
  register _JSAMPLE *rescale = source->rescale;
201
7.48k
  JDIMENSION col;
202
7.48k
  unsigned int maxval = source->maxval;
203
204
7.48k
  ptr = source->pub._buffer[0];
205
7.48k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
4.65k
    for (col = cinfo->image_width; col > 0; col--) {
207
3.04k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
3.04k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
3.04k
      ptr += 4;
210
3.04k
    }
211
5.88k
  } else {
212
14.6k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.74k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
8.74k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
8.74k
                  ptr + 1, ptr + 2, ptr + 3);
216
8.74k
      ptr += 4;
217
8.74k
    }
218
5.88k
  }
219
7.48k
  return 1;
220
7.48k
}
rdppm-16.c:get_text_gray_cmyk_row
Line
Count
Source
196
3.71k
{
197
3.71k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
3.71k
  FILE *infile = source->pub.input_file;
199
3.71k
  register _JSAMPROW ptr;
200
3.71k
  register _JSAMPLE *rescale = source->rescale;
201
3.71k
  JDIMENSION col;
202
3.71k
  unsigned int maxval = source->maxval;
203
204
3.71k
  ptr = source->pub._buffer[0];
205
3.71k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
2.52k
    for (col = cinfo->image_width; col > 0; col--) {
207
1.84k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
1.84k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
1.84k
      ptr += 4;
210
1.84k
    }
211
3.02k
  } else {
212
8.16k
    for (col = cinfo->image_width; col > 0; col--) {
213
5.13k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
5.13k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
5.13k
                  ptr + 1, ptr + 2, ptr + 3);
216
5.13k
      ptr += 4;
217
5.13k
    }
218
3.02k
  }
219
3.71k
  return 1;
220
3.71k
}
221
222
223
7.44M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
224
80.4M
  for (col = cinfo->image_width; col > 0; col--) { \
225
73.0M
    ptr[rindex] = read_op; \
226
73.0M
    ptr[gindex] = read_op; \
227
73.0M
    ptr[bindex] = read_op; \
228
73.0M
    alpha_set_op \
229
73.0M
    ptr += ps; \
230
73.0M
  } \
231
7.44M
}
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
118k
{
237
118k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
118k
  FILE *infile = source->pub.input_file;
239
118k
  register _JSAMPROW ptr;
240
118k
  register _JSAMPLE *rescale = source->rescale;
241
118k
  JDIMENSION col;
242
118k
  unsigned int maxval = source->maxval;
243
118k
  register int rindex = rgb_red[cinfo->in_color_space];
244
118k
  register int gindex = rgb_green[cinfo->in_color_space];
245
118k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
118k
  register int aindex = alpha_index[cinfo->in_color_space];
247
118k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
118k
  ptr = source->pub._buffer[0];
250
118k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
25.9k
    if (aindex >= 0)
252
4.49k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
25.9k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
21.4k
    else
255
21.4k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
92.6k
  } else {
257
92.6k
    if (aindex >= 0)
258
15.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
92.6k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
76.8k
    else
261
76.8k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
92.6k
  }
263
118k
  return 1;
264
118k
}
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.8k
    if (aindex >= 0)
252
1.65k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
11.8k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
10.1k
    else
255
10.1k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
45.4k
  } else {
257
45.4k
    if (aindex >= 0)
258
6.36k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
45.4k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
39.1k
    else
261
39.1k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
45.4k
  }
263
57.2k
  return 1;
264
57.2k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
236
36.3k
{
237
36.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
36.3k
  FILE *infile = source->pub.input_file;
239
36.3k
  register _JSAMPROW ptr;
240
36.3k
  register _JSAMPLE *rescale = source->rescale;
241
36.3k
  JDIMENSION col;
242
36.3k
  unsigned int maxval = source->maxval;
243
36.3k
  register int rindex = rgb_red[cinfo->in_color_space];
244
36.3k
  register int gindex = rgb_green[cinfo->in_color_space];
245
36.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
36.3k
  register int aindex = alpha_index[cinfo->in_color_space];
247
36.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
36.3k
  ptr = source->pub._buffer[0];
250
36.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
9.75k
    if (aindex >= 0)
252
2.39k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
9.75k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
7.36k
    else
255
7.36k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
26.6k
  } else {
257
26.6k
    if (aindex >= 0)
258
4.88k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
26.6k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
21.7k
    else
261
21.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
26.6k
  }
263
36.3k
  return 1;
264
36.3k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
236
24.9k
{
237
24.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
24.9k
  FILE *infile = source->pub.input_file;
239
24.9k
  register _JSAMPROW ptr;
240
24.9k
  register _JSAMPLE *rescale = source->rescale;
241
24.9k
  JDIMENSION col;
242
24.9k
  unsigned int maxval = source->maxval;
243
24.9k
  register int rindex = rgb_red[cinfo->in_color_space];
244
24.9k
  register int gindex = rgb_green[cinfo->in_color_space];
245
24.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
24.9k
  register int aindex = alpha_index[cinfo->in_color_space];
247
24.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
24.9k
  ptr = source->pub._buffer[0];
250
24.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
4.41k
    if (aindex >= 0)
252
449
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
4.41k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
3.96k
    else
255
3.96k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
20.5k
  } else {
257
20.5k
    if (aindex >= 0)
258
4.54k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
20.5k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
16.0k
    else
261
16.0k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
20.5k
  }
263
24.9k
  return 1;
264
24.9k
}
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.2k
{
272
20.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
20.2k
  FILE *infile = source->pub.input_file;
274
20.2k
  register _JSAMPROW ptr;
275
20.2k
  register _JSAMPLE *rescale = source->rescale;
276
20.2k
  JDIMENSION col;
277
20.2k
  unsigned int maxval = source->maxval;
278
279
20.2k
  ptr = source->pub._buffer[0];
280
20.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
21.4k
    for (col = cinfo->image_width; col > 0; col--) {
282
14.9k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
14.9k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
14.9k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
14.9k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
14.9k
      ptr += 4;
287
14.9k
    }
288
13.7k
  } else {
289
39.3k
    for (col = cinfo->image_width; col > 0; col--) {
290
25.5k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
25.5k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
25.5k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
25.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
25.5k
                  ptr + 2, ptr + 3);
295
25.5k
      ptr += 4;
296
25.5k
    }
297
13.7k
  }
298
20.2k
  return 1;
299
20.2k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
271
8.02k
{
272
8.02k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
8.02k
  FILE *infile = source->pub.input_file;
274
8.02k
  register _JSAMPROW ptr;
275
8.02k
  register _JSAMPLE *rescale = source->rescale;
276
8.02k
  JDIMENSION col;
277
8.02k
  unsigned int maxval = source->maxval;
278
279
8.02k
  ptr = source->pub._buffer[0];
280
8.02k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
7.51k
    for (col = cinfo->image_width; col > 0; col--) {
282
4.96k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
4.96k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
4.96k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
4.96k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
4.96k
      ptr += 4;
287
4.96k
    }
288
5.47k
  } else {
289
15.8k
    for (col = cinfo->image_width; col > 0; col--) {
290
10.4k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
10.4k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
10.4k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
10.4k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
10.4k
                  ptr + 2, ptr + 3);
295
10.4k
      ptr += 4;
296
10.4k
    }
297
5.47k
  }
298
8.02k
  return 1;
299
8.02k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
271
7.27k
{
272
7.27k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
7.27k
  FILE *infile = source->pub.input_file;
274
7.27k
  register _JSAMPROW ptr;
275
7.27k
  register _JSAMPLE *rescale = source->rescale;
276
7.27k
  JDIMENSION col;
277
7.27k
  unsigned int maxval = source->maxval;
278
279
7.27k
  ptr = source->pub._buffer[0];
280
7.27k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
8.37k
    for (col = cinfo->image_width; col > 0; col--) {
282
6.14k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
6.14k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
6.14k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
6.14k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
6.14k
      ptr += 4;
287
6.14k
    }
288
5.05k
  } else {
289
14.4k
    for (col = cinfo->image_width; col > 0; col--) {
290
9.36k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
9.36k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
9.36k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
9.36k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
9.36k
                  ptr + 2, ptr + 3);
295
9.36k
      ptr += 4;
296
9.36k
    }
297
5.05k
  }
298
7.27k
  return 1;
299
7.27k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
271
4.99k
{
272
4.99k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
4.99k
  FILE *infile = source->pub.input_file;
274
4.99k
  register _JSAMPROW ptr;
275
4.99k
  register _JSAMPLE *rescale = source->rescale;
276
4.99k
  JDIMENSION col;
277
4.99k
  unsigned int maxval = source->maxval;
278
279
4.99k
  ptr = source->pub._buffer[0];
280
4.99k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
5.61k
    for (col = cinfo->image_width; col > 0; col--) {
282
3.87k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
3.87k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
3.87k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
3.87k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
3.87k
      ptr += 4;
287
3.87k
    }
288
3.25k
  } else {
289
9.01k
    for (col = cinfo->image_width; col > 0; col--) {
290
5.75k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
5.75k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
5.75k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
5.75k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
5.75k
                  ptr + 2, ptr + 3);
295
5.75k
      ptr += 4;
296
5.75k
    }
297
3.25k
  }
298
4.99k
  return 1;
299
4.99k
}
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.5M
{
306
32.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
32.5M
  register _JSAMPROW ptr;
308
32.5M
  register unsigned char *bufferptr;
309
32.5M
  register _JSAMPLE *rescale = source->rescale;
310
32.5M
  JDIMENSION col;
311
312
32.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
1.44k
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
32.5M
  ptr = source->pub._buffer[0];
315
32.5M
  bufferptr = source->iobuffer;
316
173M
  for (col = cinfo->image_width; col > 0; col--) {
317
140M
    *ptr++ = rescale[*bufferptr++];
318
140M
  }
319
32.5M
  return 1;
320
32.5M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
305
16.4M
{
306
16.4M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
16.4M
  register _JSAMPROW ptr;
308
16.4M
  register unsigned char *bufferptr;
309
16.4M
  register _JSAMPLE *rescale = source->rescale;
310
16.4M
  JDIMENSION col;
311
312
16.4M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
981
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
16.4M
  ptr = source->pub._buffer[0];
315
16.4M
  bufferptr = source->iobuffer;
316
84.4M
  for (col = cinfo->image_width; col > 0; col--) {
317
68.0M
    *ptr++ = rescale[*bufferptr++];
318
68.0M
  }
319
16.4M
  return 1;
320
16.4M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
305
12.3M
{
306
12.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
12.3M
  register _JSAMPROW ptr;
308
12.3M
  register unsigned char *bufferptr;
309
12.3M
  register _JSAMPLE *rescale = source->rescale;
310
12.3M
  JDIMENSION col;
311
312
12.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
322
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
12.3M
  ptr = source->pub._buffer[0];
315
12.3M
  bufferptr = source->iobuffer;
316
67.6M
  for (col = cinfo->image_width; col > 0; col--) {
317
55.2M
    *ptr++ = rescale[*bufferptr++];
318
55.2M
  }
319
12.3M
  return 1;
320
12.3M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
305
3.75M
{
306
3.75M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
3.75M
  register _JSAMPROW ptr;
308
3.75M
  register unsigned char *bufferptr;
309
3.75M
  register _JSAMPLE *rescale = source->rescale;
310
3.75M
  JDIMENSION col;
311
312
3.75M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
144
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
3.75M
  ptr = source->pub._buffer[0];
315
3.75M
  bufferptr = source->iobuffer;
316
21.1M
  for (col = cinfo->image_width; col > 0; col--) {
317
17.3M
    *ptr++ = rescale[*bufferptr++];
318
17.3M
  }
319
3.75M
  return 1;
320
3.75M
}
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
171M
{
328
171M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
171M
  register _JSAMPROW ptr;
330
171M
  register unsigned char *bufferptr;
331
171M
  register _JSAMPLE *rescale = source->rescale;
332
171M
  JDIMENSION col;
333
171M
  unsigned int maxval = source->maxval;
334
171M
  register int rindex = rgb_red[cinfo->in_color_space];
335
171M
  register int gindex = rgb_green[cinfo->in_color_space];
336
171M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
171M
  register int aindex = alpha_index[cinfo->in_color_space];
338
171M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
171M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
6.07k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
171M
  ptr = source->pub._buffer[0];
343
171M
  bufferptr = source->iobuffer;
344
171M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
8.41M
    if (aindex >= 0)
346
714k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
7.70M
    else
348
7.70M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
162M
  } else {
350
162M
    if (aindex >= 0)
351
23.6M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
162M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
139M
    else
354
139M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
162M
  }
356
171M
  return 1;
357
171M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
327
90.5M
{
328
90.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
90.5M
  register _JSAMPROW ptr;
330
90.5M
  register unsigned char *bufferptr;
331
90.5M
  register _JSAMPLE *rescale = source->rescale;
332
90.5M
  JDIMENSION col;
333
90.5M
  unsigned int maxval = source->maxval;
334
90.5M
  register int rindex = rgb_red[cinfo->in_color_space];
335
90.5M
  register int gindex = rgb_green[cinfo->in_color_space];
336
90.5M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
90.5M
  register int aindex = alpha_index[cinfo->in_color_space];
338
90.5M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
90.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
3.74k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
90.5M
  ptr = source->pub._buffer[0];
343
90.5M
  bufferptr = source->iobuffer;
344
90.5M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
8.41M
    if (aindex >= 0)
346
714k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
7.70M
    else
348
7.70M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
82.1M
  } else {
350
82.1M
    if (aindex >= 0)
351
7.52M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
82.1M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
74.6M
    else
354
74.6M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
82.1M
  }
356
90.5M
  return 1;
357
90.5M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
327
61.8M
{
328
61.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
61.8M
  register _JSAMPROW ptr;
330
61.8M
  register unsigned char *bufferptr;
331
61.8M
  register _JSAMPLE *rescale = source->rescale;
332
61.8M
  JDIMENSION col;
333
61.8M
  unsigned int maxval = source->maxval;
334
61.8M
  register int rindex = rgb_red[cinfo->in_color_space];
335
61.8M
  register int gindex = rgb_green[cinfo->in_color_space];
336
61.8M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
61.8M
  register int aindex = alpha_index[cinfo->in_color_space];
338
61.8M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
61.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
1.61k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
61.8M
  ptr = source->pub._buffer[0];
343
61.8M
  bufferptr = source->iobuffer;
344
61.8M
  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
61.8M
  } else {
350
61.8M
    if (aindex >= 0)
351
12.3M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
61.8M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
49.5M
    else
354
49.5M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
61.8M
  }
356
61.8M
  return 1;
357
61.8M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
327
18.7M
{
328
18.7M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
18.7M
  register _JSAMPROW ptr;
330
18.7M
  register unsigned char *bufferptr;
331
18.7M
  register _JSAMPLE *rescale = source->rescale;
332
18.7M
  JDIMENSION col;
333
18.7M
  unsigned int maxval = source->maxval;
334
18.7M
  register int rindex = rgb_red[cinfo->in_color_space];
335
18.7M
  register int gindex = rgb_green[cinfo->in_color_space];
336
18.7M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
18.7M
  register int aindex = alpha_index[cinfo->in_color_space];
338
18.7M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
18.7M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
720
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
18.7M
  ptr = source->pub._buffer[0];
343
18.7M
  bufferptr = source->iobuffer;
344
18.7M
  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
18.7M
  } else {
350
18.7M
    if (aindex >= 0)
351
3.75M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
18.7M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
15.0M
    else
354
15.0M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
18.7M
  }
356
18.7M
  return 1;
357
18.7M
}
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.3M
{
365
24.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
24.3M
  register _JSAMPROW ptr;
367
24.3M
  register unsigned char *bufferptr;
368
24.3M
  register _JSAMPLE *rescale = source->rescale;
369
24.3M
  JDIMENSION col;
370
24.3M
  unsigned int maxval = source->maxval;
371
372
24.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
1.00k
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
24.3M
  ptr = source->pub._buffer[0];
375
24.3M
  bufferptr = source->iobuffer;
376
24.3M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
5.35M
    for (col = cinfo->image_width; col > 0; col--) {
378
4.26M
      _JSAMPLE gray = *bufferptr++;
379
4.26M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
4.26M
      ptr += 4;
381
4.26M
    }
382
23.2M
  } else {
383
140M
    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
23.2M
  }
390
24.3M
  return 1;
391
24.3M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
364
8.23M
{
365
8.23M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
8.23M
  register _JSAMPROW ptr;
367
8.23M
  register unsigned char *bufferptr;
368
8.23M
  register _JSAMPLE *rescale = source->rescale;
369
8.23M
  JDIMENSION col;
370
8.23M
  unsigned int maxval = source->maxval;
371
372
8.23M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
537
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
8.23M
  ptr = source->pub._buffer[0];
375
8.23M
  bufferptr = source->iobuffer;
376
8.23M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
5.35M
    for (col = cinfo->image_width; col > 0; col--) {
378
4.26M
      _JSAMPLE gray = *bufferptr++;
379
4.26M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
4.26M
      ptr += 4;
381
4.26M
    }
382
7.14M
  } else {
383
51.2M
    for (col = cinfo->image_width; col > 0; col--) {
384
44.1M
      _JSAMPLE gray = rescale[*bufferptr++];
385
44.1M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
44.1M
                  ptr + 1, ptr + 2, ptr + 3);
387
44.1M
      ptr += 4;
388
44.1M
    }
389
7.14M
  }
390
8.23M
  return 1;
391
8.23M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
364
12.3M
{
365
12.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
12.3M
  register _JSAMPROW ptr;
367
12.3M
  register unsigned char *bufferptr;
368
12.3M
  register _JSAMPLE *rescale = source->rescale;
369
12.3M
  JDIMENSION col;
370
12.3M
  unsigned int maxval = source->maxval;
371
372
12.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
322
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
12.3M
  ptr = source->pub._buffer[0];
375
12.3M
  bufferptr = source->iobuffer;
376
12.3M
  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
12.3M
  } else {
383
67.6M
    for (col = cinfo->image_width; col > 0; col--) {
384
55.2M
      _JSAMPLE gray = rescale[*bufferptr++];
385
55.2M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
55.2M
                  ptr + 1, ptr + 2, ptr + 3);
387
55.2M
      ptr += 4;
388
55.2M
    }
389
12.3M
  }
390
12.3M
  return 1;
391
12.3M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
364
3.75M
{
365
3.75M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
3.75M
  register _JSAMPROW ptr;
367
3.75M
  register unsigned char *bufferptr;
368
3.75M
  register _JSAMPLE *rescale = source->rescale;
369
3.75M
  JDIMENSION col;
370
3.75M
  unsigned int maxval = source->maxval;
371
372
3.75M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
144
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
3.75M
  ptr = source->pub._buffer[0];
375
3.75M
  bufferptr = source->iobuffer;
376
3.75M
  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.75M
  } else {
383
21.1M
    for (col = cinfo->image_width; col > 0; col--) {
384
17.3M
      _JSAMPLE gray = rescale[*bufferptr++];
385
17.3M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
17.3M
                  ptr + 1, ptr + 2, ptr + 3);
387
17.3M
      ptr += 4;
388
17.3M
    }
389
3.75M
  }
390
3.75M
  return 1;
391
3.75M
}
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
7.33M
{
398
7.33M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
7.33M
  register _JSAMPROW ptr;
400
7.33M
  register unsigned char *bufferptr;
401
7.33M
  register _JSAMPLE *rescale = source->rescale;
402
7.33M
  JDIMENSION col;
403
7.33M
  unsigned int maxval = source->maxval;
404
7.33M
  register int rindex = rgb_red[cinfo->in_color_space];
405
7.33M
  register int gindex = rgb_green[cinfo->in_color_space];
406
7.33M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
7.33M
  register int aindex = alpha_index[cinfo->in_color_space];
408
7.33M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
7.33M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
7.69k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
7.33M
  ptr = source->pub._buffer[0];
413
7.33M
  bufferptr = source->iobuffer;
414
7.33M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
78.3k
    if (aindex >= 0)
416
13.6k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
64.6k
    else
418
64.6k
      RGB_READ_LOOP(*bufferptr++, {})
419
7.25M
  } else {
420
7.25M
    if (aindex >= 0)
421
1.41M
      RGB_READ_LOOP(rescale[*bufferptr++],
422
7.25M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
5.83M
    else
424
5.83M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
7.25M
  }
426
7.33M
  return 1;
427
7.33M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
397
1.97M
{
398
1.97M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
1.97M
  register _JSAMPROW ptr;
400
1.97M
  register unsigned char *bufferptr;
401
1.97M
  register _JSAMPLE *rescale = source->rescale;
402
1.97M
  JDIMENSION col;
403
1.97M
  unsigned int maxval = source->maxval;
404
1.97M
  register int rindex = rgb_red[cinfo->in_color_space];
405
1.97M
  register int gindex = rgb_green[cinfo->in_color_space];
406
1.97M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
1.97M
  register int aindex = alpha_index[cinfo->in_color_space];
408
1.97M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
1.97M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
4.45k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
1.97M
  ptr = source->pub._buffer[0];
413
1.97M
  bufferptr = source->iobuffer;
414
1.97M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
78.3k
    if (aindex >= 0)
416
13.6k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
64.6k
    else
418
64.6k
      RGB_READ_LOOP(*bufferptr++, {})
419
1.89M
  } else {
420
1.89M
    if (aindex >= 0)
421
342k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
1.89M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
1.55M
    else
424
1.55M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
1.89M
  }
426
1.97M
  return 1;
427
1.97M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
397
4.53M
{
398
4.53M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
4.53M
  register _JSAMPROW ptr;
400
4.53M
  register unsigned char *bufferptr;
401
4.53M
  register _JSAMPLE *rescale = source->rescale;
402
4.53M
  JDIMENSION col;
403
4.53M
  unsigned int maxval = source->maxval;
404
4.53M
  register int rindex = rgb_red[cinfo->in_color_space];
405
4.53M
  register int gindex = rgb_green[cinfo->in_color_space];
406
4.53M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
4.53M
  register int aindex = alpha_index[cinfo->in_color_space];
408
4.53M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
4.53M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
2.12k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
4.53M
  ptr = source->pub._buffer[0];
413
4.53M
  bufferptr = source->iobuffer;
414
4.53M
  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.53M
  } else {
420
4.53M
    if (aindex >= 0)
421
907k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
4.53M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
3.63M
    else
424
3.63M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
4.53M
  }
426
4.53M
  return 1;
427
4.53M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
397
817k
{
398
817k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
817k
  register _JSAMPROW ptr;
400
817k
  register unsigned char *bufferptr;
401
817k
  register _JSAMPLE *rescale = source->rescale;
402
817k
  JDIMENSION col;
403
817k
  unsigned int maxval = source->maxval;
404
817k
  register int rindex = rgb_red[cinfo->in_color_space];
405
817k
  register int gindex = rgb_green[cinfo->in_color_space];
406
817k
  register int bindex = rgb_blue[cinfo->in_color_space];
407
817k
  register int aindex = alpha_index[cinfo->in_color_space];
408
817k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
817k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
1.11k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
817k
  ptr = source->pub._buffer[0];
413
817k
  bufferptr = source->iobuffer;
414
817k
  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
817k
  } else {
420
817k
    if (aindex >= 0)
421
163k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
817k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
654k
    else
424
654k
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
817k
  }
426
817k
  return 1;
427
817k
}
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.42M
{
435
1.42M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
1.42M
  register _JSAMPROW ptr;
437
1.42M
  register unsigned char *bufferptr;
438
1.42M
  register _JSAMPLE *rescale = source->rescale;
439
1.42M
  JDIMENSION col;
440
1.42M
  unsigned int maxval = source->maxval;
441
442
1.42M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
1.32k
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
1.42M
  ptr = source->pub._buffer[0];
445
1.42M
  bufferptr = source->iobuffer;
446
1.42M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
200k
    for (col = cinfo->image_width; col > 0; col--) {
448
182k
      _JSAMPLE r = *bufferptr++;
449
182k
      _JSAMPLE g = *bufferptr++;
450
182k
      _JSAMPLE b = *bufferptr++;
451
182k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
182k
      ptr += 4;
453
182k
    }
454
1.41M
  } else {
455
15.4M
    for (col = cinfo->image_width; col > 0; col--) {
456
14.0M
      _JSAMPLE r = rescale[*bufferptr++];
457
14.0M
      _JSAMPLE g = rescale[*bufferptr++];
458
14.0M
      _JSAMPLE b = rescale[*bufferptr++];
459
14.0M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
14.0M
                  ptr + 2, ptr + 3);
461
14.0M
      ptr += 4;
462
14.0M
    }
463
1.41M
  }
464
1.42M
  return 1;
465
1.42M
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
434
357k
{
435
357k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
357k
  register _JSAMPROW ptr;
437
357k
  register unsigned char *bufferptr;
438
357k
  register _JSAMPLE *rescale = source->rescale;
439
357k
  JDIMENSION col;
440
357k
  unsigned int maxval = source->maxval;
441
442
357k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
674
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
357k
  ptr = source->pub._buffer[0];
445
357k
  bufferptr = source->iobuffer;
446
357k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
200k
    for (col = cinfo->image_width; col > 0; col--) {
448
182k
      _JSAMPLE r = *bufferptr++;
449
182k
      _JSAMPLE g = *bufferptr++;
450
182k
      _JSAMPLE b = *bufferptr++;
451
182k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
182k
      ptr += 4;
453
182k
    }
454
339k
  } else {
455
3.05M
    for (col = cinfo->image_width; col > 0; col--) {
456
2.71M
      _JSAMPLE r = rescale[*bufferptr++];
457
2.71M
      _JSAMPLE g = rescale[*bufferptr++];
458
2.71M
      _JSAMPLE b = rescale[*bufferptr++];
459
2.71M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
2.71M
                  ptr + 2, ptr + 3);
461
2.71M
      ptr += 4;
462
2.71M
    }
463
339k
  }
464
357k
  return 1;
465
357k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
434
907k
{
435
907k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
907k
  register _JSAMPROW ptr;
437
907k
  register unsigned char *bufferptr;
438
907k
  register _JSAMPLE *rescale = source->rescale;
439
907k
  JDIMENSION col;
440
907k
  unsigned int maxval = source->maxval;
441
442
907k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
425
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
907k
  ptr = source->pub._buffer[0];
445
907k
  bufferptr = source->iobuffer;
446
907k
  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
907k
  } else {
455
8.65M
    for (col = cinfo->image_width; col > 0; col--) {
456
7.74M
      _JSAMPLE r = rescale[*bufferptr++];
457
7.74M
      _JSAMPLE g = rescale[*bufferptr++];
458
7.74M
      _JSAMPLE b = rescale[*bufferptr++];
459
7.74M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
7.74M
                  ptr + 2, ptr + 3);
461
7.74M
      ptr += 4;
462
7.74M
    }
463
907k
  }
464
907k
  return 1;
465
907k
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
434
163k
{
435
163k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
163k
  register _JSAMPROW ptr;
437
163k
  register unsigned char *bufferptr;
438
163k
  register _JSAMPLE *rescale = source->rescale;
439
163k
  JDIMENSION col;
440
163k
  unsigned int maxval = source->maxval;
441
442
163k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
222
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
163k
  ptr = source->pub._buffer[0];
445
163k
  bufferptr = source->iobuffer;
446
163k
  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
163k
  } else {
455
3.74M
    for (col = cinfo->image_width; col > 0; col--) {
456
3.58M
      _JSAMPLE r = rescale[*bufferptr++];
457
3.58M
      _JSAMPLE g = rescale[*bufferptr++];
458
3.58M
      _JSAMPLE b = rescale[*bufferptr++];
459
3.58M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
3.58M
                  ptr + 2, ptr + 3);
461
3.58M
      ptr += 4;
462
3.58M
    }
463
163k
  }
464
163k
  return 1;
465
163k
}
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
1.71M
{
478
1.71M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
479
480
1.71M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
481
421
    ERREXIT(cinfo, JERR_INPUT_EOF);
482
1.71M
  return 1;
483
1.71M
}
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
112k
{
492
112k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
112k
  register _JSAMPROW ptr;
494
112k
  register unsigned char *bufferptr;
495
112k
  register _JSAMPLE *rescale = source->rescale;
496
112k
  JDIMENSION col;
497
112k
  unsigned int maxval = source->maxval;
498
499
112k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
1.12k
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
112k
  ptr = source->pub._buffer[0];
502
112k
  bufferptr = source->iobuffer;
503
428k
  for (col = cinfo->image_width; col > 0; col--) {
504
315k
    register unsigned int temp;
505
315k
    temp  = (*bufferptr++) << 8;
506
315k
    temp |= (*bufferptr++);
507
315k
    if (temp > maxval)
508
710
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
315k
    *ptr++ = rescale[temp];
510
315k
  }
511
112k
  return 1;
512
112k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
491
15.4k
{
492
15.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
15.4k
  register _JSAMPROW ptr;
494
15.4k
  register unsigned char *bufferptr;
495
15.4k
  register _JSAMPLE *rescale = source->rescale;
496
15.4k
  JDIMENSION col;
497
15.4k
  unsigned int maxval = source->maxval;
498
499
15.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
530
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
15.4k
  ptr = source->pub._buffer[0];
502
15.4k
  bufferptr = source->iobuffer;
503
83.6k
  for (col = cinfo->image_width; col > 0; col--) {
504
68.2k
    register unsigned int temp;
505
68.2k
    temp  = (*bufferptr++) << 8;
506
68.2k
    temp |= (*bufferptr++);
507
68.2k
    if (temp > maxval)
508
352
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
68.2k
    *ptr++ = rescale[temp];
510
68.2k
  }
511
15.4k
  return 1;
512
15.4k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
491
67.1k
{
492
67.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
67.1k
  register _JSAMPROW ptr;
494
67.1k
  register unsigned char *bufferptr;
495
67.1k
  register _JSAMPLE *rescale = source->rescale;
496
67.1k
  JDIMENSION col;
497
67.1k
  unsigned int maxval = source->maxval;
498
499
67.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
367
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
67.1k
  ptr = source->pub._buffer[0];
502
67.1k
  bufferptr = source->iobuffer;
503
141k
  for (col = cinfo->image_width; col > 0; col--) {
504
74.6k
    register unsigned int temp;
505
74.6k
    temp  = (*bufferptr++) << 8;
506
74.6k
    temp |= (*bufferptr++);
507
74.6k
    if (temp > maxval)
508
285
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
74.6k
    *ptr++ = rescale[temp];
510
74.6k
  }
511
67.1k
  return 1;
512
67.1k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
491
29.9k
{
492
29.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
29.9k
  register _JSAMPROW ptr;
494
29.9k
  register unsigned char *bufferptr;
495
29.9k
  register _JSAMPLE *rescale = source->rescale;
496
29.9k
  JDIMENSION col;
497
29.9k
  unsigned int maxval = source->maxval;
498
499
29.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
223
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
29.9k
  ptr = source->pub._buffer[0];
502
29.9k
  bufferptr = source->iobuffer;
503
202k
  for (col = cinfo->image_width; col > 0; col--) {
504
172k
    register unsigned int temp;
505
172k
    temp  = (*bufferptr++) << 8;
506
172k
    temp |= (*bufferptr++);
507
172k
    if (temp > maxval)
508
73
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
172k
    *ptr++ = rescale[temp];
510
172k
  }
511
29.9k
  return 1;
512
29.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
558k
{
519
558k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
558k
  register _JSAMPROW ptr;
521
558k
  register unsigned char *bufferptr;
522
558k
  register _JSAMPLE *rescale = source->rescale;
523
558k
  JDIMENSION col;
524
558k
  unsigned int maxval = source->maxval;
525
558k
  register int rindex = rgb_red[cinfo->in_color_space];
526
558k
  register int gindex = rgb_green[cinfo->in_color_space];
527
558k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
558k
  register int aindex = alpha_index[cinfo->in_color_space];
529
558k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
558k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
4.81k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
558k
  ptr = source->pub._buffer[0];
534
558k
  bufferptr = source->iobuffer;
535
2.12M
  for (col = cinfo->image_width; col > 0; col--) {
536
1.57M
    register unsigned int temp;
537
1.57M
    temp  = (*bufferptr++) << 8;
538
1.57M
    temp |= (*bufferptr++);
539
1.57M
    if (temp > maxval)
540
2.99k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
1.57M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
1.57M
    if (aindex >= 0)
543
265k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
1.57M
    ptr += ps;
545
1.57M
  }
546
558k
  return 1;
547
558k
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
518
72.5k
{
519
72.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
72.5k
  register _JSAMPROW ptr;
521
72.5k
  register unsigned char *bufferptr;
522
72.5k
  register _JSAMPLE *rescale = source->rescale;
523
72.5k
  JDIMENSION col;
524
72.5k
  unsigned int maxval = source->maxval;
525
72.5k
  register int rindex = rgb_red[cinfo->in_color_space];
526
72.5k
  register int gindex = rgb_green[cinfo->in_color_space];
527
72.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
72.5k
  register int aindex = alpha_index[cinfo->in_color_space];
529
72.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
72.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.86k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
72.5k
  ptr = source->pub._buffer[0];
534
72.5k
  bufferptr = source->iobuffer;
535
407k
  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.20k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
334k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
334k
    if (aindex >= 0)
543
18.1k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
334k
    ptr += ps;
545
334k
  }
546
72.5k
  return 1;
547
72.5k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
518
335k
{
519
335k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
335k
  register _JSAMPROW ptr;
521
335k
  register unsigned char *bufferptr;
522
335k
  register _JSAMPLE *rescale = source->rescale;
523
335k
  JDIMENSION col;
524
335k
  unsigned int maxval = source->maxval;
525
335k
  register int rindex = rgb_red[cinfo->in_color_space];
526
335k
  register int gindex = rgb_green[cinfo->in_color_space];
527
335k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
335k
  register int aindex = alpha_index[cinfo->in_color_space];
529
335k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
335k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.83k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
335k
  ptr = source->pub._buffer[0];
534
335k
  bufferptr = source->iobuffer;
535
708k
  for (col = cinfo->image_width; col > 0; col--) {
536
373k
    register unsigned int temp;
537
373k
    temp  = (*bufferptr++) << 8;
538
373k
    temp |= (*bufferptr++);
539
373k
    if (temp > maxval)
540
1.42k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
373k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
373k
    if (aindex >= 0)
543
74.3k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
373k
    ptr += ps;
545
373k
  }
546
335k
  return 1;
547
335k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
518
149k
{
519
149k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
149k
  register _JSAMPROW ptr;
521
149k
  register unsigned char *bufferptr;
522
149k
  register _JSAMPLE *rescale = source->rescale;
523
149k
  JDIMENSION col;
524
149k
  unsigned int maxval = source->maxval;
525
149k
  register int rindex = rgb_red[cinfo->in_color_space];
526
149k
  register int gindex = rgb_green[cinfo->in_color_space];
527
149k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
149k
  register int aindex = alpha_index[cinfo->in_color_space];
529
149k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
149k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.11k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
149k
  ptr = source->pub._buffer[0];
534
149k
  bufferptr = source->iobuffer;
535
1.01M
  for (col = cinfo->image_width; col > 0; col--) {
536
863k
    register unsigned int temp;
537
863k
    temp  = (*bufferptr++) << 8;
538
863k
    temp |= (*bufferptr++);
539
863k
    if (temp > maxval)
540
365
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
863k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
863k
    if (aindex >= 0)
543
172k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
863k
    ptr += ps;
545
863k
  }
546
149k
  return 1;
547
149k
}
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
108k
{
554
108k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
108k
  register _JSAMPROW ptr;
556
108k
  register unsigned char *bufferptr;
557
108k
  register _JSAMPLE *rescale = source->rescale;
558
108k
  JDIMENSION col;
559
108k
  unsigned int maxval = source->maxval;
560
561
108k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
850
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
108k
  ptr = source->pub._buffer[0];
564
108k
  bufferptr = source->iobuffer;
565
108k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
189k
    for (col = cinfo->image_width; col > 0; col--) {
567
163k
      register unsigned int gray;
568
163k
      gray  = (*bufferptr++) << 8;
569
163k
      gray |= (*bufferptr++);
570
163k
      if (gray > maxval)
571
91
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
163k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
163k
                  ptr + 1, ptr + 2, ptr + 3);
574
163k
      ptr += 4;
575
163k
    }
576
82.6k
  } else {
577
184k
    for (col = cinfo->image_width; col > 0; col--) {
578
101k
      register unsigned int temp;
579
101k
      _JSAMPLE gray;
580
101k
      temp  = (*bufferptr++) << 8;
581
101k
      temp |= (*bufferptr++);
582
101k
      if (temp > maxval)
583
431
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
101k
      gray = rescale[temp];
585
101k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
101k
                  ptr + 1, ptr + 2, ptr + 3);
587
101k
      ptr += 4;
588
101k
    }
589
82.6k
  }
590
108k
  return 1;
591
108k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
553
10.8k
{
554
10.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
10.8k
  register _JSAMPROW ptr;
556
10.8k
  register unsigned char *bufferptr;
557
10.8k
  register _JSAMPLE *rescale = source->rescale;
558
10.8k
  JDIMENSION col;
559
10.8k
  unsigned int maxval = source->maxval;
560
561
10.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
260
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
10.8k
  ptr = source->pub._buffer[0];
564
10.8k
  bufferptr = source->iobuffer;
565
10.8k
  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.8k
  } else {
577
29.2k
    for (col = cinfo->image_width; col > 0; col--) {
578
18.3k
      register unsigned int temp;
579
18.3k
      _JSAMPLE gray;
580
18.3k
      temp  = (*bufferptr++) << 8;
581
18.3k
      temp |= (*bufferptr++);
582
18.3k
      if (temp > maxval)
583
164
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
18.3k
      gray = rescale[temp];
585
18.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
18.3k
                  ptr + 1, ptr + 2, ptr + 3);
587
18.3k
      ptr += 4;
588
18.3k
    }
589
10.8k
  }
590
10.8k
  return 1;
591
10.8k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
553
67.1k
{
554
67.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
67.1k
  register _JSAMPROW ptr;
556
67.1k
  register unsigned char *bufferptr;
557
67.1k
  register _JSAMPLE *rescale = source->rescale;
558
67.1k
  JDIMENSION col;
559
67.1k
  unsigned int maxval = source->maxval;
560
561
67.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
367
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
67.1k
  ptr = source->pub._buffer[0];
564
67.1k
  bufferptr = source->iobuffer;
565
67.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
7.15k
    for (col = cinfo->image_width; col > 0; col--) {
567
4.66k
      register unsigned int gray;
568
4.66k
      gray  = (*bufferptr++) << 8;
569
4.66k
      gray |= (*bufferptr++);
570
4.66k
      if (gray > maxval)
571
91
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
4.66k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
4.66k
                  ptr + 1, ptr + 2, ptr + 3);
574
4.66k
      ptr += 4;
575
4.66k
    }
576
64.6k
  } else {
577
134k
    for (col = cinfo->image_width; col > 0; col--) {
578
69.9k
      register unsigned int temp;
579
69.9k
      _JSAMPLE gray;
580
69.9k
      temp  = (*bufferptr++) << 8;
581
69.9k
      temp |= (*bufferptr++);
582
69.9k
      if (temp > maxval)
583
194
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
69.9k
      gray = rescale[temp];
585
69.9k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
69.9k
                  ptr + 1, ptr + 2, ptr + 3);
587
69.9k
      ptr += 4;
588
69.9k
    }
589
64.6k
  }
590
67.1k
  return 1;
591
67.1k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
553
29.9k
{
554
29.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
29.9k
  register _JSAMPROW ptr;
556
29.9k
  register unsigned char *bufferptr;
557
29.9k
  register _JSAMPLE *rescale = source->rescale;
558
29.9k
  JDIMENSION col;
559
29.9k
  unsigned int maxval = source->maxval;
560
561
29.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
223
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
29.9k
  ptr = source->pub._buffer[0];
564
29.9k
  bufferptr = source->iobuffer;
565
29.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
181k
    for (col = cinfo->image_width; col > 0; col--) {
567
159k
      register unsigned int gray;
568
159k
      gray  = (*bufferptr++) << 8;
569
159k
      gray |= (*bufferptr++);
570
159k
      if (gray > maxval)
571
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
159k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
159k
                  ptr + 1, ptr + 2, ptr + 3);
574
159k
      ptr += 4;
575
159k
    }
576
22.8k
  } else {
577
20.6k
    for (col = cinfo->image_width; col > 0; col--) {
578
13.5k
      register unsigned int temp;
579
13.5k
      _JSAMPLE gray;
580
13.5k
      temp  = (*bufferptr++) << 8;
581
13.5k
      temp |= (*bufferptr++);
582
13.5k
      if (temp > maxval)
583
73
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
13.5k
      gray = rescale[temp];
585
13.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
13.5k
                  ptr + 1, ptr + 2, ptr + 3);
587
13.5k
      ptr += 4;
588
13.5k
    }
589
7.10k
  }
590
29.9k
  return 1;
591
29.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
164k
{
598
164k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
164k
  register _JSAMPROW ptr;
600
164k
  register unsigned char *bufferptr;
601
164k
  register _JSAMPLE *rescale = source->rescale;
602
164k
  JDIMENSION col;
603
164k
  unsigned int maxval = source->maxval;
604
164k
  register int rindex = rgb_red[cinfo->in_color_space];
605
164k
  register int gindex = rgb_green[cinfo->in_color_space];
606
164k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
164k
  register int aindex = alpha_index[cinfo->in_color_space];
608
164k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
164k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
6.13k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
164k
  ptr = source->pub._buffer[0];
613
164k
  bufferptr = source->iobuffer;
614
647k
  for (col = cinfo->image_width; col > 0; col--) {
615
482k
    register unsigned int temp;
616
482k
    temp  = (*bufferptr++) << 8;
617
482k
    temp |= (*bufferptr++);
618
482k
    if (temp > maxval)
619
2.20k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
482k
    ptr[rindex] = rescale[temp];
621
482k
    temp  = (*bufferptr++) << 8;
622
482k
    temp |= (*bufferptr++);
623
482k
    if (temp > maxval)
624
1.99k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
482k
    ptr[gindex] = rescale[temp];
626
482k
    temp  = (*bufferptr++) << 8;
627
482k
    temp |= (*bufferptr++);
628
482k
    if (temp > maxval)
629
1.99k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
482k
    ptr[bindex] = rescale[temp];
631
482k
    if (aindex >= 0)
632
91.4k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
482k
    ptr += ps;
634
482k
  }
635
164k
  return 1;
636
164k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
597
56.0k
{
598
56.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
56.0k
  register _JSAMPROW ptr;
600
56.0k
  register unsigned char *bufferptr;
601
56.0k
  register _JSAMPLE *rescale = source->rescale;
602
56.0k
  JDIMENSION col;
603
56.0k
  unsigned int maxval = source->maxval;
604
56.0k
  register int rindex = rgb_red[cinfo->in_color_space];
605
56.0k
  register int gindex = rgb_green[cinfo->in_color_space];
606
56.0k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
56.0k
  register int aindex = alpha_index[cinfo->in_color_space];
608
56.0k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
56.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
2.33k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
56.0k
  ptr = source->pub._buffer[0];
613
56.0k
  bufferptr = source->iobuffer;
614
141k
  for (col = cinfo->image_width; col > 0; col--) {
615
85.9k
    register unsigned int temp;
616
85.9k
    temp  = (*bufferptr++) << 8;
617
85.9k
    temp |= (*bufferptr++);
618
85.9k
    if (temp > maxval)
619
719
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
85.9k
    ptr[rindex] = rescale[temp];
621
85.9k
    temp  = (*bufferptr++) << 8;
622
85.9k
    temp |= (*bufferptr++);
623
85.9k
    if (temp > maxval)
624
865
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
85.9k
    ptr[gindex] = rescale[temp];
626
85.9k
    temp  = (*bufferptr++) << 8;
627
85.9k
    temp |= (*bufferptr++);
628
85.9k
    if (temp > maxval)
629
793
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
85.9k
    ptr[bindex] = rescale[temp];
631
85.9k
    if (aindex >= 0)
632
12.8k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
85.9k
    ptr += ps;
634
85.9k
  }
635
56.0k
  return 1;
636
56.0k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
597
67.5k
{
598
67.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
67.5k
  register _JSAMPROW ptr;
600
67.5k
  register unsigned char *bufferptr;
601
67.5k
  register _JSAMPLE *rescale = source->rescale;
602
67.5k
  JDIMENSION col;
603
67.5k
  unsigned int maxval = source->maxval;
604
67.5k
  register int rindex = rgb_red[cinfo->in_color_space];
605
67.5k
  register int gindex = rgb_green[cinfo->in_color_space];
606
67.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
67.5k
  register int aindex = alpha_index[cinfo->in_color_space];
608
67.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
67.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
2.40k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
67.5k
  ptr = source->pub._buffer[0];
613
67.5k
  bufferptr = source->iobuffer;
614
223k
  for (col = cinfo->image_width; col > 0; col--) {
615
156k
    register unsigned int temp;
616
156k
    temp  = (*bufferptr++) << 8;
617
156k
    temp |= (*bufferptr++);
618
156k
    if (temp > maxval)
619
1.14k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
156k
    ptr[rindex] = rescale[temp];
621
156k
    temp  = (*bufferptr++) << 8;
622
156k
    temp |= (*bufferptr++);
623
156k
    if (temp > maxval)
624
885
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
156k
    ptr[gindex] = rescale[temp];
626
156k
    temp  = (*bufferptr++) << 8;
627
156k
    temp |= (*bufferptr++);
628
156k
    if (temp > maxval)
629
945
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
156k
    ptr[bindex] = rescale[temp];
631
156k
    if (aindex >= 0)
632
30.6k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
156k
    ptr += ps;
634
156k
  }
635
67.5k
  return 1;
636
67.5k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
597
41.2k
{
598
41.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
41.2k
  register _JSAMPROW ptr;
600
41.2k
  register unsigned char *bufferptr;
601
41.2k
  register _JSAMPLE *rescale = source->rescale;
602
41.2k
  JDIMENSION col;
603
41.2k
  unsigned int maxval = source->maxval;
604
41.2k
  register int rindex = rgb_red[cinfo->in_color_space];
605
41.2k
  register int gindex = rgb_green[cinfo->in_color_space];
606
41.2k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
41.2k
  register int aindex = alpha_index[cinfo->in_color_space];
608
41.2k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
41.2k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
1.39k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
41.2k
  ptr = source->pub._buffer[0];
613
41.2k
  bufferptr = source->iobuffer;
614
282k
  for (col = cinfo->image_width; col > 0; col--) {
615
240k
    register unsigned int temp;
616
240k
    temp  = (*bufferptr++) << 8;
617
240k
    temp |= (*bufferptr++);
618
240k
    if (temp > maxval)
619
345
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
240k
    ptr[rindex] = rescale[temp];
621
240k
    temp  = (*bufferptr++) << 8;
622
240k
    temp |= (*bufferptr++);
623
240k
    if (temp > maxval)
624
245
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
240k
    ptr[gindex] = rescale[temp];
626
240k
    temp  = (*bufferptr++) << 8;
627
240k
    temp |= (*bufferptr++);
628
240k
    if (temp > maxval)
629
255
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
240k
    ptr[bindex] = rescale[temp];
631
240k
    if (aindex >= 0)
632
48.0k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
240k
    ptr += ps;
634
240k
  }
635
41.2k
  return 1;
636
41.2k
}
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
30.2k
{
643
30.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
30.2k
  register _JSAMPROW ptr;
645
30.2k
  register unsigned char *bufferptr;
646
30.2k
  register _JSAMPLE *rescale = source->rescale;
647
30.2k
  JDIMENSION col;
648
30.2k
  unsigned int maxval = source->maxval;
649
650
30.2k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
1.09k
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
30.2k
  ptr = source->pub._buffer[0];
653
30.2k
  bufferptr = source->iobuffer;
654
30.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
61.8k
    for (col = cinfo->image_width; col > 0; col--) {
656
52.0k
      register unsigned int r, g, b;
657
52.0k
      r  = (*bufferptr++) << 8;
658
52.0k
      r |= (*bufferptr++);
659
52.0k
      if (r > maxval)
660
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
52.0k
      g  = (*bufferptr++) << 8;
662
52.0k
      g |= (*bufferptr++);
663
52.0k
      if (g > maxval)
664
73
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
52.0k
      b  = (*bufferptr++) << 8;
666
52.0k
      b |= (*bufferptr++);
667
52.0k
      if (b > maxval)
668
87
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
52.0k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
52.0k
                  ptr + 2, ptr + 3);
671
52.0k
      ptr += 4;
672
52.0k
    }
673
20.4k
  } else {
674
60.9k
    for (col = cinfo->image_width; col > 0; col--) {
675
40.5k
      register unsigned int r, g, b;
676
40.5k
      r  = (*bufferptr++) << 8;
677
40.5k
      r |= (*bufferptr++);
678
40.5k
      if (r > maxval)
679
326
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
40.5k
      g  = (*bufferptr++) << 8;
681
40.5k
      g |= (*bufferptr++);
682
40.5k
      if (g > maxval)
683
267
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
40.5k
      b  = (*bufferptr++) << 8;
685
40.5k
      b |= (*bufferptr++);
686
40.5k
      if (b > maxval)
687
249
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
40.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
40.5k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
40.5k
      ptr += 4;
691
40.5k
    }
692
20.4k
  }
693
30.2k
  return 1;
694
30.2k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
642
8.50k
{
643
8.50k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
8.50k
  register _JSAMPROW ptr;
645
8.50k
  register unsigned char *bufferptr;
646
8.50k
  register _JSAMPLE *rescale = source->rescale;
647
8.50k
  JDIMENSION col;
648
8.50k
  unsigned int maxval = source->maxval;
649
650
8.50k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
332
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
8.50k
  ptr = source->pub._buffer[0];
653
8.50k
  bufferptr = source->iobuffer;
654
8.50k
  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.50k
  } else {
674
21.6k
    for (col = cinfo->image_width; col > 0; col--) {
675
13.1k
      register unsigned int r, g, b;
676
13.1k
      r  = (*bufferptr++) << 8;
677
13.1k
      r |= (*bufferptr++);
678
13.1k
      if (r > maxval)
679
115
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
13.1k
      g  = (*bufferptr++) << 8;
681
13.1k
      g |= (*bufferptr++);
682
13.1k
      if (g > maxval)
683
114
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
13.1k
      b  = (*bufferptr++) << 8;
685
13.1k
      b |= (*bufferptr++);
686
13.1k
      if (b > maxval)
687
96
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
13.1k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
13.1k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
13.1k
      ptr += 4;
691
13.1k
    }
692
8.50k
  }
693
8.50k
  return 1;
694
8.50k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
642
13.5k
{
643
13.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
13.5k
  register _JSAMPROW ptr;
645
13.5k
  register unsigned char *bufferptr;
646
13.5k
  register _JSAMPLE *rescale = source->rescale;
647
13.5k
  JDIMENSION col;
648
13.5k
  unsigned int maxval = source->maxval;
649
650
13.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
481
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
13.5k
  ptr = source->pub._buffer[0];
653
13.5k
  bufferptr = source->iobuffer;
654
13.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
13.3k
    for (col = cinfo->image_width; col > 0; col--) {
656
8.79k
      register unsigned int r, g, b;
657
8.79k
      r  = (*bufferptr++) << 8;
658
8.79k
      r |= (*bufferptr++);
659
8.79k
      if (r > maxval)
660
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
8.79k
      g  = (*bufferptr++) << 8;
662
8.79k
      g |= (*bufferptr++);
663
8.79k
      if (g > maxval)
664
73
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
8.79k
      b  = (*bufferptr++) << 8;
666
8.79k
      b |= (*bufferptr++);
667
8.79k
      if (b > maxval)
668
87
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
8.79k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
8.79k
                  ptr + 2, ptr + 3);
671
8.79k
      ptr += 4;
672
8.79k
    }
673
8.97k
  } else {
674
31.4k
    for (col = cinfo->image_width; col > 0; col--) {
675
22.4k
      register unsigned int r, g, b;
676
22.4k
      r  = (*bufferptr++) << 8;
677
22.4k
      r |= (*bufferptr++);
678
22.4k
      if (r > maxval)
679
142
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
22.4k
      g  = (*bufferptr++) << 8;
681
22.4k
      g |= (*bufferptr++);
682
22.4k
      if (g > maxval)
683
104
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
22.4k
      b  = (*bufferptr++) << 8;
685
22.4k
      b |= (*bufferptr++);
686
22.4k
      if (b > maxval)
687
102
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
22.4k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
22.4k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
22.4k
      ptr += 4;
691
22.4k
    }
692
8.97k
  }
693
13.5k
  return 1;
694
13.5k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
642
8.24k
{
643
8.24k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
8.24k
  register _JSAMPROW ptr;
645
8.24k
  register unsigned char *bufferptr;
646
8.24k
  register _JSAMPLE *rescale = source->rescale;
647
8.24k
  JDIMENSION col;
648
8.24k
  unsigned int maxval = source->maxval;
649
650
8.24k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
278
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
8.24k
  ptr = source->pub._buffer[0];
653
8.24k
  bufferptr = source->iobuffer;
654
8.24k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
48.5k
    for (col = cinfo->image_width; col > 0; col--) {
656
43.2k
      register unsigned int r, g, b;
657
43.2k
      r  = (*bufferptr++) << 8;
658
43.2k
      r |= (*bufferptr++);
659
43.2k
      if (r > maxval)
660
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
43.2k
      g  = (*bufferptr++) << 8;
662
43.2k
      g |= (*bufferptr++);
663
43.2k
      if (g > maxval)
664
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
43.2k
      b  = (*bufferptr++) << 8;
666
43.2k
      b |= (*bufferptr++);
667
43.2k
      if (b > maxval)
668
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
43.2k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
43.2k
                  ptr + 2, ptr + 3);
671
43.2k
      ptr += 4;
672
43.2k
    }
673
5.29k
  } else {
674
7.86k
    for (col = cinfo->image_width; col > 0; col--) {
675
4.91k
      register unsigned int r, g, b;
676
4.91k
      r  = (*bufferptr++) << 8;
677
4.91k
      r |= (*bufferptr++);
678
4.91k
      if (r > maxval)
679
69
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
4.91k
      g  = (*bufferptr++) << 8;
681
4.91k
      g |= (*bufferptr++);
682
4.91k
      if (g > maxval)
683
49
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
4.91k
      b  = (*bufferptr++) << 8;
685
4.91k
      b |= (*bufferptr++);
686
4.91k
      if (b > maxval)
687
51
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
4.91k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
4.91k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
4.91k
      ptr += 4;
691
4.91k
    }
692
2.95k
  }
693
8.24k
  return 1;
694
8.24k
}
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
185k
{
704
185k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
185k
  int c;
706
185k
  unsigned int w, h, maxval;
707
185k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
185k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
185k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
185k
  switch (c) {
716
18.9k
  case '2':                     /* it's a text-format PGM file */
717
40.1k
  case '3':                     /* it's a text-format PPM file */
718
139k
  case '5':                     /* it's a raw-format PGM file */
719
184k
  case '6':                     /* it's a raw-format PPM file */
720
184k
    break;
721
711
  default:
722
711
    ERREXIT(cinfo, JERR_PPM_NOT);
723
711
    break;
724
185k
  }
725
726
  /* fetch the remaining header info */
727
184k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
184k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
184k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
184k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
361
    ERREXIT(cinfo, JERR_PPM_NOT);
733
184k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
262
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
184k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
2.76k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
184k
  cinfo->image_width = (JDIMENSION)w;
739
184k
  cinfo->image_height = (JDIMENSION)h;
740
184k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
184k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
184k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
184k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
184k
  switch (c) {
748
14.4k
  case '2':                     /* it's a text-format PGM file */
749
14.4k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
14.4k
        cinfo->in_color_space == JCS_RGB)
751
220
      cinfo->in_color_space = JCS_GRAYSCALE;
752
14.4k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
14.4k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
2.28k
      source->pub.get_pixel_rows = get_text_gray_row;
755
12.1k
    else if (IsExtRGB(cinfo->in_color_space))
756
10.3k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
1.80k
    else if (cinfo->in_color_space == JCS_CMYK)
758
1.80k
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
14.4k
    need_iobuffer = FALSE;
762
14.4k
    break;
763
764
16.8k
  case '3':                     /* it's a text-format PPM file */
765
16.8k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
16.8k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
16.8k
    if (IsExtRGB(cinfo->in_color_space))
769
12.3k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
4.53k
    else if (cinfo->in_color_space == JCS_CMYK)
771
2.14k
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
2.39k
    else
773
2.39k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
16.8k
    need_iobuffer = FALSE;
775
16.8k
    break;
776
777
94.1k
  case '5':                     /* it's a raw-format PGM file */
778
94.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
94.1k
        cinfo->in_color_space == JCS_RGB)
780
864
      cinfo->in_color_space = JCS_GRAYSCALE;
781
94.1k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
94.1k
    if (maxval > 255) {
783
12.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
2.10k
        source->pub.get_pixel_rows = get_word_gray_row;
785
10.6k
      else if (IsExtRGB(cinfo->in_color_space))
786
9.05k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
1.60k
      else if (cinfo->in_color_space == JCS_CMYK)
788
1.60k
        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
47.3k
    } else if (maxval <= _MAXJSAMPLE &&
793
47.3k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
5.49k
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
925
      source->pub.get_pixel_rows = get_raw_row;
796
925
      use_raw_buffer = TRUE;
797
925
      need_rescale = FALSE;
798
#endif
799
80.4k
    } else {
800
80.4k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
11.5k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
68.8k
      else if (IsExtRGB(cinfo->in_color_space))
803
59.7k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
9.12k
      else if (cinfo->in_color_space == JCS_CMYK)
805
9.12k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
80.4k
    }
809
94.1k
    break;
810
811
40.7k
  case '6':                     /* it's a raw-format PPM file */
812
40.7k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
40.7k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
40.7k
    if (maxval > 255) {
816
17.9k
      if (IsExtRGB(cinfo->in_color_space))
817
13.1k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
4.87k
      else if (cinfo->in_color_space == JCS_CMYK)
819
2.33k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
2.54k
      else
821
2.54k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
13.2k
    } else if (maxval <= _MAXJSAMPLE &&
824
13.2k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
2.34k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
2.34k
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
2.04k
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
348
      source->pub.get_pixel_rows = get_raw_row;
832
348
      use_raw_buffer = TRUE;
833
348
      need_rescale = FALSE;
834
#endif
835
22.4k
    } else {
836
22.4k
      if (IsExtRGB(cinfo->in_color_space))
837
16.4k
        source->pub.get_pixel_rows = get_rgb_row;
838
6.04k
      else if (cinfo->in_color_space == JCS_CMYK)
839
2.78k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
3.26k
      else
841
3.26k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
22.4k
    }
843
40.7k
    break;
844
184k
  }
845
846
158k
  if (IsExtRGB(cinfo->in_color_space))
847
121k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
36.7k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
16.9k
    cinfo->input_components = 1;
850
19.7k
  else if (cinfo->in_color_space == JCS_CMYK)
851
19.7k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
158k
  if (need_iobuffer) {
855
129k
    if (c == '6')
856
34.9k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
94.1k
    else
858
94.1k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
129k
    source->iobuffer = (unsigned char *)
860
129k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
129k
                                  source->buffer_width);
862
129k
  }
863
864
  /* Create compressor input buffer. */
865
158k
  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.27k
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
1.27k
    source->pub._buffer = &source->pixrow;
870
1.27k
    source->pub.buffer_height = 1;
871
156k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
156k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
156k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
156k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
156k
    source->pub.buffer_height = 1;
877
156k
  }
878
879
  /* Compute the rescaling array if required. */
880
158k
  if (need_rescale) {
881
156k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
156k
    source->rescale = (_JSAMPLE *)
885
156k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
156k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
156k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
156k
    half_maxval = (size_t)maxval / 2;
889
628M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
628M
      source->rescale[val] =
892
628M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
628M
                   maxval);
894
628M
    }
895
156k
  }
896
158k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
703
95.5k
{
704
95.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
95.5k
  int c;
706
95.5k
  unsigned int w, h, maxval;
707
95.5k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
95.5k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
95.5k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
95.5k
  switch (c) {
716
9.04k
  case '2':                     /* it's a text-format PGM file */
717
18.5k
  case '3':                     /* it's a text-format PPM file */
718
73.5k
  case '5':                     /* it's a raw-format PGM file */
719
95.2k
  case '6':                     /* it's a raw-format PPM file */
720
95.2k
    break;
721
298
  default:
722
298
    ERREXIT(cinfo, JERR_PPM_NOT);
723
298
    break;
724
95.5k
  }
725
726
  /* fetch the remaining header info */
727
95.2k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
95.2k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
95.2k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
95.2k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
165
    ERREXIT(cinfo, JERR_PPM_NOT);
733
95.2k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
122
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
95.2k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.24k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
95.2k
  cinfo->image_width = (JDIMENSION)w;
739
95.2k
  cinfo->image_height = (JDIMENSION)h;
740
95.2k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
95.2k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
95.2k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
95.2k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
95.2k
  switch (c) {
748
6.65k
  case '2':                     /* it's a text-format PGM file */
749
6.65k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
6.65k
        cinfo->in_color_space == JCS_RGB)
751
220
      cinfo->in_color_space = JCS_GRAYSCALE;
752
6.65k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
6.65k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
1.17k
      source->pub.get_pixel_rows = get_text_gray_row;
755
5.47k
    else if (IsExtRGB(cinfo->in_color_space))
756
4.78k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
698
    else if (cinfo->in_color_space == JCS_CMYK)
758
698
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
6.65k
    need_iobuffer = FALSE;
762
6.65k
    break;
763
764
7.68k
  case '3':                     /* it's a text-format PPM file */
765
7.68k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
7.68k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
7.68k
    if (IsExtRGB(cinfo->in_color_space))
769
5.77k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.91k
    else if (cinfo->in_color_space == JCS_CMYK)
771
831
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
1.08k
    else
773
1.08k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
7.68k
    need_iobuffer = FALSE;
775
7.68k
    break;
776
777
52.1k
  case '5':                     /* it's a raw-format PGM file */
778
52.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
52.1k
        cinfo->in_color_space == JCS_RGB)
780
864
      cinfo->in_color_space = JCS_GRAYSCALE;
781
52.1k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
52.1k
    if (maxval > 255) {
783
4.77k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
962
        source->pub.get_pixel_rows = get_word_gray_row;
785
3.81k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.35k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
464
      else if (cinfo->in_color_space == JCS_CMYK)
788
464
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
4.77k
#if BITS_IN_JSAMPLE == 8
792
47.3k
    } else if (maxval <= _MAXJSAMPLE &&
793
47.3k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
5.49k
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
925
      source->pub.get_pixel_rows = get_raw_row;
796
925
      use_raw_buffer = TRUE;
797
925
      need_rescale = FALSE;
798
925
#endif
799
46.3k
    } else {
800
46.3k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
6.72k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
39.6k
      else if (IsExtRGB(cinfo->in_color_space))
803
35.4k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
4.26k
      else if (cinfo->in_color_space == JCS_CMYK)
805
4.26k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
46.3k
    }
809
52.1k
    break;
810
811
19.7k
  case '6':                     /* it's a raw-format PPM file */
812
19.7k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
19.7k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
19.7k
    if (maxval > 255) {
816
6.50k
      if (IsExtRGB(cinfo->in_color_space))
817
4.91k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
1.59k
      else if (cinfo->in_color_space == JCS_CMYK)
819
689
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
906
      else
821
906
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
6.50k
#if BITS_IN_JSAMPLE == 8
823
13.2k
    } else if (maxval <= _MAXJSAMPLE &&
824
13.2k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
2.34k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
2.34k
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
2.04k
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
348
      source->pub.get_pixel_rows = get_raw_row;
832
348
      use_raw_buffer = TRUE;
833
348
      need_rescale = FALSE;
834
348
#endif
835
12.9k
    } else {
836
12.9k
      if (IsExtRGB(cinfo->in_color_space))
837
9.58k
        source->pub.get_pixel_rows = get_rgb_row;
838
3.31k
      else if (cinfo->in_color_space == JCS_CMYK)
839
1.42k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
1.89k
      else
841
1.89k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
12.9k
    }
843
19.7k
    break;
844
95.2k
  }
845
846
82.3k
  if (IsExtRGB(cinfo->in_color_space))
847
64.1k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
18.1k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
9.79k
    cinfo->input_components = 1;
850
8.36k
  else if (cinfo->in_color_space == JCS_CMYK)
851
8.36k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
82.3k
  if (need_iobuffer) {
855
69.0k
    if (c == '6')
856
16.9k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
52.1k
    else
858
52.1k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
69.0k
    source->iobuffer = (unsigned char *)
860
69.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
69.0k
                                  source->buffer_width);
862
69.0k
  }
863
864
  /* Create compressor input buffer. */
865
82.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
1.27k
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
1.27k
    source->pub._buffer = &source->pixrow;
870
1.27k
    source->pub.buffer_height = 1;
871
81.0k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
81.0k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
81.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
81.0k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
81.0k
    source->pub.buffer_height = 1;
877
81.0k
  }
878
879
  /* Compute the rescaling array if required. */
880
82.3k
  if (need_rescale) {
881
81.0k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
81.0k
    source->rescale = (_JSAMPLE *)
885
81.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
81.0k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
81.0k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
81.0k
    half_maxval = (size_t)maxval / 2;
889
162M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
162M
      source->rescale[val] =
892
162M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
162M
                   maxval);
894
162M
    }
895
81.0k
  }
896
82.3k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
703
64.4k
{
704
64.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
64.4k
  int c;
706
64.4k
  unsigned int w, h, maxval;
707
64.4k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
64.4k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
64.4k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
64.4k
  switch (c) {
716
6.61k
  case '2':                     /* it's a text-format PGM file */
717
14.1k
  case '3':                     /* it's a text-format PPM file */
718
47.8k
  case '5':                     /* it's a raw-format PGM file */
719
64.1k
  case '6':                     /* it's a raw-format PPM file */
720
64.1k
    break;
721
336
  default:
722
336
    ERREXIT(cinfo, JERR_PPM_NOT);
723
336
    break;
724
64.4k
  }
725
726
  /* fetch the remaining header info */
727
64.1k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
64.1k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
64.1k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
64.1k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
133
    ERREXIT(cinfo, JERR_PPM_NOT);
733
64.1k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
84
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
64.1k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.01k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
64.1k
  cinfo->image_width = (JDIMENSION)w;
739
64.1k
  cinfo->image_height = (JDIMENSION)h;
740
64.1k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
64.1k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
64.1k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
64.1k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
64.1k
  switch (c) {
748
5.07k
  case '2':                     /* it's a text-format PGM file */
749
5.07k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
5.07k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
5.07k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
5.07k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
725
      source->pub.get_pixel_rows = get_text_gray_row;
755
4.35k
    else if (IsExtRGB(cinfo->in_color_space))
756
3.62k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
725
    else if (cinfo->in_color_space == JCS_CMYK)
758
725
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
5.07k
    need_iobuffer = FALSE;
762
5.07k
    break;
763
764
5.90k
  case '3':                     /* it's a text-format PPM file */
765
5.90k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
5.90k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
5.90k
    if (IsExtRGB(cinfo->in_color_space))
769
4.22k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.68k
    else if (cinfo->in_color_space == JCS_CMYK)
771
844
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
844
    else
773
844
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
5.90k
    need_iobuffer = FALSE;
775
5.90k
    break;
776
777
31.9k
  case '5':                     /* it's a raw-format PGM file */
778
31.9k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
31.9k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
31.9k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
31.9k
    if (maxval > 255) {
783
5.23k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
748
        source->pub.get_pixel_rows = get_word_gray_row;
785
4.48k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.74k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
748
      else if (cinfo->in_color_space == JCS_CMYK)
788
748
        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.7k
    } else {
800
26.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
3.82k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
22.9k
      else if (IsExtRGB(cinfo->in_color_space))
803
19.1k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
3.82k
      else if (cinfo->in_color_space == JCS_CMYK)
805
3.82k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
26.7k
    }
809
31.9k
    break;
810
811
14.9k
  case '6':                     /* it's a raw-format PPM file */
812
14.9k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
14.9k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
14.9k
    if (maxval > 255) {
816
7.95k
      if (IsExtRGB(cinfo->in_color_space))
817
5.68k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
2.27k
      else if (cinfo->in_color_space == JCS_CMYK)
819
1.13k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
1.13k
      else
821
1.13k
        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.95k
    } else {
836
6.94k
      if (IsExtRGB(cinfo->in_color_space))
837
4.96k
        source->pub.get_pixel_rows = get_rgb_row;
838
1.98k
      else if (cinfo->in_color_space == JCS_CMYK)
839
992
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
992
      else
841
992
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
6.94k
    }
843
14.9k
    break;
844
64.1k
  }
845
846
54.8k
  if (IsExtRGB(cinfo->in_color_space))
847
41.3k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
13.5k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
5.29k
    cinfo->input_components = 1;
850
8.26k
  else if (cinfo->in_color_space == JCS_CMYK)
851
8.26k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
54.8k
  if (need_iobuffer) {
855
44.7k
    if (c == '6')
856
12.7k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
31.9k
    else
858
31.9k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
44.7k
    source->iobuffer = (unsigned char *)
860
44.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
44.7k
                                  source->buffer_width);
862
44.7k
  }
863
864
  /* Create compressor input buffer. */
865
54.8k
  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
54.8k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
54.8k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
54.8k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
54.8k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
54.8k
    source->pub.buffer_height = 1;
877
54.8k
  }
878
879
  /* Compute the rescaling array if required. */
880
54.8k
  if (need_rescale) {
881
54.8k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
54.8k
    source->rescale = (_JSAMPLE *)
885
54.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
54.8k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
54.8k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
54.8k
    half_maxval = (size_t)maxval / 2;
889
153M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
153M
      source->rescale[val] =
892
153M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
153M
                   maxval);
894
153M
    }
895
54.8k
  }
896
54.8k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
703
25.2k
{
704
25.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
25.2k
  int c;
706
25.2k
  unsigned int w, h, maxval;
707
25.2k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
25.2k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
25.2k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
25.2k
  switch (c) {
716
3.28k
  case '2':                     /* it's a text-format PGM file */
717
7.51k
  case '3':                     /* it's a text-format PPM file */
718
18.3k
  case '5':                     /* it's a raw-format PGM file */
719
25.2k
  case '6':                     /* it's a raw-format PPM file */
720
25.2k
    break;
721
77
  default:
722
77
    ERREXIT(cinfo, JERR_PPM_NOT);
723
77
    break;
724
25.2k
  }
725
726
  /* fetch the remaining header info */
727
25.2k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
25.2k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
25.2k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
25.2k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
63
    ERREXIT(cinfo, JERR_PPM_NOT);
733
25.2k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
56
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
25.2k
  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.2k
  cinfo->image_width = (JDIMENSION)w;
739
25.2k
  cinfo->image_height = (JDIMENSION)h;
740
25.2k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
25.2k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
25.2k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
25.2k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
25.2k
  switch (c) {
748
2.69k
  case '2':                     /* it's a text-format PGM file */
749
2.69k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
2.69k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
2.69k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
2.69k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
385
      source->pub.get_pixel_rows = get_text_gray_row;
755
2.31k
    else if (IsExtRGB(cinfo->in_color_space))
756
1.92k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
385
    else if (cinfo->in_color_space == JCS_CMYK)
758
385
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
2.69k
    need_iobuffer = FALSE;
762
2.69k
    break;
763
764
3.27k
  case '3':                     /* it's a text-format PPM file */
765
3.27k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
3.27k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
3.27k
    if (IsExtRGB(cinfo->in_color_space))
769
2.34k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
936
    else if (cinfo->in_color_space == JCS_CMYK)
771
468
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
468
    else
773
468
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
3.27k
    need_iobuffer = FALSE;
775
3.27k
    break;
776
777
10.0k
  case '5':                     /* it's a raw-format PGM file */
778
10.0k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
10.0k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
10.0k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
10.0k
    if (maxval > 255) {
783
2.74k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
392
        source->pub.get_pixel_rows = get_word_gray_row;
785
2.35k
      else if (IsExtRGB(cinfo->in_color_space))
786
1.96k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
392
      else if (cinfo->in_color_space == JCS_CMYK)
788
392
        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
7.34k
    } else {
800
7.34k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
1.04k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
6.29k
      else if (IsExtRGB(cinfo->in_color_space))
803
5.24k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
1.04k
      else if (cinfo->in_color_space == JCS_CMYK)
805
1.04k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
7.34k
    }
809
10.0k
    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.52k
      if (IsExtRGB(cinfo->in_color_space))
817
2.52k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
1.00k
      else if (cinfo->in_color_space == JCS_CMYK)
819
504
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
504
      else
821
504
        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.52k
    } else {
836
2.59k
      if (IsExtRGB(cinfo->in_color_space))
837
1.85k
        source->pub.get_pixel_rows = get_rgb_row;
838
742
      else if (cinfo->in_color_space == JCS_CMYK)
839
371
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
371
      else
841
371
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
2.59k
    }
843
6.12k
    break;
844
25.2k
  }
845
846
20.8k
  if (IsExtRGB(cinfo->in_color_space))
847
15.8k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
4.99k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
1.82k
    cinfo->input_components = 1;
850
3.16k
  else if (cinfo->in_color_space == JCS_CMYK)
851
3.16k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
20.8k
  if (need_iobuffer) {
855
15.3k
    if (c == '6')
856
5.25k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
10.0k
    else
858
10.0k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
15.3k
    source->iobuffer = (unsigned char *)
860
15.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
15.3k
                                  source->buffer_width);
862
15.3k
  }
863
864
  /* Create compressor input buffer. */
865
20.8k
  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
20.8k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
20.8k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
20.8k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
20.8k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
20.8k
    source->pub.buffer_height = 1;
877
20.8k
  }
878
879
  /* Compute the rescaling array if required. */
880
20.8k
  if (need_rescale) {
881
20.8k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
20.8k
    source->rescale = (_JSAMPLE *)
885
20.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
20.8k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
20.8k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
20.8k
    half_maxval = (size_t)maxval / 2;
889
312M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
312M
      source->rescale[val] =
892
312M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
312M
                   maxval);
894
312M
    }
895
20.8k
  }
896
20.8k
}
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
134k
{
906
  /* no work */
907
134k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
905
71.7k
{
906
  /* no work */
907
71.7k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
905
46.6k
{
906
  /* no work */
907
46.6k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
905
16.5k
{
906
  /* no work */
907
16.5k
}
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
185k
{
917
185k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
95.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
89.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
89.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
185k
  source = (ppm_source_ptr)
929
185k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
185k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
185k
  source->pub.start_input = start_input_ppm;
933
185k
  source->pub.finish_input = finish_input_ppm;
934
185k
  source->pub.max_pixels = 0;
935
936
185k
  return (cjpeg_source_ptr)source;
937
185k
}
jinit_read_ppm
Line
Count
Source
916
95.5k
{
917
95.5k
  ppm_source_ptr source;
918
919
95.5k
#if BITS_IN_JSAMPLE == 8
920
95.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
95.5k
  source = (ppm_source_ptr)
929
95.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
95.5k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
95.5k
  source->pub.start_input = start_input_ppm;
933
95.5k
  source->pub.finish_input = finish_input_ppm;
934
95.5k
  source->pub.max_pixels = 0;
935
936
95.5k
  return (cjpeg_source_ptr)source;
937
95.5k
}
j12init_read_ppm
Line
Count
Source
916
64.4k
{
917
64.4k
  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
64.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
64.4k
      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
64.4k
  source = (ppm_source_ptr)
929
64.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
64.4k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
64.4k
  source->pub.start_input = start_input_ppm;
933
64.4k
  source->pub.finish_input = finish_input_ppm;
934
64.4k
  source->pub.max_pixels = 0;
935
936
64.4k
  return (cjpeg_source_ptr)source;
937
64.4k
}
j16init_read_ppm
Line
Count
Source
916
25.2k
{
917
25.2k
  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.2k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
25.2k
      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.2k
  source = (ppm_source_ptr)
929
25.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
25.2k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
25.2k
  source->pub.start_input = start_input_ppm;
933
25.2k
  source->pub.finish_input = finish_input_ppm;
934
25.2k
  source->pub.max_pixels = 0;
935
936
25.2k
  return (cjpeg_source_ptr)source;
937
25.2k
}
938
939
#endif /* defined(PPM_SUPPORTED) &&
940
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */