Coverage Report

Created: 2026-01-09 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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-2025, D. R. Commander.
9
 * For conditions of distribution and use, see the accompanying README.ijg
10
 * file.
11
 *
12
 * This file contains routines to read input images in PPM/PGM format.
13
 * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
14
 * The PBMPLUS library is NOT required to compile this software
15
 * (but it is highly useful as a set of PPM image manipulation programs).
16
 *
17
 * These routines may need modification for non-Unix environments or
18
 * specialized applications.  As they stand, they assume input from
19
 * an ordinary stdio stream.  They further assume that reading begins
20
 * at the start of the file; start_input may need work if the
21
 * user interface has already read some data (e.g., to determine that
22
 * the file is indeed PPM format).
23
 */
24
25
#include "cmyk.h"
26
#include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
27
28
#if defined(PPM_SUPPORTED) && \
29
    (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
30
31
32
/* Portions of this code are based on the PBMPLUS library, which is:
33
**
34
** Copyright (C) 1988 by Jef Poskanzer.
35
**
36
** Permission to use, copy, modify, and distribute this software and its
37
** documentation for any purpose and without fee is hereby granted, provided
38
** that the above copyright notice appear in all copies and that both that
39
** copyright notice and this permission notice appear in supporting
40
** documentation.  This software is provided "as is" without express or
41
** implied warranty.
42
*/
43
44
45
/* Macros to deal with unsigned chars as efficiently as compiler allows */
46
47
typedef unsigned char U_CHAR;
48
277M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
364M
  (fread(buffer, 1, len, file) == ((size_t)(len)))
53
54
static int alpha_index[JPEG_NUMCS] = {
55
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
56
};
57
58
59
/* Private version of data source object */
60
61
typedef struct {
62
  struct cjpeg_source_struct pub; /* public fields */
63
64
  /* Usually these two pointers point to the same place: */
65
  U_CHAR *iobuffer;             /* fread's I/O buffer */
66
  _JSAMPROW pixrow;             /* compressor input buffer */
67
  size_t buffer_width;          /* width of I/O buffer */
68
  _JSAMPLE *rescale;            /* => maxval-remapping array, or NULL */
69
  unsigned int maxval;
70
} ppm_source_struct;
71
72
typedef ppm_source_struct *ppm_source_ptr;
73
74
75
LOCAL(int)
76
pbm_getc(FILE *infile)
77
/* Read next char, skipping over any comments */
78
/* A comment/newline sequence is returned as a newline */
79
3.80M
{
80
3.80M
  register int ch;
81
82
3.80M
  ch = getc(infile);
83
3.80M
  if (ch == '#') {
84
786k
    do {
85
786k
      ch = getc(infile);
86
786k
    } while (ch != '\n' && ch != EOF);
87
46.5k
  }
88
3.80M
  return ch;
89
3.80M
}
rdppm-8.c:pbm_getc
Line
Count
Source
79
1.81M
{
80
1.81M
  register int ch;
81
82
1.81M
  ch = getc(infile);
83
1.81M
  if (ch == '#') {
84
297k
    do {
85
297k
      ch = getc(infile);
86
297k
    } while (ch != '\n' && ch != EOF);
87
22.2k
  }
88
1.81M
  return ch;
89
1.81M
}
rdppm-12.c:pbm_getc
Line
Count
Source
79
1.38M
{
80
1.38M
  register int ch;
81
82
1.38M
  ch = getc(infile);
83
1.38M
  if (ch == '#') {
84
398k
    do {
85
398k
      ch = getc(infile);
86
398k
    } while (ch != '\n' && ch != EOF);
87
16.2k
  }
88
1.38M
  return ch;
89
1.38M
}
rdppm-16.c:pbm_getc
Line
Count
Source
79
605k
{
80
605k
  register int ch;
81
82
605k
  ch = getc(infile);
83
605k
  if (ch == '#') {
84
90.5k
    do {
85
90.5k
      ch = getc(infile);
86
90.5k
    } while (ch != '\n' && ch != EOF);
87
8.03k
  }
88
605k
  return ch;
89
605k
}
90
91
92
LOCAL(unsigned int)
93
read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
94
/* Read an unsigned decimal integer from the PPM file */
95
/* Swallows one trailing character after the integer */
96
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
97
/* This should not be a problem in practice. */
98
1.60M
{
99
1.60M
  register int ch;
100
1.60M
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
1.70M
  do {
104
1.70M
    ch = pbm_getc(infile);
105
1.70M
    if (ch == EOF)
106
33.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
1.70M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
1.60M
  if (ch < '0' || ch > '9')
110
2.84k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
1.60M
  val = ch - '0';
113
2.14M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
536k
    val *= 10;
115
536k
    val += ch - '0';
116
536k
    if (val > maxval)
117
1.60k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
536k
  }
119
120
1.60M
  return val;
121
1.60M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
98
772k
{
99
772k
  register int ch;
100
772k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
815k
  do {
104
815k
    ch = pbm_getc(infile);
105
815k
    if (ch == EOF)
106
15.9k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
815k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
772k
  if (ch < '0' || ch > '9')
110
1.26k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
772k
  val = ch - '0';
113
1.01M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
241k
    val *= 10;
115
241k
    val += ch - '0';
116
241k
    if (val > maxval)
117
775
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
241k
  }
119
120
772k
  return val;
121
772k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
98
571k
{
99
571k
  register int ch;
100
571k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
611k
  do {
104
611k
    ch = pbm_getc(infile);
105
611k
    if (ch == EOF)
106
11.4k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
611k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
571k
  if (ch < '0' || ch > '9')
110
1.09k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
571k
  val = ch - '0';
113
791k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
219k
    val *= 10;
115
219k
    val += ch - '0';
116
219k
    if (val > maxval)
117
552
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
219k
  }
119
120
571k
  return val;
121
571k
}
rdppm-16.c:read_pbm_integer
Line
Count
Source
98
260k
{
99
260k
  register int ch;
100
260k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
276k
  do {
104
276k
    ch = pbm_getc(infile);
105
276k
    if (ch == EOF)
106
6.50k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
276k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
260k
  if (ch < '0' || ch > '9')
110
491
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
260k
  val = ch - '0';
113
335k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
75.5k
    val *= 10;
115
75.5k
    val += ch - '0';
116
75.5k
    if (val > maxval)
117
277
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
75.5k
  }
119
120
260k
  return val;
121
260k
}
122
123
124
/*
125
 * Read one row of pixels.
126
 *
127
 * We provide several different versions depending on input file format.
128
 * In all cases, input is scaled to cinfo->data_precision.
129
 *
130
 * A really fast path is provided for reading byte/sample raw files with
131
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U,
132
 * which is the normal case for 8-bit data.
133
 */
134
135
136
METHODDEF(JDIMENSION)
137
get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
138
/* This version is for reading text-format PGM files with any maxval */
139
21.5k
{
140
21.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
21.5k
  FILE *infile = source->pub.input_file;
142
21.5k
  register _JSAMPROW ptr;
143
21.5k
  register _JSAMPLE *rescale = source->rescale;
144
21.5k
  JDIMENSION col;
145
21.5k
  unsigned int maxval = source->maxval;
146
147
21.5k
  ptr = source->pub._buffer[0];
148
59.7k
  for (col = cinfo->image_width; col > 0; col--) {
149
38.2k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
38.2k
  }
151
21.5k
  return 1;
152
21.5k
}
rdppm-8.c:get_text_gray_row
Line
Count
Source
139
10.9k
{
140
10.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
10.9k
  FILE *infile = source->pub.input_file;
142
10.9k
  register _JSAMPROW ptr;
143
10.9k
  register _JSAMPLE *rescale = source->rescale;
144
10.9k
  JDIMENSION col;
145
10.9k
  unsigned int maxval = source->maxval;
146
147
10.9k
  ptr = source->pub._buffer[0];
148
30.1k
  for (col = cinfo->image_width; col > 0; col--) {
149
19.1k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
19.1k
  }
151
10.9k
  return 1;
152
10.9k
}
rdppm-12.c:get_text_gray_row
Line
Count
Source
139
6.70k
{
140
6.70k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
6.70k
  FILE *infile = source->pub.input_file;
142
6.70k
  register _JSAMPROW ptr;
143
6.70k
  register _JSAMPLE *rescale = source->rescale;
144
6.70k
  JDIMENSION col;
145
6.70k
  unsigned int maxval = source->maxval;
146
147
6.70k
  ptr = source->pub._buffer[0];
148
19.0k
  for (col = cinfo->image_width; col > 0; col--) {
149
12.3k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
12.3k
  }
151
6.70k
  return 1;
152
6.70k
}
rdppm-16.c:get_text_gray_row
Line
Count
Source
139
3.86k
{
140
3.86k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
3.86k
  FILE *infile = source->pub.input_file;
142
3.86k
  register _JSAMPROW ptr;
143
3.86k
  register _JSAMPLE *rescale = source->rescale;
144
3.86k
  JDIMENSION col;
145
3.86k
  unsigned int maxval = source->maxval;
146
147
3.86k
  ptr = source->pub._buffer[0];
148
10.6k
  for (col = cinfo->image_width; col > 0; col--) {
149
6.78k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
6.78k
  }
151
3.86k
  return 1;
152
3.86k
}
153
154
155
264M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
156
936M
  for (col = cinfo->image_width; col > 0; col--) { \
157
671M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
158
671M
    alpha_set_op \
159
671M
    ptr += ps; \
160
671M
  } \
161
264M
}
162
163
METHODDEF(JDIMENSION)
164
get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
165
/* This version is for reading text-format PGM files with any maxval and
166
   converting to extended RGB */
167
107k
{
168
107k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
107k
  FILE *infile = source->pub.input_file;
170
107k
  register _JSAMPROW ptr;
171
107k
  register _JSAMPLE *rescale = source->rescale;
172
107k
  JDIMENSION col;
173
107k
  unsigned int maxval = source->maxval;
174
107k
  register int rindex = rgb_red[cinfo->in_color_space];
175
107k
  register int gindex = rgb_green[cinfo->in_color_space];
176
107k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
107k
  register int aindex = alpha_index[cinfo->in_color_space];
178
107k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
107k
  ptr = source->pub._buffer[0];
181
107k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
19.2k
    if (aindex >= 0)
183
2.90k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
19.2k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
16.3k
    else
186
16.3k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
88.3k
  } else {
188
88.3k
    if (aindex >= 0)
189
14.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
88.3k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
73.7k
    else
192
73.7k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
88.3k
  }
194
107k
  return 1;
195
107k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
167
54.7k
{
168
54.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
54.7k
  FILE *infile = source->pub.input_file;
170
54.7k
  register _JSAMPROW ptr;
171
54.7k
  register _JSAMPLE *rescale = source->rescale;
172
54.7k
  JDIMENSION col;
173
54.7k
  unsigned int maxval = source->maxval;
174
54.7k
  register int rindex = rgb_red[cinfo->in_color_space];
175
54.7k
  register int gindex = rgb_green[cinfo->in_color_space];
176
54.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
54.7k
  register int aindex = alpha_index[cinfo->in_color_space];
178
54.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
54.7k
  ptr = source->pub._buffer[0];
181
54.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
9.39k
    if (aindex >= 0)
183
985
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
9.39k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
8.41k
    else
186
8.41k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
45.3k
  } else {
188
45.3k
    if (aindex >= 0)
189
5.92k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
45.3k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
39.4k
    else
192
39.4k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
45.3k
  }
194
54.7k
  return 1;
195
54.7k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
167
33.5k
{
168
33.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
33.5k
  FILE *infile = source->pub.input_file;
170
33.5k
  register _JSAMPROW ptr;
171
33.5k
  register _JSAMPLE *rescale = source->rescale;
172
33.5k
  JDIMENSION col;
173
33.5k
  unsigned int maxval = source->maxval;
174
33.5k
  register int rindex = rgb_red[cinfo->in_color_space];
175
33.5k
  register int gindex = rgb_green[cinfo->in_color_space];
176
33.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
33.5k
  register int aindex = alpha_index[cinfo->in_color_space];
178
33.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
33.5k
  ptr = source->pub._buffer[0];
181
33.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
7.57k
    if (aindex >= 0)
183
1.47k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
7.57k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
6.09k
    else
186
6.09k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
25.9k
  } else {
188
25.9k
    if (aindex >= 0)
189
5.23k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
25.9k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
20.7k
    else
192
20.7k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
25.9k
  }
194
33.5k
  return 1;
195
33.5k
}
rdppm-16.c:get_text_gray_rgb_row
Line
Count
Source
167
19.3k
{
168
19.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
19.3k
  FILE *infile = source->pub.input_file;
170
19.3k
  register _JSAMPROW ptr;
171
19.3k
  register _JSAMPLE *rescale = source->rescale;
172
19.3k
  JDIMENSION col;
173
19.3k
  unsigned int maxval = source->maxval;
174
19.3k
  register int rindex = rgb_red[cinfo->in_color_space];
175
19.3k
  register int gindex = rgb_green[cinfo->in_color_space];
176
19.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
19.3k
  register int aindex = alpha_index[cinfo->in_color_space];
178
19.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
19.3k
  ptr = source->pub._buffer[0];
181
19.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
2.31k
    if (aindex >= 0)
183
442
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
2.31k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
1.87k
    else
186
1.87k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
16.9k
  } else {
188
16.9k
    if (aindex >= 0)
189
3.41k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
16.9k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
13.5k
    else
192
13.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
16.9k
  }
194
19.3k
  return 1;
195
19.3k
}
196
197
198
METHODDEF(JDIMENSION)
199
get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
200
/* This version is for reading text-format PGM files with any maxval and
201
   converting to CMYK */
202
17.4k
{
203
17.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
17.4k
  FILE *infile = source->pub.input_file;
205
17.4k
  register _JSAMPROW ptr;
206
17.4k
  register _JSAMPLE *rescale = source->rescale;
207
17.4k
  JDIMENSION col;
208
17.4k
  unsigned int maxval = source->maxval;
209
210
17.4k
  ptr = source->pub._buffer[0];
211
17.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
13.3k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.88k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
8.88k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
8.88k
      ptr += 4;
216
8.88k
    }
217
13.0k
  } else {
218
35.6k
    for (col = cinfo->image_width; col > 0; col--) {
219
22.5k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
22.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
22.5k
                  ptr + 1, ptr + 2, ptr + 3);
222
22.5k
      ptr += 4;
223
22.5k
    }
224
13.0k
  }
225
17.4k
  return 1;
226
17.4k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.90k
{
203
6.90k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.90k
  FILE *infile = source->pub.input_file;
205
6.90k
  register _JSAMPROW ptr;
206
6.90k
  register _JSAMPLE *rescale = source->rescale;
207
6.90k
  JDIMENSION col;
208
6.90k
  unsigned int maxval = source->maxval;
209
210
6.90k
  ptr = source->pub._buffer[0];
211
6.90k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
5.06k
    for (col = cinfo->image_width; col > 0; col--) {
213
3.29k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
3.29k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
3.29k
      ptr += 4;
216
3.29k
    }
217
5.12k
  } else {
218
14.2k
    for (col = cinfo->image_width; col > 0; col--) {
219
9.08k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
9.08k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
9.08k
                  ptr + 1, ptr + 2, ptr + 3);
222
9.08k
      ptr += 4;
223
9.08k
    }
224
5.12k
  }
225
6.90k
  return 1;
226
6.90k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.70k
{
203
6.70k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.70k
  FILE *infile = source->pub.input_file;
205
6.70k
  register _JSAMPROW ptr;
206
6.70k
  register _JSAMPLE *rescale = source->rescale;
207
6.70k
  JDIMENSION col;
208
6.70k
  unsigned int maxval = source->maxval;
209
210
6.70k
  ptr = source->pub._buffer[0];
211
6.70k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
6.02k
    for (col = cinfo->image_width; col > 0; col--) {
213
4.10k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
4.10k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
4.10k
      ptr += 4;
216
4.10k
    }
217
4.78k
  } else {
218
12.9k
    for (col = cinfo->image_width; col > 0; col--) {
219
8.20k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
8.20k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
8.20k
                  ptr + 1, ptr + 2, ptr + 3);
222
8.20k
      ptr += 4;
223
8.20k
    }
224
4.78k
  }
225
6.70k
  return 1;
226
6.70k
}
rdppm-16.c:get_text_gray_cmyk_row
Line
Count
Source
202
3.86k
{
203
3.86k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
3.86k
  FILE *infile = source->pub.input_file;
205
3.86k
  register _JSAMPROW ptr;
206
3.86k
  register _JSAMPLE *rescale = source->rescale;
207
3.86k
  JDIMENSION col;
208
3.86k
  unsigned int maxval = source->maxval;
209
210
3.86k
  ptr = source->pub._buffer[0];
211
3.86k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
2.24k
    for (col = cinfo->image_width; col > 0; col--) {
213
1.49k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
1.49k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
1.49k
      ptr += 4;
216
1.49k
    }
217
3.10k
  } else {
218
8.40k
    for (col = cinfo->image_width; col > 0; col--) {
219
5.29k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
5.29k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
5.29k
                  ptr + 1, ptr + 2, ptr + 3);
222
5.29k
      ptr += 4;
223
5.29k
    }
224
3.10k
  }
225
3.86k
  return 1;
226
3.86k
}
227
228
229
3.52M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
230
41.8M
  for (col = cinfo->image_width; col > 0; col--) { \
231
38.3M
    ptr[rindex] = read_op; \
232
38.3M
    ptr[gindex] = read_op; \
233
38.3M
    ptr[bindex] = read_op; \
234
38.3M
    alpha_set_op \
235
38.3M
    ptr += ps; \
236
38.3M
  } \
237
3.52M
}
238
239
METHODDEF(JDIMENSION)
240
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
241
/* This version is for reading text-format PPM files with any maxval */
242
126k
{
243
126k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
126k
  FILE *infile = source->pub.input_file;
245
126k
  register _JSAMPROW ptr;
246
126k
  register _JSAMPLE *rescale = source->rescale;
247
126k
  JDIMENSION col;
248
126k
  unsigned int maxval = source->maxval;
249
126k
  register int rindex = rgb_red[cinfo->in_color_space];
250
126k
  register int gindex = rgb_green[cinfo->in_color_space];
251
126k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
126k
  register int aindex = alpha_index[cinfo->in_color_space];
253
126k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
126k
  ptr = source->pub._buffer[0];
256
126k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
23.7k
    if (aindex >= 0)
258
3.30k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
23.7k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
20.4k
    else
261
20.4k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
102k
  } else {
263
102k
    if (aindex >= 0)
264
18.2k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
102k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
84.1k
    else
267
84.1k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
102k
  }
269
126k
  return 1;
270
126k
}
rdppm-8.c:get_text_rgb_row
Line
Count
Source
242
60.1k
{
243
60.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
60.1k
  FILE *infile = source->pub.input_file;
245
60.1k
  register _JSAMPROW ptr;
246
60.1k
  register _JSAMPLE *rescale = source->rescale;
247
60.1k
  JDIMENSION col;
248
60.1k
  unsigned int maxval = source->maxval;
249
60.1k
  register int rindex = rgb_red[cinfo->in_color_space];
250
60.1k
  register int gindex = rgb_green[cinfo->in_color_space];
251
60.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
60.1k
  register int aindex = alpha_index[cinfo->in_color_space];
253
60.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
60.1k
  ptr = source->pub._buffer[0];
256
60.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
11.6k
    if (aindex >= 0)
258
1.32k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
11.6k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
10.2k
    else
261
10.2k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
48.5k
  } else {
263
48.5k
    if (aindex >= 0)
264
7.04k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
48.5k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
41.5k
    else
267
41.5k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
48.5k
  }
269
60.1k
  return 1;
270
60.1k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
242
41.6k
{
243
41.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
41.6k
  FILE *infile = source->pub.input_file;
245
41.6k
  register _JSAMPROW ptr;
246
41.6k
  register _JSAMPLE *rescale = source->rescale;
247
41.6k
  JDIMENSION col;
248
41.6k
  unsigned int maxval = source->maxval;
249
41.6k
  register int rindex = rgb_red[cinfo->in_color_space];
250
41.6k
  register int gindex = rgb_green[cinfo->in_color_space];
251
41.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
41.6k
  register int aindex = alpha_index[cinfo->in_color_space];
253
41.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
41.6k
  ptr = source->pub._buffer[0];
256
41.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
8.82k
    if (aindex >= 0)
258
1.65k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
8.82k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
7.17k
    else
261
7.17k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
32.8k
  } else {
263
32.8k
    if (aindex >= 0)
264
6.68k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
32.8k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
26.1k
    else
267
26.1k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
32.8k
  }
269
41.6k
  return 1;
270
41.6k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
242
24.3k
{
243
24.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
24.3k
  FILE *infile = source->pub.input_file;
245
24.3k
  register _JSAMPROW ptr;
246
24.3k
  register _JSAMPLE *rescale = source->rescale;
247
24.3k
  JDIMENSION col;
248
24.3k
  unsigned int maxval = source->maxval;
249
24.3k
  register int rindex = rgb_red[cinfo->in_color_space];
250
24.3k
  register int gindex = rgb_green[cinfo->in_color_space];
251
24.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
24.3k
  register int aindex = alpha_index[cinfo->in_color_space];
253
24.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
24.3k
  ptr = source->pub._buffer[0];
256
24.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
3.32k
    if (aindex >= 0)
258
319
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
3.32k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
3.00k
    else
261
3.00k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
20.9k
  } else {
263
20.9k
    if (aindex >= 0)
264
4.54k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
20.9k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
16.4k
    else
267
16.4k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
20.9k
  }
269
24.3k
  return 1;
270
24.3k
}
271
272
273
METHODDEF(JDIMENSION)
274
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
275
/* This version is for reading text-format PPM files with any maxval and
276
   converting to CMYK */
277
21.5k
{
278
21.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
21.5k
  FILE *infile = source->pub.input_file;
280
21.5k
  register _JSAMPROW ptr;
281
21.5k
  register _JSAMPLE *rescale = source->rescale;
282
21.5k
  JDIMENSION col;
283
21.5k
  unsigned int maxval = source->maxval;
284
285
21.5k
  ptr = source->pub._buffer[0];
286
21.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
21.4k
    for (col = cinfo->image_width; col > 0; col--) {
288
14.5k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
14.5k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
14.5k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
14.5k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
14.5k
      ptr += 4;
293
14.5k
    }
294
14.7k
  } else {
295
41.1k
    for (col = cinfo->image_width; col > 0; col--) {
296
26.3k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
26.3k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
26.3k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
26.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
26.3k
                  ptr + 2, ptr + 3);
301
26.3k
      ptr += 4;
302
26.3k
    }
303
14.7k
  }
304
21.5k
  return 1;
305
21.5k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
277
8.37k
{
278
8.37k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
8.37k
  FILE *infile = source->pub.input_file;
280
8.37k
  register _JSAMPROW ptr;
281
8.37k
  register _JSAMPLE *rescale = source->rescale;
282
8.37k
  JDIMENSION col;
283
8.37k
  unsigned int maxval = source->maxval;
284
285
8.37k
  ptr = source->pub._buffer[0];
286
8.37k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
9.02k
    for (col = cinfo->image_width; col > 0; col--) {
288
5.88k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
5.88k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
5.88k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
5.88k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
5.88k
      ptr += 4;
293
5.88k
    }
294
5.22k
  } else {
295
15.4k
    for (col = cinfo->image_width; col > 0; col--) {
296
10.2k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.2k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
10.2k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
10.2k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
10.2k
                  ptr + 2, ptr + 3);
301
10.2k
      ptr += 4;
302
10.2k
    }
303
5.22k
  }
304
8.37k
  return 1;
305
8.37k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
277
8.33k
{
278
8.33k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
8.33k
  FILE *infile = source->pub.input_file;
280
8.33k
  register _JSAMPROW ptr;
281
8.33k
  register _JSAMPLE *rescale = source->rescale;
282
8.33k
  JDIMENSION col;
283
8.33k
  unsigned int maxval = source->maxval;
284
285
8.33k
  ptr = source->pub._buffer[0];
286
8.33k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
8.52k
    for (col = cinfo->image_width; col > 0; col--) {
288
6.07k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
6.07k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
6.07k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
6.07k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
6.07k
      ptr += 4;
293
6.07k
    }
294
5.88k
  } else {
295
16.4k
    for (col = cinfo->image_width; col > 0; col--) {
296
10.6k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.6k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
10.6k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
10.6k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
10.6k
                  ptr + 2, ptr + 3);
301
10.6k
      ptr += 4;
302
10.6k
    }
303
5.88k
  }
304
8.33k
  return 1;
305
8.33k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
277
4.86k
{
278
4.86k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
4.86k
  FILE *infile = source->pub.input_file;
280
4.86k
  register _JSAMPROW ptr;
281
4.86k
  register _JSAMPLE *rescale = source->rescale;
282
4.86k
  JDIMENSION col;
283
4.86k
  unsigned int maxval = source->maxval;
284
285
4.86k
  ptr = source->pub._buffer[0];
286
4.86k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
3.87k
    for (col = cinfo->image_width; col > 0; col--) {
288
2.61k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
2.61k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
2.61k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
2.61k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
2.61k
      ptr += 4;
293
2.61k
    }
294
3.61k
  } else {
295
9.15k
    for (col = cinfo->image_width; col > 0; col--) {
296
5.54k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
5.54k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
5.54k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
5.54k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
5.54k
                  ptr + 2, ptr + 3);
301
5.54k
      ptr += 4;
302
5.54k
    }
303
3.61k
  }
304
4.86k
  return 1;
305
4.86k
}
306
307
308
METHODDEF(JDIMENSION)
309
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
310
/* This version is for reading raw-byte-format PGM files with any maxval */
311
49.5M
{
312
49.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
49.5M
  register _JSAMPROW ptr;
314
49.5M
  register U_CHAR *bufferptr;
315
49.5M
  register _JSAMPLE *rescale = source->rescale;
316
49.5M
  JDIMENSION col;
317
318
49.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
791
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
49.5M
  ptr = source->pub._buffer[0];
321
49.5M
  bufferptr = source->iobuffer;
322
179M
  for (col = cinfo->image_width; col > 0; col--) {
323
129M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
129M
  }
325
49.5M
  return 1;
326
49.5M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
311
23.4M
{
312
23.4M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
23.4M
  register _JSAMPROW ptr;
314
23.4M
  register U_CHAR *bufferptr;
315
23.4M
  register _JSAMPLE *rescale = source->rescale;
316
23.4M
  JDIMENSION col;
317
318
23.4M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
434
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
23.4M
  ptr = source->pub._buffer[0];
321
23.4M
  bufferptr = source->iobuffer;
322
79.2M
  for (col = cinfo->image_width; col > 0; col--) {
323
55.7M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
55.7M
  }
325
23.4M
  return 1;
326
23.4M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
311
21.0M
{
312
21.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
21.0M
  register _JSAMPROW ptr;
314
21.0M
  register U_CHAR *bufferptr;
315
21.0M
  register _JSAMPLE *rescale = source->rescale;
316
21.0M
  JDIMENSION col;
317
318
21.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
230
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
21.0M
  ptr = source->pub._buffer[0];
321
21.0M
  bufferptr = source->iobuffer;
322
73.5M
  for (col = cinfo->image_width; col > 0; col--) {
323
52.5M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
52.5M
  }
325
21.0M
  return 1;
326
21.0M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
311
5.05M
{
312
5.05M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
5.05M
  register _JSAMPROW ptr;
314
5.05M
  register U_CHAR *bufferptr;
315
5.05M
  register _JSAMPLE *rescale = source->rescale;
316
5.05M
  JDIMENSION col;
317
318
5.05M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
127
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
5.05M
  ptr = source->pub._buffer[0];
321
5.05M
  bufferptr = source->iobuffer;
322
26.6M
  for (col = cinfo->image_width; col > 0; col--) {
323
21.6M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
21.6M
  }
325
5.05M
  return 1;
326
5.05M
}
327
328
329
METHODDEF(JDIMENSION)
330
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
331
/* This version is for reading raw-byte-format PGM files with any maxval
332
   and converting to extended RGB */
333
264M
{
334
264M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
264M
  register _JSAMPROW ptr;
336
264M
  register U_CHAR *bufferptr;
337
264M
  register _JSAMPLE *rescale = source->rescale;
338
264M
  JDIMENSION col;
339
264M
  unsigned int maxval = source->maxval;
340
264M
  register int rindex = rgb_red[cinfo->in_color_space];
341
264M
  register int gindex = rgb_green[cinfo->in_color_space];
342
264M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
264M
  register int aindex = alpha_index[cinfo->in_color_space];
344
264M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
264M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
4.72k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
264M
  ptr = source->pub._buffer[0];
349
264M
  bufferptr = source->iobuffer;
350
264M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
17.2M
    if (aindex >= 0)
352
387k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
16.8M
    else
354
16.8M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
247M
  } else {
356
247M
    if (aindex >= 0)
357
41.5M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
247M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
205M
    else
360
205M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
247M
  }
362
264M
  return 1;
363
264M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
333
134M
{
334
134M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
134M
  register _JSAMPROW ptr;
336
134M
  register U_CHAR *bufferptr;
337
134M
  register _JSAMPLE *rescale = source->rescale;
338
134M
  JDIMENSION col;
339
134M
  unsigned int maxval = source->maxval;
340
134M
  register int rindex = rgb_red[cinfo->in_color_space];
341
134M
  register int gindex = rgb_green[cinfo->in_color_space];
342
134M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
134M
  register int aindex = alpha_index[cinfo->in_color_space];
344
134M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
134M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
2.93k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
134M
  ptr = source->pub._buffer[0];
349
134M
  bufferptr = source->iobuffer;
350
134M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
17.2M
    if (aindex >= 0)
352
387k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
16.8M
    else
354
16.8M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
116M
  } else {
356
116M
    if (aindex >= 0)
357
15.5M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
116M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
101M
    else
360
101M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
116M
  }
362
134M
  return 1;
363
134M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
333
105M
{
334
105M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
105M
  register _JSAMPROW ptr;
336
105M
  register U_CHAR *bufferptr;
337
105M
  register _JSAMPLE *rescale = source->rescale;
338
105M
  JDIMENSION col;
339
105M
  unsigned int maxval = source->maxval;
340
105M
  register int rindex = rgb_red[cinfo->in_color_space];
341
105M
  register int gindex = rgb_green[cinfo->in_color_space];
342
105M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
105M
  register int aindex = alpha_index[cinfo->in_color_space];
344
105M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
105M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
1.15k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
105M
  ptr = source->pub._buffer[0];
349
105M
  bufferptr = source->iobuffer;
350
105M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
0
    if (aindex >= 0)
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
0
    else
354
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
105M
  } else {
356
105M
    if (aindex >= 0)
357
21.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
105M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
84.0M
    else
360
84.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
105M
  }
362
105M
  return 1;
363
105M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
333
25.2M
{
334
25.2M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
25.2M
  register _JSAMPROW ptr;
336
25.2M
  register U_CHAR *bufferptr;
337
25.2M
  register _JSAMPLE *rescale = source->rescale;
338
25.2M
  JDIMENSION col;
339
25.2M
  unsigned int maxval = source->maxval;
340
25.2M
  register int rindex = rgb_red[cinfo->in_color_space];
341
25.2M
  register int gindex = rgb_green[cinfo->in_color_space];
342
25.2M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
25.2M
  register int aindex = alpha_index[cinfo->in_color_space];
344
25.2M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
25.2M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
635
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
25.2M
  ptr = source->pub._buffer[0];
349
25.2M
  bufferptr = source->iobuffer;
350
25.2M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
0
    if (aindex >= 0)
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
0
    else
354
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
25.2M
  } else {
356
25.2M
    if (aindex >= 0)
357
5.05M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
25.2M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
20.2M
    else
360
20.2M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
25.2M
  }
362
25.2M
  return 1;
363
25.2M
}
364
365
366
METHODDEF(JDIMENSION)
367
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
368
/* This version is for reading raw-byte-format PGM files with any maxval
369
   and converting to CMYK */
370
41.9M
{
371
41.9M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
41.9M
  register _JSAMPROW ptr;
373
41.9M
  register U_CHAR *bufferptr;
374
41.9M
  register _JSAMPLE *rescale = source->rescale;
375
41.9M
  JDIMENSION col;
376
41.9M
  unsigned int maxval = source->maxval;
377
378
41.9M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
779
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
41.9M
  ptr = source->pub._buffer[0];
381
41.9M
  bufferptr = source->iobuffer;
382
41.9M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
2.75M
    for (col = cinfo->image_width; col > 0; col--) {
384
2.20M
      _JSAMPLE gray = *bufferptr++;
385
2.20M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
2.20M
      ptr += 4;
387
2.20M
    }
388
41.4M
  } else {
389
150M
    for (col = cinfo->image_width; col > 0; col--) {
390
108M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
108M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
108M
                  ptr + 1, ptr + 2, ptr + 3);
393
108M
      ptr += 4;
394
108M
    }
395
41.4M
  }
396
41.9M
  return 1;
397
41.9M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
370
15.9M
{
371
15.9M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
15.9M
  register _JSAMPROW ptr;
373
15.9M
  register U_CHAR *bufferptr;
374
15.9M
  register _JSAMPLE *rescale = source->rescale;
375
15.9M
  JDIMENSION col;
376
15.9M
  unsigned int maxval = source->maxval;
377
378
15.9M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
422
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
15.9M
  ptr = source->pub._buffer[0];
381
15.9M
  bufferptr = source->iobuffer;
382
15.9M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
2.75M
    for (col = cinfo->image_width; col > 0; col--) {
384
2.20M
      _JSAMPLE gray = *bufferptr++;
385
2.20M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
2.20M
      ptr += 4;
387
2.20M
    }
388
15.3M
  } else {
389
49.7M
    for (col = cinfo->image_width; col > 0; col--) {
390
34.4M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
34.4M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
34.4M
                  ptr + 1, ptr + 2, ptr + 3);
393
34.4M
      ptr += 4;
394
34.4M
    }
395
15.3M
  }
396
15.9M
  return 1;
397
15.9M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
370
21.0M
{
371
21.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
21.0M
  register _JSAMPROW ptr;
373
21.0M
  register U_CHAR *bufferptr;
374
21.0M
  register _JSAMPLE *rescale = source->rescale;
375
21.0M
  JDIMENSION col;
376
21.0M
  unsigned int maxval = source->maxval;
377
378
21.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
230
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
21.0M
  ptr = source->pub._buffer[0];
381
21.0M
  bufferptr = source->iobuffer;
382
21.0M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
0
    for (col = cinfo->image_width; col > 0; col--) {
384
0
      _JSAMPLE gray = *bufferptr++;
385
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
0
      ptr += 4;
387
0
    }
388
21.0M
  } else {
389
73.5M
    for (col = cinfo->image_width; col > 0; col--) {
390
52.5M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
52.5M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
52.5M
                  ptr + 1, ptr + 2, ptr + 3);
393
52.5M
      ptr += 4;
394
52.5M
    }
395
21.0M
  }
396
21.0M
  return 1;
397
21.0M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
370
5.05M
{
371
5.05M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
5.05M
  register _JSAMPROW ptr;
373
5.05M
  register U_CHAR *bufferptr;
374
5.05M
  register _JSAMPLE *rescale = source->rescale;
375
5.05M
  JDIMENSION col;
376
5.05M
  unsigned int maxval = source->maxval;
377
378
5.05M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
127
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
5.05M
  ptr = source->pub._buffer[0];
381
5.05M
  bufferptr = source->iobuffer;
382
5.05M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
0
    for (col = cinfo->image_width; col > 0; col--) {
384
0
      _JSAMPLE gray = *bufferptr++;
385
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
0
      ptr += 4;
387
0
    }
388
5.05M
  } else {
389
26.6M
    for (col = cinfo->image_width; col > 0; col--) {
390
21.6M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
21.6M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
21.6M
                  ptr + 1, ptr + 2, ptr + 3);
393
21.6M
      ptr += 4;
394
21.6M
    }
395
5.05M
  }
396
5.05M
  return 1;
397
5.05M
}
398
399
400
METHODDEF(JDIMENSION)
401
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
402
/* This version is for reading raw-byte-format PPM files with any maxval */
403
3.39M
{
404
3.39M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
3.39M
  register _JSAMPROW ptr;
406
3.39M
  register U_CHAR *bufferptr;
407
3.39M
  register _JSAMPLE *rescale = source->rescale;
408
3.39M
  JDIMENSION col;
409
3.39M
  unsigned int maxval = source->maxval;
410
3.39M
  register int rindex = rgb_red[cinfo->in_color_space];
411
3.39M
  register int gindex = rgb_green[cinfo->in_color_space];
412
3.39M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
3.39M
  register int aindex = alpha_index[cinfo->in_color_space];
414
3.39M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
3.39M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
6.78k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
3.39M
  ptr = source->pub._buffer[0];
419
3.39M
  bufferptr = source->iobuffer;
420
3.39M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
76.7k
    if (aindex >= 0)
422
9.40k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
67.3k
    else
424
67.3k
      RGB_READ_LOOP(*bufferptr++, {})
425
3.32M
  } else {
426
3.32M
    if (aindex >= 0)
427
645k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
3.32M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
2.67M
    else
430
2.67M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
3.32M
  }
432
3.39M
  return 1;
433
3.39M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
403
1.74M
{
404
1.74M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
1.74M
  register _JSAMPROW ptr;
406
1.74M
  register U_CHAR *bufferptr;
407
1.74M
  register _JSAMPLE *rescale = source->rescale;
408
1.74M
  JDIMENSION col;
409
1.74M
  unsigned int maxval = source->maxval;
410
1.74M
  register int rindex = rgb_red[cinfo->in_color_space];
411
1.74M
  register int gindex = rgb_green[cinfo->in_color_space];
412
1.74M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
1.74M
  register int aindex = alpha_index[cinfo->in_color_space];
414
1.74M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
1.74M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
3.81k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
1.74M
  ptr = source->pub._buffer[0];
419
1.74M
  bufferptr = source->iobuffer;
420
1.74M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
76.7k
    if (aindex >= 0)
422
9.40k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
67.3k
    else
424
67.3k
      RGB_READ_LOOP(*bufferptr++, {})
425
1.66M
  } else {
426
1.66M
    if (aindex >= 0)
427
315k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
1.66M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
1.35M
    else
430
1.35M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
1.66M
  }
432
1.74M
  return 1;
433
1.74M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
403
1.54M
{
404
1.54M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
1.54M
  register _JSAMPROW ptr;
406
1.54M
  register U_CHAR *bufferptr;
407
1.54M
  register _JSAMPLE *rescale = source->rescale;
408
1.54M
  JDIMENSION col;
409
1.54M
  unsigned int maxval = source->maxval;
410
1.54M
  register int rindex = rgb_red[cinfo->in_color_space];
411
1.54M
  register int gindex = rgb_green[cinfo->in_color_space];
412
1.54M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
1.54M
  register int aindex = alpha_index[cinfo->in_color_space];
414
1.54M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
1.54M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
1.94k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
1.54M
  ptr = source->pub._buffer[0];
419
1.54M
  bufferptr = source->iobuffer;
420
1.54M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
0
    if (aindex >= 0)
422
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
0
    else
424
0
      RGB_READ_LOOP(*bufferptr++, {})
425
1.54M
  } else {
426
1.54M
    if (aindex >= 0)
427
308k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
1.54M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
1.23M
    else
430
1.23M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
1.54M
  }
432
1.54M
  return 1;
433
1.54M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
403
107k
{
404
107k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
107k
  register _JSAMPROW ptr;
406
107k
  register U_CHAR *bufferptr;
407
107k
  register _JSAMPLE *rescale = source->rescale;
408
107k
  JDIMENSION col;
409
107k
  unsigned int maxval = source->maxval;
410
107k
  register int rindex = rgb_red[cinfo->in_color_space];
411
107k
  register int gindex = rgb_green[cinfo->in_color_space];
412
107k
  register int bindex = rgb_blue[cinfo->in_color_space];
413
107k
  register int aindex = alpha_index[cinfo->in_color_space];
414
107k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
107k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
1.02k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
107k
  ptr = source->pub._buffer[0];
419
107k
  bufferptr = source->iobuffer;
420
107k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
0
    if (aindex >= 0)
422
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
0
    else
424
0
      RGB_READ_LOOP(*bufferptr++, {})
425
107k
  } else {
426
107k
    if (aindex >= 0)
427
21.3k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
107k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
86.4k
    else
430
86.4k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
107k
  }
432
107k
  return 1;
433
107k
}
434
435
436
METHODDEF(JDIMENSION)
437
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
438
/* This version is for reading raw-byte-format PPM files with any maxval and
439
   converting to CMYK */
440
656k
{
441
656k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
656k
  register _JSAMPROW ptr;
443
656k
  register U_CHAR *bufferptr;
444
656k
  register _JSAMPLE *rescale = source->rescale;
445
656k
  JDIMENSION col;
446
656k
  unsigned int maxval = source->maxval;
447
448
656k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
1.23k
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
656k
  ptr = source->pub._buffer[0];
451
656k
  bufferptr = source->iobuffer;
452
656k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
547k
    for (col = cinfo->image_width; col > 0; col--) {
454
535k
      _JSAMPLE r = *bufferptr++;
455
535k
      _JSAMPLE g = *bufferptr++;
456
535k
      _JSAMPLE b = *bufferptr++;
457
535k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
535k
      ptr += 4;
459
535k
    }
460
644k
  } else {
461
7.23M
    for (col = cinfo->image_width; col > 0; col--) {
462
6.59M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
6.59M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
6.59M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
6.59M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
6.59M
                  ptr + 2, ptr + 3);
467
6.59M
      ptr += 4;
468
6.59M
    }
469
644k
  }
470
656k
  return 1;
471
656k
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
440
325k
{
441
325k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
325k
  register _JSAMPROW ptr;
443
325k
  register U_CHAR *bufferptr;
444
325k
  register _JSAMPLE *rescale = source->rescale;
445
325k
  JDIMENSION col;
446
325k
  unsigned int maxval = source->maxval;
447
448
325k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
640
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
325k
  ptr = source->pub._buffer[0];
451
325k
  bufferptr = source->iobuffer;
452
325k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
547k
    for (col = cinfo->image_width; col > 0; col--) {
454
535k
      _JSAMPLE r = *bufferptr++;
455
535k
      _JSAMPLE g = *bufferptr++;
456
535k
      _JSAMPLE b = *bufferptr++;
457
535k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
535k
      ptr += 4;
459
535k
    }
460
313k
  } else {
461
1.57M
    for (col = cinfo->image_width; col > 0; col--) {
462
1.26M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
1.26M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
1.26M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
1.26M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
1.26M
                  ptr + 2, ptr + 3);
467
1.26M
      ptr += 4;
468
1.26M
    }
469
313k
  }
470
325k
  return 1;
471
325k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
440
309k
{
441
309k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
309k
  register _JSAMPROW ptr;
443
309k
  register U_CHAR *bufferptr;
444
309k
  register _JSAMPLE *rescale = source->rescale;
445
309k
  JDIMENSION col;
446
309k
  unsigned int maxval = source->maxval;
447
448
309k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
388
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
309k
  ptr = source->pub._buffer[0];
451
309k
  bufferptr = source->iobuffer;
452
309k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
0
    for (col = cinfo->image_width; col > 0; col--) {
454
0
      _JSAMPLE r = *bufferptr++;
455
0
      _JSAMPLE g = *bufferptr++;
456
0
      _JSAMPLE b = *bufferptr++;
457
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
0
      ptr += 4;
459
0
    }
460
309k
  } else {
461
4.47M
    for (col = cinfo->image_width; col > 0; col--) {
462
4.16M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
4.16M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
4.16M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
4.16M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
4.16M
                  ptr + 2, ptr + 3);
467
4.16M
      ptr += 4;
468
4.16M
    }
469
309k
  }
470
309k
  return 1;
471
309k
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
440
21.5k
{
441
21.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
21.5k
  register _JSAMPROW ptr;
443
21.5k
  register U_CHAR *bufferptr;
444
21.5k
  register _JSAMPLE *rescale = source->rescale;
445
21.5k
  JDIMENSION col;
446
21.5k
  unsigned int maxval = source->maxval;
447
448
21.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
205
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
21.5k
  ptr = source->pub._buffer[0];
451
21.5k
  bufferptr = source->iobuffer;
452
21.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
0
    for (col = cinfo->image_width; col > 0; col--) {
454
0
      _JSAMPLE r = *bufferptr++;
455
0
      _JSAMPLE g = *bufferptr++;
456
0
      _JSAMPLE b = *bufferptr++;
457
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
0
      ptr += 4;
459
0
    }
460
21.5k
  } else {
461
1.18M
    for (col = cinfo->image_width; col > 0; col--) {
462
1.16M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
1.16M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
1.16M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
1.16M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
1.16M
                  ptr + 2, ptr + 3);
467
1.16M
      ptr += 4;
468
1.16M
    }
469
21.5k
  }
470
21.5k
  return 1;
471
21.5k
}
472
473
474
METHODDEF(JDIMENSION)
475
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
476
/* This version is for reading raw-byte-format files with
477
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
478
 * In this case we just read right into the _JSAMPLE buffer!
479
 * Note that same code works for PPM and PGM files.
480
 */
481
3.40M
{
482
3.40M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
483
484
3.40M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
485
319
    ERREXIT(cinfo, JERR_INPUT_EOF);
486
3.40M
  return 1;
487
3.40M
}
rdppm-8.c:get_raw_row
Line
Count
Source
481
3.40M
{
482
3.40M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
483
484
3.40M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
485
319
    ERREXIT(cinfo, JERR_INPUT_EOF);
486
3.40M
  return 1;
487
3.40M
}
Unexecuted instantiation: rdppm-12.c:get_raw_row
Unexecuted instantiation: rdppm-16.c:get_raw_row
488
489
490
METHODDEF(JDIMENSION)
491
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
492
/* This version is for reading raw-word-format PGM files with any maxval */
493
124k
{
494
124k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
124k
  register _JSAMPROW ptr;
496
124k
  register U_CHAR *bufferptr;
497
124k
  register _JSAMPLE *rescale = source->rescale;
498
124k
  JDIMENSION col;
499
124k
  unsigned int maxval = source->maxval;
500
501
124k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
918
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
124k
  ptr = source->pub._buffer[0];
504
124k
  bufferptr = source->iobuffer;
505
1.20M
  for (col = cinfo->image_width; col > 0; col--) {
506
1.08M
    register unsigned int temp;
507
1.08M
    temp  = UCH(*bufferptr++) << 8;
508
1.08M
    temp |= UCH(*bufferptr++);
509
1.08M
    if (temp > maxval)
510
585
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
1.08M
    *ptr++ = rescale[temp];
512
1.08M
  }
513
124k
  return 1;
514
124k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
493
24.1k
{
494
24.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
24.1k
  register _JSAMPROW ptr;
496
24.1k
  register U_CHAR *bufferptr;
497
24.1k
  register _JSAMPLE *rescale = source->rescale;
498
24.1k
  JDIMENSION col;
499
24.1k
  unsigned int maxval = source->maxval;
500
501
24.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
362
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
24.1k
  ptr = source->pub._buffer[0];
504
24.1k
  bufferptr = source->iobuffer;
505
459k
  for (col = cinfo->image_width; col > 0; col--) {
506
435k
    register unsigned int temp;
507
435k
    temp  = UCH(*bufferptr++) << 8;
508
435k
    temp |= UCH(*bufferptr++);
509
435k
    if (temp > maxval)
510
232
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
435k
    *ptr++ = rescale[temp];
512
435k
  }
513
24.1k
  return 1;
514
24.1k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
493
87.4k
{
494
87.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
87.4k
  register _JSAMPROW ptr;
496
87.4k
  register U_CHAR *bufferptr;
497
87.4k
  register _JSAMPLE *rescale = source->rescale;
498
87.4k
  JDIMENSION col;
499
87.4k
  unsigned int maxval = source->maxval;
500
501
87.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
354
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
87.4k
  ptr = source->pub._buffer[0];
504
87.4k
  bufferptr = source->iobuffer;
505
314k
  for (col = cinfo->image_width; col > 0; col--) {
506
227k
    register unsigned int temp;
507
227k
    temp  = UCH(*bufferptr++) << 8;
508
227k
    temp |= UCH(*bufferptr++);
509
227k
    if (temp > maxval)
510
277
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
227k
    *ptr++ = rescale[temp];
512
227k
  }
513
87.4k
  return 1;
514
87.4k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
493
13.0k
{
494
13.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
13.0k
  register _JSAMPROW ptr;
496
13.0k
  register U_CHAR *bufferptr;
497
13.0k
  register _JSAMPLE *rescale = source->rescale;
498
13.0k
  JDIMENSION col;
499
13.0k
  unsigned int maxval = source->maxval;
500
501
13.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
202
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
13.0k
  ptr = source->pub._buffer[0];
504
13.0k
  bufferptr = source->iobuffer;
505
434k
  for (col = cinfo->image_width; col > 0; col--) {
506
421k
    register unsigned int temp;
507
421k
    temp  = UCH(*bufferptr++) << 8;
508
421k
    temp |= UCH(*bufferptr++);
509
421k
    if (temp > maxval)
510
76
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
421k
    *ptr++ = rescale[temp];
512
421k
  }
513
13.0k
  return 1;
514
13.0k
}
515
516
517
METHODDEF(JDIMENSION)
518
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
519
/* This version is for reading raw-word-format PGM files with any maxval */
520
623k
{
521
623k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
623k
  register _JSAMPROW ptr;
523
623k
  register U_CHAR *bufferptr;
524
623k
  register _JSAMPLE *rescale = source->rescale;
525
623k
  JDIMENSION col;
526
623k
  unsigned int maxval = source->maxval;
527
623k
  register int rindex = rgb_red[cinfo->in_color_space];
528
623k
  register int gindex = rgb_green[cinfo->in_color_space];
529
623k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
623k
  register int aindex = alpha_index[cinfo->in_color_space];
531
623k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
623k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
4.59k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
623k
  ptr = source->pub._buffer[0];
536
623k
  bufferptr = source->iobuffer;
537
6.04M
  for (col = cinfo->image_width; col > 0; col--) {
538
5.42M
    register unsigned int temp;
539
5.42M
    temp  = UCH(*bufferptr++) << 8;
540
5.42M
    temp |= UCH(*bufferptr++);
541
5.42M
    if (temp > maxval)
542
2.92k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
5.42M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
5.42M
    if (aindex >= 0)
545
958k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
5.42M
    ptr += ps;
547
5.42M
  }
548
623k
  return 1;
549
623k
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
520
120k
{
521
120k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
120k
  register _JSAMPROW ptr;
523
120k
  register U_CHAR *bufferptr;
524
120k
  register _JSAMPLE *rescale = source->rescale;
525
120k
  JDIMENSION col;
526
120k
  unsigned int maxval = source->maxval;
527
120k
  register int rindex = rgb_red[cinfo->in_color_space];
528
120k
  register int gindex = rgb_green[cinfo->in_color_space];
529
120k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
120k
  register int aindex = alpha_index[cinfo->in_color_space];
531
120k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
120k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.81k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
120k
  ptr = source->pub._buffer[0];
536
120k
  bufferptr = source->iobuffer;
537
2.29M
  for (col = cinfo->image_width; col > 0; col--) {
538
2.17M
    register unsigned int temp;
539
2.17M
    temp  = UCH(*bufferptr++) << 8;
540
2.17M
    temp |= UCH(*bufferptr++);
541
2.17M
    if (temp > maxval)
542
1.16k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
2.17M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
2.17M
    if (aindex >= 0)
545
310k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
2.17M
    ptr += ps;
547
2.17M
  }
548
120k
  return 1;
549
120k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
520
437k
{
521
437k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
437k
  register _JSAMPROW ptr;
523
437k
  register U_CHAR *bufferptr;
524
437k
  register _JSAMPLE *rescale = source->rescale;
525
437k
  JDIMENSION col;
526
437k
  unsigned int maxval = source->maxval;
527
437k
  register int rindex = rgb_red[cinfo->in_color_space];
528
437k
  register int gindex = rgb_green[cinfo->in_color_space];
529
437k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
437k
  register int aindex = alpha_index[cinfo->in_color_space];
531
437k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
437k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.77k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
437k
  ptr = source->pub._buffer[0];
536
437k
  bufferptr = source->iobuffer;
537
1.57M
  for (col = cinfo->image_width; col > 0; col--) {
538
1.13M
    register unsigned int temp;
539
1.13M
    temp  = UCH(*bufferptr++) << 8;
540
1.13M
    temp |= UCH(*bufferptr++);
541
1.13M
    if (temp > maxval)
542
1.38k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
1.13M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
1.13M
    if (aindex >= 0)
545
227k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
1.13M
    ptr += ps;
547
1.13M
  }
548
437k
  return 1;
549
437k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
520
65.4k
{
521
65.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
65.4k
  register _JSAMPROW ptr;
523
65.4k
  register U_CHAR *bufferptr;
524
65.4k
  register _JSAMPLE *rescale = source->rescale;
525
65.4k
  JDIMENSION col;
526
65.4k
  unsigned int maxval = source->maxval;
527
65.4k
  register int rindex = rgb_red[cinfo->in_color_space];
528
65.4k
  register int gindex = rgb_green[cinfo->in_color_space];
529
65.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
65.4k
  register int aindex = alpha_index[cinfo->in_color_space];
531
65.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
65.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.01k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
65.4k
  ptr = source->pub._buffer[0];
536
65.4k
  bufferptr = source->iobuffer;
537
2.17M
  for (col = cinfo->image_width; col > 0; col--) {
538
2.10M
    register unsigned int temp;
539
2.10M
    temp  = UCH(*bufferptr++) << 8;
540
2.10M
    temp |= UCH(*bufferptr++);
541
2.10M
    if (temp > maxval)
542
380
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
2.10M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
2.10M
    if (aindex >= 0)
545
421k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
2.10M
    ptr += ps;
547
2.10M
  }
548
65.4k
  return 1;
549
65.4k
}
550
551
552
METHODDEF(JDIMENSION)
553
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
554
/* This version is for reading raw-word-format PGM files with any maxval */
555
110k
{
556
110k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
110k
  register _JSAMPROW ptr;
558
110k
  register U_CHAR *bufferptr;
559
110k
  register _JSAMPLE *rescale = source->rescale;
560
110k
  JDIMENSION col;
561
110k
  unsigned int maxval = source->maxval;
562
563
110k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
811
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
110k
  ptr = source->pub._buffer[0];
566
110k
  bufferptr = source->iobuffer;
567
110k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
427k
    for (col = cinfo->image_width; col > 0; col--) {
569
415k
      register unsigned int gray;
570
415k
      gray  = UCH(*bufferptr++) << 8;
571
415k
      gray |= UCH(*bufferptr++);
572
415k
      if (gray > maxval)
573
109
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
415k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
415k
                  ptr + 1, ptr + 2, ptr + 3);
576
415k
      ptr += 4;
577
415k
    }
578
99.5k
  } else {
579
643k
    for (col = cinfo->image_width; col > 0; col--) {
580
543k
      register unsigned int temp;
581
543k
      _JSAMPLE gray;
582
543k
      temp  = UCH(*bufferptr++) << 8;
583
543k
      temp |= UCH(*bufferptr++);
584
543k
      if (temp > maxval)
585
412
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
543k
      gray = rescale[temp];
587
543k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
543k
                  ptr + 1, ptr + 2, ptr + 3);
589
543k
      ptr += 4;
590
543k
    }
591
99.5k
  }
592
110k
  return 1;
593
110k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
555
10.1k
{
556
10.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
10.1k
  register _JSAMPROW ptr;
558
10.1k
  register U_CHAR *bufferptr;
559
10.1k
  register _JSAMPLE *rescale = source->rescale;
560
10.1k
  JDIMENSION col;
561
10.1k
  unsigned int maxval = source->maxval;
562
563
10.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
255
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
10.1k
  ptr = source->pub._buffer[0];
566
10.1k
  bufferptr = source->iobuffer;
567
10.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
0
    for (col = cinfo->image_width; col > 0; col--) {
569
0
      register unsigned int gray;
570
0
      gray  = UCH(*bufferptr++) << 8;
571
0
      gray |= UCH(*bufferptr++);
572
0
      if (gray > maxval)
573
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
0
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
0
                  ptr + 1, ptr + 2, ptr + 3);
576
0
      ptr += 4;
577
0
    }
578
10.1k
  } else {
579
320k
    for (col = cinfo->image_width; col > 0; col--) {
580
310k
      register unsigned int temp;
581
310k
      _JSAMPLE gray;
582
310k
      temp  = UCH(*bufferptr++) << 8;
583
310k
      temp |= UCH(*bufferptr++);
584
310k
      if (temp > maxval)
585
168
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
310k
      gray = rescale[temp];
587
310k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
310k
                  ptr + 1, ptr + 2, ptr + 3);
589
310k
      ptr += 4;
590
310k
    }
591
10.1k
  }
592
10.1k
  return 1;
593
10.1k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
555
87.4k
{
556
87.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
87.4k
  register _JSAMPROW ptr;
558
87.4k
  register U_CHAR *bufferptr;
559
87.4k
  register _JSAMPLE *rescale = source->rescale;
560
87.4k
  JDIMENSION col;
561
87.4k
  unsigned int maxval = source->maxval;
562
563
87.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
354
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
87.4k
  ptr = source->pub._buffer[0];
566
87.4k
  bufferptr = source->iobuffer;
567
87.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
6.31k
    for (col = cinfo->image_width; col > 0; col--) {
569
4.56k
      register unsigned int gray;
570
4.56k
      gray  = UCH(*bufferptr++) << 8;
571
4.56k
      gray |= UCH(*bufferptr++);
572
4.56k
      if (gray > maxval)
573
109
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
4.56k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
4.56k
                  ptr + 1, ptr + 2, ptr + 3);
576
4.56k
      ptr += 4;
577
4.56k
    }
578
85.7k
  } else {
579
308k
    for (col = cinfo->image_width; col > 0; col--) {
580
222k
      register unsigned int temp;
581
222k
      _JSAMPLE gray;
582
222k
      temp  = UCH(*bufferptr++) << 8;
583
222k
      temp |= UCH(*bufferptr++);
584
222k
      if (temp > maxval)
585
168
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
222k
      gray = rescale[temp];
587
222k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
222k
                  ptr + 1, ptr + 2, ptr + 3);
589
222k
      ptr += 4;
590
222k
    }
591
85.7k
  }
592
87.4k
  return 1;
593
87.4k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
555
13.0k
{
556
13.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
13.0k
  register _JSAMPROW ptr;
558
13.0k
  register U_CHAR *bufferptr;
559
13.0k
  register _JSAMPLE *rescale = source->rescale;
560
13.0k
  JDIMENSION col;
561
13.0k
  unsigned int maxval = source->maxval;
562
563
13.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
202
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
13.0k
  ptr = source->pub._buffer[0];
566
13.0k
  bufferptr = source->iobuffer;
567
13.0k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
420k
    for (col = cinfo->image_width; col > 0; col--) {
569
411k
      register unsigned int gray;
570
411k
      gray  = UCH(*bufferptr++) << 8;
571
411k
      gray |= UCH(*bufferptr++);
572
411k
      if (gray > maxval)
573
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
411k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
411k
                  ptr + 1, ptr + 2, ptr + 3);
576
411k
      ptr += 4;
577
411k
    }
578
9.42k
  } else {
579
13.9k
    for (col = cinfo->image_width; col > 0; col--) {
580
10.2k
      register unsigned int temp;
581
10.2k
      _JSAMPLE gray;
582
10.2k
      temp  = UCH(*bufferptr++) << 8;
583
10.2k
      temp |= UCH(*bufferptr++);
584
10.2k
      if (temp > maxval)
585
76
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
10.2k
      gray = rescale[temp];
587
10.2k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
10.2k
                  ptr + 1, ptr + 2, ptr + 3);
589
10.2k
      ptr += 4;
590
10.2k
    }
591
3.67k
  }
592
13.0k
  return 1;
593
13.0k
}
594
595
596
METHODDEF(JDIMENSION)
597
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
598
/* This version is for reading raw-word-format PPM files with any maxval */
599
186k
{
600
186k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
186k
  register _JSAMPROW ptr;
602
186k
  register U_CHAR *bufferptr;
603
186k
  register _JSAMPLE *rescale = source->rescale;
604
186k
  JDIMENSION col;
605
186k
  unsigned int maxval = source->maxval;
606
186k
  register int rindex = rgb_red[cinfo->in_color_space];
607
186k
  register int gindex = rgb_green[cinfo->in_color_space];
608
186k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
186k
  register int aindex = alpha_index[cinfo->in_color_space];
610
186k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
186k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
5.60k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
186k
  ptr = source->pub._buffer[0];
615
186k
  bufferptr = source->iobuffer;
616
812k
  for (col = cinfo->image_width; col > 0; col--) {
617
625k
    register unsigned int temp;
618
625k
    temp  = UCH(*bufferptr++) << 8;
619
625k
    temp |= UCH(*bufferptr++);
620
625k
    if (temp > maxval)
621
2.18k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
625k
    ptr[rindex] = rescale[temp];
623
625k
    temp  = UCH(*bufferptr++) << 8;
624
625k
    temp |= UCH(*bufferptr++);
625
625k
    if (temp > maxval)
626
1.90k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
625k
    ptr[gindex] = rescale[temp];
628
625k
    temp  = UCH(*bufferptr++) << 8;
629
625k
    temp |= UCH(*bufferptr++);
630
625k
    if (temp > maxval)
631
1.75k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
625k
    ptr[bindex] = rescale[temp];
633
625k
    if (aindex >= 0)
634
120k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
625k
    ptr += ps;
636
625k
  }
637
186k
  return 1;
638
186k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
599
56.4k
{
600
56.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
56.4k
  register _JSAMPROW ptr;
602
56.4k
  register U_CHAR *bufferptr;
603
56.4k
  register _JSAMPLE *rescale = source->rescale;
604
56.4k
  JDIMENSION col;
605
56.4k
  unsigned int maxval = source->maxval;
606
56.4k
  register int rindex = rgb_red[cinfo->in_color_space];
607
56.4k
  register int gindex = rgb_green[cinfo->in_color_space];
608
56.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
56.4k
  register int aindex = alpha_index[cinfo->in_color_space];
610
56.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
56.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
1.97k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
56.4k
  ptr = source->pub._buffer[0];
615
56.4k
  bufferptr = source->iobuffer;
616
151k
  for (col = cinfo->image_width; col > 0; col--) {
617
95.5k
    register unsigned int temp;
618
95.5k
    temp  = UCH(*bufferptr++) << 8;
619
95.5k
    temp |= UCH(*bufferptr++);
620
95.5k
    if (temp > maxval)
621
675
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
95.5k
    ptr[rindex] = rescale[temp];
623
95.5k
    temp  = UCH(*bufferptr++) << 8;
624
95.5k
    temp |= UCH(*bufferptr++);
625
95.5k
    if (temp > maxval)
626
695
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
95.5k
    ptr[gindex] = rescale[temp];
628
95.5k
    temp  = UCH(*bufferptr++) << 8;
629
95.5k
    temp |= UCH(*bufferptr++);
630
95.5k
    if (temp > maxval)
631
670
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
95.5k
    ptr[bindex] = rescale[temp];
633
95.5k
    if (aindex >= 0)
634
14.8k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
95.5k
    ptr += ps;
636
95.5k
  }
637
56.4k
  return 1;
638
56.4k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
599
87.8k
{
600
87.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
87.8k
  register _JSAMPROW ptr;
602
87.8k
  register U_CHAR *bufferptr;
603
87.8k
  register _JSAMPLE *rescale = source->rescale;
604
87.8k
  JDIMENSION col;
605
87.8k
  unsigned int maxval = source->maxval;
606
87.8k
  register int rindex = rgb_red[cinfo->in_color_space];
607
87.8k
  register int gindex = rgb_green[cinfo->in_color_space];
608
87.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
87.8k
  register int aindex = alpha_index[cinfo->in_color_space];
610
87.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
87.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
2.24k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
87.8k
  ptr = source->pub._buffer[0];
615
87.8k
  bufferptr = source->iobuffer;
616
241k
  for (col = cinfo->image_width; col > 0; col--) {
617
153k
    register unsigned int temp;
618
153k
    temp  = UCH(*bufferptr++) << 8;
619
153k
    temp |= UCH(*bufferptr++);
620
153k
    if (temp > maxval)
621
1.17k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
153k
    ptr[rindex] = rescale[temp];
623
153k
    temp  = UCH(*bufferptr++) << 8;
624
153k
    temp |= UCH(*bufferptr++);
625
153k
    if (temp > maxval)
626
955
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
153k
    ptr[gindex] = rescale[temp];
628
153k
    temp  = UCH(*bufferptr++) << 8;
629
153k
    temp |= UCH(*bufferptr++);
630
153k
    if (temp > maxval)
631
860
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
153k
    ptr[bindex] = rescale[temp];
633
153k
    if (aindex >= 0)
634
30.1k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
153k
    ptr += ps;
636
153k
  }
637
87.8k
  return 1;
638
87.8k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
599
42.7k
{
600
42.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
42.7k
  register _JSAMPROW ptr;
602
42.7k
  register U_CHAR *bufferptr;
603
42.7k
  register _JSAMPLE *rescale = source->rescale;
604
42.7k
  JDIMENSION col;
605
42.7k
  unsigned int maxval = source->maxval;
606
42.7k
  register int rindex = rgb_red[cinfo->in_color_space];
607
42.7k
  register int gindex = rgb_green[cinfo->in_color_space];
608
42.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
42.7k
  register int aindex = alpha_index[cinfo->in_color_space];
610
42.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
42.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
1.39k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
42.7k
  ptr = source->pub._buffer[0];
615
42.7k
  bufferptr = source->iobuffer;
616
419k
  for (col = cinfo->image_width; col > 0; col--) {
617
376k
    register unsigned int temp;
618
376k
    temp  = UCH(*bufferptr++) << 8;
619
376k
    temp |= UCH(*bufferptr++);
620
376k
    if (temp > maxval)
621
330
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
376k
    ptr[rindex] = rescale[temp];
623
376k
    temp  = UCH(*bufferptr++) << 8;
624
376k
    temp |= UCH(*bufferptr++);
625
376k
    if (temp > maxval)
626
250
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
376k
    ptr[gindex] = rescale[temp];
628
376k
    temp  = UCH(*bufferptr++) << 8;
629
376k
    temp |= UCH(*bufferptr++);
630
376k
    if (temp > maxval)
631
225
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
376k
    ptr[bindex] = rescale[temp];
633
376k
    if (aindex >= 0)
634
75.1k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
376k
    ptr += ps;
636
376k
  }
637
42.7k
  return 1;
638
42.7k
}
639
640
641
METHODDEF(JDIMENSION)
642
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
643
/* This version is for reading raw-word-format PPM files with any maxval */
644
34.6k
{
645
34.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
34.6k
  register _JSAMPROW ptr;
647
34.6k
  register U_CHAR *bufferptr;
648
34.6k
  register _JSAMPLE *rescale = source->rescale;
649
34.6k
  JDIMENSION col;
650
34.6k
  unsigned int maxval = source->maxval;
651
652
34.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
1.02k
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
34.6k
  ptr = source->pub._buffer[0];
655
34.6k
  bufferptr = source->iobuffer;
656
34.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
85.0k
    for (col = cinfo->image_width; col > 0; col--) {
658
77.3k
      register unsigned int r, g, b;
659
77.3k
      r  = UCH(*bufferptr++) << 8;
660
77.3k
      r |= UCH(*bufferptr++);
661
77.3k
      if (r > maxval)
662
79
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
77.3k
      g  = UCH(*bufferptr++) << 8;
664
77.3k
      g |= UCH(*bufferptr++);
665
77.3k
      if (g > maxval)
666
82
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
77.3k
      b  = UCH(*bufferptr++) << 8;
668
77.3k
      b |= UCH(*bufferptr++);
669
77.3k
      if (b > maxval)
670
80
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
77.3k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
77.3k
                  ptr + 2, ptr + 3);
673
77.3k
      ptr += 4;
674
77.3k
    }
675
26.9k
  } else {
676
70.7k
    for (col = cinfo->image_width; col > 0; col--) {
677
43.7k
      register unsigned int r, g, b;
678
43.7k
      r  = UCH(*bufferptr++) << 8;
679
43.7k
      r |= UCH(*bufferptr++);
680
43.7k
      if (r > maxval)
681
341
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
43.7k
      g  = UCH(*bufferptr++) << 8;
683
43.7k
      g |= UCH(*bufferptr++);
684
43.7k
      if (g > maxval)
685
260
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
43.7k
      b  = UCH(*bufferptr++) << 8;
687
43.7k
      b |= UCH(*bufferptr++);
688
43.7k
      if (b > maxval)
689
231
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
43.7k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
43.7k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
43.7k
      ptr += 4;
693
43.7k
    }
694
26.9k
  }
695
34.6k
  return 1;
696
34.6k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
644
8.51k
{
645
8.51k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
8.51k
  register _JSAMPROW ptr;
647
8.51k
  register U_CHAR *bufferptr;
648
8.51k
  register _JSAMPLE *rescale = source->rescale;
649
8.51k
  JDIMENSION col;
650
8.51k
  unsigned int maxval = source->maxval;
651
652
8.51k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
302
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
8.51k
  ptr = source->pub._buffer[0];
655
8.51k
  bufferptr = source->iobuffer;
656
8.51k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
0
    for (col = cinfo->image_width; col > 0; col--) {
658
0
      register unsigned int r, g, b;
659
0
      r  = UCH(*bufferptr++) << 8;
660
0
      r |= UCH(*bufferptr++);
661
0
      if (r > maxval)
662
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
0
      g  = UCH(*bufferptr++) << 8;
664
0
      g |= UCH(*bufferptr++);
665
0
      if (g > maxval)
666
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
0
      b  = UCH(*bufferptr++) << 8;
668
0
      b |= UCH(*bufferptr++);
669
0
      if (b > maxval)
670
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
0
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
0
                  ptr + 2, ptr + 3);
673
0
      ptr += 4;
674
0
    }
675
8.51k
  } else {
676
23.6k
    for (col = cinfo->image_width; col > 0; col--) {
677
15.1k
      register unsigned int r, g, b;
678
15.1k
      r  = UCH(*bufferptr++) << 8;
679
15.1k
      r |= UCH(*bufferptr++);
680
15.1k
      if (r > maxval)
681
119
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
15.1k
      g  = UCH(*bufferptr++) << 8;
683
15.1k
      g |= UCH(*bufferptr++);
684
15.1k
      if (g > maxval)
685
101
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
15.1k
      b  = UCH(*bufferptr++) << 8;
687
15.1k
      b |= UCH(*bufferptr++);
688
15.1k
      if (b > maxval)
689
94
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
15.1k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
15.1k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
15.1k
      ptr += 4;
693
15.1k
    }
694
8.51k
  }
695
8.51k
  return 1;
696
8.51k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
644
17.5k
{
645
17.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
17.5k
  register _JSAMPROW ptr;
647
17.5k
  register U_CHAR *bufferptr;
648
17.5k
  register _JSAMPLE *rescale = source->rescale;
649
17.5k
  JDIMENSION col;
650
17.5k
  unsigned int maxval = source->maxval;
651
652
17.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
448
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
17.5k
  ptr = source->pub._buffer[0];
655
17.5k
  bufferptr = source->iobuffer;
656
17.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
9.26k
    for (col = cinfo->image_width; col > 0; col--) {
658
6.86k
      register unsigned int r, g, b;
659
6.86k
      r  = UCH(*bufferptr++) << 8;
660
6.86k
      r |= UCH(*bufferptr++);
661
6.86k
      if (r > maxval)
662
79
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
6.86k
      g  = UCH(*bufferptr++) << 8;
664
6.86k
      g |= UCH(*bufferptr++);
665
6.86k
      if (g > maxval)
666
82
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
6.86k
      b  = UCH(*bufferptr++) << 8;
668
6.86k
      b |= UCH(*bufferptr++);
669
6.86k
      if (b > maxval)
670
80
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
6.86k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
6.86k
                  ptr + 2, ptr + 3);
673
6.86k
      ptr += 4;
674
6.86k
    }
675
15.1k
  } else {
676
39.0k
    for (col = cinfo->image_width; col > 0; col--) {
677
23.8k
      register unsigned int r, g, b;
678
23.8k
      r  = UCH(*bufferptr++) << 8;
679
23.8k
      r |= UCH(*bufferptr++);
680
23.8k
      if (r > maxval)
681
156
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
23.8k
      g  = UCH(*bufferptr++) << 8;
683
23.8k
      g |= UCH(*bufferptr++);
684
23.8k
      if (g > maxval)
685
109
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
23.8k
      b  = UCH(*bufferptr++) << 8;
687
23.8k
      b |= UCH(*bufferptr++);
688
23.8k
      if (b > maxval)
689
92
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
23.8k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
23.8k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
23.8k
      ptr += 4;
693
23.8k
    }
694
15.1k
  }
695
17.5k
  return 1;
696
17.5k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
644
8.55k
{
645
8.55k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
8.55k
  register _JSAMPROW ptr;
647
8.55k
  register U_CHAR *bufferptr;
648
8.55k
  register _JSAMPLE *rescale = source->rescale;
649
8.55k
  JDIMENSION col;
650
8.55k
  unsigned int maxval = source->maxval;
651
652
8.55k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
279
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
8.55k
  ptr = source->pub._buffer[0];
655
8.55k
  bufferptr = source->iobuffer;
656
8.55k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
75.7k
    for (col = cinfo->image_width; col > 0; col--) {
658
70.4k
      register unsigned int r, g, b;
659
70.4k
      r  = UCH(*bufferptr++) << 8;
660
70.4k
      r |= UCH(*bufferptr++);
661
70.4k
      if (r > maxval)
662
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
70.4k
      g  = UCH(*bufferptr++) << 8;
664
70.4k
      g |= UCH(*bufferptr++);
665
70.4k
      if (g > maxval)
666
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
70.4k
      b  = UCH(*bufferptr++) << 8;
668
70.4k
      b |= UCH(*bufferptr++);
669
70.4k
      if (b > maxval)
670
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
70.4k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
70.4k
                  ptr + 2, ptr + 3);
673
70.4k
      ptr += 4;
674
70.4k
    }
675
5.26k
  } else {
676
8.08k
    for (col = cinfo->image_width; col > 0; col--) {
677
4.79k
      register unsigned int r, g, b;
678
4.79k
      r  = UCH(*bufferptr++) << 8;
679
4.79k
      r |= UCH(*bufferptr++);
680
4.79k
      if (r > maxval)
681
66
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
4.79k
      g  = UCH(*bufferptr++) << 8;
683
4.79k
      g |= UCH(*bufferptr++);
684
4.79k
      if (g > maxval)
685
50
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
4.79k
      b  = UCH(*bufferptr++) << 8;
687
4.79k
      b |= UCH(*bufferptr++);
688
4.79k
      if (b > maxval)
689
45
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
4.79k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
4.79k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
4.79k
      ptr += 4;
693
4.79k
    }
694
3.29k
  }
695
8.55k
  return 1;
696
8.55k
}
697
698
699
/*
700
 * Read the file header; return image size and component count.
701
 */
702
703
METHODDEF(void)
704
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
705
187k
{
706
187k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
187k
  int c;
708
187k
  unsigned int w, h, maxval;
709
187k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
187k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
187k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
187k
  switch (c) {
718
17.6k
  case '2':                     /* it's a text-format PGM file */
719
37.4k
  case '3':                     /* it's a text-format PPM file */
720
145k
  case '5':                     /* it's a raw-format PGM file */
721
187k
  case '6':                     /* it's a raw-format PPM file */
722
187k
    break;
723
164
  default:
724
164
    ERREXIT(cinfo, JERR_PPM_NOT);
725
164
    break;
726
187k
  }
727
728
  /* fetch the remaining header info */
729
187k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
187k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
187k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
187k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
378
    ERREXIT(cinfo, JERR_PPM_NOT);
735
187k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
2.85k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
187k
  cinfo->image_width = (JDIMENSION)w;
739
187k
  cinfo->image_height = (JDIMENSION)h;
740
187k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
187k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
187k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
187k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
187k
  switch (c) {
748
13.3k
  case '2':                     /* it's a text-format PGM file */
749
13.3k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
13.3k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
13.3k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
13.3k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
1.94k
      source->pub.get_pixel_rows = get_text_gray_row;
755
11.3k
    else if (IsExtRGB(cinfo->in_color_space))
756
9.71k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
1.67k
    else if (cinfo->in_color_space == JCS_CMYK)
758
1.67k
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
13.3k
    need_iobuffer = FALSE;
762
13.3k
    break;
763
764
15.6k
  case '3':                     /* it's a text-format PPM file */
765
15.6k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
15.6k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
15.6k
    if (IsExtRGB(cinfo->in_color_space))
769
11.3k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
4.29k
    else if (cinfo->in_color_space == JCS_CMYK)
771
2.01k
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
2.27k
    else
773
2.27k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
15.6k
    need_iobuffer = FALSE;
775
15.6k
    break;
776
777
103k
  case '5':                     /* it's a raw-format PGM file */
778
103k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
103k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
103k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
103k
    if (maxval > 255) {
783
11.6k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
1.69k
        source->pub.get_pixel_rows = get_word_gray_row;
785
9.96k
      else if (IsExtRGB(cinfo->in_color_space))
786
8.46k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
1.50k
      else if (cinfo->in_color_space == JCS_CMYK)
788
1.50k
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
92.0k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
52.3k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
4.10k
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
667
      source->pub.get_pixel_rows = get_raw_row;
795
667
      use_raw_buffer = TRUE;
796
667
      need_rescale = FALSE;
797
91.4k
    } else {
798
91.4k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
12.9k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
78.4k
      else if (IsExtRGB(cinfo->in_color_space))
801
68.1k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
10.2k
      else if (cinfo->in_color_space == JCS_CMYK)
803
10.2k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
91.4k
    }
807
103k
    break;
808
809
38.4k
  case '6':                     /* it's a raw-format PPM file */
810
38.4k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
38.4k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
38.4k
    if (maxval > 255) {
814
16.8k
      if (IsExtRGB(cinfo->in_color_space))
815
12.1k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
4.68k
      else if (cinfo->in_color_space == JCS_CMYK)
817
2.24k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
2.43k
      else
819
2.43k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
21.5k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
12.0k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
2.41k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
2.41k
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
2.08k
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
338
      source->pub.get_pixel_rows = get_raw_row;
829
338
      use_raw_buffer = TRUE;
830
338
      need_rescale = FALSE;
831
21.1k
    } else {
832
21.1k
      if (IsExtRGB(cinfo->in_color_space))
833
15.4k
        source->pub.get_pixel_rows = get_rgb_row;
834
5.76k
      else if (cinfo->in_color_space == JCS_CMYK)
835
2.61k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
3.15k
      else
837
3.15k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
21.1k
    }
839
38.4k
    break;
840
187k
  }
841
842
163k
  if (IsExtRGB(cinfo->in_color_space))
843
125k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
37.6k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
17.2k
    cinfo->input_components = 1;
846
20.3k
  else if (cinfo->in_color_space == JCS_CMYK)
847
20.3k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
163k
  if (need_iobuffer) {
851
136k
    if (c == '6')
852
32.8k
      source->buffer_width = (size_t)w * 3 *
853
32.8k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
103k
    else
855
103k
      source->buffer_width = (size_t)w *
856
103k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
136k
    source->iobuffer = (U_CHAR *)
858
136k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
136k
                                  source->buffer_width);
860
136k
  }
861
862
  /* Create compressor input buffer. */
863
163k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
1.00k
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
1.00k
    source->pub._buffer = &source->pixrow;
868
1.00k
    source->pub.buffer_height = 1;
869
162k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
162k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
162k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
162k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
162k
    source->pub.buffer_height = 1;
875
162k
  }
876
877
  /* Compute the rescaling array if required. */
878
163k
  if (need_rescale) {
879
162k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
162k
    source->rescale = (_JSAMPLE *)
883
162k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
162k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
162k
                                           sizeof(_JSAMPLE)));
886
162k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
162k
                                        sizeof(_JSAMPLE)));
888
162k
    half_maxval = maxval / 2;
889
568M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
568M
      source->rescale[val] =
892
568M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
568M
                   maxval);
894
568M
    }
895
162k
  }
896
163k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
705
95.7k
{
706
95.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
95.7k
  int c;
708
95.7k
  unsigned int w, h, maxval;
709
95.7k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
95.7k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
95.7k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
95.7k
  switch (c) {
718
8.12k
  case '2':                     /* it's a text-format PGM file */
719
16.9k
  case '3':                     /* it's a text-format PPM file */
720
76.0k
  case '5':                     /* it's a raw-format PGM file */
721
95.6k
  case '6':                     /* it's a raw-format PPM file */
722
95.6k
    break;
723
87
  default:
724
87
    ERREXIT(cinfo, JERR_PPM_NOT);
725
87
    break;
726
95.7k
  }
727
728
  /* fetch the remaining header info */
729
95.6k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
95.6k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
95.6k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
95.6k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
168
    ERREXIT(cinfo, JERR_PPM_NOT);
735
95.6k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.33k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
95.6k
  cinfo->image_width = (JDIMENSION)w;
739
95.6k
  cinfo->image_height = (JDIMENSION)h;
740
95.6k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
95.6k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
95.6k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
95.6k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
95.6k
  switch (c) {
748
6.07k
  case '2':                     /* it's a text-format PGM file */
749
6.07k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
6.07k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
6.07k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
6.07k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
905
      source->pub.get_pixel_rows = get_text_gray_row;
755
5.16k
    else if (IsExtRGB(cinfo->in_color_space))
756
4.52k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
640
    else if (cinfo->in_color_space == JCS_CMYK)
758
640
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
6.07k
    need_iobuffer = FALSE;
762
6.07k
    break;
763
764
7.09k
  case '3':                     /* it's a text-format PPM file */
765
7.09k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
7.09k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
7.09k
    if (IsExtRGB(cinfo->in_color_space))
769
5.25k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.84k
    else if (cinfo->in_color_space == JCS_CMYK)
771
792
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
1.05k
    else
773
1.05k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
7.09k
    need_iobuffer = FALSE;
775
7.09k
    break;
776
777
56.7k
  case '5':                     /* it's a raw-format PGM file */
778
56.7k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
56.7k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
56.7k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
56.7k
    if (maxval > 255) {
783
4.36k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
650
        source->pub.get_pixel_rows = get_word_gray_row;
785
3.71k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.25k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
463
      else if (cinfo->in_color_space == JCS_CMYK)
788
463
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
52.3k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
52.3k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
4.10k
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
667
      source->pub.get_pixel_rows = get_raw_row;
795
667
      use_raw_buffer = TRUE;
796
667
      need_rescale = FALSE;
797
51.7k
    } else {
798
51.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
7.29k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
44.4k
      else if (IsExtRGB(cinfo->in_color_space))
801
39.8k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
4.61k
      else if (cinfo->in_color_space == JCS_CMYK)
803
4.61k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
51.7k
    }
807
56.7k
    break;
808
809
17.7k
  case '6':                     /* it's a raw-format PPM file */
810
17.7k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
17.7k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
17.7k
    if (maxval > 255) {
814
5.74k
      if (IsExtRGB(cinfo->in_color_space))
815
4.24k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
1.50k
      else if (cinfo->in_color_space == JCS_CMYK)
817
654
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
848
      else
819
848
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
12.0k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
12.0k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
2.41k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
2.41k
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
2.08k
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
338
      source->pub.get_pixel_rows = get_raw_row;
829
338
      use_raw_buffer = TRUE;
830
338
      need_rescale = FALSE;
831
11.7k
    } else {
832
11.7k
      if (IsExtRGB(cinfo->in_color_space))
833
8.65k
        source->pub.get_pixel_rows = get_rgb_row;
834
3.05k
      else if (cinfo->in_color_space == JCS_CMYK)
835
1.25k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
1.79k
      else
837
1.79k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
11.7k
    }
839
17.7k
    break;
840
95.6k
  }
841
842
84.0k
  if (IsExtRGB(cinfo->in_color_space))
843
66.0k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
17.9k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
9.51k
    cinfo->input_components = 1;
846
8.41k
  else if (cinfo->in_color_space == JCS_CMYK)
847
8.41k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
84.0k
  if (need_iobuffer) {
851
71.9k
    if (c == '6')
852
15.1k
      source->buffer_width = (size_t)w * 3 *
853
15.1k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
56.7k
    else
855
56.7k
      source->buffer_width = (size_t)w *
856
56.7k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
71.9k
    source->iobuffer = (U_CHAR *)
858
71.9k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
71.9k
                                  source->buffer_width);
860
71.9k
  }
861
862
  /* Create compressor input buffer. */
863
84.0k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
1.00k
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
1.00k
    source->pub._buffer = &source->pixrow;
868
1.00k
    source->pub.buffer_height = 1;
869
83.0k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
83.0k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
83.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
83.0k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
83.0k
    source->pub.buffer_height = 1;
875
83.0k
  }
876
877
  /* Compute the rescaling array if required. */
878
84.0k
  if (need_rescale) {
879
83.0k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
83.0k
    source->rescale = (_JSAMPLE *)
883
83.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
83.0k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
83.0k
                                           sizeof(_JSAMPLE)));
886
83.0k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
83.0k
                                        sizeof(_JSAMPLE)));
888
83.0k
    half_maxval = maxval / 2;
889
134M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
133M
      source->rescale[val] =
892
133M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
133M
                   maxval);
894
133M
    }
895
83.0k
  }
896
84.0k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
705
67.1k
{
706
67.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
67.1k
  int c;
708
67.1k
  unsigned int w, h, maxval;
709
67.1k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
67.1k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
67.1k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
67.1k
  switch (c) {
718
6.30k
  case '2':                     /* it's a text-format PGM file */
719
13.2k
  case '3':                     /* it's a text-format PPM file */
720
50.8k
  case '5':                     /* it's a raw-format PGM file */
721
67.1k
  case '6':                     /* it's a raw-format PPM file */
722
67.1k
    break;
723
42
  default:
724
42
    ERREXIT(cinfo, JERR_PPM_NOT);
725
42
    break;
726
67.1k
  }
727
728
  /* fetch the remaining header info */
729
67.1k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
67.1k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
67.1k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
67.1k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
126
    ERREXIT(cinfo, JERR_PPM_NOT);
735
67.1k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.00k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
67.1k
  cinfo->image_width = (JDIMENSION)w;
739
67.1k
  cinfo->image_height = (JDIMENSION)h;
740
67.1k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
67.1k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
67.1k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
67.1k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
67.1k
  switch (c) {
748
4.69k
  case '2':                     /* it's a text-format PGM file */
749
4.69k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
4.69k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
4.69k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
4.69k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
670
      source->pub.get_pixel_rows = get_text_gray_row;
755
4.02k
    else if (IsExtRGB(cinfo->in_color_space))
756
3.35k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
670
    else if (cinfo->in_color_space == JCS_CMYK)
758
670
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
4.69k
    need_iobuffer = FALSE;
762
4.69k
    break;
763
764
5.50k
  case '3':                     /* it's a text-format PPM file */
765
5.50k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
5.50k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
5.50k
    if (IsExtRGB(cinfo->in_color_space))
769
3.93k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.57k
    else if (cinfo->in_color_space == JCS_CMYK)
771
787
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
787
    else
773
787
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
5.50k
    need_iobuffer = FALSE;
775
5.50k
    break;
776
777
36.1k
  case '5':                     /* it's a raw-format PGM file */
778
36.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
36.1k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
36.1k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
36.1k
    if (maxval > 255) {
783
4.87k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
697
        source->pub.get_pixel_rows = get_word_gray_row;
785
4.18k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.48k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
697
      else if (cinfo->in_color_space == JCS_CMYK)
788
697
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
31.2k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
0
      source->pub.get_pixel_rows = get_raw_row;
795
0
      use_raw_buffer = TRUE;
796
0
      need_rescale = FALSE;
797
31.2k
    } else {
798
31.2k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
4.46k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
26.7k
      else if (IsExtRGB(cinfo->in_color_space))
801
22.3k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
4.46k
      else if (cinfo->in_color_space == JCS_CMYK)
803
4.46k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
31.2k
    }
807
36.1k
    break;
808
809
15.1k
  case '6':                     /* it's a raw-format PPM file */
810
15.1k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
15.1k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
15.1k
    if (maxval > 255) {
814
7.77k
      if (IsExtRGB(cinfo->in_color_space))
815
5.55k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
2.22k
      else if (cinfo->in_color_space == JCS_CMYK)
817
1.11k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
1.11k
      else
819
1.11k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
7.77k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
0
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
0
      source->pub.get_pixel_rows = get_raw_row;
829
0
      use_raw_buffer = TRUE;
830
0
      need_rescale = FALSE;
831
7.35k
    } else {
832
7.35k
      if (IsExtRGB(cinfo->in_color_space))
833
5.25k
        source->pub.get_pixel_rows = get_rgb_row;
834
2.10k
      else if (cinfo->in_color_space == JCS_CMYK)
835
1.05k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
1.05k
      else
837
1.05k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
7.35k
    }
839
15.1k
    break;
840
67.1k
  }
841
842
58.4k
  if (IsExtRGB(cinfo->in_color_space))
843
43.8k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
14.6k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
5.82k
    cinfo->input_components = 1;
846
8.77k
  else if (cinfo->in_color_space == JCS_CMYK)
847
8.77k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
58.4k
  if (need_iobuffer) {
851
49.0k
    if (c == '6')
852
12.9k
      source->buffer_width = (size_t)w * 3 *
853
12.9k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
36.1k
    else
855
36.1k
      source->buffer_width = (size_t)w *
856
36.1k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
49.0k
    source->iobuffer = (U_CHAR *)
858
49.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
49.0k
                                  source->buffer_width);
860
49.0k
  }
861
862
  /* Create compressor input buffer. */
863
58.4k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
0
    source->pub._buffer = &source->pixrow;
868
0
    source->pub.buffer_height = 1;
869
58.4k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
58.4k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
58.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
58.4k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
58.4k
    source->pub.buffer_height = 1;
875
58.4k
  }
876
877
  /* Compute the rescaling array if required. */
878
58.4k
  if (need_rescale) {
879
58.4k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
58.4k
    source->rescale = (_JSAMPLE *)
883
58.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
58.4k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
58.4k
                                           sizeof(_JSAMPLE)));
886
58.4k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
58.4k
                                        sizeof(_JSAMPLE)));
888
58.4k
    half_maxval = maxval / 2;
889
155M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
155M
      source->rescale[val] =
892
155M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
155M
                   maxval);
894
155M
    }
895
58.4k
  }
896
58.4k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
705
24.9k
{
706
24.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
24.9k
  int c;
708
24.9k
  unsigned int w, h, maxval;
709
24.9k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
24.9k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
24.9k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
24.9k
  switch (c) {
718
3.19k
  case '2':                     /* it's a text-format PGM file */
719
7.14k
  case '3':                     /* it's a text-format PPM file */
720
18.7k
  case '5':                     /* it's a raw-format PGM file */
721
24.8k
  case '6':                     /* it's a raw-format PPM file */
722
24.8k
    break;
723
35
  default:
724
35
    ERREXIT(cinfo, JERR_PPM_NOT);
725
35
    break;
726
24.9k
  }
727
728
  /* fetch the remaining header info */
729
24.8k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
24.8k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
24.8k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
24.8k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
84
    ERREXIT(cinfo, JERR_PPM_NOT);
735
24.8k
  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
24.8k
  cinfo->image_width = (JDIMENSION)w;
739
24.8k
  cinfo->image_height = (JDIMENSION)h;
740
24.8k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
24.8k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
24.8k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
24.8k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
24.8k
  switch (c) {
748
2.56k
  case '2':                     /* it's a text-format PGM file */
749
2.56k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
2.56k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
2.56k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
2.56k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
367
      source->pub.get_pixel_rows = get_text_gray_row;
755
2.20k
    else if (IsExtRGB(cinfo->in_color_space))
756
1.83k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
367
    else if (cinfo->in_color_space == JCS_CMYK)
758
367
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
2.56k
    need_iobuffer = FALSE;
762
2.56k
    break;
763
764
3.07k
  case '3':                     /* it's a text-format PPM file */
765
3.07k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
3.07k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
3.07k
    if (IsExtRGB(cinfo->in_color_space))
769
2.19k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
878
    else if (cinfo->in_color_space == JCS_CMYK)
771
439
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
439
    else
773
439
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
3.07k
    need_iobuffer = FALSE;
775
3.07k
    break;
776
777
10.8k
  case '5':                     /* it's a raw-format PGM file */
778
10.8k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
10.8k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
10.8k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
10.8k
    if (maxval > 255) {
783
2.41k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
345
        source->pub.get_pixel_rows = get_word_gray_row;
785
2.07k
      else if (IsExtRGB(cinfo->in_color_space))
786
1.72k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
345
      else if (cinfo->in_color_space == JCS_CMYK)
788
345
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
8.47k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
0
      source->pub.get_pixel_rows = get_raw_row;
795
0
      use_raw_buffer = TRUE;
796
0
      need_rescale = FALSE;
797
8.47k
    } else {
798
8.47k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
1.21k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
7.26k
      else if (IsExtRGB(cinfo->in_color_space))
801
6.05k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
1.21k
      else if (cinfo->in_color_space == JCS_CMYK)
803
1.21k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
8.47k
    }
807
10.8k
    break;
808
809
5.50k
  case '6':                     /* it's a raw-format PPM file */
810
5.50k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
5.50k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
5.50k
    if (maxval > 255) {
814
3.36k
      if (IsExtRGB(cinfo->in_color_space))
815
2.40k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
962
      else if (cinfo->in_color_space == JCS_CMYK)
817
481
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
481
      else
819
481
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
3.36k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
0
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
0
      source->pub.get_pixel_rows = get_raw_row;
829
0
      use_raw_buffer = TRUE;
830
0
      need_rescale = FALSE;
831
2.13k
    } else {
832
2.13k
      if (IsExtRGB(cinfo->in_color_space))
833
1.52k
        source->pub.get_pixel_rows = get_rgb_row;
834
610
      else if (cinfo->in_color_space == JCS_CMYK)
835
305
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
305
      else
837
305
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
2.13k
    }
839
5.50k
    break;
840
24.8k
  }
841
842
20.8k
  if (IsExtRGB(cinfo->in_color_space))
843
15.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
5.06k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
1.92k
    cinfo->input_components = 1;
846
3.14k
  else if (cinfo->in_color_space == JCS_CMYK)
847
3.14k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
20.8k
  if (need_iobuffer) {
851
15.6k
    if (c == '6')
852
4.71k
      source->buffer_width = (size_t)w * 3 *
853
4.71k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
10.8k
    else
855
10.8k
      source->buffer_width = (size_t)w *
856
10.8k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
15.6k
    source->iobuffer = (U_CHAR *)
858
15.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
15.6k
                                  source->buffer_width);
860
15.6k
  }
861
862
  /* Create compressor input buffer. */
863
20.8k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
0
    source->pub._buffer = &source->pixrow;
868
0
    source->pub.buffer_height = 1;
869
20.8k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
20.8k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
20.8k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
20.8k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
20.8k
    source->pub.buffer_height = 1;
875
20.8k
  }
876
877
  /* Compute the rescaling array if required. */
878
20.8k
  if (need_rescale) {
879
20.8k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
20.8k
    source->rescale = (_JSAMPLE *)
883
20.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
20.8k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
20.8k
                                           sizeof(_JSAMPLE)));
886
20.8k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
20.8k
                                        sizeof(_JSAMPLE)));
888
20.8k
    half_maxval = maxval / 2;
889
278M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
278M
      source->rescale[val] =
892
278M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
278M
                   maxval);
894
278M
    }
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
99.7k
{
906
  /* no work */
907
99.7k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
905
55.2k
{
906
  /* no work */
907
55.2k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
905
35.3k
{
906
  /* no work */
907
35.3k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
905
9.08k
{
906
  /* no work */
907
9.08k
}
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
187k
{
917
187k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
95.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
92.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
92.0k
      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
187k
  source = (ppm_source_ptr)
929
187k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
187k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
187k
  source->pub.start_input = start_input_ppm;
933
187k
  source->pub.finish_input = finish_input_ppm;
934
187k
  source->pub.max_pixels = 0;
935
936
187k
  return (cjpeg_source_ptr)source;
937
187k
}
jinit_read_ppm
Line
Count
Source
916
95.7k
{
917
95.7k
  ppm_source_ptr source;
918
919
95.7k
#if BITS_IN_JSAMPLE == 8
920
95.7k
  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.7k
  source = (ppm_source_ptr)
929
95.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
95.7k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
95.7k
  source->pub.start_input = start_input_ppm;
933
95.7k
  source->pub.finish_input = finish_input_ppm;
934
95.7k
  source->pub.max_pixels = 0;
935
936
95.7k
  return (cjpeg_source_ptr)source;
937
95.7k
}
j12init_read_ppm
Line
Count
Source
916
67.1k
{
917
67.1k
  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
67.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
67.1k
      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
67.1k
  source = (ppm_source_ptr)
929
67.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
67.1k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
67.1k
  source->pub.start_input = start_input_ppm;
933
67.1k
  source->pub.finish_input = finish_input_ppm;
934
67.1k
  source->pub.max_pixels = 0;
935
936
67.1k
  return (cjpeg_source_ptr)source;
937
67.1k
}
j16init_read_ppm
Line
Count
Source
916
24.9k
{
917
24.9k
  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
24.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
24.9k
      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
24.9k
  source = (ppm_source_ptr)
929
24.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
24.9k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
24.9k
  source->pub.start_input = start_input_ppm;
933
24.9k
  source->pub.finish_input = finish_input_ppm;
934
24.9k
  source->pub.max_pixels = 0;
935
936
24.9k
  return (cjpeg_source_ptr)source;
937
24.9k
}
938
939
#endif /* defined(PPM_SUPPORTED) &&
940
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */