Coverage Report

Created: 2026-01-25 06:04

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
313M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
273M
  (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.59M
{
80
3.59M
  register int ch;
81
82
3.59M
  ch = getc(infile);
83
3.59M
  if (ch == '#') {
84
672k
    do {
85
672k
      ch = getc(infile);
86
672k
    } while (ch != '\n' && ch != EOF);
87
44.5k
  }
88
3.59M
  return ch;
89
3.59M
}
rdppm-8.c:pbm_getc
Line
Count
Source
79
1.69M
{
80
1.69M
  register int ch;
81
82
1.69M
  ch = getc(infile);
83
1.69M
  if (ch == '#') {
84
276k
    do {
85
276k
      ch = getc(infile);
86
276k
    } while (ch != '\n' && ch != EOF);
87
21.1k
  }
88
1.69M
  return ch;
89
1.69M
}
rdppm-12.c:pbm_getc
Line
Count
Source
79
1.29M
{
80
1.29M
  register int ch;
81
82
1.29M
  ch = getc(infile);
83
1.29M
  if (ch == '#') {
84
312k
    do {
85
312k
      ch = getc(infile);
86
312k
    } while (ch != '\n' && ch != EOF);
87
15.2k
  }
88
1.29M
  return ch;
89
1.29M
}
rdppm-16.c:pbm_getc
Line
Count
Source
79
616k
{
80
616k
  register int ch;
81
82
616k
  ch = getc(infile);
83
616k
  if (ch == '#') {
84
83.7k
    do {
85
83.7k
      ch = getc(infile);
86
83.7k
    } while (ch != '\n' && ch != EOF);
87
8.12k
  }
88
616k
  return ch;
89
616k
}
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.53M
{
99
1.53M
  register int ch;
100
1.53M
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
1.62M
  do {
104
1.62M
    ch = pbm_getc(infile);
105
1.62M
    if (ch == EOF)
106
33.7k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
1.62M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
1.53M
  if (ch < '0' || ch > '9')
110
3.38k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
1.53M
  val = ch - '0';
113
2.00M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
478k
    val *= 10;
115
478k
    val += ch - '0';
116
478k
    if (val > maxval)
117
1.72k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
478k
  }
119
120
1.53M
  return val;
121
1.53M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
98
729k
{
99
729k
  register int ch;
100
729k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
772k
  do {
104
772k
    ch = pbm_getc(infile);
105
772k
    if (ch == EOF)
106
15.9k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
772k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
729k
  if (ch < '0' || ch > '9')
110
1.45k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
729k
  val = ch - '0';
113
936k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
206k
    val *= 10;
115
206k
    val += ch - '0';
116
206k
    if (val > maxval)
117
803
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
206k
  }
119
120
729k
  return val;
121
729k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
98
535k
{
99
535k
  register int ch;
100
535k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
573k
  do {
104
573k
    ch = pbm_getc(infile);
105
573k
    if (ch == EOF)
106
11.3k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
573k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
535k
  if (ch < '0' || ch > '9')
110
1.35k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
535k
  val = ch - '0';
113
731k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
195k
    val *= 10;
115
195k
    val += ch - '0';
116
195k
    if (val > maxval)
117
633
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
195k
  }
119
120
535k
  return val;
121
535k
}
rdppm-16.c:read_pbm_integer
Line
Count
Source
98
265k
{
99
265k
  register int ch;
100
265k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
282k
  do {
104
282k
    ch = pbm_getc(infile);
105
282k
    if (ch == EOF)
106
6.47k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
282k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
265k
  if (ch < '0' || ch > '9')
110
571
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
265k
  val = ch - '0';
113
341k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
75.7k
    val *= 10;
115
75.7k
    val += ch - '0';
116
75.7k
    if (val > maxval)
117
291
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
75.7k
  }
119
120
265k
  return val;
121
265k
}
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.9k
{
140
21.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
21.9k
  FILE *infile = source->pub.input_file;
142
21.9k
  register _JSAMPROW ptr;
143
21.9k
  register _JSAMPLE *rescale = source->rescale;
144
21.9k
  JDIMENSION col;
145
21.9k
  unsigned int maxval = source->maxval;
146
147
21.9k
  ptr = source->pub._buffer[0];
148
60.1k
  for (col = cinfo->image_width; col > 0; col--) {
149
38.2k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
38.2k
  }
151
21.9k
  return 1;
152
21.9k
}
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.0k
  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
7.12k
{
140
7.12k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
7.12k
  FILE *infile = source->pub.input_file;
142
7.12k
  register _JSAMPROW ptr;
143
7.12k
  register _JSAMPLE *rescale = source->rescale;
144
7.12k
  JDIMENSION col;
145
7.12k
  unsigned int maxval = source->maxval;
146
147
7.12k
  ptr = source->pub._buffer[0];
148
19.4k
  for (col = cinfo->image_width; col > 0; col--) {
149
12.3k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
12.3k
  }
151
7.12k
  return 1;
152
7.12k
}
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.80k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
6.80k
  }
151
3.86k
  return 1;
152
3.86k
}
153
154
155
194M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
156
910M
  for (col = cinfo->image_width; col > 0; col--) { \
157
716M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
158
716M
    alpha_set_op \
159
716M
    ptr += ps; \
160
716M
  } \
161
194M
}
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
109k
{
168
109k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
109k
  FILE *infile = source->pub.input_file;
170
109k
  register _JSAMPROW ptr;
171
109k
  register _JSAMPLE *rescale = source->rescale;
172
109k
  JDIMENSION col;
173
109k
  unsigned int maxval = source->maxval;
174
109k
  register int rindex = rgb_red[cinfo->in_color_space];
175
109k
  register int gindex = rgb_green[cinfo->in_color_space];
176
109k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
109k
  register int aindex = alpha_index[cinfo->in_color_space];
178
109k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
109k
  ptr = source->pub._buffer[0];
181
109k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
18.1k
    if (aindex >= 0)
183
2.63k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
18.1k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
15.5k
    else
186
15.5k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
91.4k
  } else {
188
91.4k
    if (aindex >= 0)
189
15.2k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
91.4k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
76.2k
    else
192
76.2k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
91.4k
  }
194
109k
  return 1;
195
109k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
167
54.6k
{
168
54.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
54.6k
  FILE *infile = source->pub.input_file;
170
54.6k
  register _JSAMPROW ptr;
171
54.6k
  register _JSAMPLE *rescale = source->rescale;
172
54.6k
  JDIMENSION col;
173
54.6k
  unsigned int maxval = source->maxval;
174
54.6k
  register int rindex = rgb_red[cinfo->in_color_space];
175
54.6k
  register int gindex = rgb_green[cinfo->in_color_space];
176
54.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
54.6k
  register int aindex = alpha_index[cinfo->in_color_space];
178
54.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
54.6k
  ptr = source->pub._buffer[0];
181
54.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
9.69k
    if (aindex >= 0)
183
991
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
9.69k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
8.70k
    else
186
8.70k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
44.9k
  } else {
188
44.9k
    if (aindex >= 0)
189
5.85k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
44.9k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
39.1k
    else
192
39.1k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
44.9k
  }
194
54.6k
  return 1;
195
54.6k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
167
35.6k
{
168
35.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
35.6k
  FILE *infile = source->pub.input_file;
170
35.6k
  register _JSAMPROW ptr;
171
35.6k
  register _JSAMPLE *rescale = source->rescale;
172
35.6k
  JDIMENSION col;
173
35.6k
  unsigned int maxval = source->maxval;
174
35.6k
  register int rindex = rgb_red[cinfo->in_color_space];
175
35.6k
  register int gindex = rgb_green[cinfo->in_color_space];
176
35.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
35.6k
  register int aindex = alpha_index[cinfo->in_color_space];
178
35.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
35.6k
  ptr = source->pub._buffer[0];
181
35.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
6.18k
    if (aindex >= 0)
183
1.19k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
6.18k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
4.98k
    else
186
4.98k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
29.4k
  } else {
188
29.4k
    if (aindex >= 0)
189
5.92k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
29.4k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
23.5k
    else
192
23.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
29.4k
  }
194
35.6k
  return 1;
195
35.6k
}
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
443
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
2.31k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
1.86k
    else
186
1.86k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
17.0k
  } else {
188
17.0k
    if (aindex >= 0)
189
3.42k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
17.0k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
13.6k
    else
192
13.6k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
17.0k
  }
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.8k
{
203
17.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
17.8k
  FILE *infile = source->pub.input_file;
205
17.8k
  register _JSAMPROW ptr;
206
17.8k
  register _JSAMPLE *rescale = source->rescale;
207
17.8k
  JDIMENSION col;
208
17.8k
  unsigned int maxval = source->maxval;
209
210
17.8k
  ptr = source->pub._buffer[0];
211
17.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
12.2k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.07k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
8.07k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
8.07k
      ptr += 4;
216
8.07k
    }
217
13.6k
  } else {
218
36.9k
    for (col = cinfo->image_width; col > 0; col--) {
219
23.3k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
23.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
23.3k
                  ptr + 1, ptr + 2, ptr + 3);
222
23.3k
      ptr += 4;
223
23.3k
    }
224
13.6k
  }
225
17.8k
  return 1;
226
17.8k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.84k
{
203
6.84k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.84k
  FILE *infile = source->pub.input_file;
205
6.84k
  register _JSAMPROW ptr;
206
6.84k
  register _JSAMPLE *rescale = source->rescale;
207
6.84k
  JDIMENSION col;
208
6.84k
  unsigned int maxval = source->maxval;
209
210
6.84k
  ptr = source->pub._buffer[0];
211
6.84k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
5.08k
    for (col = cinfo->image_width; col > 0; col--) {
213
3.30k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
3.30k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
3.30k
      ptr += 4;
216
3.30k
    }
217
5.05k
  } else {
218
14.0k
    for (col = cinfo->image_width; col > 0; col--) {
219
9.00k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
9.00k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
9.00k
                  ptr + 1, ptr + 2, ptr + 3);
222
9.00k
      ptr += 4;
223
9.00k
    }
224
5.05k
  }
225
6.84k
  return 1;
226
6.84k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
202
7.12k
{
203
7.12k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
7.12k
  FILE *infile = source->pub.input_file;
205
7.12k
  register _JSAMPROW ptr;
206
7.12k
  register _JSAMPLE *rescale = source->rescale;
207
7.12k
  JDIMENSION col;
208
7.12k
  unsigned int maxval = source->maxval;
209
210
7.12k
  ptr = source->pub._buffer[0];
211
7.12k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
4.92k
    for (col = cinfo->image_width; col > 0; col--) {
213
3.28k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
3.28k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
3.28k
      ptr += 4;
216
3.28k
    }
217
5.47k
  } else {
218
14.4k
    for (col = cinfo->image_width; col > 0; col--) {
219
9.01k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
9.01k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
9.01k
                  ptr + 1, ptr + 2, ptr + 3);
222
9.01k
      ptr += 4;
223
9.01k
    }
224
5.47k
  }
225
7.12k
  return 1;
226
7.12k
}
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.23k
    for (col = cinfo->image_width; col > 0; col--) {
213
1.48k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
1.48k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
1.48k
      ptr += 4;
216
1.48k
    }
217
3.11k
  } else {
218
8.43k
    for (col = cinfo->image_width; col > 0; col--) {
219
5.31k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
5.31k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
5.31k
                  ptr + 1, ptr + 2, ptr + 3);
222
5.31k
      ptr += 4;
223
5.31k
    }
224
3.11k
  }
225
3.86k
  return 1;
226
3.86k
}
227
228
229
9.06M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
230
91.3M
  for (col = cinfo->image_width; col > 0; col--) { \
231
82.3M
    ptr[rindex] = read_op; \
232
82.3M
    ptr[gindex] = read_op; \
233
82.3M
    ptr[bindex] = read_op; \
234
82.3M
    alpha_set_op \
235
82.3M
    ptr += ps; \
236
82.3M
  } \
237
9.06M
}
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
122k
{
243
122k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
122k
  FILE *infile = source->pub.input_file;
245
122k
  register _JSAMPROW ptr;
246
122k
  register _JSAMPLE *rescale = source->rescale;
247
122k
  JDIMENSION col;
248
122k
  unsigned int maxval = source->maxval;
249
122k
  register int rindex = rgb_red[cinfo->in_color_space];
250
122k
  register int gindex = rgb_green[cinfo->in_color_space];
251
122k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
122k
  register int aindex = alpha_index[cinfo->in_color_space];
253
122k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
122k
  ptr = source->pub._buffer[0];
256
122k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
22.4k
    if (aindex >= 0)
258
2.99k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
22.4k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
19.4k
    else
261
19.4k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
99.7k
  } else {
263
99.7k
    if (aindex >= 0)
264
17.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
99.7k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
81.9k
    else
267
81.9k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
99.7k
  }
269
122k
  return 1;
270
122k
}
rdppm-8.c:get_text_rgb_row
Line
Count
Source
242
60.5k
{
243
60.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
60.5k
  FILE *infile = source->pub.input_file;
245
60.5k
  register _JSAMPROW ptr;
246
60.5k
  register _JSAMPLE *rescale = source->rescale;
247
60.5k
  JDIMENSION col;
248
60.5k
  unsigned int maxval = source->maxval;
249
60.5k
  register int rindex = rgb_red[cinfo->in_color_space];
250
60.5k
  register int gindex = rgb_green[cinfo->in_color_space];
251
60.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
60.5k
  register int aindex = alpha_index[cinfo->in_color_space];
253
60.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
60.5k
  ptr = source->pub._buffer[0];
256
60.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
11.7k
    if (aindex >= 0)
258
1.36k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
11.7k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
10.3k
    else
261
10.3k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
48.8k
  } else {
263
48.8k
    if (aindex >= 0)
264
7.05k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
48.8k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
41.7k
    else
267
41.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
48.8k
  }
269
60.5k
  return 1;
270
60.5k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
242
36.9k
{
243
36.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
36.9k
  FILE *infile = source->pub.input_file;
245
36.9k
  register _JSAMPROW ptr;
246
36.9k
  register _JSAMPLE *rescale = source->rescale;
247
36.9k
  JDIMENSION col;
248
36.9k
  unsigned int maxval = source->maxval;
249
36.9k
  register int rindex = rgb_red[cinfo->in_color_space];
250
36.9k
  register int gindex = rgb_green[cinfo->in_color_space];
251
36.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
36.9k
  register int aindex = alpha_index[cinfo->in_color_space];
253
36.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
36.9k
  ptr = source->pub._buffer[0];
256
36.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
7.27k
    if (aindex >= 0)
258
1.31k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
7.27k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
5.96k
    else
261
5.96k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
29.6k
  } else {
263
29.6k
    if (aindex >= 0)
264
6.07k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
29.6k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
23.5k
    else
267
23.5k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
29.6k
  }
269
36.9k
  return 1;
270
36.9k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
242
24.8k
{
243
24.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
24.8k
  FILE *infile = source->pub.input_file;
245
24.8k
  register _JSAMPROW ptr;
246
24.8k
  register _JSAMPLE *rescale = source->rescale;
247
24.8k
  JDIMENSION col;
248
24.8k
  unsigned int maxval = source->maxval;
249
24.8k
  register int rindex = rgb_red[cinfo->in_color_space];
250
24.8k
  register int gindex = rgb_green[cinfo->in_color_space];
251
24.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
24.8k
  register int aindex = alpha_index[cinfo->in_color_space];
253
24.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
24.8k
  ptr = source->pub._buffer[0];
256
24.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
3.51k
    if (aindex >= 0)
258
322
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
3.51k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
3.19k
    else
261
3.19k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
21.3k
  } else {
263
21.3k
    if (aindex >= 0)
264
4.64k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
21.3k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
16.6k
    else
267
16.6k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
21.3k
  }
269
24.8k
  return 1;
270
24.8k
}
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
20.7k
{
278
20.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
20.7k
  FILE *infile = source->pub.input_file;
280
20.7k
  register _JSAMPROW ptr;
281
20.7k
  register _JSAMPLE *rescale = source->rescale;
282
20.7k
  JDIMENSION col;
283
20.7k
  unsigned int maxval = source->maxval;
284
285
20.7k
  ptr = source->pub._buffer[0];
286
20.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
21.0k
    for (col = cinfo->image_width; col > 0; col--) {
288
14.4k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
14.4k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
14.4k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
14.4k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
14.4k
      ptr += 4;
293
14.4k
    }
294
14.1k
  } else {
295
40.1k
    for (col = cinfo->image_width; col > 0; col--) {
296
25.9k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
25.9k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
25.9k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
25.9k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
25.9k
                  ptr + 2, ptr + 3);
301
25.9k
      ptr += 4;
302
25.9k
    }
303
14.1k
  }
304
20.7k
  return 1;
305
20.7k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
277
8.42k
{
278
8.42k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
8.42k
  FILE *infile = source->pub.input_file;
280
8.42k
  register _JSAMPROW ptr;
281
8.42k
  register _JSAMPLE *rescale = source->rescale;
282
8.42k
  JDIMENSION col;
283
8.42k
  unsigned int maxval = source->maxval;
284
285
8.42k
  ptr = source->pub._buffer[0];
286
8.42k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
8.98k
    for (col = cinfo->image_width; col > 0; col--) {
288
5.84k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
5.84k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
5.84k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
5.84k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
5.84k
      ptr += 4;
293
5.84k
    }
294
5.28k
  } else {
295
15.5k
    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.28k
  }
304
8.42k
  return 1;
305
8.42k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
277
7.38k
{
278
7.38k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
7.38k
  FILE *infile = source->pub.input_file;
280
7.38k
  register _JSAMPROW ptr;
281
7.38k
  register _JSAMPLE *rescale = source->rescale;
282
7.38k
  JDIMENSION col;
283
7.38k
  unsigned int maxval = source->maxval;
284
285
7.38k
  ptr = source->pub._buffer[0];
286
7.38k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
7.95k
    for (col = cinfo->image_width; col > 0; col--) {
288
5.84k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
5.84k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
5.84k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
5.84k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
5.84k
      ptr += 4;
293
5.84k
    }
294
5.28k
  } else {
295
15.2k
    for (col = cinfo->image_width; col > 0; col--) {
296
9.98k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
9.98k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
9.98k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
9.98k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
9.98k
                  ptr + 2, ptr + 3);
301
9.98k
      ptr += 4;
302
9.98k
    }
303
5.28k
  }
304
7.38k
  return 1;
305
7.38k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
277
4.96k
{
278
4.96k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
4.96k
  FILE *infile = source->pub.input_file;
280
4.96k
  register _JSAMPROW ptr;
281
4.96k
  register _JSAMPLE *rescale = source->rescale;
282
4.96k
  JDIMENSION col;
283
4.96k
  unsigned int maxval = source->maxval;
284
285
4.96k
  ptr = source->pub._buffer[0];
286
4.96k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
4.06k
    for (col = cinfo->image_width; col > 0; col--) {
288
2.72k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
2.72k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
2.72k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
2.72k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
2.72k
      ptr += 4;
293
2.72k
    }
294
3.62k
  } else {
295
9.36k
    for (col = cinfo->image_width; col > 0; col--) {
296
5.74k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
5.74k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
5.74k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
5.74k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
5.74k
                  ptr + 2, ptr + 3);
301
5.74k
      ptr += 4;
302
5.74k
    }
303
3.62k
  }
304
4.96k
  return 1;
305
4.96k
}
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
37.0M
{
312
37.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
37.0M
  register _JSAMPROW ptr;
314
37.0M
  register U_CHAR *bufferptr;
315
37.0M
  register _JSAMPLE *rescale = source->rescale;
316
37.0M
  JDIMENSION col;
317
318
37.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
846
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
37.0M
  ptr = source->pub._buffer[0];
321
37.0M
  bufferptr = source->iobuffer;
322
177M
  for (col = cinfo->image_width; col > 0; col--) {
323
140M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
140M
  }
325
37.0M
  return 1;
326
37.0M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
311
19.0M
{
312
19.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
19.0M
  register _JSAMPROW ptr;
314
19.0M
  register U_CHAR *bufferptr;
315
19.0M
  register _JSAMPLE *rescale = source->rescale;
316
19.0M
  JDIMENSION col;
317
318
19.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
462
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
19.0M
  ptr = source->pub._buffer[0];
321
19.0M
  bufferptr = source->iobuffer;
322
86.1M
  for (col = cinfo->image_width; col > 0; col--) {
323
67.1M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
67.1M
  }
325
19.0M
  return 1;
326
19.0M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
311
13.5M
{
312
13.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
13.5M
  register _JSAMPROW ptr;
314
13.5M
  register U_CHAR *bufferptr;
315
13.5M
  register _JSAMPLE *rescale = source->rescale;
316
13.5M
  JDIMENSION col;
317
318
13.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
263
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
13.5M
  ptr = source->pub._buffer[0];
321
13.5M
  bufferptr = source->iobuffer;
322
64.6M
  for (col = cinfo->image_width; col > 0; col--) {
323
51.0M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
51.0M
  }
325
13.5M
  return 1;
326
13.5M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
311
4.48M
{
312
4.48M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
4.48M
  register _JSAMPROW ptr;
314
4.48M
  register U_CHAR *bufferptr;
315
4.48M
  register _JSAMPLE *rescale = source->rescale;
316
4.48M
  JDIMENSION col;
317
318
4.48M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
121
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
4.48M
  ptr = source->pub._buffer[0];
321
4.48M
  bufferptr = source->iobuffer;
322
26.6M
  for (col = cinfo->image_width; col > 0; col--) {
323
22.1M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
22.1M
  }
325
4.48M
  return 1;
326
4.48M
}
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
194M
{
334
194M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
194M
  register _JSAMPROW ptr;
336
194M
  register U_CHAR *bufferptr;
337
194M
  register _JSAMPLE *rescale = source->rescale;
338
194M
  JDIMENSION col;
339
194M
  unsigned int maxval = source->maxval;
340
194M
  register int rindex = rgb_red[cinfo->in_color_space];
341
194M
  register int gindex = rgb_green[cinfo->in_color_space];
342
194M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
194M
  register int aindex = alpha_index[cinfo->in_color_space];
344
194M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
194M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
5.05k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
194M
  ptr = source->pub._buffer[0];
349
194M
  bufferptr = source->iobuffer;
350
194M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
9.51M
    if (aindex >= 0)
352
356k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
9.15M
    else
354
9.15M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
185M
  } else {
356
185M
    if (aindex >= 0)
357
27.3M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
185M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
157M
    else
360
157M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
185M
  }
362
194M
  return 1;
363
194M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
333
104M
{
334
104M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
104M
  register _JSAMPROW ptr;
336
104M
  register U_CHAR *bufferptr;
337
104M
  register _JSAMPLE *rescale = source->rescale;
338
104M
  JDIMENSION col;
339
104M
  unsigned int maxval = source->maxval;
340
104M
  register int rindex = rgb_red[cinfo->in_color_space];
341
104M
  register int gindex = rgb_green[cinfo->in_color_space];
342
104M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
104M
  register int aindex = alpha_index[cinfo->in_color_space];
344
104M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
104M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
3.13k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
104M
  ptr = source->pub._buffer[0];
349
104M
  bufferptr = source->iobuffer;
350
104M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
9.51M
    if (aindex >= 0)
352
356k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
9.15M
    else
354
9.15M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
94.9M
  } else {
356
94.9M
    if (aindex >= 0)
357
9.32M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
94.9M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
85.6M
    else
360
85.6M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
94.9M
  }
362
104M
  return 1;
363
104M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
333
67.7M
{
334
67.7M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
67.7M
  register _JSAMPROW ptr;
336
67.7M
  register U_CHAR *bufferptr;
337
67.7M
  register _JSAMPLE *rescale = source->rescale;
338
67.7M
  JDIMENSION col;
339
67.7M
  unsigned int maxval = source->maxval;
340
67.7M
  register int rindex = rgb_red[cinfo->in_color_space];
341
67.7M
  register int gindex = rgb_green[cinfo->in_color_space];
342
67.7M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
67.7M
  register int aindex = alpha_index[cinfo->in_color_space];
344
67.7M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
67.7M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
1.31k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
67.7M
  ptr = source->pub._buffer[0];
349
67.7M
  bufferptr = source->iobuffer;
350
67.7M
  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
67.7M
  } else {
356
67.7M
    if (aindex >= 0)
357
13.5M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
67.7M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
54.2M
    else
360
54.2M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
67.7M
  }
362
67.7M
  return 1;
363
67.7M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
333
22.4M
{
334
22.4M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
22.4M
  register _JSAMPROW ptr;
336
22.4M
  register U_CHAR *bufferptr;
337
22.4M
  register _JSAMPLE *rescale = source->rescale;
338
22.4M
  JDIMENSION col;
339
22.4M
  unsigned int maxval = source->maxval;
340
22.4M
  register int rindex = rgb_red[cinfo->in_color_space];
341
22.4M
  register int gindex = rgb_green[cinfo->in_color_space];
342
22.4M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
22.4M
  register int aindex = alpha_index[cinfo->in_color_space];
344
22.4M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
22.4M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
605
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
22.4M
  ptr = source->pub._buffer[0];
349
22.4M
  bufferptr = source->iobuffer;
350
22.4M
  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
22.4M
  } else {
356
22.4M
    if (aindex >= 0)
357
4.48M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
22.4M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
17.9M
    else
360
17.9M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
22.4M
  }
362
22.4M
  return 1;
363
22.4M
}
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
27.7M
{
371
27.7M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
27.7M
  register _JSAMPROW ptr;
373
27.7M
  register U_CHAR *bufferptr;
374
27.7M
  register _JSAMPLE *rescale = source->rescale;
375
27.7M
  JDIMENSION col;
376
27.7M
  unsigned int maxval = source->maxval;
377
378
27.7M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
825
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
27.7M
  ptr = source->pub._buffer[0];
381
27.7M
  bufferptr = source->iobuffer;
382
27.7M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
2.90M
    for (col = cinfo->image_width; col > 0; col--) {
384
2.38M
      _JSAMPLE gray = *bufferptr++;
385
2.38M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
2.38M
      ptr += 4;
387
2.38M
    }
388
27.2M
  } else {
389
132M
    for (col = cinfo->image_width; col > 0; col--) {
390
105M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
105M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
105M
                  ptr + 1, ptr + 2, ptr + 3);
393
105M
      ptr += 4;
394
105M
    }
395
27.2M
  }
396
27.7M
  return 1;
397
27.7M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
370
9.68M
{
371
9.68M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
9.68M
  register _JSAMPROW ptr;
373
9.68M
  register U_CHAR *bufferptr;
374
9.68M
  register _JSAMPLE *rescale = source->rescale;
375
9.68M
  JDIMENSION col;
376
9.68M
  unsigned int maxval = source->maxval;
377
378
9.68M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
441
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
9.68M
  ptr = source->pub._buffer[0];
381
9.68M
  bufferptr = source->iobuffer;
382
9.68M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
2.90M
    for (col = cinfo->image_width; col > 0; col--) {
384
2.38M
      _JSAMPLE gray = *bufferptr++;
385
2.38M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
2.38M
      ptr += 4;
387
2.38M
    }
388
9.16M
  } else {
389
41.2M
    for (col = cinfo->image_width; col > 0; col--) {
390
32.0M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
32.0M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
32.0M
                  ptr + 1, ptr + 2, ptr + 3);
393
32.0M
      ptr += 4;
394
32.0M
    }
395
9.16M
  }
396
9.68M
  return 1;
397
9.68M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
370
13.5M
{
371
13.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
13.5M
  register _JSAMPROW ptr;
373
13.5M
  register U_CHAR *bufferptr;
374
13.5M
  register _JSAMPLE *rescale = source->rescale;
375
13.5M
  JDIMENSION col;
376
13.5M
  unsigned int maxval = source->maxval;
377
378
13.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
263
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
13.5M
  ptr = source->pub._buffer[0];
381
13.5M
  bufferptr = source->iobuffer;
382
13.5M
  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
13.5M
  } else {
389
64.6M
    for (col = cinfo->image_width; col > 0; col--) {
390
51.0M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
51.0M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
51.0M
                  ptr + 1, ptr + 2, ptr + 3);
393
51.0M
      ptr += 4;
394
51.0M
    }
395
13.5M
  }
396
13.5M
  return 1;
397
13.5M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
370
4.48M
{
371
4.48M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
4.48M
  register _JSAMPROW ptr;
373
4.48M
  register U_CHAR *bufferptr;
374
4.48M
  register _JSAMPLE *rescale = source->rescale;
375
4.48M
  JDIMENSION col;
376
4.48M
  unsigned int maxval = source->maxval;
377
378
4.48M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
121
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
4.48M
  ptr = source->pub._buffer[0];
381
4.48M
  bufferptr = source->iobuffer;
382
4.48M
  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
4.48M
  } else {
389
26.6M
    for (col = cinfo->image_width; col > 0; col--) {
390
22.1M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
22.1M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
22.1M
                  ptr + 1, ptr + 2, ptr + 3);
393
22.1M
      ptr += 4;
394
22.1M
    }
395
4.48M
  }
396
4.48M
  return 1;
397
4.48M
}
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
8.94M
{
404
8.94M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
8.94M
  register _JSAMPROW ptr;
406
8.94M
  register U_CHAR *bufferptr;
407
8.94M
  register _JSAMPLE *rescale = source->rescale;
408
8.94M
  JDIMENSION col;
409
8.94M
  unsigned int maxval = source->maxval;
410
8.94M
  register int rindex = rgb_red[cinfo->in_color_space];
411
8.94M
  register int gindex = rgb_green[cinfo->in_color_space];
412
8.94M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
8.94M
  register int aindex = alpha_index[cinfo->in_color_space];
414
8.94M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
8.94M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
6.82k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
8.94M
  ptr = source->pub._buffer[0];
419
8.94M
  bufferptr = source->iobuffer;
420
8.94M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
87.9k
    if (aindex >= 0)
422
17.3k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
70.6k
    else
424
70.6k
      RGB_READ_LOOP(*bufferptr++, {})
425
8.85M
  } else {
426
8.85M
    if (aindex >= 0)
427
1.74M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
8.85M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
7.10M
    else
430
7.10M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
8.85M
  }
432
8.94M
  return 1;
433
8.94M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
403
2.11M
{
404
2.11M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
2.11M
  register _JSAMPROW ptr;
406
2.11M
  register U_CHAR *bufferptr;
407
2.11M
  register _JSAMPLE *rescale = source->rescale;
408
2.11M
  JDIMENSION col;
409
2.11M
  unsigned int maxval = source->maxval;
410
2.11M
  register int rindex = rgb_red[cinfo->in_color_space];
411
2.11M
  register int gindex = rgb_green[cinfo->in_color_space];
412
2.11M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
2.11M
  register int aindex = alpha_index[cinfo->in_color_space];
414
2.11M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
2.11M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
3.85k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
2.11M
  ptr = source->pub._buffer[0];
419
2.11M
  bufferptr = source->iobuffer;
420
2.11M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
87.9k
    if (aindex >= 0)
422
17.3k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
70.6k
    else
424
70.6k
      RGB_READ_LOOP(*bufferptr++, {})
425
2.03M
  } else {
426
2.03M
    if (aindex >= 0)
427
383k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
2.03M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
1.64M
    else
430
1.64M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
2.03M
  }
432
2.11M
  return 1;
433
2.11M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
403
6.71M
{
404
6.71M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
6.71M
  register _JSAMPROW ptr;
406
6.71M
  register U_CHAR *bufferptr;
407
6.71M
  register _JSAMPLE *rescale = source->rescale;
408
6.71M
  JDIMENSION col;
409
6.71M
  unsigned int maxval = source->maxval;
410
6.71M
  register int rindex = rgb_red[cinfo->in_color_space];
411
6.71M
  register int gindex = rgb_green[cinfo->in_color_space];
412
6.71M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
6.71M
  register int aindex = alpha_index[cinfo->in_color_space];
414
6.71M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
6.71M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
1.95k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
6.71M
  ptr = source->pub._buffer[0];
419
6.71M
  bufferptr = source->iobuffer;
420
6.71M
  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
6.71M
  } else {
426
6.71M
    if (aindex >= 0)
427
1.34M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
6.71M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
5.37M
    else
430
5.37M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
6.71M
  }
432
6.71M
  return 1;
433
6.71M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
403
106k
{
404
106k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
106k
  register _JSAMPROW ptr;
406
106k
  register U_CHAR *bufferptr;
407
106k
  register _JSAMPLE *rescale = source->rescale;
408
106k
  JDIMENSION col;
409
106k
  unsigned int maxval = source->maxval;
410
106k
  register int rindex = rgb_red[cinfo->in_color_space];
411
106k
  register int gindex = rgb_green[cinfo->in_color_space];
412
106k
  register int bindex = rgb_blue[cinfo->in_color_space];
413
106k
  register int aindex = alpha_index[cinfo->in_color_space];
414
106k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
106k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
1.02k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
106k
  ptr = source->pub._buffer[0];
419
106k
  bufferptr = source->iobuffer;
420
106k
  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
106k
  } else {
426
106k
    if (aindex >= 0)
427
21.0k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
106k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
85.1k
    else
430
85.1k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
106k
  }
432
106k
  return 1;
433
106k
}
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
1.76M
{
441
1.76M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
1.76M
  register _JSAMPROW ptr;
443
1.76M
  register U_CHAR *bufferptr;
444
1.76M
  register _JSAMPLE *rescale = source->rescale;
445
1.76M
  JDIMENSION col;
446
1.76M
  unsigned int maxval = source->maxval;
447
448
1.76M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
1.23k
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
1.76M
  ptr = source->pub._buffer[0];
451
1.76M
  bufferptr = source->iobuffer;
452
1.76M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
604k
    for (col = cinfo->image_width; col > 0; col--) {
454
583k
      _JSAMPLE r = *bufferptr++;
455
583k
      _JSAMPLE g = *bufferptr++;
456
583k
      _JSAMPLE b = *bufferptr++;
457
583k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
583k
      ptr += 4;
459
583k
    }
460
1.74M
  } else {
461
17.2M
    for (col = cinfo->image_width; col > 0; col--) {
462
15.5M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
15.5M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
15.5M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
15.5M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
15.5M
                  ptr + 2, ptr + 3);
467
15.5M
      ptr += 4;
468
15.5M
    }
469
1.74M
  }
470
1.76M
  return 1;
471
1.76M
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
440
401k
{
441
401k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
401k
  register _JSAMPROW ptr;
443
401k
  register U_CHAR *bufferptr;
444
401k
  register _JSAMPLE *rescale = source->rescale;
445
401k
  JDIMENSION col;
446
401k
  unsigned int maxval = source->maxval;
447
448
401k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
645
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
401k
  ptr = source->pub._buffer[0];
451
401k
  bufferptr = source->iobuffer;
452
401k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
604k
    for (col = cinfo->image_width; col > 0; col--) {
454
583k
      _JSAMPLE r = *bufferptr++;
455
583k
      _JSAMPLE g = *bufferptr++;
456
583k
      _JSAMPLE b = *bufferptr++;
457
583k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
583k
      ptr += 4;
459
583k
    }
460
381k
  } else {
461
1.83M
    for (col = cinfo->image_width; col > 0; col--) {
462
1.45M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
1.45M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
1.45M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
1.45M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
1.45M
                  ptr + 2, ptr + 3);
467
1.45M
      ptr += 4;
468
1.45M
    }
469
381k
  }
470
401k
  return 1;
471
401k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
440
1.34M
{
441
1.34M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
1.34M
  register _JSAMPROW ptr;
443
1.34M
  register U_CHAR *bufferptr;
444
1.34M
  register _JSAMPLE *rescale = source->rescale;
445
1.34M
  JDIMENSION col;
446
1.34M
  unsigned int maxval = source->maxval;
447
448
1.34M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
390
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
1.34M
  ptr = source->pub._buffer[0];
451
1.34M
  bufferptr = source->iobuffer;
452
1.34M
  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
1.34M
  } else {
461
14.2M
    for (col = cinfo->image_width; col > 0; col--) {
462
12.9M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
12.9M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
12.9M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
12.9M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
12.9M
                  ptr + 2, ptr + 3);
467
12.9M
      ptr += 4;
468
12.9M
    }
469
1.34M
  }
470
1.34M
  return 1;
471
1.34M
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
440
21.2k
{
441
21.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
21.2k
  register _JSAMPROW ptr;
443
21.2k
  register U_CHAR *bufferptr;
444
21.2k
  register _JSAMPLE *rescale = source->rescale;
445
21.2k
  JDIMENSION col;
446
21.2k
  unsigned int maxval = source->maxval;
447
448
21.2k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
204
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
21.2k
  ptr = source->pub._buffer[0];
451
21.2k
  bufferptr = source->iobuffer;
452
21.2k
  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.2k
  } else {
461
1.16M
    for (col = cinfo->image_width; col > 0; col--) {
462
1.14M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
1.14M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
1.14M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
1.14M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
1.14M
                  ptr + 2, ptr + 3);
467
1.14M
      ptr += 4;
468
1.14M
    }
469
21.2k
  }
470
21.2k
  return 1;
471
21.2k
}
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
1.87M
{
482
1.87M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
483
484
1.87M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
485
330
    ERREXIT(cinfo, JERR_INPUT_EOF);
486
1.87M
  return 1;
487
1.87M
}
rdppm-8.c:get_raw_row
Line
Count
Source
481
1.87M
{
482
1.87M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
483
484
1.87M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
485
330
    ERREXIT(cinfo, JERR_INPUT_EOF);
486
1.87M
  return 1;
487
1.87M
}
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
129k
{
494
129k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
129k
  register _JSAMPROW ptr;
496
129k
  register U_CHAR *bufferptr;
497
129k
  register _JSAMPLE *rescale = source->rescale;
498
129k
  JDIMENSION col;
499
129k
  unsigned int maxval = source->maxval;
500
501
129k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
950
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
129k
  ptr = source->pub._buffer[0];
504
129k
  bufferptr = source->iobuffer;
505
1.32M
  for (col = cinfo->image_width; col > 0; col--) {
506
1.19M
    register unsigned int temp;
507
1.19M
    temp  = UCH(*bufferptr++) << 8;
508
1.19M
    temp |= UCH(*bufferptr++);
509
1.19M
    if (temp > maxval)
510
603
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
1.19M
    *ptr++ = rescale[temp];
512
1.19M
  }
513
129k
  return 1;
514
129k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
493
14.1k
{
494
14.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
14.1k
  register _JSAMPROW ptr;
496
14.1k
  register U_CHAR *bufferptr;
497
14.1k
  register _JSAMPLE *rescale = source->rescale;
498
14.1k
  JDIMENSION col;
499
14.1k
  unsigned int maxval = source->maxval;
500
501
14.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
377
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
14.1k
  ptr = source->pub._buffer[0];
504
14.1k
  bufferptr = source->iobuffer;
505
306k
  for (col = cinfo->image_width; col > 0; col--) {
506
291k
    register unsigned int temp;
507
291k
    temp  = UCH(*bufferptr++) << 8;
508
291k
    temp |= UCH(*bufferptr++);
509
291k
    if (temp > maxval)
510
231
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
291k
    *ptr++ = rescale[temp];
512
291k
  }
513
14.1k
  return 1;
514
14.1k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
493
88.3k
{
494
88.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
88.3k
  register _JSAMPROW ptr;
496
88.3k
  register U_CHAR *bufferptr;
497
88.3k
  register _JSAMPLE *rescale = source->rescale;
498
88.3k
  JDIMENSION col;
499
88.3k
  unsigned int maxval = source->maxval;
500
501
88.3k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
352
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
88.3k
  ptr = source->pub._buffer[0];
504
88.3k
  bufferptr = source->iobuffer;
505
513k
  for (col = cinfo->image_width; col > 0; col--) {
506
425k
    register unsigned int temp;
507
425k
    temp  = UCH(*bufferptr++) << 8;
508
425k
    temp |= UCH(*bufferptr++);
509
425k
    if (temp > maxval)
510
302
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
425k
    *ptr++ = rescale[temp];
512
425k
  }
513
88.3k
  return 1;
514
88.3k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
493
26.9k
{
494
26.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
26.9k
  register _JSAMPROW ptr;
496
26.9k
  register U_CHAR *bufferptr;
497
26.9k
  register _JSAMPLE *rescale = source->rescale;
498
26.9k
  JDIMENSION col;
499
26.9k
  unsigned int maxval = source->maxval;
500
501
26.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
221
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
26.9k
  ptr = source->pub._buffer[0];
504
26.9k
  bufferptr = source->iobuffer;
505
507k
  for (col = cinfo->image_width; col > 0; col--) {
506
480k
    register unsigned int temp;
507
480k
    temp  = UCH(*bufferptr++) << 8;
508
480k
    temp |= UCH(*bufferptr++);
509
480k
    if (temp > maxval)
510
70
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
480k
    *ptr++ = rescale[temp];
512
480k
  }
513
26.9k
  return 1;
514
26.9k
}
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
647k
{
521
647k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
647k
  register _JSAMPROW ptr;
523
647k
  register U_CHAR *bufferptr;
524
647k
  register _JSAMPLE *rescale = source->rescale;
525
647k
  JDIMENSION col;
526
647k
  unsigned int maxval = source->maxval;
527
647k
  register int rindex = rgb_red[cinfo->in_color_space];
528
647k
  register int gindex = rgb_green[cinfo->in_color_space];
529
647k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
647k
  register int aindex = alpha_index[cinfo->in_color_space];
531
647k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
647k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
4.75k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
647k
  ptr = source->pub._buffer[0];
536
647k
  bufferptr = source->iobuffer;
537
6.63M
  for (col = cinfo->image_width; col > 0; col--) {
538
5.98M
    register unsigned int temp;
539
5.98M
    temp  = UCH(*bufferptr++) << 8;
540
5.98M
    temp |= UCH(*bufferptr++);
541
5.98M
    if (temp > maxval)
542
3.01k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
5.98M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
5.98M
    if (aindex >= 0)
545
1.15M
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
5.98M
    ptr += ps;
547
5.98M
  }
548
647k
  return 1;
549
647k
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
520
70.6k
{
521
70.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
70.6k
  register _JSAMPROW ptr;
523
70.6k
  register U_CHAR *bufferptr;
524
70.6k
  register _JSAMPLE *rescale = source->rescale;
525
70.6k
  JDIMENSION col;
526
70.6k
  unsigned int maxval = source->maxval;
527
70.6k
  register int rindex = rgb_red[cinfo->in_color_space];
528
70.6k
  register int gindex = rgb_green[cinfo->in_color_space];
529
70.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
70.6k
  register int aindex = alpha_index[cinfo->in_color_space];
531
70.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
70.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.88k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
70.6k
  ptr = source->pub._buffer[0];
536
70.6k
  bufferptr = source->iobuffer;
537
1.53M
  for (col = cinfo->image_width; col > 0; col--) {
538
1.45M
    register unsigned int temp;
539
1.45M
    temp  = UCH(*bufferptr++) << 8;
540
1.45M
    temp |= UCH(*bufferptr++);
541
1.45M
    if (temp > maxval)
542
1.15k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
1.45M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
1.45M
    if (aindex >= 0)
545
245k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
1.45M
    ptr += ps;
547
1.45M
  }
548
70.6k
  return 1;
549
70.6k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
520
441k
{
521
441k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
441k
  register _JSAMPROW ptr;
523
441k
  register U_CHAR *bufferptr;
524
441k
  register _JSAMPLE *rescale = source->rescale;
525
441k
  JDIMENSION col;
526
441k
  unsigned int maxval = source->maxval;
527
441k
  register int rindex = rgb_red[cinfo->in_color_space];
528
441k
  register int gindex = rgb_green[cinfo->in_color_space];
529
441k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
441k
  register int aindex = alpha_index[cinfo->in_color_space];
531
441k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
441k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.76k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
441k
  ptr = source->pub._buffer[0];
536
441k
  bufferptr = source->iobuffer;
537
2.56M
  for (col = cinfo->image_width; col > 0; col--) {
538
2.12M
    register unsigned int temp;
539
2.12M
    temp  = UCH(*bufferptr++) << 8;
540
2.12M
    temp |= UCH(*bufferptr++);
541
2.12M
    if (temp > maxval)
542
1.51k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
2.12M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
2.12M
    if (aindex >= 0)
545
425k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
2.12M
    ptr += ps;
547
2.12M
  }
548
441k
  return 1;
549
441k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
520
134k
{
521
134k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
134k
  register _JSAMPROW ptr;
523
134k
  register U_CHAR *bufferptr;
524
134k
  register _JSAMPLE *rescale = source->rescale;
525
134k
  JDIMENSION col;
526
134k
  unsigned int maxval = source->maxval;
527
134k
  register int rindex = rgb_red[cinfo->in_color_space];
528
134k
  register int gindex = rgb_green[cinfo->in_color_space];
529
134k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
134k
  register int aindex = alpha_index[cinfo->in_color_space];
531
134k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
134k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.10k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
134k
  ptr = source->pub._buffer[0];
536
134k
  bufferptr = source->iobuffer;
537
2.53M
  for (col = cinfo->image_width; col > 0; col--) {
538
2.40M
    register unsigned int temp;
539
2.40M
    temp  = UCH(*bufferptr++) << 8;
540
2.40M
    temp |= UCH(*bufferptr++);
541
2.40M
    if (temp > maxval)
542
350
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
2.40M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
2.40M
    if (aindex >= 0)
545
480k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
2.40M
    ptr += ps;
547
2.40M
  }
548
134k
  return 1;
549
134k
}
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
126k
{
556
126k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
126k
  register _JSAMPROW ptr;
558
126k
  register U_CHAR *bufferptr;
559
126k
  register _JSAMPLE *rescale = source->rescale;
560
126k
  JDIMENSION col;
561
126k
  unsigned int maxval = source->maxval;
562
563
126k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
843
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
126k
  ptr = source->pub._buffer[0];
566
126k
  bufferptr = source->iobuffer;
567
126k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
499k
    for (col = cinfo->image_width; col > 0; col--) {
569
474k
      register unsigned int gray;
570
474k
      gray  = UCH(*bufferptr++) << 8;
571
474k
      gray |= UCH(*bufferptr++);
572
474k
      if (gray > maxval)
573
119
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
474k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
474k
                  ptr + 1, ptr + 2, ptr + 3);
576
474k
      ptr += 4;
577
474k
    }
578
101k
  } else {
579
778k
    for (col = cinfo->image_width; col > 0; col--) {
580
677k
      register unsigned int temp;
581
677k
      _JSAMPLE gray;
582
677k
      temp  = UCH(*bufferptr++) << 8;
583
677k
      temp |= UCH(*bufferptr++);
584
677k
      if (temp > maxval)
585
420
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
677k
      gray = rescale[temp];
587
677k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
677k
                  ptr + 1, ptr + 2, ptr + 3);
589
677k
      ptr += 4;
590
677k
    }
591
101k
  }
592
126k
  return 1;
593
126k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
555
11.1k
{
556
11.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
11.1k
  register _JSAMPROW ptr;
558
11.1k
  register U_CHAR *bufferptr;
559
11.1k
  register _JSAMPLE *rescale = source->rescale;
560
11.1k
  JDIMENSION col;
561
11.1k
  unsigned int maxval = source->maxval;
562
563
11.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
270
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
11.1k
  ptr = source->pub._buffer[0];
566
11.1k
  bufferptr = source->iobuffer;
567
11.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
11.1k
  } else {
579
257k
    for (col = cinfo->image_width; col > 0; col--) {
580
246k
      register unsigned int temp;
581
246k
      _JSAMPLE gray;
582
246k
      temp  = UCH(*bufferptr++) << 8;
583
246k
      temp |= UCH(*bufferptr++);
584
246k
      if (temp > maxval)
585
167
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
246k
      gray = rescale[temp];
587
246k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
246k
                  ptr + 1, ptr + 2, ptr + 3);
589
246k
      ptr += 4;
590
246k
    }
591
11.1k
  }
592
11.1k
  return 1;
593
11.1k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
555
88.3k
{
556
88.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
88.3k
  register _JSAMPROW ptr;
558
88.3k
  register U_CHAR *bufferptr;
559
88.3k
  register _JSAMPLE *rescale = source->rescale;
560
88.3k
  JDIMENSION col;
561
88.3k
  unsigned int maxval = source->maxval;
562
563
88.3k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
352
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
88.3k
  ptr = source->pub._buffer[0];
566
88.3k
  bufferptr = source->iobuffer;
567
88.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
6.68k
    for (col = cinfo->image_width; col > 0; col--) {
569
4.72k
      register unsigned int gray;
570
4.72k
      gray  = UCH(*bufferptr++) << 8;
571
4.72k
      gray |= UCH(*bufferptr++);
572
4.72k
      if (gray > maxval)
573
119
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
4.72k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
4.72k
                  ptr + 1, ptr + 2, ptr + 3);
576
4.72k
      ptr += 4;
577
4.72k
    }
578
86.4k
  } else {
579
507k
    for (col = cinfo->image_width; col > 0; col--) {
580
420k
      register unsigned int temp;
581
420k
      _JSAMPLE gray;
582
420k
      temp  = UCH(*bufferptr++) << 8;
583
420k
      temp |= UCH(*bufferptr++);
584
420k
      if (temp > maxval)
585
183
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
420k
      gray = rescale[temp];
587
420k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
420k
                  ptr + 1, ptr + 2, ptr + 3);
589
420k
      ptr += 4;
590
420k
    }
591
86.4k
  }
592
88.3k
  return 1;
593
88.3k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
555
26.9k
{
556
26.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
26.9k
  register _JSAMPROW ptr;
558
26.9k
  register U_CHAR *bufferptr;
559
26.9k
  register _JSAMPLE *rescale = source->rescale;
560
26.9k
  JDIMENSION col;
561
26.9k
  unsigned int maxval = source->maxval;
562
563
26.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
221
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
26.9k
  ptr = source->pub._buffer[0];
566
26.9k
  bufferptr = source->iobuffer;
567
26.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
493k
    for (col = cinfo->image_width; col > 0; col--) {
569
469k
      register unsigned int gray;
570
469k
      gray  = UCH(*bufferptr++) << 8;
571
469k
      gray |= UCH(*bufferptr++);
572
469k
      if (gray > maxval)
573
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
469k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
469k
                  ptr + 1, ptr + 2, ptr + 3);
576
469k
      ptr += 4;
577
469k
    }
578
23.2k
  } else {
579
13.8k
    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
70
        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.64k
  }
592
26.9k
  return 1;
593
26.9k
}
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
163k
{
600
163k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
163k
  register _JSAMPROW ptr;
602
163k
  register U_CHAR *bufferptr;
603
163k
  register _JSAMPLE *rescale = source->rescale;
604
163k
  JDIMENSION col;
605
163k
  unsigned int maxval = source->maxval;
606
163k
  register int rindex = rgb_red[cinfo->in_color_space];
607
163k
  register int gindex = rgb_green[cinfo->in_color_space];
608
163k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
163k
  register int aindex = alpha_index[cinfo->in_color_space];
610
163k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
163k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
5.74k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
163k
  ptr = source->pub._buffer[0];
615
163k
  bufferptr = source->iobuffer;
616
895k
  for (col = cinfo->image_width; col > 0; col--) {
617
732k
    register unsigned int temp;
618
732k
    temp  = UCH(*bufferptr++) << 8;
619
732k
    temp |= UCH(*bufferptr++);
620
732k
    if (temp > maxval)
621
2.24k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
732k
    ptr[rindex] = rescale[temp];
623
732k
    temp  = UCH(*bufferptr++) << 8;
624
732k
    temp |= UCH(*bufferptr++);
625
732k
    if (temp > maxval)
626
1.90k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
732k
    ptr[gindex] = rescale[temp];
628
732k
    temp  = UCH(*bufferptr++) << 8;
629
732k
    temp |= UCH(*bufferptr++);
630
732k
    if (temp > maxval)
631
1.79k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
732k
    ptr[bindex] = rescale[temp];
633
732k
    if (aindex >= 0)
634
104k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
732k
    ptr += ps;
636
732k
  }
637
163k
  return 1;
638
163k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
599
59.2k
{
600
59.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
59.2k
  register _JSAMPROW ptr;
602
59.2k
  register U_CHAR *bufferptr;
603
59.2k
  register _JSAMPLE *rescale = source->rescale;
604
59.2k
  JDIMENSION col;
605
59.2k
  unsigned int maxval = source->maxval;
606
59.2k
  register int rindex = rgb_red[cinfo->in_color_space];
607
59.2k
  register int gindex = rgb_green[cinfo->in_color_space];
608
59.2k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
59.2k
  register int aindex = alpha_index[cinfo->in_color_space];
610
59.2k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
59.2k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
2.01k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
59.2k
  ptr = source->pub._buffer[0];
615
59.2k
  bufferptr = source->iobuffer;
616
344k
  for (col = cinfo->image_width; col > 0; col--) {
617
284k
    register unsigned int temp;
618
284k
    temp  = UCH(*bufferptr++) << 8;
619
284k
    temp |= UCH(*bufferptr++);
620
284k
    if (temp > maxval)
621
680
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
284k
    ptr[rindex] = rescale[temp];
623
284k
    temp  = UCH(*bufferptr++) << 8;
624
284k
    temp |= UCH(*bufferptr++);
625
284k
    if (temp > maxval)
626
715
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
284k
    ptr[gindex] = rescale[temp];
628
284k
    temp  = UCH(*bufferptr++) << 8;
629
284k
    temp |= UCH(*bufferptr++);
630
284k
    if (temp > maxval)
631
685
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
284k
    ptr[bindex] = rescale[temp];
633
284k
    if (aindex >= 0)
634
16.0k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
284k
    ptr += ps;
636
284k
  }
637
59.2k
  return 1;
638
59.2k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
599
69.7k
{
600
69.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
69.7k
  register _JSAMPROW ptr;
602
69.7k
  register U_CHAR *bufferptr;
603
69.7k
  register _JSAMPLE *rescale = source->rescale;
604
69.7k
  JDIMENSION col;
605
69.7k
  unsigned int maxval = source->maxval;
606
69.7k
  register int rindex = rgb_red[cinfo->in_color_space];
607
69.7k
  register int gindex = rgb_green[cinfo->in_color_space];
608
69.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
69.7k
  register int aindex = alpha_index[cinfo->in_color_space];
610
69.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
69.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
2.31k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
69.7k
  ptr = source->pub._buffer[0];
615
69.7k
  bufferptr = source->iobuffer;
616
350k
  for (col = cinfo->image_width; col > 0; col--) {
617
280k
    register unsigned int temp;
618
280k
    temp  = UCH(*bufferptr++) << 8;
619
280k
    temp |= UCH(*bufferptr++);
620
280k
    if (temp > maxval)
621
1.23k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
280k
    ptr[rindex] = rescale[temp];
623
280k
    temp  = UCH(*bufferptr++) << 8;
624
280k
    temp |= UCH(*bufferptr++);
625
280k
    if (temp > maxval)
626
930
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
280k
    ptr[gindex] = rescale[temp];
628
280k
    temp  = UCH(*bufferptr++) << 8;
629
280k
    temp |= UCH(*bufferptr++);
630
280k
    if (temp > maxval)
631
885
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
280k
    ptr[bindex] = rescale[temp];
633
280k
    if (aindex >= 0)
634
55.5k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
280k
    ptr += ps;
636
280k
  }
637
69.7k
  return 1;
638
69.7k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
599
34.5k
{
600
34.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
34.5k
  register _JSAMPROW ptr;
602
34.5k
  register U_CHAR *bufferptr;
603
34.5k
  register _JSAMPLE *rescale = source->rescale;
604
34.5k
  JDIMENSION col;
605
34.5k
  unsigned int maxval = source->maxval;
606
34.5k
  register int rindex = rgb_red[cinfo->in_color_space];
607
34.5k
  register int gindex = rgb_green[cinfo->in_color_space];
608
34.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
34.5k
  register int aindex = alpha_index[cinfo->in_color_space];
610
34.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
34.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
1.41k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
34.5k
  ptr = source->pub._buffer[0];
615
34.5k
  bufferptr = source->iobuffer;
616
201k
  for (col = cinfo->image_width; col > 0; col--) {
617
166k
    register unsigned int temp;
618
166k
    temp  = UCH(*bufferptr++) << 8;
619
166k
    temp |= UCH(*bufferptr++);
620
166k
    if (temp > maxval)
621
325
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
166k
    ptr[rindex] = rescale[temp];
623
166k
    temp  = UCH(*bufferptr++) << 8;
624
166k
    temp |= UCH(*bufferptr++);
625
166k
    if (temp > maxval)
626
255
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
166k
    ptr[gindex] = rescale[temp];
628
166k
    temp  = UCH(*bufferptr++) << 8;
629
166k
    temp |= UCH(*bufferptr++);
630
166k
    if (temp > maxval)
631
220
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
166k
    ptr[bindex] = rescale[temp];
633
166k
    if (aindex >= 0)
634
33.2k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
166k
    ptr += ps;
636
166k
  }
637
34.5k
  return 1;
638
34.5k
}
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
29.5k
{
645
29.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
29.5k
  register _JSAMPROW ptr;
647
29.5k
  register U_CHAR *bufferptr;
648
29.5k
  register _JSAMPLE *rescale = source->rescale;
649
29.5k
  JDIMENSION col;
650
29.5k
  unsigned int maxval = source->maxval;
651
652
29.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
1.05k
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
29.5k
  ptr = source->pub._buffer[0];
655
29.5k
  bufferptr = source->iobuffer;
656
29.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
41.0k
    for (col = cinfo->image_width; col > 0; col--) {
658
35.3k
      register unsigned int r, g, b;
659
35.3k
      r  = UCH(*bufferptr++) << 8;
660
35.3k
      r |= UCH(*bufferptr++);
661
35.3k
      if (r > maxval)
662
80
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
35.3k
      g  = UCH(*bufferptr++) << 8;
664
35.3k
      g |= UCH(*bufferptr++);
665
35.3k
      if (g > maxval)
666
84
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
35.3k
      b  = UCH(*bufferptr++) << 8;
668
35.3k
      b |= UCH(*bufferptr++);
669
35.3k
      if (b > maxval)
670
78
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
35.3k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
35.3k
                  ptr + 2, ptr + 3);
673
35.3k
      ptr += 4;
674
35.3k
    }
675
23.8k
  } else {
676
94.4k
    for (col = cinfo->image_width; col > 0; col--) {
677
70.5k
      register unsigned int r, g, b;
678
70.5k
      r  = UCH(*bufferptr++) << 8;
679
70.5k
      r |= UCH(*bufferptr++);
680
70.5k
      if (r > maxval)
681
351
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
70.5k
      g  = UCH(*bufferptr++) << 8;
683
70.5k
      g |= UCH(*bufferptr++);
684
70.5k
      if (g > maxval)
685
258
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
70.5k
      b  = UCH(*bufferptr++) << 8;
687
70.5k
      b |= UCH(*bufferptr++);
688
70.5k
      if (b > maxval)
689
240
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
70.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
70.5k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
70.5k
      ptr += 4;
693
70.5k
    }
694
23.8k
  }
695
29.5k
  return 1;
696
29.5k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
644
8.69k
{
645
8.69k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
8.69k
  register _JSAMPROW ptr;
647
8.69k
  register U_CHAR *bufferptr;
648
8.69k
  register _JSAMPLE *rescale = source->rescale;
649
8.69k
  JDIMENSION col;
650
8.69k
  unsigned int maxval = source->maxval;
651
652
8.69k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
309
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
8.69k
  ptr = source->pub._buffer[0];
655
8.69k
  bufferptr = source->iobuffer;
656
8.69k
  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.69k
  } else {
676
25.0k
    for (col = cinfo->image_width; col > 0; col--) {
677
16.3k
      register unsigned int r, g, b;
678
16.3k
      r  = UCH(*bufferptr++) << 8;
679
16.3k
      r |= UCH(*bufferptr++);
680
16.3k
      if (r > maxval)
681
119
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
16.3k
      g  = UCH(*bufferptr++) << 8;
683
16.3k
      g |= UCH(*bufferptr++);
684
16.3k
      if (g > maxval)
685
105
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
16.3k
      b  = UCH(*bufferptr++) << 8;
687
16.3k
      b |= UCH(*bufferptr++);
688
16.3k
      if (b > maxval)
689
97
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
16.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
16.3k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
16.3k
      ptr += 4;
693
16.3k
    }
694
8.69k
  }
695
8.69k
  return 1;
696
8.69k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
644
13.9k
{
645
13.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
13.9k
  register _JSAMPROW ptr;
647
13.9k
  register U_CHAR *bufferptr;
648
13.9k
  register _JSAMPLE *rescale = source->rescale;
649
13.9k
  JDIMENSION col;
650
13.9k
  unsigned int maxval = source->maxval;
651
652
13.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
463
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
13.9k
  ptr = source->pub._buffer[0];
655
13.9k
  bufferptr = source->iobuffer;
656
13.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
9.83k
    for (col = cinfo->image_width; col > 0; col--) {
658
7.21k
      register unsigned int r, g, b;
659
7.21k
      r  = UCH(*bufferptr++) << 8;
660
7.21k
      r |= UCH(*bufferptr++);
661
7.21k
      if (r > maxval)
662
80
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
7.21k
      g  = UCH(*bufferptr++) << 8;
664
7.21k
      g |= UCH(*bufferptr++);
665
7.21k
      if (g > maxval)
666
84
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
7.21k
      b  = UCH(*bufferptr++) << 8;
668
7.21k
      b |= UCH(*bufferptr++);
669
7.21k
      if (b > maxval)
670
78
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
7.21k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
7.21k
                  ptr + 2, ptr + 3);
673
7.21k
      ptr += 4;
674
7.21k
    }
675
11.3k
  } else {
676
60.2k
    for (col = cinfo->image_width; col > 0; col--) {
677
48.9k
      register unsigned int r, g, b;
678
48.9k
      r  = UCH(*bufferptr++) << 8;
679
48.9k
      r |= UCH(*bufferptr++);
680
48.9k
      if (r > maxval)
681
167
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
48.9k
      g  = UCH(*bufferptr++) << 8;
683
48.9k
      g |= UCH(*bufferptr++);
684
48.9k
      if (g > maxval)
685
102
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
48.9k
      b  = UCH(*bufferptr++) << 8;
687
48.9k
      b |= UCH(*bufferptr++);
688
48.9k
      if (b > maxval)
689
99
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
48.9k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
48.9k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
48.9k
      ptr += 4;
693
48.9k
    }
694
11.3k
  }
695
13.9k
  return 1;
696
13.9k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
644
6.90k
{
645
6.90k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
6.90k
  register _JSAMPROW ptr;
647
6.90k
  register U_CHAR *bufferptr;
648
6.90k
  register _JSAMPLE *rescale = source->rescale;
649
6.90k
  JDIMENSION col;
650
6.90k
  unsigned int maxval = source->maxval;
651
652
6.90k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
283
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
6.90k
  ptr = source->pub._buffer[0];
655
6.90k
  bufferptr = source->iobuffer;
656
6.90k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
31.1k
    for (col = cinfo->image_width; col > 0; col--) {
658
28.1k
      register unsigned int r, g, b;
659
28.1k
      r  = UCH(*bufferptr++) << 8;
660
28.1k
      r |= UCH(*bufferptr++);
661
28.1k
      if (r > maxval)
662
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
28.1k
      g  = UCH(*bufferptr++) << 8;
664
28.1k
      g |= UCH(*bufferptr++);
665
28.1k
      if (g > maxval)
666
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
28.1k
      b  = UCH(*bufferptr++) << 8;
668
28.1k
      b |= UCH(*bufferptr++);
669
28.1k
      if (b > maxval)
670
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
28.1k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
28.1k
                  ptr + 2, ptr + 3);
673
28.1k
      ptr += 4;
674
28.1k
    }
675
3.85k
  } else {
676
9.12k
    for (col = cinfo->image_width; col > 0; col--) {
677
5.26k
      register unsigned int r, g, b;
678
5.26k
      r  = UCH(*bufferptr++) << 8;
679
5.26k
      r |= UCH(*bufferptr++);
680
5.26k
      if (r > maxval)
681
65
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
5.26k
      g  = UCH(*bufferptr++) << 8;
683
5.26k
      g |= UCH(*bufferptr++);
684
5.26k
      if (g > maxval)
685
51
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
5.26k
      b  = UCH(*bufferptr++) << 8;
687
5.26k
      b |= UCH(*bufferptr++);
688
5.26k
      if (b > maxval)
689
44
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
5.26k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
5.26k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
5.26k
      ptr += 4;
693
5.26k
    }
694
3.85k
  }
695
6.90k
  return 1;
696
6.90k
}
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
167k
{
706
167k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
167k
  int c;
708
167k
  unsigned int w, h, maxval;
709
167k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
167k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
167k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
167k
  switch (c) {
718
17.5k
  case '2':                     /* it's a text-format PGM file */
719
37.3k
  case '3':                     /* it's a text-format PPM file */
720
126k
  case '5':                     /* it's a raw-format PGM file */
721
166k
  case '6':                     /* it's a raw-format PPM file */
722
166k
    break;
723
500
  default:
724
500
    ERREXIT(cinfo, JERR_PPM_NOT);
725
500
    break;
726
167k
  }
727
728
  /* fetch the remaining header info */
729
166k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
166k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
166k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
166k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
405
    ERREXIT(cinfo, JERR_PPM_NOT);
735
166k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
2.83k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
166k
  cinfo->image_width = (JDIMENSION)w;
739
166k
  cinfo->image_height = (JDIMENSION)h;
740
166k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
166k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
166k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
166k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
166k
  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.70k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
1.68k
    else if (cinfo->in_color_space == JCS_CMYK)
758
1.68k
      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
84.2k
  case '5':                     /* it's a raw-format PGM file */
778
84.2k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
84.2k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
84.2k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
84.2k
    if (maxval > 255) {
783
12.0k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
1.74k
        source->pub.get_pixel_rows = get_word_gray_row;
785
10.3k
      else if (IsExtRGB(cinfo->in_color_space))
786
8.74k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
1.56k
      else if (cinfo->in_color_space == JCS_CMYK)
788
1.56k
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
72.2k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
39.5k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
3.65k
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
592
      source->pub.get_pixel_rows = get_raw_row;
795
592
      use_raw_buffer = TRUE;
796
592
      need_rescale = FALSE;
797
71.6k
    } else {
798
71.6k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
10.0k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
61.5k
      else if (IsExtRGB(cinfo->in_color_space))
801
53.3k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
8.23k
      else if (cinfo->in_color_space == JCS_CMYK)
803
8.23k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
71.6k
    }
807
84.2k
    break;
808
809
36.5k
  case '6':                     /* it's a raw-format PPM file */
810
36.5k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
36.5k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
36.5k
    if (maxval > 255) {
814
17.1k
      if (IsExtRGB(cinfo->in_color_space))
815
12.3k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
4.75k
      else if (cinfo->in_color_space == JCS_CMYK)
817
2.27k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
2.47k
      else
819
2.47k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
19.3k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
10.6k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
2.22k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
2.22k
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
1.91k
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
304
      source->pub.get_pixel_rows = get_raw_row;
829
304
      use_raw_buffer = TRUE;
830
304
      need_rescale = FALSE;
831
19.0k
    } else {
832
19.0k
      if (IsExtRGB(cinfo->in_color_space))
833
13.8k
        source->pub.get_pixel_rows = get_rgb_row;
834
5.26k
      else if (cinfo->in_color_space == JCS_CMYK)
835
2.44k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
2.82k
      else
837
2.82k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
19.0k
    }
839
36.5k
    break;
840
166k
  }
841
842
142k
  if (IsExtRGB(cinfo->in_color_space))
843
109k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
32.5k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
14.3k
    cinfo->input_components = 1;
846
18.2k
  else if (cinfo->in_color_space == JCS_CMYK)
847
18.2k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
142k
  if (need_iobuffer) {
851
115k
    if (c == '6')
852
31.2k
      source->buffer_width = (size_t)w * 3 *
853
31.2k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
84.2k
    else
855
84.2k
      source->buffer_width = (size_t)w *
856
84.2k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
115k
    source->iobuffer = (U_CHAR *)
858
115k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
115k
                                  source->buffer_width);
860
115k
  }
861
862
  /* Create compressor input buffer. */
863
142k
  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
896
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
896
    source->pub._buffer = &source->pixrow;
868
896
    source->pub.buffer_height = 1;
869
141k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
141k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
141k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
141k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
141k
    source->pub.buffer_height = 1;
875
141k
  }
876
877
  /* Compute the rescaling array if required. */
878
142k
  if (need_rescale) {
879
141k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
141k
    source->rescale = (_JSAMPLE *)
883
141k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
141k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
141k
                                           sizeof(_JSAMPLE)));
886
141k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
141k
                                        sizeof(_JSAMPLE)));
888
141k
    half_maxval = maxval / 2;
889
584M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
583M
      source->rescale[val] =
892
583M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
583M
                   maxval);
894
583M
    }
895
141k
  }
896
142k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
705
81.9k
{
706
81.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
81.9k
  int c;
708
81.9k
  unsigned int w, h, maxval;
709
81.9k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
81.9k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
81.9k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
81.9k
  switch (c) {
718
8.07k
  case '2':                     /* it's a text-format PGM file */
719
17.0k
  case '3':                     /* it's a text-format PPM file */
720
63.4k
  case '5':                     /* it's a raw-format PGM file */
721
81.7k
  case '6':                     /* it's a raw-format PPM file */
722
81.7k
    break;
723
213
  default:
724
213
    ERREXIT(cinfo, JERR_PPM_NOT);
725
213
    break;
726
81.9k
  }
727
728
  /* fetch the remaining header info */
729
81.7k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
81.7k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
81.7k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
81.7k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
188
    ERREXIT(cinfo, JERR_PPM_NOT);
735
81.7k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.31k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
81.7k
  cinfo->image_width = (JDIMENSION)w;
739
81.7k
  cinfo->image_height = (JDIMENSION)h;
740
81.7k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
81.7k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
81.7k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
81.7k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
81.7k
  switch (c) {
748
6.08k
  case '2':                     /* it's a text-format PGM file */
749
6.08k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
6.08k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
6.08k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
6.08k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
907
      source->pub.get_pixel_rows = get_text_gray_row;
755
5.18k
    else if (IsExtRGB(cinfo->in_color_space))
756
4.53k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
647
    else if (cinfo->in_color_space == JCS_CMYK)
758
647
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
6.08k
    need_iobuffer = FALSE;
762
6.08k
    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
791
      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
43.9k
  case '5':                     /* it's a raw-format PGM file */
778
43.9k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
43.9k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
43.9k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
43.9k
    if (maxval > 255) {
783
4.44k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
661
        source->pub.get_pixel_rows = get_word_gray_row;
785
3.77k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.30k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
474
      else if (cinfo->in_color_space == JCS_CMYK)
788
474
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
39.5k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
39.5k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
3.65k
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
592
      source->pub.get_pixel_rows = get_raw_row;
795
592
      use_raw_buffer = TRUE;
796
592
      need_rescale = FALSE;
797
38.9k
    } else {
798
38.9k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
5.40k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
33.5k
      else if (IsExtRGB(cinfo->in_color_space))
801
29.9k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
3.56k
      else if (cinfo->in_color_space == JCS_CMYK)
803
3.56k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
38.9k
    }
807
43.9k
    break;
808
809
16.4k
  case '6':                     /* it's a raw-format PPM file */
810
16.4k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
16.4k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
16.4k
    if (maxval > 255) {
814
5.85k
      if (IsExtRGB(cinfo->in_color_space))
815
4.32k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
1.53k
      else if (cinfo->in_color_space == JCS_CMYK)
817
665
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
865
      else
819
865
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
10.6k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
10.6k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
2.22k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
2.22k
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
1.91k
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
304
      source->pub.get_pixel_rows = get_raw_row;
829
304
      use_raw_buffer = TRUE;
830
304
      need_rescale = FALSE;
831
10.3k
    } else {
832
10.3k
      if (IsExtRGB(cinfo->in_color_space))
833
7.55k
        source->pub.get_pixel_rows = get_rgb_row;
834
2.76k
      else if (cinfo->in_color_space == JCS_CMYK)
835
1.19k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
1.57k
      else
837
1.57k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
10.3k
    }
839
16.4k
    break;
840
81.7k
  }
841
842
70.1k
  if (IsExtRGB(cinfo->in_color_space))
843
55.2k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
14.9k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
7.56k
    cinfo->input_components = 1;
846
7.33k
  else if (cinfo->in_color_space == JCS_CMYK)
847
7.33k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
70.1k
  if (need_iobuffer) {
851
58.0k
    if (c == '6')
852
14.0k
      source->buffer_width = (size_t)w * 3 *
853
14.0k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
43.9k
    else
855
43.9k
      source->buffer_width = (size_t)w *
856
43.9k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
58.0k
    source->iobuffer = (U_CHAR *)
858
58.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
58.0k
                                  source->buffer_width);
860
58.0k
  }
861
862
  /* Create compressor input buffer. */
863
70.1k
  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
896
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
896
    source->pub._buffer = &source->pixrow;
868
896
    source->pub.buffer_height = 1;
869
69.2k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
69.2k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
69.2k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
69.2k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
69.2k
    source->pub.buffer_height = 1;
875
69.2k
  }
876
877
  /* Compute the rescaling array if required. */
878
70.1k
  if (need_rescale) {
879
69.2k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
69.2k
    source->rescale = (_JSAMPLE *)
883
69.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
69.2k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
69.2k
                                           sizeof(_JSAMPLE)));
886
69.2k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
69.2k
                                        sizeof(_JSAMPLE)));
888
69.2k
    half_maxval = maxval / 2;
889
138M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
138M
      source->rescale[val] =
892
138M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
138M
                   maxval);
894
138M
    }
895
69.2k
  }
896
70.1k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
705
60.4k
{
706
60.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
60.4k
  int c;
708
60.4k
  unsigned int w, h, maxval;
709
60.4k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
60.4k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
60.4k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
60.4k
  switch (c) {
718
6.25k
  case '2':                     /* it's a text-format PGM file */
719
13.2k
  case '3':                     /* it's a text-format PPM file */
720
44.5k
  case '5':                     /* it's a raw-format PGM file */
721
60.2k
  case '6':                     /* it's a raw-format PPM file */
722
60.2k
    break;
723
259
  default:
724
259
    ERREXIT(cinfo, JERR_PPM_NOT);
725
259
    break;
726
60.4k
  }
727
728
  /* fetch the remaining header info */
729
60.2k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
60.2k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
60.2k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
60.2k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
126
    ERREXIT(cinfo, JERR_PPM_NOT);
735
60.2k
  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
60.2k
  cinfo->image_width = (JDIMENSION)w;
739
60.2k
  cinfo->image_height = (JDIMENSION)h;
740
60.2k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
60.2k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
60.2k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
60.2k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
60.2k
  switch (c) {
748
4.64k
  case '2':                     /* it's a text-format PGM file */
749
4.64k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
4.64k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
4.64k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
4.64k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
663
      source->pub.get_pixel_rows = get_text_gray_row;
755
3.97k
    else if (IsExtRGB(cinfo->in_color_space))
756
3.31k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
663
    else if (cinfo->in_color_space == JCS_CMYK)
758
663
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
4.64k
    need_iobuffer = FALSE;
762
4.64k
    break;
763
764
5.48k
  case '3':                     /* it's a text-format PPM file */
765
5.48k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
5.48k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
5.48k
    if (IsExtRGB(cinfo->in_color_space))
769
3.92k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.56k
    else if (cinfo->in_color_space == JCS_CMYK)
771
784
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
784
    else
773
784
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
5.48k
    need_iobuffer = FALSE;
775
5.48k
    break;
776
777
29.6k
  case '5':                     /* it's a raw-format PGM file */
778
29.6k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
29.6k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
29.6k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
29.6k
    if (maxval > 255) {
783
5.06k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
723
        source->pub.get_pixel_rows = get_word_gray_row;
785
4.33k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.61k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
723
      else if (cinfo->in_color_space == JCS_CMYK)
788
723
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
24.5k
    } 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
24.5k
    } else {
798
24.5k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
3.50k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
21.0k
      else if (IsExtRGB(cinfo->in_color_space))
801
17.5k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
3.50k
      else if (cinfo->in_color_space == JCS_CMYK)
803
3.50k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
24.5k
    }
807
29.6k
    break;
808
809
14.5k
  case '6':                     /* it's a raw-format PPM file */
810
14.5k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
14.5k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
14.5k
    if (maxval > 255) {
814
7.93k
      if (IsExtRGB(cinfo->in_color_space))
815
5.66k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
2.26k
      else if (cinfo->in_color_space == JCS_CMYK)
817
1.13k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
1.13k
      else
819
1.13k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
7.93k
    } 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
6.62k
    } else {
832
6.62k
      if (IsExtRGB(cinfo->in_color_space))
833
4.73k
        source->pub.get_pixel_rows = get_rgb_row;
834
1.89k
      else if (cinfo->in_color_space == JCS_CMYK)
835
946
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
946
      else
837
946
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
6.62k
    }
839
14.5k
    break;
840
60.2k
  }
841
842
51.4k
  if (IsExtRGB(cinfo->in_color_space))
843
38.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
12.6k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
4.89k
    cinfo->input_components = 1;
846
7.75k
  else if (cinfo->in_color_space == JCS_CMYK)
847
7.75k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
51.4k
  if (need_iobuffer) {
851
42.0k
    if (c == '6')
852
12.4k
      source->buffer_width = (size_t)w * 3 *
853
12.4k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
29.6k
    else
855
29.6k
      source->buffer_width = (size_t)w *
856
29.6k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
42.0k
    source->iobuffer = (U_CHAR *)
858
42.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
42.0k
                                  source->buffer_width);
860
42.0k
  }
861
862
  /* Create compressor input buffer. */
863
51.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
51.4k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
51.4k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
51.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
51.4k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
51.4k
    source->pub.buffer_height = 1;
875
51.4k
  }
876
877
  /* Compute the rescaling array if required. */
878
51.4k
  if (need_rescale) {
879
51.4k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
51.4k
    source->rescale = (_JSAMPLE *)
883
51.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
51.4k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
51.4k
                                           sizeof(_JSAMPLE)));
886
51.4k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
51.4k
                                        sizeof(_JSAMPLE)));
888
51.4k
    half_maxval = maxval / 2;
889
158M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
158M
      source->rescale[val] =
892
158M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
158M
                   maxval);
894
158M
    }
895
51.4k
  }
896
51.4k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
705
24.7k
{
706
24.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
24.7k
  int c;
708
24.7k
  unsigned int w, h, maxval;
709
24.7k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
24.7k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
24.7k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
24.7k
  switch (c) {
718
3.18k
  case '2':                     /* it's a text-format PGM file */
719
7.14k
  case '3':                     /* it's a text-format PPM file */
720
18.6k
  case '5':                     /* it's a raw-format PGM file */
721
24.7k
  case '6':                     /* it's a raw-format PPM file */
722
24.7k
    break;
723
28
  default:
724
28
    ERREXIT(cinfo, JERR_PPM_NOT);
725
28
    break;
726
24.7k
  }
727
728
  /* fetch the remaining header info */
729
24.7k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
24.7k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
24.7k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
24.7k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
91
    ERREXIT(cinfo, JERR_PPM_NOT);
735
24.7k
  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.7k
  cinfo->image_width = (JDIMENSION)w;
739
24.7k
  cinfo->image_height = (JDIMENSION)h;
740
24.7k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
24.7k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
24.7k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
24.7k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
24.7k
  switch (c) {
748
2.59k
  case '2':                     /* it's a text-format PGM file */
749
2.59k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
2.59k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
2.59k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
2.59k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
371
      source->pub.get_pixel_rows = get_text_gray_row;
755
2.22k
    else if (IsExtRGB(cinfo->in_color_space))
756
1.85k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
371
    else if (cinfo->in_color_space == JCS_CMYK)
758
371
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
2.59k
    need_iobuffer = FALSE;
762
2.59k
    break;
763
764
3.09k
  case '3':                     /* it's a text-format PPM file */
765
3.09k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
3.09k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
3.09k
    if (IsExtRGB(cinfo->in_color_space))
769
2.21k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
884
    else if (cinfo->in_color_space == JCS_CMYK)
771
442
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
442
    else
773
442
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
3.09k
    need_iobuffer = FALSE;
775
3.09k
    break;
776
777
10.6k
  case '5':                     /* it's a raw-format PGM file */
778
10.6k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
10.6k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
10.6k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
10.6k
    if (maxval > 255) {
783
2.55k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
365
        source->pub.get_pixel_rows = get_word_gray_row;
785
2.19k
      else if (IsExtRGB(cinfo->in_color_space))
786
1.82k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
365
      else if (cinfo->in_color_space == JCS_CMYK)
788
365
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
8.14k
    } 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.14k
    } else {
798
8.14k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
1.16k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
6.97k
      else if (IsExtRGB(cinfo->in_color_space))
801
5.81k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
1.16k
      else if (cinfo->in_color_space == JCS_CMYK)
803
1.16k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
8.14k
    }
807
10.6k
    break;
808
809
5.46k
  case '6':                     /* it's a raw-format PPM file */
810
5.46k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
5.46k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
5.46k
    if (maxval > 255) {
814
3.34k
      if (IsExtRGB(cinfo->in_color_space))
815
2.39k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
956
      else if (cinfo->in_color_space == JCS_CMYK)
817
478
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
478
      else
819
478
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
3.34k
    } 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.12k
    } else {
832
2.12k
      if (IsExtRGB(cinfo->in_color_space))
833
1.51k
        source->pub.get_pixel_rows = get_rgb_row;
834
606
      else if (cinfo->in_color_space == JCS_CMYK)
835
303
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
303
      else
837
303
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
2.12k
    }
839
5.46k
    break;
840
24.7k
  }
841
842
20.6k
  if (IsExtRGB(cinfo->in_color_space))
843
15.6k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
5.02k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
1.89k
    cinfo->input_components = 1;
846
3.12k
  else if (cinfo->in_color_space == JCS_CMYK)
847
3.12k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
20.6k
  if (need_iobuffer) {
851
15.3k
    if (c == '6')
852
4.68k
      source->buffer_width = (size_t)w * 3 *
853
4.68k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
10.6k
    else
855
10.6k
      source->buffer_width = (size_t)w *
856
10.6k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
15.3k
    source->iobuffer = (U_CHAR *)
858
15.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
15.3k
                                  source->buffer_width);
860
15.3k
  }
861
862
  /* Create compressor input buffer. */
863
20.6k
  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.6k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
20.6k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
20.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
20.6k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
20.6k
    source->pub.buffer_height = 1;
875
20.6k
  }
876
877
  /* Compute the rescaling array if required. */
878
20.6k
  if (need_rescale) {
879
20.6k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
20.6k
    source->rescale = (_JSAMPLE *)
883
20.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
20.6k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
20.6k
                                           sizeof(_JSAMPLE)));
886
20.6k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
20.6k
                                        sizeof(_JSAMPLE)));
888
20.6k
    half_maxval = maxval / 2;
889
287M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
287M
      source->rescale[val] =
892
287M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
287M
                   maxval);
894
287M
    }
895
20.6k
  }
896
20.6k
}
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
77.3k
{
906
  /* no work */
907
77.3k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
905
40.8k
{
906
  /* no work */
907
40.8k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
905
27.6k
{
906
  /* no work */
907
27.6k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
905
8.83k
{
906
  /* no work */
907
8.83k
}
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
167k
{
917
167k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
81.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
85.2k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
85.2k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
167k
  source = (ppm_source_ptr)
929
167k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
167k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
167k
  source->pub.start_input = start_input_ppm;
933
167k
  source->pub.finish_input = finish_input_ppm;
934
167k
  source->pub.max_pixels = 0;
935
936
167k
  return (cjpeg_source_ptr)source;
937
167k
}
jinit_read_ppm
Line
Count
Source
916
81.9k
{
917
81.9k
  ppm_source_ptr source;
918
919
81.9k
#if BITS_IN_JSAMPLE == 8
920
81.9k
  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
81.9k
  source = (ppm_source_ptr)
929
81.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
81.9k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
81.9k
  source->pub.start_input = start_input_ppm;
933
81.9k
  source->pub.finish_input = finish_input_ppm;
934
81.9k
  source->pub.max_pixels = 0;
935
936
81.9k
  return (cjpeg_source_ptr)source;
937
81.9k
}
j12init_read_ppm
Line
Count
Source
916
60.4k
{
917
60.4k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
60.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
60.4k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
60.4k
  source = (ppm_source_ptr)
929
60.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
60.4k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
60.4k
  source->pub.start_input = start_input_ppm;
933
60.4k
  source->pub.finish_input = finish_input_ppm;
934
60.4k
  source->pub.max_pixels = 0;
935
936
60.4k
  return (cjpeg_source_ptr)source;
937
60.4k
}
j16init_read_ppm
Line
Count
Source
916
24.7k
{
917
24.7k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
24.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
24.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
24.7k
  source = (ppm_source_ptr)
929
24.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
24.7k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
24.7k
  source->pub.start_input = start_input_ppm;
933
24.7k
  source->pub.finish_input = finish_input_ppm;
934
24.7k
  source->pub.max_pixels = 0;
935
936
24.7k
  return (cjpeg_source_ptr)source;
937
24.7k
}
938
939
#endif /* defined(PPM_SUPPORTED) &&
940
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */