Coverage Report

Created: 2025-10-13 06:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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-2024, D. R. Commander.
9
 * For conditions of distribution and use, see the accompanying README.ijg
10
 * file.
11
 *
12
 * This file contains routines to read input images in PPM/PGM format.
13
 * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
14
 * The PBMPLUS library is NOT required to compile this software
15
 * (but it is highly useful as a set of PPM image manipulation programs).
16
 *
17
 * These routines may need modification for non-Unix environments or
18
 * specialized applications.  As they stand, they assume input from
19
 * an ordinary stdio stream.  They further assume that reading begins
20
 * at the start of the file; start_input may need work if the
21
 * user interface has already read some data (e.g., to determine that
22
 * the file is indeed PPM format).
23
 */
24
25
#include "cmyk.h"
26
#include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
27
28
#if defined(PPM_SUPPORTED) && \
29
    (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
30
31
32
/* Portions of this code are based on the PBMPLUS library, which is:
33
**
34
** Copyright (C) 1988 by Jef Poskanzer.
35
**
36
** Permission to use, copy, modify, and distribute this software and its
37
** documentation for any purpose and without fee is hereby granted, provided
38
** that the above copyright notice appear in all copies and that both that
39
** copyright notice and this permission notice appear in supporting
40
** documentation.  This software is provided "as is" without express or
41
** implied warranty.
42
*/
43
44
45
/* Macros to deal with unsigned chars as efficiently as compiler allows */
46
47
typedef unsigned char U_CHAR;
48
266M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
351M
  (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.78M
{
80
3.78M
  register int ch;
81
82
3.78M
  ch = getc(infile);
83
3.78M
  if (ch == '#') {
84
744k
    do {
85
744k
      ch = getc(infile);
86
744k
    } while (ch != '\n' && ch != EOF);
87
46.9k
  }
88
3.78M
  return ch;
89
3.78M
}
rdppm-8.c:pbm_getc
Line
Count
Source
79
1.83M
{
80
1.83M
  register int ch;
81
82
1.83M
  ch = getc(infile);
83
1.83M
  if (ch == '#') {
84
317k
    do {
85
317k
      ch = getc(infile);
86
317k
    } while (ch != '\n' && ch != EOF);
87
23.2k
  }
88
1.83M
  return ch;
89
1.83M
}
rdppm-12.c:pbm_getc
Line
Count
Source
79
1.35M
{
80
1.35M
  register int ch;
81
82
1.35M
  ch = getc(infile);
83
1.35M
  if (ch == '#') {
84
327k
    do {
85
327k
      ch = getc(infile);
86
327k
    } while (ch != '\n' && ch != EOF);
87
15.5k
  }
88
1.35M
  return ch;
89
1.35M
}
rdppm-16.c:pbm_getc
Line
Count
Source
79
598k
{
80
598k
  register int ch;
81
82
598k
  ch = getc(infile);
83
598k
  if (ch == '#') {
84
98.8k
    do {
85
98.8k
      ch = getc(infile);
86
98.8k
    } while (ch != '\n' && ch != EOF);
87
8.15k
  }
88
598k
  return ch;
89
598k
}
90
91
92
LOCAL(unsigned int)
93
read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
94
/* Read an unsigned decimal integer from the PPM file */
95
/* Swallows one trailing character after the integer */
96
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
97
/* This should not be a problem in practice. */
98
1.60M
{
99
1.60M
  register int ch;
100
1.60M
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
1.70M
  do {
104
1.70M
    ch = pbm_getc(infile);
105
1.70M
    if (ch == EOF)
106
32.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
1.70M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
1.60M
  if (ch < '0' || ch > '9')
110
2.99k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
1.60M
  val = ch - '0';
113
2.11M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
517k
    val *= 10;
115
517k
    val += ch - '0';
116
517k
    if (val > maxval)
117
1.62k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
517k
  }
119
120
1.60M
  return val;
121
1.60M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
98
784k
{
99
784k
  register int ch;
100
784k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
832k
  do {
104
832k
    ch = pbm_getc(infile);
105
832k
    if (ch == EOF)
106
15.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
832k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
784k
  if (ch < '0' || ch > '9')
110
1.32k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
784k
  val = ch - '0';
113
1.02M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
237k
    val *= 10;
115
237k
    val += ch - '0';
116
237k
    if (val > maxval)
117
761
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
237k
  }
119
120
784k
  return val;
121
784k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
98
557k
{
99
557k
  register int ch;
100
557k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
597k
  do {
104
597k
    ch = pbm_getc(infile);
105
597k
    if (ch == EOF)
106
10.9k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
597k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
557k
  if (ch < '0' || ch > '9')
110
1.15k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
557k
  val = ch - '0';
113
767k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
210k
    val *= 10;
115
210k
    val += ch - '0';
116
210k
    if (val > maxval)
117
564
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
210k
  }
119
120
557k
  return val;
121
557k
}
rdppm-16.c:read_pbm_integer
Line
Count
Source
98
259k
{
99
259k
  register int ch;
100
259k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
276k
  do {
104
276k
    ch = pbm_getc(infile);
105
276k
    if (ch == EOF)
106
6.15k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
276k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
259k
  if (ch < '0' || ch > '9')
110
517
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
259k
  val = ch - '0';
113
329k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
70.0k
    val *= 10;
115
70.0k
    val += ch - '0';
116
70.0k
    if (val > maxval)
117
298
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
70.0k
  }
119
120
259k
  return val;
121
259k
}
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.3k
{
140
21.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
21.3k
  FILE *infile = source->pub.input_file;
142
21.3k
  register _JSAMPROW ptr;
143
21.3k
  register _JSAMPLE *rescale = source->rescale;
144
21.3k
  JDIMENSION col;
145
21.3k
  unsigned int maxval = source->maxval;
146
147
21.3k
  ptr = source->pub._buffer[0];
148
60.1k
  for (col = cinfo->image_width; col > 0; col--) {
149
38.8k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
38.8k
  }
151
21.3k
  return 1;
152
21.3k
}
rdppm-8.c:get_text_gray_row
Line
Count
Source
139
10.8k
{
140
10.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
10.8k
  FILE *infile = source->pub.input_file;
142
10.8k
  register _JSAMPROW ptr;
143
10.8k
  register _JSAMPLE *rescale = source->rescale;
144
10.8k
  JDIMENSION col;
145
10.8k
  unsigned int maxval = source->maxval;
146
147
10.8k
  ptr = source->pub._buffer[0];
148
29.9k
  for (col = cinfo->image_width; col > 0; col--) {
149
19.0k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
19.0k
  }
151
10.8k
  return 1;
152
10.8k
}
rdppm-12.c:get_text_gray_row
Line
Count
Source
139
6.58k
{
140
6.58k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
6.58k
  FILE *infile = source->pub.input_file;
142
6.58k
  register _JSAMPROW ptr;
143
6.58k
  register _JSAMPLE *rescale = source->rescale;
144
6.58k
  JDIMENSION col;
145
6.58k
  unsigned int maxval = source->maxval;
146
147
6.58k
  ptr = source->pub._buffer[0];
148
19.5k
  for (col = cinfo->image_width; col > 0; col--) {
149
12.9k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
12.9k
  }
151
6.58k
  return 1;
152
6.58k
}
rdppm-16.c:get_text_gray_row
Line
Count
Source
139
3.90k
{
140
3.90k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
3.90k
  FILE *infile = source->pub.input_file;
142
3.90k
  register _JSAMPROW ptr;
143
3.90k
  register _JSAMPLE *rescale = source->rescale;
144
3.90k
  JDIMENSION col;
145
3.90k
  unsigned int maxval = source->maxval;
146
147
3.90k
  ptr = source->pub._buffer[0];
148
10.6k
  for (col = cinfo->image_width; col > 0; col--) {
149
6.77k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
6.77k
  }
151
3.90k
  return 1;
152
3.90k
}
153
154
155
255M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
156
908M
  for (col = cinfo->image_width; col > 0; col--) { \
157
653M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
158
653M
    alpha_set_op \
159
653M
    ptr += ps; \
160
653M
  } \
161
255M
}
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
106k
{
168
106k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
106k
  FILE *infile = source->pub.input_file;
170
106k
  register _JSAMPROW ptr;
171
106k
  register _JSAMPLE *rescale = source->rescale;
172
106k
  JDIMENSION col;
173
106k
  unsigned int maxval = source->maxval;
174
106k
  register int rindex = rgb_red[cinfo->in_color_space];
175
106k
  register int gindex = rgb_green[cinfo->in_color_space];
176
106k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
106k
  register int aindex = alpha_index[cinfo->in_color_space];
178
106k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
106k
  ptr = source->pub._buffer[0];
181
106k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
20.2k
    if (aindex >= 0)
183
2.96k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
20.2k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
17.3k
    else
186
17.3k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
86.4k
  } else {
188
86.4k
    if (aindex >= 0)
189
14.3k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
86.4k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
72.1k
    else
192
72.1k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
86.4k
  }
194
106k
  return 1;
195
106k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
167
54.3k
{
168
54.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
54.3k
  FILE *infile = source->pub.input_file;
170
54.3k
  register _JSAMPROW ptr;
171
54.3k
  register _JSAMPLE *rescale = source->rescale;
172
54.3k
  JDIMENSION col;
173
54.3k
  unsigned int maxval = source->maxval;
174
54.3k
  register int rindex = rgb_red[cinfo->in_color_space];
175
54.3k
  register int gindex = rgb_green[cinfo->in_color_space];
176
54.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
54.3k
  register int aindex = alpha_index[cinfo->in_color_space];
178
54.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
54.3k
  ptr = source->pub._buffer[0];
181
54.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
9.36k
    if (aindex >= 0)
183
986
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
9.36k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
8.38k
    else
186
8.38k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
44.9k
  } else {
188
44.9k
    if (aindex >= 0)
189
5.83k
      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.3k
  return 1;
195
54.3k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
167
32.9k
{
168
32.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
32.9k
  FILE *infile = source->pub.input_file;
170
32.9k
  register _JSAMPROW ptr;
171
32.9k
  register _JSAMPLE *rescale = source->rescale;
172
32.9k
  JDIMENSION col;
173
32.9k
  unsigned int maxval = source->maxval;
174
32.9k
  register int rindex = rgb_red[cinfo->in_color_space];
175
32.9k
  register int gindex = rgb_green[cinfo->in_color_space];
176
32.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
32.9k
  register int aindex = alpha_index[cinfo->in_color_space];
178
32.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
32.9k
  ptr = source->pub._buffer[0];
181
32.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
8.57k
    if (aindex >= 0)
183
1.53k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
8.57k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
7.03k
    else
186
7.03k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
24.3k
  } else {
188
24.3k
    if (aindex >= 0)
189
5.04k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
24.3k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
19.3k
    else
192
19.3k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
24.3k
  }
194
32.9k
  return 1;
195
32.9k
}
rdppm-16.c:get_text_gray_rgb_row
Line
Count
Source
167
19.5k
{
168
19.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
19.5k
  FILE *infile = source->pub.input_file;
170
19.5k
  register _JSAMPROW ptr;
171
19.5k
  register _JSAMPLE *rescale = source->rescale;
172
19.5k
  JDIMENSION col;
173
19.5k
  unsigned int maxval = source->maxval;
174
19.5k
  register int rindex = rgb_red[cinfo->in_color_space];
175
19.5k
  register int gindex = rgb_green[cinfo->in_color_space];
176
19.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
19.5k
  register int aindex = alpha_index[cinfo->in_color_space];
178
19.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
19.5k
  ptr = source->pub._buffer[0];
181
19.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
2.34k
    if (aindex >= 0)
183
445
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
2.34k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
1.90k
    else
186
1.90k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
17.1k
  } else {
188
17.1k
    if (aindex >= 0)
189
3.45k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
17.1k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
13.7k
    else
192
13.7k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
17.1k
  }
194
19.5k
  return 1;
195
19.5k
}
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.3k
{
203
17.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
17.3k
  FILE *infile = source->pub.input_file;
205
17.3k
  register _JSAMPROW ptr;
206
17.3k
  register _JSAMPLE *rescale = source->rescale;
207
17.3k
  JDIMENSION col;
208
17.3k
  unsigned int maxval = source->maxval;
209
210
17.3k
  ptr = source->pub._buffer[0];
211
17.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
14.9k
    for (col = cinfo->image_width; col > 0; col--) {
213
10.1k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
10.1k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
10.1k
      ptr += 4;
216
10.1k
    }
217
12.5k
  } else {
218
34.4k
    for (col = cinfo->image_width; col > 0; col--) {
219
21.8k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
21.8k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
221
21.8k
      ptr += 4;
222
21.8k
    }
223
12.5k
  }
224
17.3k
  return 1;
225
17.3k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.82k
{
203
6.82k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.82k
  FILE *infile = source->pub.input_file;
205
6.82k
  register _JSAMPROW ptr;
206
6.82k
  register _JSAMPLE *rescale = source->rescale;
207
6.82k
  JDIMENSION col;
208
6.82k
  unsigned int maxval = source->maxval;
209
210
6.82k
  ptr = source->pub._buffer[0];
211
6.82k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
4.83k
    for (col = cinfo->image_width; col > 0; col--) {
213
3.17k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
3.17k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
3.17k
      ptr += 4;
216
3.17k
    }
217
5.15k
  } else {
218
14.2k
    for (col = cinfo->image_width; col > 0; col--) {
219
9.12k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
9.12k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
221
9.12k
      ptr += 4;
222
9.12k
    }
223
5.15k
  }
224
6.82k
  return 1;
225
6.82k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.58k
{
203
6.58k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.58k
  FILE *infile = source->pub.input_file;
205
6.58k
  register _JSAMPROW ptr;
206
6.58k
  register _JSAMPLE *rescale = source->rescale;
207
6.58k
  JDIMENSION col;
208
6.58k
  unsigned int maxval = source->maxval;
209
210
6.58k
  ptr = source->pub._buffer[0];
211
6.58k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
7.81k
    for (col = cinfo->image_width; col > 0; col--) {
213
5.49k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
5.49k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
5.49k
      ptr += 4;
216
5.49k
    }
217
4.26k
  } else {
218
11.7k
    for (col = cinfo->image_width; col > 0; col--) {
219
7.47k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
7.47k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
221
7.47k
      ptr += 4;
222
7.47k
    }
223
4.26k
  }
224
6.58k
  return 1;
225
6.58k
}
rdppm-16.c:get_text_gray_cmyk_row
Line
Count
Source
202
3.90k
{
203
3.90k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
3.90k
  FILE *infile = source->pub.input_file;
205
3.90k
  register _JSAMPROW ptr;
206
3.90k
  register _JSAMPLE *rescale = source->rescale;
207
3.90k
  JDIMENSION col;
208
3.90k
  unsigned int maxval = source->maxval;
209
210
3.90k
  ptr = source->pub._buffer[0];
211
3.90k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
2.26k
    for (col = cinfo->image_width; col > 0; col--) {
213
1.49k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
1.49k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
1.49k
      ptr += 4;
216
1.49k
    }
217
3.13k
  } else {
218
8.41k
    for (col = cinfo->image_width; col > 0; col--) {
219
5.28k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
5.28k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
221
5.28k
      ptr += 4;
222
5.28k
    }
223
3.13k
  }
224
3.90k
  return 1;
225
3.90k
}
226
227
228
3.10M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
229
34.8M
  for (col = cinfo->image_width; col > 0; col--) { \
230
31.7M
    ptr[rindex] = read_op; \
231
31.7M
    ptr[gindex] = read_op; \
232
31.7M
    ptr[bindex] = read_op; \
233
31.7M
    alpha_set_op \
234
31.7M
    ptr += ps; \
235
31.7M
  } \
236
3.10M
}
237
238
METHODDEF(JDIMENSION)
239
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
240
/* This version is for reading text-format PPM files with any maxval */
241
132k
{
242
132k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
243
132k
  FILE *infile = source->pub.input_file;
244
132k
  register _JSAMPROW ptr;
245
132k
  register _JSAMPLE *rescale = source->rescale;
246
132k
  JDIMENSION col;
247
132k
  unsigned int maxval = source->maxval;
248
132k
  register int rindex = rgb_red[cinfo->in_color_space];
249
132k
  register int gindex = rgb_green[cinfo->in_color_space];
250
132k
  register int bindex = rgb_blue[cinfo->in_color_space];
251
132k
  register int aindex = alpha_index[cinfo->in_color_space];
252
132k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
253
254
132k
  ptr = source->pub._buffer[0];
255
132k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
256
23.8k
    if (aindex >= 0)
257
2.98k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
258
23.8k
                    ptr[aindex] = (_JSAMPLE)maxval;)
259
20.9k
    else
260
20.9k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
261
108k
  } else {
262
108k
    if (aindex >= 0)
263
19.8k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
264
108k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
265
88.5k
    else
266
88.5k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
267
108k
  }
268
132k
  return 1;
269
132k
}
rdppm-8.c:get_text_rgb_row
Line
Count
Source
241
65.1k
{
242
65.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
243
65.1k
  FILE *infile = source->pub.input_file;
244
65.1k
  register _JSAMPROW ptr;
245
65.1k
  register _JSAMPLE *rescale = source->rescale;
246
65.1k
  JDIMENSION col;
247
65.1k
  unsigned int maxval = source->maxval;
248
65.1k
  register int rindex = rgb_red[cinfo->in_color_space];
249
65.1k
  register int gindex = rgb_green[cinfo->in_color_space];
250
65.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
251
65.1k
  register int aindex = alpha_index[cinfo->in_color_space];
252
65.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
253
254
65.1k
  ptr = source->pub._buffer[0];
255
65.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
256
11.5k
    if (aindex >= 0)
257
1.33k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
258
11.5k
                    ptr[aindex] = (_JSAMPLE)maxval;)
259
10.2k
    else
260
10.2k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
261
53.6k
  } else {
262
53.6k
    if (aindex >= 0)
263
8.05k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
264
53.6k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
265
45.5k
    else
266
45.5k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
267
53.6k
  }
268
65.1k
  return 1;
269
65.1k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
241
42.1k
{
242
42.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
243
42.1k
  FILE *infile = source->pub.input_file;
244
42.1k
  register _JSAMPROW ptr;
245
42.1k
  register _JSAMPLE *rescale = source->rescale;
246
42.1k
  JDIMENSION col;
247
42.1k
  unsigned int maxval = source->maxval;
248
42.1k
  register int rindex = rgb_red[cinfo->in_color_space];
249
42.1k
  register int gindex = rgb_green[cinfo->in_color_space];
250
42.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
251
42.1k
  register int aindex = alpha_index[cinfo->in_color_space];
252
42.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
253
254
42.1k
  ptr = source->pub._buffer[0];
255
42.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
256
8.77k
    if (aindex >= 0)
257
1.33k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
258
8.77k
                    ptr[aindex] = (_JSAMPLE)maxval;)
259
7.43k
    else
260
7.43k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
261
33.3k
  } else {
262
33.3k
    if (aindex >= 0)
263
7.09k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
264
33.3k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
265
26.2k
    else
266
26.2k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
267
33.3k
  }
268
42.1k
  return 1;
269
42.1k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
241
24.9k
{
242
24.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
243
24.9k
  FILE *infile = source->pub.input_file;
244
24.9k
  register _JSAMPROW ptr;
245
24.9k
  register _JSAMPLE *rescale = source->rescale;
246
24.9k
  JDIMENSION col;
247
24.9k
  unsigned int maxval = source->maxval;
248
24.9k
  register int rindex = rgb_red[cinfo->in_color_space];
249
24.9k
  register int gindex = rgb_green[cinfo->in_color_space];
250
24.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
251
24.9k
  register int aindex = alpha_index[cinfo->in_color_space];
252
24.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
253
254
24.9k
  ptr = source->pub._buffer[0];
255
24.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
256
3.58k
    if (aindex >= 0)
257
312
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
258
3.58k
                    ptr[aindex] = (_JSAMPLE)maxval;)
259
3.27k
    else
260
3.27k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
261
21.4k
  } else {
262
21.4k
    if (aindex >= 0)
263
4.68k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
264
21.4k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
265
16.7k
    else
266
16.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
267
21.4k
  }
268
24.9k
  return 1;
269
24.9k
}
270
271
272
METHODDEF(JDIMENSION)
273
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
274
/* This version is for reading text-format PPM files with any maxval and
275
   converting to CMYK */
276
22.8k
{
277
22.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
278
22.8k
  FILE *infile = source->pub.input_file;
279
22.8k
  register _JSAMPROW ptr;
280
22.8k
  register _JSAMPLE *rescale = source->rescale;
281
22.8k
  JDIMENSION col;
282
22.8k
  unsigned int maxval = source->maxval;
283
284
22.8k
  ptr = source->pub._buffer[0];
285
22.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
286
23.8k
    for (col = cinfo->image_width; col > 0; col--) {
287
15.9k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
15.9k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
15.9k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
15.9k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
291
15.9k
      ptr += 4;
292
15.9k
    }
293
14.8k
  } else {
294
41.4k
    for (col = cinfo->image_width; col > 0; col--) {
295
26.5k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
26.5k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
26.5k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
26.5k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
299
26.5k
      ptr += 4;
300
26.5k
    }
301
14.8k
  }
302
22.8k
  return 1;
303
22.8k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
276
9.38k
{
277
9.38k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
278
9.38k
  FILE *infile = source->pub.input_file;
279
9.38k
  register _JSAMPROW ptr;
280
9.38k
  register _JSAMPLE *rescale = source->rescale;
281
9.38k
  JDIMENSION col;
282
9.38k
  unsigned int maxval = source->maxval;
283
284
9.38k
  ptr = source->pub._buffer[0];
285
9.38k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
286
10.6k
    for (col = cinfo->image_width; col > 0; col--) {
287
6.68k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
6.68k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
6.68k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
6.68k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
291
6.68k
      ptr += 4;
292
6.68k
    }
293
5.42k
  } else {
294
15.9k
    for (col = cinfo->image_width; col > 0; col--) {
295
10.4k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
10.4k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.4k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
10.4k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
299
10.4k
      ptr += 4;
300
10.4k
    }
301
5.42k
  }
302
9.38k
  return 1;
303
9.38k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
276
8.42k
{
277
8.42k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
278
8.42k
  FILE *infile = source->pub.input_file;
279
8.42k
  register _JSAMPROW ptr;
280
8.42k
  register _JSAMPLE *rescale = source->rescale;
281
8.42k
  JDIMENSION col;
282
8.42k
  unsigned int maxval = source->maxval;
283
284
8.42k
  ptr = source->pub._buffer[0];
285
8.42k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
286
8.87k
    for (col = cinfo->image_width; col > 0; col--) {
287
6.29k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
6.29k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
6.29k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
6.29k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
291
6.29k
      ptr += 4;
292
6.29k
    }
293
5.85k
  } else {
294
16.3k
    for (col = cinfo->image_width; col > 0; col--) {
295
10.5k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
10.5k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.5k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
10.5k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
299
10.5k
      ptr += 4;
300
10.5k
    }
301
5.85k
  }
302
8.42k
  return 1;
303
8.42k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
276
4.99k
{
277
4.99k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
278
4.99k
  FILE *infile = source->pub.input_file;
279
4.99k
  register _JSAMPROW ptr;
280
4.99k
  register _JSAMPLE *rescale = source->rescale;
281
4.99k
  JDIMENSION col;
282
4.99k
  unsigned int maxval = source->maxval;
283
284
4.99k
  ptr = source->pub._buffer[0];
285
4.99k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
286
4.35k
    for (col = cinfo->image_width; col > 0; col--) {
287
2.96k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
288
2.96k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
2.96k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
2.96k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
291
2.96k
      ptr += 4;
292
2.96k
    }
293
3.61k
  } else {
294
9.17k
    for (col = cinfo->image_width; col > 0; col--) {
295
5.56k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
296
5.56k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
5.56k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
5.56k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
299
5.56k
      ptr += 4;
300
5.56k
    }
301
3.61k
  }
302
4.99k
  return 1;
303
4.99k
}
304
305
306
METHODDEF(JDIMENSION)
307
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
308
/* This version is for reading raw-byte-format PGM files with any maxval */
309
47.3M
{
310
47.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
311
47.3M
  register _JSAMPROW ptr;
312
47.3M
  register U_CHAR *bufferptr;
313
47.3M
  register _JSAMPLE *rescale = source->rescale;
314
47.3M
  JDIMENSION col;
315
316
47.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
317
772
    ERREXIT(cinfo, JERR_INPUT_EOF);
318
47.3M
  ptr = source->pub._buffer[0];
319
47.3M
  bufferptr = source->iobuffer;
320
173M
  for (col = cinfo->image_width; col > 0; col--) {
321
125M
    *ptr++ = rescale[UCH(*bufferptr++)];
322
125M
  }
323
47.3M
  return 1;
324
47.3M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
309
21.8M
{
310
21.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
311
21.8M
  register _JSAMPROW ptr;
312
21.8M
  register U_CHAR *bufferptr;
313
21.8M
  register _JSAMPLE *rescale = source->rescale;
314
21.8M
  JDIMENSION col;
315
316
21.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
317
424
    ERREXIT(cinfo, JERR_INPUT_EOF);
318
21.8M
  ptr = source->pub._buffer[0];
319
21.8M
  bufferptr = source->iobuffer;
320
79.8M
  for (col = cinfo->image_width; col > 0; col--) {
321
57.9M
    *ptr++ = rescale[UCH(*bufferptr++)];
322
57.9M
  }
323
21.8M
  return 1;
324
21.8M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
309
20.8M
{
310
20.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
311
20.8M
  register _JSAMPROW ptr;
312
20.8M
  register U_CHAR *bufferptr;
313
20.8M
  register _JSAMPLE *rescale = source->rescale;
314
20.8M
  JDIMENSION col;
315
316
20.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
317
221
    ERREXIT(cinfo, JERR_INPUT_EOF);
318
20.8M
  ptr = source->pub._buffer[0];
319
20.8M
  bufferptr = source->iobuffer;
320
68.0M
  for (col = cinfo->image_width; col > 0; col--) {
321
47.1M
    *ptr++ = rescale[UCH(*bufferptr++)];
322
47.1M
  }
323
20.8M
  return 1;
324
20.8M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
309
4.55M
{
310
4.55M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
311
4.55M
  register _JSAMPROW ptr;
312
4.55M
  register U_CHAR *bufferptr;
313
4.55M
  register _JSAMPLE *rescale = source->rescale;
314
4.55M
  JDIMENSION col;
315
316
4.55M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
317
127
    ERREXIT(cinfo, JERR_INPUT_EOF);
318
4.55M
  ptr = source->pub._buffer[0];
319
4.55M
  bufferptr = source->iobuffer;
320
25.3M
  for (col = cinfo->image_width; col > 0; col--) {
321
20.8M
    *ptr++ = rescale[UCH(*bufferptr++)];
322
20.8M
  }
323
4.55M
  return 1;
324
4.55M
}
325
326
327
METHODDEF(JDIMENSION)
328
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
329
/* This version is for reading raw-byte-format PGM files with any maxval
330
   and converting to extended RGB */
331
255M
{
332
255M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
333
255M
  register _JSAMPROW ptr;
334
255M
  register U_CHAR *bufferptr;
335
255M
  register _JSAMPLE *rescale = source->rescale;
336
255M
  JDIMENSION col;
337
255M
  unsigned int maxval = source->maxval;
338
255M
  register int rindex = rgb_red[cinfo->in_color_space];
339
255M
  register int gindex = rgb_green[cinfo->in_color_space];
340
255M
  register int bindex = rgb_blue[cinfo->in_color_space];
341
255M
  register int aindex = alpha_index[cinfo->in_color_space];
342
255M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
343
344
255M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
345
4.65k
    ERREXIT(cinfo, JERR_INPUT_EOF);
346
255M
  ptr = source->pub._buffer[0];
347
255M
  bufferptr = source->iobuffer;
348
255M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
349
18.9M
    if (aindex >= 0)
350
477k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
351
18.4M
    else
352
18.4M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
353
236M
  } else {
354
236M
    if (aindex >= 0)
355
40.1M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
356
236M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
357
195M
    else
358
195M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
359
236M
  }
360
255M
  return 1;
361
255M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
331
127M
{
332
127M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
333
127M
  register _JSAMPROW ptr;
334
127M
  register U_CHAR *bufferptr;
335
127M
  register _JSAMPLE *rescale = source->rescale;
336
127M
  JDIMENSION col;
337
127M
  unsigned int maxval = source->maxval;
338
127M
  register int rindex = rgb_red[cinfo->in_color_space];
339
127M
  register int gindex = rgb_green[cinfo->in_color_space];
340
127M
  register int bindex = rgb_blue[cinfo->in_color_space];
341
127M
  register int aindex = alpha_index[cinfo->in_color_space];
342
127M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
343
344
127M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
345
2.91k
    ERREXIT(cinfo, JERR_INPUT_EOF);
346
127M
  ptr = source->pub._buffer[0];
347
127M
  bufferptr = source->iobuffer;
348
127M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
349
18.9M
    if (aindex >= 0)
350
477k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
351
18.4M
    else
352
18.4M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
353
108M
  } else {
354
108M
    if (aindex >= 0)
355
14.7M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
356
108M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
357
94.1M
    else
358
94.1M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
359
108M
  }
360
127M
  return 1;
361
127M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
331
104M
{
332
104M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
333
104M
  register _JSAMPROW ptr;
334
104M
  register U_CHAR *bufferptr;
335
104M
  register _JSAMPLE *rescale = source->rescale;
336
104M
  JDIMENSION col;
337
104M
  unsigned int maxval = source->maxval;
338
104M
  register int rindex = rgb_red[cinfo->in_color_space];
339
104M
  register int gindex = rgb_green[cinfo->in_color_space];
340
104M
  register int bindex = rgb_blue[cinfo->in_color_space];
341
104M
  register int aindex = alpha_index[cinfo->in_color_space];
342
104M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
343
344
104M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
345
1.10k
    ERREXIT(cinfo, JERR_INPUT_EOF);
346
104M
  ptr = source->pub._buffer[0];
347
104M
  bufferptr = source->iobuffer;
348
104M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
349
0
    if (aindex >= 0)
350
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
351
0
    else
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
353
104M
  } else {
354
104M
    if (aindex >= 0)
355
20.8M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
356
104M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
357
83.5M
    else
358
83.5M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
359
104M
  }
360
104M
  return 1;
361
104M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
331
22.7M
{
332
22.7M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
333
22.7M
  register _JSAMPROW ptr;
334
22.7M
  register U_CHAR *bufferptr;
335
22.7M
  register _JSAMPLE *rescale = source->rescale;
336
22.7M
  JDIMENSION col;
337
22.7M
  unsigned int maxval = source->maxval;
338
22.7M
  register int rindex = rgb_red[cinfo->in_color_space];
339
22.7M
  register int gindex = rgb_green[cinfo->in_color_space];
340
22.7M
  register int bindex = rgb_blue[cinfo->in_color_space];
341
22.7M
  register int aindex = alpha_index[cinfo->in_color_space];
342
22.7M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
343
344
22.7M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
345
635
    ERREXIT(cinfo, JERR_INPUT_EOF);
346
22.7M
  ptr = source->pub._buffer[0];
347
22.7M
  bufferptr = source->iobuffer;
348
22.7M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
349
0
    if (aindex >= 0)
350
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
351
0
    else
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
353
22.7M
  } else {
354
22.7M
    if (aindex >= 0)
355
4.55M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
356
22.7M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
357
18.2M
    else
358
18.2M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
359
22.7M
  }
360
22.7M
  return 1;
361
22.7M
}
362
363
364
METHODDEF(JDIMENSION)
365
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
366
/* This version is for reading raw-byte-format PGM files with any maxval
367
   and converting to CMYK */
368
40.6M
{
369
40.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
370
40.6M
  register _JSAMPROW ptr;
371
40.6M
  register U_CHAR *bufferptr;
372
40.6M
  register _JSAMPLE *rescale = source->rescale;
373
40.6M
  JDIMENSION col;
374
40.6M
  unsigned int maxval = source->maxval;
375
376
40.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
377
763
    ERREXIT(cinfo, JERR_INPUT_EOF);
378
40.6M
  ptr = source->pub._buffer[0];
379
40.6M
  bufferptr = source->iobuffer;
380
40.6M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
381
2.82M
    for (col = cinfo->image_width; col > 0; col--) {
382
2.19M
      _JSAMPLE gray = *bufferptr++;
383
2.19M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
384
2.19M
      ptr += 4;
385
2.19M
    }
386
40.0M
  } else {
387
142M
    for (col = cinfo->image_width; col > 0; col--) {
388
102M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
389
102M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
390
102M
      ptr += 4;
391
102M
    }
392
40.0M
  }
393
40.6M
  return 1;
394
40.6M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
368
15.2M
{
369
15.2M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
370
15.2M
  register _JSAMPROW ptr;
371
15.2M
  register U_CHAR *bufferptr;
372
15.2M
  register _JSAMPLE *rescale = source->rescale;
373
15.2M
  JDIMENSION col;
374
15.2M
  unsigned int maxval = source->maxval;
375
376
15.2M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
377
415
    ERREXIT(cinfo, JERR_INPUT_EOF);
378
15.2M
  ptr = source->pub._buffer[0];
379
15.2M
  bufferptr = source->iobuffer;
380
15.2M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
381
2.82M
    for (col = cinfo->image_width; col > 0; col--) {
382
2.19M
      _JSAMPLE gray = *bufferptr++;
383
2.19M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
384
2.19M
      ptr += 4;
385
2.19M
    }
386
14.5M
  } else {
387
48.8M
    for (col = cinfo->image_width; col > 0; col--) {
388
34.3M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
389
34.3M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
390
34.3M
      ptr += 4;
391
34.3M
    }
392
14.5M
  }
393
15.2M
  return 1;
394
15.2M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
368
20.8M
{
369
20.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
370
20.8M
  register _JSAMPROW ptr;
371
20.8M
  register U_CHAR *bufferptr;
372
20.8M
  register _JSAMPLE *rescale = source->rescale;
373
20.8M
  JDIMENSION col;
374
20.8M
  unsigned int maxval = source->maxval;
375
376
20.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
377
221
    ERREXIT(cinfo, JERR_INPUT_EOF);
378
20.8M
  ptr = source->pub._buffer[0];
379
20.8M
  bufferptr = source->iobuffer;
380
20.8M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
381
0
    for (col = cinfo->image_width; col > 0; col--) {
382
0
      _JSAMPLE gray = *bufferptr++;
383
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
384
0
      ptr += 4;
385
0
    }
386
20.8M
  } else {
387
68.0M
    for (col = cinfo->image_width; col > 0; col--) {
388
47.1M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
389
47.1M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
390
47.1M
      ptr += 4;
391
47.1M
    }
392
20.8M
  }
393
20.8M
  return 1;
394
20.8M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
368
4.55M
{
369
4.55M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
370
4.55M
  register _JSAMPROW ptr;
371
4.55M
  register U_CHAR *bufferptr;
372
4.55M
  register _JSAMPLE *rescale = source->rescale;
373
4.55M
  JDIMENSION col;
374
4.55M
  unsigned int maxval = source->maxval;
375
376
4.55M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
377
127
    ERREXIT(cinfo, JERR_INPUT_EOF);
378
4.55M
  ptr = source->pub._buffer[0];
379
4.55M
  bufferptr = source->iobuffer;
380
4.55M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
381
0
    for (col = cinfo->image_width; col > 0; col--) {
382
0
      _JSAMPLE gray = *bufferptr++;
383
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
384
0
      ptr += 4;
385
0
    }
386
4.55M
  } else {
387
25.3M
    for (col = cinfo->image_width; col > 0; col--) {
388
20.8M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
389
20.8M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
390
20.8M
      ptr += 4;
391
20.8M
    }
392
4.55M
  }
393
4.55M
  return 1;
394
4.55M
}
395
396
397
METHODDEF(JDIMENSION)
398
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
399
/* This version is for reading raw-byte-format PPM files with any maxval */
400
2.96M
{
401
2.96M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
402
2.96M
  register _JSAMPROW ptr;
403
2.96M
  register U_CHAR *bufferptr;
404
2.96M
  register _JSAMPLE *rescale = source->rescale;
405
2.96M
  JDIMENSION col;
406
2.96M
  unsigned int maxval = source->maxval;
407
2.96M
  register int rindex = rgb_red[cinfo->in_color_space];
408
2.96M
  register int gindex = rgb_green[cinfo->in_color_space];
409
2.96M
  register int bindex = rgb_blue[cinfo->in_color_space];
410
2.96M
  register int aindex = alpha_index[cinfo->in_color_space];
411
2.96M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
412
413
2.96M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
414
6.52k
    ERREXIT(cinfo, JERR_INPUT_EOF);
415
2.96M
  ptr = source->pub._buffer[0];
416
2.96M
  bufferptr = source->iobuffer;
417
2.96M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
418
64.3k
    if (aindex >= 0)
419
9.28k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
420
55.0k
    else
421
55.0k
      RGB_READ_LOOP(*bufferptr++, {})
422
2.90M
  } else {
423
2.90M
    if (aindex >= 0)
424
560k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
425
2.90M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
426
2.34M
    else
427
2.34M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
428
2.90M
  }
429
2.96M
  return 1;
430
2.96M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
400
1.40M
{
401
1.40M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
402
1.40M
  register _JSAMPROW ptr;
403
1.40M
  register U_CHAR *bufferptr;
404
1.40M
  register _JSAMPLE *rescale = source->rescale;
405
1.40M
  JDIMENSION col;
406
1.40M
  unsigned int maxval = source->maxval;
407
1.40M
  register int rindex = rgb_red[cinfo->in_color_space];
408
1.40M
  register int gindex = rgb_green[cinfo->in_color_space];
409
1.40M
  register int bindex = rgb_blue[cinfo->in_color_space];
410
1.40M
  register int aindex = alpha_index[cinfo->in_color_space];
411
1.40M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
412
413
1.40M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
414
3.80k
    ERREXIT(cinfo, JERR_INPUT_EOF);
415
1.40M
  ptr = source->pub._buffer[0];
416
1.40M
  bufferptr = source->iobuffer;
417
1.40M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
418
64.3k
    if (aindex >= 0)
419
9.28k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
420
55.0k
    else
421
55.0k
      RGB_READ_LOOP(*bufferptr++, {})
422
1.34M
  } else {
423
1.34M
    if (aindex >= 0)
424
249k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
425
1.34M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
426
1.09M
    else
427
1.09M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
428
1.34M
  }
429
1.40M
  return 1;
430
1.40M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
400
1.53M
{
401
1.53M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
402
1.53M
  register _JSAMPROW ptr;
403
1.53M
  register U_CHAR *bufferptr;
404
1.53M
  register _JSAMPLE *rescale = source->rescale;
405
1.53M
  JDIMENSION col;
406
1.53M
  unsigned int maxval = source->maxval;
407
1.53M
  register int rindex = rgb_red[cinfo->in_color_space];
408
1.53M
  register int gindex = rgb_green[cinfo->in_color_space];
409
1.53M
  register int bindex = rgb_blue[cinfo->in_color_space];
410
1.53M
  register int aindex = alpha_index[cinfo->in_color_space];
411
1.53M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
412
413
1.53M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
414
1.77k
    ERREXIT(cinfo, JERR_INPUT_EOF);
415
1.53M
  ptr = source->pub._buffer[0];
416
1.53M
  bufferptr = source->iobuffer;
417
1.53M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
418
0
    if (aindex >= 0)
419
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
420
0
    else
421
0
      RGB_READ_LOOP(*bufferptr++, {})
422
1.53M
  } else {
423
1.53M
    if (aindex >= 0)
424
306k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
425
1.53M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
426
1.22M
    else
427
1.22M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
428
1.53M
  }
429
1.53M
  return 1;
430
1.53M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
400
24.1k
{
401
24.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
402
24.1k
  register _JSAMPROW ptr;
403
24.1k
  register U_CHAR *bufferptr;
404
24.1k
  register _JSAMPLE *rescale = source->rescale;
405
24.1k
  JDIMENSION col;
406
24.1k
  unsigned int maxval = source->maxval;
407
24.1k
  register int rindex = rgb_red[cinfo->in_color_space];
408
24.1k
  register int gindex = rgb_green[cinfo->in_color_space];
409
24.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
410
24.1k
  register int aindex = alpha_index[cinfo->in_color_space];
411
24.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
412
413
24.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
414
950
    ERREXIT(cinfo, JERR_INPUT_EOF);
415
24.1k
  ptr = source->pub._buffer[0];
416
24.1k
  bufferptr = source->iobuffer;
417
24.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
418
0
    if (aindex >= 0)
419
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
420
0
    else
421
0
      RGB_READ_LOOP(*bufferptr++, {})
422
24.1k
  } else {
423
24.1k
    if (aindex >= 0)
424
4.64k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
425
24.1k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
426
19.5k
    else
427
19.5k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
428
24.1k
  }
429
24.1k
  return 1;
430
24.1k
}
431
432
433
METHODDEF(JDIMENSION)
434
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
435
/* This version is for reading raw-byte-format PPM files with any maxval and
436
   converting to CMYK */
437
570k
{
438
570k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
439
570k
  register _JSAMPROW ptr;
440
570k
  register U_CHAR *bufferptr;
441
570k
  register _JSAMPLE *rescale = source->rescale;
442
570k
  JDIMENSION col;
443
570k
  unsigned int maxval = source->maxval;
444
445
570k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
446
1.17k
    ERREXIT(cinfo, JERR_INPUT_EOF);
447
570k
  ptr = source->pub._buffer[0];
448
570k
  bufferptr = source->iobuffer;
449
570k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
450
480k
    for (col = cinfo->image_width; col > 0; col--) {
451
469k
      _JSAMPLE r = *bufferptr++;
452
469k
      _JSAMPLE g = *bufferptr++;
453
469k
      _JSAMPLE b = *bufferptr++;
454
469k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
455
469k
      ptr += 4;
456
469k
    }
457
559k
  } else {
458
6.28M
    for (col = cinfo->image_width; col > 0; col--) {
459
5.72M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
460
5.72M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
461
5.72M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
462
5.72M
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
463
5.72M
      ptr += 4;
464
5.72M
    }
465
559k
  }
466
570k
  return 1;
467
570k
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
437
258k
{
438
258k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
439
258k
  register _JSAMPROW ptr;
440
258k
  register U_CHAR *bufferptr;
441
258k
  register _JSAMPLE *rescale = source->rescale;
442
258k
  JDIMENSION col;
443
258k
  unsigned int maxval = source->maxval;
444
445
258k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
446
633
    ERREXIT(cinfo, JERR_INPUT_EOF);
447
258k
  ptr = source->pub._buffer[0];
448
258k
  bufferptr = source->iobuffer;
449
258k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
450
480k
    for (col = cinfo->image_width; col > 0; col--) {
451
469k
      _JSAMPLE r = *bufferptr++;
452
469k
      _JSAMPLE g = *bufferptr++;
453
469k
      _JSAMPLE b = *bufferptr++;
454
469k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
455
469k
      ptr += 4;
456
469k
    }
457
247k
  } else {
458
1.38M
    for (col = cinfo->image_width; col > 0; col--) {
459
1.13M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
460
1.13M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
461
1.13M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
462
1.13M
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
463
1.13M
      ptr += 4;
464
1.13M
    }
465
247k
  }
466
258k
  return 1;
467
258k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
437
307k
{
438
307k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
439
307k
  register _JSAMPROW ptr;
440
307k
  register U_CHAR *bufferptr;
441
307k
  register _JSAMPLE *rescale = source->rescale;
442
307k
  JDIMENSION col;
443
307k
  unsigned int maxval = source->maxval;
444
445
307k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
446
354
    ERREXIT(cinfo, JERR_INPUT_EOF);
447
307k
  ptr = source->pub._buffer[0];
448
307k
  bufferptr = source->iobuffer;
449
307k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
450
0
    for (col = cinfo->image_width; col > 0; col--) {
451
0
      _JSAMPLE r = *bufferptr++;
452
0
      _JSAMPLE g = *bufferptr++;
453
0
      _JSAMPLE b = *bufferptr++;
454
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
455
0
      ptr += 4;
456
0
    }
457
307k
  } else {
458
3.65M
    for (col = cinfo->image_width; col > 0; col--) {
459
3.35M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
460
3.35M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
461
3.35M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
462
3.35M
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
463
3.35M
      ptr += 4;
464
3.35M
    }
465
307k
  }
466
307k
  return 1;
467
307k
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
437
4.83k
{
438
4.83k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
439
4.83k
  register _JSAMPROW ptr;
440
4.83k
  register U_CHAR *bufferptr;
441
4.83k
  register _JSAMPLE *rescale = source->rescale;
442
4.83k
  JDIMENSION col;
443
4.83k
  unsigned int maxval = source->maxval;
444
445
4.83k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
446
190
    ERREXIT(cinfo, JERR_INPUT_EOF);
447
4.83k
  ptr = source->pub._buffer[0];
448
4.83k
  bufferptr = source->iobuffer;
449
4.83k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
450
0
    for (col = cinfo->image_width; col > 0; col--) {
451
0
      _JSAMPLE r = *bufferptr++;
452
0
      _JSAMPLE g = *bufferptr++;
453
0
      _JSAMPLE b = *bufferptr++;
454
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
455
0
      ptr += 4;
456
0
    }
457
4.83k
  } else {
458
1.24M
    for (col = cinfo->image_width; col > 0; col--) {
459
1.24M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
460
1.24M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
461
1.24M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
462
1.24M
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
463
1.24M
      ptr += 4;
464
1.24M
    }
465
4.83k
  }
466
4.83k
  return 1;
467
4.83k
}
468
469
470
METHODDEF(JDIMENSION)
471
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
472
/* This version is for reading raw-byte-format files with
473
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
474
 * In this case we just read right into the _JSAMPLE buffer!
475
 * Note that same code works for PPM and PGM files.
476
 */
477
3.72M
{
478
3.72M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
479
480
3.72M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
481
337
    ERREXIT(cinfo, JERR_INPUT_EOF);
482
3.72M
  return 1;
483
3.72M
}
rdppm-8.c:get_raw_row
Line
Count
Source
477
3.72M
{
478
3.72M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
479
480
3.72M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
481
337
    ERREXIT(cinfo, JERR_INPUT_EOF);
482
3.72M
  return 1;
483
3.72M
}
Unexecuted instantiation: rdppm-12.c:get_raw_row
Unexecuted instantiation: rdppm-16.c:get_raw_row
484
485
486
METHODDEF(JDIMENSION)
487
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
488
/* This version is for reading raw-word-format PGM files with any maxval */
489
136k
{
490
136k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
491
136k
  register _JSAMPROW ptr;
492
136k
  register U_CHAR *bufferptr;
493
136k
  register _JSAMPLE *rescale = source->rescale;
494
136k
  JDIMENSION col;
495
136k
  unsigned int maxval = source->maxval;
496
497
136k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
498
702
    ERREXIT(cinfo, JERR_INPUT_EOF);
499
136k
  ptr = source->pub._buffer[0];
500
136k
  bufferptr = source->iobuffer;
501
904k
  for (col = cinfo->image_width; col > 0; col--) {
502
768k
    register unsigned int temp;
503
768k
    temp  = UCH(*bufferptr++) << 8;
504
768k
    temp |= UCH(*bufferptr++);
505
768k
    if (temp > maxval)
506
422
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
507
768k
    *ptr++ = rescale[temp];
508
768k
  }
509
136k
  return 1;
510
136k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
489
24.1k
{
490
24.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
491
24.1k
  register _JSAMPROW ptr;
492
24.1k
  register U_CHAR *bufferptr;
493
24.1k
  register _JSAMPLE *rescale = source->rescale;
494
24.1k
  JDIMENSION col;
495
24.1k
  unsigned int maxval = source->maxval;
496
497
24.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
498
341
    ERREXIT(cinfo, JERR_INPUT_EOF);
499
24.1k
  ptr = source->pub._buffer[0];
500
24.1k
  bufferptr = source->iobuffer;
501
361k
  for (col = cinfo->image_width; col > 0; col--) {
502
337k
    register unsigned int temp;
503
337k
    temp  = UCH(*bufferptr++) << 8;
504
337k
    temp |= UCH(*bufferptr++);
505
337k
    if (temp > maxval)
506
213
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
507
337k
    *ptr++ = rescale[temp];
508
337k
  }
509
24.1k
  return 1;
510
24.1k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
489
98.7k
{
490
98.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
491
98.7k
  register _JSAMPROW ptr;
492
98.7k
  register U_CHAR *bufferptr;
493
98.7k
  register _JSAMPLE *rescale = source->rescale;
494
98.7k
  JDIMENSION col;
495
98.7k
  unsigned int maxval = source->maxval;
496
497
98.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
498
238
    ERREXIT(cinfo, JERR_INPUT_EOF);
499
98.7k
  ptr = source->pub._buffer[0];
500
98.7k
  bufferptr = source->iobuffer;
501
336k
  for (col = cinfo->image_width; col > 0; col--) {
502
237k
    register unsigned int temp;
503
237k
    temp  = UCH(*bufferptr++) << 8;
504
237k
    temp |= UCH(*bufferptr++);
505
237k
    if (temp > maxval)
506
141
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
507
237k
    *ptr++ = rescale[temp];
508
237k
  }
509
98.7k
  return 1;
510
98.7k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
489
13.0k
{
490
13.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
491
13.0k
  register _JSAMPROW ptr;
492
13.0k
  register U_CHAR *bufferptr;
493
13.0k
  register _JSAMPLE *rescale = source->rescale;
494
13.0k
  JDIMENSION col;
495
13.0k
  unsigned int maxval = source->maxval;
496
497
13.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
498
123
    ERREXIT(cinfo, JERR_INPUT_EOF);
499
13.0k
  ptr = source->pub._buffer[0];
500
13.0k
  bufferptr = source->iobuffer;
501
206k
  for (col = cinfo->image_width; col > 0; col--) {
502
193k
    register unsigned int temp;
503
193k
    temp  = UCH(*bufferptr++) << 8;
504
193k
    temp |= UCH(*bufferptr++);
505
193k
    if (temp > maxval)
506
68
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
507
193k
    *ptr++ = rescale[temp];
508
193k
  }
509
13.0k
  return 1;
510
13.0k
}
511
512
513
METHODDEF(JDIMENSION)
514
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
515
/* This version is for reading raw-word-format PGM files with any maxval */
516
680k
{
517
680k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
518
680k
  register _JSAMPROW ptr;
519
680k
  register U_CHAR *bufferptr;
520
680k
  register _JSAMPLE *rescale = source->rescale;
521
680k
  JDIMENSION col;
522
680k
  unsigned int maxval = source->maxval;
523
680k
  register int rindex = rgb_red[cinfo->in_color_space];
524
680k
  register int gindex = rgb_green[cinfo->in_color_space];
525
680k
  register int bindex = rgb_blue[cinfo->in_color_space];
526
680k
  register int aindex = alpha_index[cinfo->in_color_space];
527
680k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
528
529
680k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
530
3.51k
    ERREXIT(cinfo, JERR_INPUT_EOF);
531
680k
  ptr = source->pub._buffer[0];
532
680k
  bufferptr = source->iobuffer;
533
4.52M
  for (col = cinfo->image_width; col > 0; col--) {
534
3.84M
    register unsigned int temp;
535
3.84M
    temp  = UCH(*bufferptr++) << 8;
536
3.84M
    temp |= UCH(*bufferptr++);
537
3.84M
    if (temp > maxval)
538
2.11k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
3.84M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
540
3.84M
    if (aindex >= 0)
541
675k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
542
3.84M
    ptr += ps;
543
3.84M
  }
544
680k
  return 1;
545
680k
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
516
120k
{
517
120k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
518
120k
  register _JSAMPROW ptr;
519
120k
  register U_CHAR *bufferptr;
520
120k
  register _JSAMPLE *rescale = source->rescale;
521
120k
  JDIMENSION col;
522
120k
  unsigned int maxval = source->maxval;
523
120k
  register int rindex = rgb_red[cinfo->in_color_space];
524
120k
  register int gindex = rgb_green[cinfo->in_color_space];
525
120k
  register int bindex = rgb_blue[cinfo->in_color_space];
526
120k
  register int aindex = alpha_index[cinfo->in_color_space];
527
120k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
528
529
120k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
530
1.70k
    ERREXIT(cinfo, JERR_INPUT_EOF);
531
120k
  ptr = source->pub._buffer[0];
532
120k
  bufferptr = source->iobuffer;
533
1.80M
  for (col = cinfo->image_width; col > 0; col--) {
534
1.68M
    register unsigned int temp;
535
1.68M
    temp  = UCH(*bufferptr++) << 8;
536
1.68M
    temp |= UCH(*bufferptr++);
537
1.68M
    if (temp > maxval)
538
1.06k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
1.68M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
540
1.68M
    if (aindex >= 0)
541
244k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
542
1.68M
    ptr += ps;
543
1.68M
  }
544
120k
  return 1;
545
120k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
516
493k
{
517
493k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
518
493k
  register _JSAMPROW ptr;
519
493k
  register U_CHAR *bufferptr;
520
493k
  register _JSAMPLE *rescale = source->rescale;
521
493k
  JDIMENSION col;
522
493k
  unsigned int maxval = source->maxval;
523
493k
  register int rindex = rgb_red[cinfo->in_color_space];
524
493k
  register int gindex = rgb_green[cinfo->in_color_space];
525
493k
  register int bindex = rgb_blue[cinfo->in_color_space];
526
493k
  register int aindex = alpha_index[cinfo->in_color_space];
527
493k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
528
529
493k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
530
1.19k
    ERREXIT(cinfo, JERR_INPUT_EOF);
531
493k
  ptr = source->pub._buffer[0];
532
493k
  bufferptr = source->iobuffer;
533
1.68M
  for (col = cinfo->image_width; col > 0; col--) {
534
1.18M
    register unsigned int temp;
535
1.18M
    temp  = UCH(*bufferptr++) << 8;
536
1.18M
    temp |= UCH(*bufferptr++);
537
1.18M
    if (temp > maxval)
538
705
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
1.18M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
540
1.18M
    if (aindex >= 0)
541
237k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
542
1.18M
    ptr += ps;
543
1.18M
  }
544
493k
  return 1;
545
493k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
516
65.4k
{
517
65.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
518
65.4k
  register _JSAMPROW ptr;
519
65.4k
  register U_CHAR *bufferptr;
520
65.4k
  register _JSAMPLE *rescale = source->rescale;
521
65.4k
  JDIMENSION col;
522
65.4k
  unsigned int maxval = source->maxval;
523
65.4k
  register int rindex = rgb_red[cinfo->in_color_space];
524
65.4k
  register int gindex = rgb_green[cinfo->in_color_space];
525
65.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
526
65.4k
  register int aindex = alpha_index[cinfo->in_color_space];
527
65.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
528
529
65.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
530
615
    ERREXIT(cinfo, JERR_INPUT_EOF);
531
65.4k
  ptr = source->pub._buffer[0];
532
65.4k
  bufferptr = source->iobuffer;
533
1.03M
  for (col = cinfo->image_width; col > 0; col--) {
534
967k
    register unsigned int temp;
535
967k
    temp  = UCH(*bufferptr++) << 8;
536
967k
    temp |= UCH(*bufferptr++);
537
967k
    if (temp > maxval)
538
340
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
539
967k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
540
967k
    if (aindex >= 0)
541
193k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
542
967k
    ptr += ps;
543
967k
  }
544
65.4k
  return 1;
545
65.4k
}
546
547
548
METHODDEF(JDIMENSION)
549
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
550
/* This version is for reading raw-word-format PGM files with any maxval */
551
122k
{
552
122k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
553
122k
  register _JSAMPROW ptr;
554
122k
  register U_CHAR *bufferptr;
555
122k
  register _JSAMPLE *rescale = source->rescale;
556
122k
  JDIMENSION col;
557
122k
  unsigned int maxval = source->maxval;
558
559
122k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
560
598
    ERREXIT(cinfo, JERR_INPUT_EOF);
561
122k
  ptr = source->pub._buffer[0];
562
122k
  bufferptr = source->iobuffer;
563
798k
  for (col = cinfo->image_width; col > 0; col--) {
564
676k
    register unsigned int gray;
565
676k
    gray  = UCH(*bufferptr++) << 8;
566
676k
    gray |= UCH(*bufferptr++);
567
676k
    if (gray > maxval)
568
360
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
569
676k
    rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
570
676k
                ptr + 1, ptr + 2, ptr + 3);
571
676k
    ptr += 4;
572
676k
  }
573
122k
  return 1;
574
122k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
551
10.1k
{
552
10.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
553
10.1k
  register _JSAMPROW ptr;
554
10.1k
  register U_CHAR *bufferptr;
555
10.1k
  register _JSAMPLE *rescale = source->rescale;
556
10.1k
  JDIMENSION col;
557
10.1k
  unsigned int maxval = source->maxval;
558
559
10.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
560
237
    ERREXIT(cinfo, JERR_INPUT_EOF);
561
10.1k
  ptr = source->pub._buffer[0];
562
10.1k
  bufferptr = source->iobuffer;
563
255k
  for (col = cinfo->image_width; col > 0; col--) {
564
244k
    register unsigned int gray;
565
244k
    gray  = UCH(*bufferptr++) << 8;
566
244k
    gray |= UCH(*bufferptr++);
567
244k
    if (gray > maxval)
568
151
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
569
244k
    rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
570
244k
                ptr + 1, ptr + 2, ptr + 3);
571
244k
    ptr += 4;
572
244k
  }
573
10.1k
  return 1;
574
10.1k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
551
98.7k
{
552
98.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
553
98.7k
  register _JSAMPROW ptr;
554
98.7k
  register U_CHAR *bufferptr;
555
98.7k
  register _JSAMPLE *rescale = source->rescale;
556
98.7k
  JDIMENSION col;
557
98.7k
  unsigned int maxval = source->maxval;
558
559
98.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
560
238
    ERREXIT(cinfo, JERR_INPUT_EOF);
561
98.7k
  ptr = source->pub._buffer[0];
562
98.7k
  bufferptr = source->iobuffer;
563
336k
  for (col = cinfo->image_width; col > 0; col--) {
564
237k
    register unsigned int gray;
565
237k
    gray  = UCH(*bufferptr++) << 8;
566
237k
    gray |= UCH(*bufferptr++);
567
237k
    if (gray > maxval)
568
141
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
569
237k
    rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
570
237k
                ptr + 1, ptr + 2, ptr + 3);
571
237k
    ptr += 4;
572
237k
  }
573
98.7k
  return 1;
574
98.7k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
551
13.0k
{
552
13.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
553
13.0k
  register _JSAMPROW ptr;
554
13.0k
  register U_CHAR *bufferptr;
555
13.0k
  register _JSAMPLE *rescale = source->rescale;
556
13.0k
  JDIMENSION col;
557
13.0k
  unsigned int maxval = source->maxval;
558
559
13.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
560
123
    ERREXIT(cinfo, JERR_INPUT_EOF);
561
13.0k
  ptr = source->pub._buffer[0];
562
13.0k
  bufferptr = source->iobuffer;
563
206k
  for (col = cinfo->image_width; col > 0; col--) {
564
193k
    register unsigned int gray;
565
193k
    gray  = UCH(*bufferptr++) << 8;
566
193k
    gray |= UCH(*bufferptr++);
567
193k
    if (gray > maxval)
568
68
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
569
193k
    rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
570
193k
                ptr + 1, ptr + 2, ptr + 3);
571
193k
    ptr += 4;
572
193k
  }
573
13.0k
  return 1;
574
13.0k
}
575
576
577
METHODDEF(JDIMENSION)
578
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
579
/* This version is for reading raw-word-format PPM files with any maxval */
580
173k
{
581
173k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
582
173k
  register _JSAMPROW ptr;
583
173k
  register U_CHAR *bufferptr;
584
173k
  register _JSAMPLE *rescale = source->rescale;
585
173k
  JDIMENSION col;
586
173k
  unsigned int maxval = source->maxval;
587
173k
  register int rindex = rgb_red[cinfo->in_color_space];
588
173k
  register int gindex = rgb_green[cinfo->in_color_space];
589
173k
  register int bindex = rgb_blue[cinfo->in_color_space];
590
173k
  register int aindex = alpha_index[cinfo->in_color_space];
591
173k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
592
593
173k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
594
4.21k
    ERREXIT(cinfo, JERR_INPUT_EOF);
595
173k
  ptr = source->pub._buffer[0];
596
173k
  bufferptr = source->iobuffer;
597
1.69M
  for (col = cinfo->image_width; col > 0; col--) {
598
1.51M
    register unsigned int temp;
599
1.51M
    temp  = UCH(*bufferptr++) << 8;
600
1.51M
    temp |= UCH(*bufferptr++);
601
1.51M
    if (temp > maxval)
602
1.80k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
603
1.51M
    ptr[rindex] = rescale[temp];
604
1.51M
    temp  = UCH(*bufferptr++) << 8;
605
1.51M
    temp |= UCH(*bufferptr++);
606
1.51M
    if (temp > maxval)
607
1.27k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
608
1.51M
    ptr[gindex] = rescale[temp];
609
1.51M
    temp  = UCH(*bufferptr++) << 8;
610
1.51M
    temp |= UCH(*bufferptr++);
611
1.51M
    if (temp > maxval)
612
1.28k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
613
1.51M
    ptr[bindex] = rescale[temp];
614
1.51M
    if (aindex >= 0)
615
299k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
616
1.51M
    ptr += ps;
617
1.51M
  }
618
173k
  return 1;
619
173k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
580
54.5k
{
581
54.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
582
54.5k
  register _JSAMPROW ptr;
583
54.5k
  register U_CHAR *bufferptr;
584
54.5k
  register _JSAMPLE *rescale = source->rescale;
585
54.5k
  JDIMENSION col;
586
54.5k
  unsigned int maxval = source->maxval;
587
54.5k
  register int rindex = rgb_red[cinfo->in_color_space];
588
54.5k
  register int gindex = rgb_green[cinfo->in_color_space];
589
54.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
590
54.5k
  register int aindex = alpha_index[cinfo->in_color_space];
591
54.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
592
593
54.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
594
1.87k
    ERREXIT(cinfo, JERR_INPUT_EOF);
595
54.5k
  ptr = source->pub._buffer[0];
596
54.5k
  bufferptr = source->iobuffer;
597
145k
  for (col = cinfo->image_width; col > 0; col--) {
598
91.2k
    register unsigned int temp;
599
91.2k
    temp  = UCH(*bufferptr++) << 8;
600
91.2k
    temp |= UCH(*bufferptr++);
601
91.2k
    if (temp > maxval)
602
845
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
603
91.2k
    ptr[rindex] = rescale[temp];
604
91.2k
    temp  = UCH(*bufferptr++) << 8;
605
91.2k
    temp |= UCH(*bufferptr++);
606
91.2k
    if (temp > maxval)
607
615
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
608
91.2k
    ptr[gindex] = rescale[temp];
609
91.2k
    temp  = UCH(*bufferptr++) << 8;
610
91.2k
    temp |= UCH(*bufferptr++);
611
91.2k
    if (temp > maxval)
612
645
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
613
91.2k
    ptr[bindex] = rescale[temp];
614
91.2k
    if (aindex >= 0)
615
13.8k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
616
91.2k
    ptr += ps;
617
91.2k
  }
618
54.5k
  return 1;
619
54.5k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
580
87.4k
{
581
87.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
582
87.4k
  register _JSAMPROW ptr;
583
87.4k
  register U_CHAR *bufferptr;
584
87.4k
  register _JSAMPLE *rescale = source->rescale;
585
87.4k
  JDIMENSION col;
586
87.4k
  unsigned int maxval = source->maxval;
587
87.4k
  register int rindex = rgb_red[cinfo->in_color_space];
588
87.4k
  register int gindex = rgb_green[cinfo->in_color_space];
589
87.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
590
87.4k
  register int aindex = alpha_index[cinfo->in_color_space];
591
87.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
592
593
87.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
594
1.56k
    ERREXIT(cinfo, JERR_INPUT_EOF);
595
87.4k
  ptr = source->pub._buffer[0];
596
87.4k
  bufferptr = source->iobuffer;
597
1.16M
  for (col = cinfo->image_width; col > 0; col--) {
598
1.07M
    register unsigned int temp;
599
1.07M
    temp  = UCH(*bufferptr++) << 8;
600
1.07M
    temp |= UCH(*bufferptr++);
601
1.07M
    if (temp > maxval)
602
625
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
603
1.07M
    ptr[rindex] = rescale[temp];
604
1.07M
    temp  = UCH(*bufferptr++) << 8;
605
1.07M
    temp |= UCH(*bufferptr++);
606
1.07M
    if (temp > maxval)
607
445
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
608
1.07M
    ptr[gindex] = rescale[temp];
609
1.07M
    temp  = UCH(*bufferptr++) << 8;
610
1.07M
    temp |= UCH(*bufferptr++);
611
1.07M
    if (temp > maxval)
612
420
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
613
1.07M
    ptr[bindex] = rescale[temp];
614
1.07M
    if (aindex >= 0)
615
214k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
616
1.07M
    ptr += ps;
617
1.07M
  }
618
87.4k
  return 1;
619
87.4k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
580
31.4k
{
581
31.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
582
31.4k
  register _JSAMPROW ptr;
583
31.4k
  register U_CHAR *bufferptr;
584
31.4k
  register _JSAMPLE *rescale = source->rescale;
585
31.4k
  JDIMENSION col;
586
31.4k
  unsigned int maxval = source->maxval;
587
31.4k
  register int rindex = rgb_red[cinfo->in_color_space];
588
31.4k
  register int gindex = rgb_green[cinfo->in_color_space];
589
31.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
590
31.4k
  register int aindex = alpha_index[cinfo->in_color_space];
591
31.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
592
593
31.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
594
785
    ERREXIT(cinfo, JERR_INPUT_EOF);
595
31.4k
  ptr = source->pub._buffer[0];
596
31.4k
  bufferptr = source->iobuffer;
597
383k
  for (col = cinfo->image_width; col > 0; col--) {
598
352k
    register unsigned int temp;
599
352k
    temp  = UCH(*bufferptr++) << 8;
600
352k
    temp |= UCH(*bufferptr++);
601
352k
    if (temp > maxval)
602
335
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
603
352k
    ptr[rindex] = rescale[temp];
604
352k
    temp  = UCH(*bufferptr++) << 8;
605
352k
    temp |= UCH(*bufferptr++);
606
352k
    if (temp > maxval)
607
210
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
608
352k
    ptr[gindex] = rescale[temp];
609
352k
    temp  = UCH(*bufferptr++) << 8;
610
352k
    temp |= UCH(*bufferptr++);
611
352k
    if (temp > maxval)
612
215
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
613
352k
    ptr[bindex] = rescale[temp];
614
352k
    if (aindex >= 0)
615
70.2k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
616
352k
    ptr += ps;
617
352k
  }
618
31.4k
  return 1;
619
31.4k
}
620
621
622
METHODDEF(JDIMENSION)
623
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
624
/* This version is for reading raw-word-format PPM files with any maxval */
625
31.9k
{
626
31.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
627
31.9k
  register _JSAMPROW ptr;
628
31.9k
  register U_CHAR *bufferptr;
629
31.9k
  register _JSAMPLE *rescale = source->rescale;
630
31.9k
  JDIMENSION col;
631
31.9k
  unsigned int maxval = source->maxval;
632
633
31.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
634
758
    ERREXIT(cinfo, JERR_INPUT_EOF);
635
31.9k
  ptr = source->pub._buffer[0];
636
31.9k
  bufferptr = source->iobuffer;
637
331k
  for (col = cinfo->image_width; col > 0; col--) {
638
299k
    register unsigned int r, g, b;
639
299k
    r  = UCH(*bufferptr++) << 8;
640
299k
    r |= UCH(*bufferptr++);
641
299k
    if (r > maxval)
642
313
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
643
299k
    g  = UCH(*bufferptr++) << 8;
644
299k
    g |= UCH(*bufferptr++);
645
299k
    if (g > maxval)
646
218
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
647
299k
    b  = UCH(*bufferptr++) << 8;
648
299k
    b |= UCH(*bufferptr++);
649
299k
    if (b > maxval)
650
212
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
651
299k
    rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
652
299k
                ptr + 2, ptr + 3);
653
299k
    ptr += 4;
654
299k
  }
655
31.9k
  return 1;
656
31.9k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
625
8.13k
{
626
8.13k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
627
8.13k
  register _JSAMPROW ptr;
628
8.13k
  register U_CHAR *bufferptr;
629
8.13k
  register _JSAMPLE *rescale = source->rescale;
630
8.13k
  JDIMENSION col;
631
8.13k
  unsigned int maxval = source->maxval;
632
633
8.13k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
634
289
    ERREXIT(cinfo, JERR_INPUT_EOF);
635
8.13k
  ptr = source->pub._buffer[0];
636
8.13k
  bufferptr = source->iobuffer;
637
22.3k
  for (col = cinfo->image_width; col > 0; col--) {
638
14.1k
    register unsigned int r, g, b;
639
14.1k
    r  = UCH(*bufferptr++) << 8;
640
14.1k
    r |= UCH(*bufferptr++);
641
14.1k
    if (r > maxval)
642
121
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
643
14.1k
    g  = UCH(*bufferptr++) << 8;
644
14.1k
    g |= UCH(*bufferptr++);
645
14.1k
    if (g > maxval)
646
87
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
647
14.1k
    b  = UCH(*bufferptr++) << 8;
648
14.1k
    b |= UCH(*bufferptr++);
649
14.1k
    if (b > maxval)
650
85
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
651
14.1k
    rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
652
14.1k
                ptr + 2, ptr + 3);
653
14.1k
    ptr += 4;
654
14.1k
  }
655
8.13k
  return 1;
656
8.13k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
625
17.4k
{
626
17.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
627
17.4k
  register _JSAMPROW ptr;
628
17.4k
  register U_CHAR *bufferptr;
629
17.4k
  register _JSAMPLE *rescale = source->rescale;
630
17.4k
  JDIMENSION col;
631
17.4k
  unsigned int maxval = source->maxval;
632
633
17.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
634
312
    ERREXIT(cinfo, JERR_INPUT_EOF);
635
17.4k
  ptr = source->pub._buffer[0];
636
17.4k
  bufferptr = source->iobuffer;
637
232k
  for (col = cinfo->image_width; col > 0; col--) {
638
215k
    register unsigned int r, g, b;
639
215k
    r  = UCH(*bufferptr++) << 8;
640
215k
    r |= UCH(*bufferptr++);
641
215k
    if (r > maxval)
642
125
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
643
215k
    g  = UCH(*bufferptr++) << 8;
644
215k
    g |= UCH(*bufferptr++);
645
215k
    if (g > maxval)
646
89
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
647
215k
    b  = UCH(*bufferptr++) << 8;
648
215k
    b |= UCH(*bufferptr++);
649
215k
    if (b > maxval)
650
84
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
651
215k
    rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
652
215k
                ptr + 2, ptr + 3);
653
215k
    ptr += 4;
654
215k
  }
655
17.4k
  return 1;
656
17.4k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
625
6.28k
{
626
6.28k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
627
6.28k
  register _JSAMPROW ptr;
628
6.28k
  register U_CHAR *bufferptr;
629
6.28k
  register _JSAMPLE *rescale = source->rescale;
630
6.28k
  JDIMENSION col;
631
6.28k
  unsigned int maxval = source->maxval;
632
633
6.28k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
634
157
    ERREXIT(cinfo, JERR_INPUT_EOF);
635
6.28k
  ptr = source->pub._buffer[0];
636
6.28k
  bufferptr = source->iobuffer;
637
76.7k
  for (col = cinfo->image_width; col > 0; col--) {
638
70.4k
    register unsigned int r, g, b;
639
70.4k
    r  = UCH(*bufferptr++) << 8;
640
70.4k
    r |= UCH(*bufferptr++);
641
70.4k
    if (r > maxval)
642
67
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
643
70.4k
    g  = UCH(*bufferptr++) << 8;
644
70.4k
    g |= UCH(*bufferptr++);
645
70.4k
    if (g > maxval)
646
42
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
647
70.4k
    b  = UCH(*bufferptr++) << 8;
648
70.4k
    b |= UCH(*bufferptr++);
649
70.4k
    if (b > maxval)
650
43
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
651
70.4k
    rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
652
70.4k
                ptr + 2, ptr + 3);
653
70.4k
    ptr += 4;
654
70.4k
  }
655
6.28k
  return 1;
656
6.28k
}
657
658
659
/*
660
 * Read the file header; return image size and component count.
661
 */
662
663
METHODDEF(void)
664
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
665
175k
{
666
175k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
667
175k
  int c;
668
175k
  unsigned int w, h, maxval;
669
175k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
670
671
175k
  if (getc(source->pub.input_file) != 'P')
672
0
    ERREXIT(cinfo, JERR_PPM_NOT);
673
674
175k
  c = getc(source->pub.input_file); /* subformat discriminator character */
675
676
  /* detect unsupported variants (ie, PBM) before trying to read header */
677
175k
  switch (c) {
678
17.2k
  case '2':                     /* it's a text-format PGM file */
679
36.7k
  case '3':                     /* it's a text-format PPM file */
680
138k
  case '5':                     /* it's a raw-format PGM file */
681
175k
  case '6':                     /* it's a raw-format PPM file */
682
175k
    break;
683
165
  default:
684
165
    ERREXIT(cinfo, JERR_PPM_NOT);
685
165
    break;
686
175k
  }
687
688
  /* fetch the remaining header info */
689
175k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
690
175k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
691
175k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
692
693
175k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
694
370
    ERREXIT(cinfo, JERR_PPM_NOT);
695
175k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
696
2.87k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
697
698
175k
  cinfo->image_width = (JDIMENSION)w;
699
175k
  cinfo->image_height = (JDIMENSION)h;
700
175k
  source->maxval = maxval;
701
702
  /* initialize flags to most common settings */
703
175k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
704
175k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
705
175k
  need_rescale = TRUE;          /* do we need a rescale array? */
706
707
175k
  switch (c) {
708
13.1k
  case '2':                     /* it's a text-format PGM file */
709
13.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
710
13.1k
        cinfo->in_color_space == JCS_RGB)
711
0
      cinfo->in_color_space = JCS_GRAYSCALE;
712
13.1k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
713
13.1k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
714
1.91k
      source->pub.get_pixel_rows = get_text_gray_row;
715
11.2k
    else if (IsExtRGB(cinfo->in_color_space))
716
9.56k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
717
1.65k
    else if (cinfo->in_color_space == JCS_CMYK)
718
1.65k
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
719
0
    else
720
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
721
13.1k
    need_iobuffer = FALSE;
722
13.1k
    break;
723
724
15.3k
  case '3':                     /* it's a text-format PPM file */
725
15.3k
    if (cinfo->in_color_space == JCS_UNKNOWN)
726
0
      cinfo->in_color_space = JCS_EXT_RGB;
727
15.3k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
728
15.3k
    if (IsExtRGB(cinfo->in_color_space))
729
11.1k
      source->pub.get_pixel_rows = get_text_rgb_row;
730
4.21k
    else if (cinfo->in_color_space == JCS_CMYK)
731
1.98k
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
732
2.22k
    else
733
2.22k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
734
15.3k
    need_iobuffer = FALSE;
735
15.3k
    break;
736
737
97.1k
  case '5':                     /* it's a raw-format PGM file */
738
97.1k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
739
97.1k
        cinfo->in_color_space == JCS_RGB)
740
0
      cinfo->in_color_space = JCS_GRAYSCALE;
741
97.1k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
742
97.1k
    if (maxval > 255) {
743
8.63k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
744
1.26k
        source->pub.get_pixel_rows = get_word_gray_row;
745
7.37k
      else if (IsExtRGB(cinfo->in_color_space))
746
6.30k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
747
1.07k
      else if (cinfo->in_color_space == JCS_CMYK)
748
1.07k
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
749
0
      else
750
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
751
88.4k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
752
51.0k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
753
4.11k
               cinfo->in_color_space == JCS_GRAYSCALE) {
754
672
      source->pub.get_pixel_rows = get_raw_row;
755
672
      use_raw_buffer = TRUE;
756
672
      need_rescale = FALSE;
757
87.8k
    } else {
758
87.8k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
759
12.4k
        source->pub.get_pixel_rows = get_scaled_gray_row;
760
75.3k
      else if (IsExtRGB(cinfo->in_color_space))
761
65.5k
        source->pub.get_pixel_rows = get_gray_rgb_row;
762
9.84k
      else if (cinfo->in_color_space == JCS_CMYK)
763
9.84k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
764
0
      else
765
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
766
87.8k
    }
767
97.1k
    break;
768
769
33.6k
  case '6':                     /* it's a raw-format PPM file */
770
33.6k
    if (cinfo->in_color_space == JCS_UNKNOWN)
771
0
      cinfo->in_color_space = JCS_EXT_RGB;
772
33.6k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
773
33.6k
    if (maxval > 255) {
774
12.7k
      if (IsExtRGB(cinfo->in_color_space))
775
9.26k
        source->pub.get_pixel_rows = get_word_rgb_row;
776
3.48k
      else if (cinfo->in_color_space == JCS_CMYK)
777
1.63k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
778
1.85k
      else
779
1.85k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
780
20.9k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
781
11.8k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
782
2.52k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
783
2.52k
               (cinfo->in_color_space == JCS_EXT_RGB ||
784
2.16k
                cinfo->in_color_space == JCS_RGB)) {
785
#else
786
               cinfo->in_color_space == JCS_EXT_RGB) {
787
#endif
788
360
      source->pub.get_pixel_rows = get_raw_row;
789
360
      use_raw_buffer = TRUE;
790
360
      need_rescale = FALSE;
791
20.5k
    } else {
792
20.5k
      if (IsExtRGB(cinfo->in_color_space))
793
14.9k
        source->pub.get_pixel_rows = get_rgb_row;
794
5.60k
      else if (cinfo->in_color_space == JCS_CMYK)
795
2.54k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
796
3.06k
      else
797
3.06k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
798
20.5k
    }
799
33.6k
    break;
800
175k
  }
801
802
152k
  if (IsExtRGB(cinfo->in_color_space))
803
117k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
804
35.0k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
805
16.2k
    cinfo->input_components = 1;
806
18.7k
  else if (cinfo->in_color_space == JCS_CMYK)
807
18.7k
    cinfo->input_components = 4;
808
809
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
810
152k
  if (need_iobuffer) {
811
125k
    if (c == '6')
812
28.7k
      source->buffer_width = (size_t)w * 3 *
813
28.7k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
814
97.1k
    else
815
97.1k
      source->buffer_width = (size_t)w *
816
97.1k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
817
125k
    source->iobuffer = (U_CHAR *)
818
125k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
819
125k
                                  source->buffer_width);
820
125k
  }
821
822
  /* Create compressor input buffer. */
823
152k
  if (use_raw_buffer) {
824
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
825
    /* Synthesize a _JSAMPARRAY pointer structure */
826
1.03k
    source->pixrow = (_JSAMPROW)source->iobuffer;
827
1.03k
    source->pub._buffer = &source->pixrow;
828
1.03k
    source->pub.buffer_height = 1;
829
151k
  } else {
830
    /* Need to translate anyway, so make a separate sample buffer. */
831
151k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
832
151k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
833
151k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
834
151k
    source->pub.buffer_height = 1;
835
151k
  }
836
837
  /* Compute the rescaling array if required. */
838
152k
  if (need_rescale) {
839
151k
    long val, half_maxval;
840
841
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
842
151k
    source->rescale = (_JSAMPLE *)
843
151k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
844
151k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
845
151k
                                           sizeof(_JSAMPLE)));
846
151k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
847
151k
                                        sizeof(_JSAMPLE)));
848
151k
    half_maxval = maxval / 2;
849
429M
    for (val = 0; val <= (long)maxval; val++) {
850
      /* The multiplication here must be done in 32 bits to avoid overflow */
851
429M
      source->rescale[val] =
852
429M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
853
429M
                   maxval);
854
429M
    }
855
151k
  }
856
152k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
665
93.7k
{
666
93.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
667
93.7k
  int c;
668
93.7k
  unsigned int w, h, maxval;
669
93.7k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
670
671
93.7k
  if (getc(source->pub.input_file) != 'P')
672
0
    ERREXIT(cinfo, JERR_PPM_NOT);
673
674
93.7k
  c = getc(source->pub.input_file); /* subformat discriminator character */
675
676
  /* detect unsupported variants (ie, PBM) before trying to read header */
677
93.7k
  switch (c) {
678
8.04k
  case '2':                     /* it's a text-format PGM file */
679
17.1k
  case '3':                     /* it's a text-format PPM file */
680
74.5k
  case '5':                     /* it's a raw-format PGM file */
681
93.6k
  case '6':                     /* it's a raw-format PPM file */
682
93.6k
    break;
683
81
  default:
684
81
    ERREXIT(cinfo, JERR_PPM_NOT);
685
81
    break;
686
93.7k
  }
687
688
  /* fetch the remaining header info */
689
93.6k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
690
93.6k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
691
93.6k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
692
693
93.6k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
694
174
    ERREXIT(cinfo, JERR_PPM_NOT);
695
93.6k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
696
1.40k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
697
698
93.6k
  cinfo->image_width = (JDIMENSION)w;
699
93.6k
  cinfo->image_height = (JDIMENSION)h;
700
93.6k
  source->maxval = maxval;
701
702
  /* initialize flags to most common settings */
703
93.6k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
704
93.6k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
705
93.6k
  need_rescale = TRUE;          /* do we need a rescale array? */
706
707
93.6k
  switch (c) {
708
6.09k
  case '2':                     /* it's a text-format PGM file */
709
6.09k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
710
6.09k
        cinfo->in_color_space == JCS_RGB)
711
0
      cinfo->in_color_space = JCS_GRAYSCALE;
712
6.09k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
713
6.09k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
714
907
      source->pub.get_pixel_rows = get_text_gray_row;
715
5.18k
    else if (IsExtRGB(cinfo->in_color_space))
716
4.53k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
717
648
    else if (cinfo->in_color_space == JCS_CMYK)
718
648
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
719
0
    else
720
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
721
6.09k
    need_iobuffer = FALSE;
722
6.09k
    break;
723
724
7.09k
  case '3':                     /* it's a text-format PPM file */
725
7.09k
    if (cinfo->in_color_space == JCS_UNKNOWN)
726
0
      cinfo->in_color_space = JCS_EXT_RGB;
727
7.09k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
728
7.09k
    if (IsExtRGB(cinfo->in_color_space))
729
5.23k
      source->pub.get_pixel_rows = get_text_rgb_row;
730
1.85k
    else if (cinfo->in_color_space == JCS_CMYK)
731
810
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
732
1.04k
    else
733
1.04k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
734
7.09k
    need_iobuffer = FALSE;
735
7.09k
    break;
736
737
55.0k
  case '5':                     /* it's a raw-format PGM file */
738
55.0k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
739
55.0k
        cinfo->in_color_space == JCS_RGB)
740
0
      cinfo->in_color_space = JCS_GRAYSCALE;
741
55.0k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
742
55.0k
    if (maxval > 255) {
743
4.03k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
744
602
        source->pub.get_pixel_rows = get_word_gray_row;
745
3.43k
      else if (IsExtRGB(cinfo->in_color_space))
746
3.01k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
747
421
      else if (cinfo->in_color_space == JCS_CMYK)
748
421
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
749
0
      else
750
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
751
51.0k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
752
51.0k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
753
4.11k
               cinfo->in_color_space == JCS_GRAYSCALE) {
754
672
      source->pub.get_pixel_rows = get_raw_row;
755
672
      use_raw_buffer = TRUE;
756
672
      need_rescale = FALSE;
757
50.3k
    } else {
758
50.3k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
759
7.08k
        source->pub.get_pixel_rows = get_scaled_gray_row;
760
43.2k
      else if (IsExtRGB(cinfo->in_color_space))
761
38.7k
        source->pub.get_pixel_rows = get_gray_rgb_row;
762
4.48k
      else if (cinfo->in_color_space == JCS_CMYK)
763
4.48k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
764
0
      else
765
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
766
50.3k
    }
767
55.0k
    break;
768
769
17.4k
  case '6':                     /* it's a raw-format PPM file */
770
17.4k
    if (cinfo->in_color_space == JCS_UNKNOWN)
771
0
      cinfo->in_color_space = JCS_EXT_RGB;
772
17.4k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
773
17.4k
    if (maxval > 255) {
774
5.62k
      if (IsExtRGB(cinfo->in_color_space))
775
4.17k
        source->pub.get_pixel_rows = get_word_rgb_row;
776
1.45k
      else if (cinfo->in_color_space == JCS_CMYK)
777
616
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
778
835
      else
779
835
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
780
11.8k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
781
11.8k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
782
2.52k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
783
2.52k
               (cinfo->in_color_space == JCS_EXT_RGB ||
784
2.16k
                cinfo->in_color_space == JCS_RGB)) {
785
#else
786
               cinfo->in_color_space == JCS_EXT_RGB) {
787
#endif
788
360
      source->pub.get_pixel_rows = get_raw_row;
789
360
      use_raw_buffer = TRUE;
790
360
      need_rescale = FALSE;
791
11.5k
    } else {
792
11.5k
      if (IsExtRGB(cinfo->in_color_space))
793
8.49k
        source->pub.get_pixel_rows = get_rgb_row;
794
3.01k
      else if (cinfo->in_color_space == JCS_CMYK)
795
1.24k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
796
1.77k
      else
797
1.77k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
798
11.5k
    }
799
17.4k
    break;
800
93.6k
  }
801
802
82.0k
  if (IsExtRGB(cinfo->in_color_space))
803
64.5k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
804
17.4k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
805
9.26k
    cinfo->input_components = 1;
806
8.22k
  else if (cinfo->in_color_space == JCS_CMYK)
807
8.22k
    cinfo->input_components = 4;
808
809
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
810
82.0k
  if (need_iobuffer) {
811
69.9k
    if (c == '6')
812
14.8k
      source->buffer_width = (size_t)w * 3 *
813
14.8k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
814
55.0k
    else
815
55.0k
      source->buffer_width = (size_t)w *
816
55.0k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
817
69.9k
    source->iobuffer = (U_CHAR *)
818
69.9k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
819
69.9k
                                  source->buffer_width);
820
69.9k
  }
821
822
  /* Create compressor input buffer. */
823
82.0k
  if (use_raw_buffer) {
824
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
825
    /* Synthesize a _JSAMPARRAY pointer structure */
826
1.03k
    source->pixrow = (_JSAMPROW)source->iobuffer;
827
1.03k
    source->pub._buffer = &source->pixrow;
828
1.03k
    source->pub.buffer_height = 1;
829
81.0k
  } else {
830
    /* Need to translate anyway, so make a separate sample buffer. */
831
81.0k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
832
81.0k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
833
81.0k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
834
81.0k
    source->pub.buffer_height = 1;
835
81.0k
  }
836
837
  /* Compute the rescaling array if required. */
838
82.0k
  if (need_rescale) {
839
81.0k
    long val, half_maxval;
840
841
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
842
81.0k
    source->rescale = (_JSAMPLE *)
843
81.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
844
81.0k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
845
81.0k
                                           sizeof(_JSAMPLE)));
846
81.0k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
847
81.0k
                                        sizeof(_JSAMPLE)));
848
81.0k
    half_maxval = maxval / 2;
849
113M
    for (val = 0; val <= (long)maxval; val++) {
850
      /* The multiplication here must be done in 32 bits to avoid overflow */
851
113M
      source->rescale[val] =
852
113M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
853
113M
                   maxval);
854
113M
    }
855
81.0k
  }
856
82.0k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
665
59.8k
{
666
59.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
667
59.8k
  int c;
668
59.8k
  unsigned int w, h, maxval;
669
59.8k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
670
671
59.8k
  if (getc(source->pub.input_file) != 'P')
672
0
    ERREXIT(cinfo, JERR_PPM_NOT);
673
674
59.8k
  c = getc(source->pub.input_file); /* subformat discriminator character */
675
676
  /* detect unsupported variants (ie, PBM) before trying to read header */
677
59.8k
  switch (c) {
678
6.02k
  case '2':                     /* it's a text-format PGM file */
679
12.7k
  case '3':                     /* it's a text-format PPM file */
680
46.8k
  case '5':                     /* it's a raw-format PGM file */
681
59.7k
  case '6':                     /* it's a raw-format PPM file */
682
59.7k
    break;
683
49
  default:
684
49
    ERREXIT(cinfo, JERR_PPM_NOT);
685
49
    break;
686
59.8k
  }
687
688
  /* fetch the remaining header info */
689
59.7k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
690
59.7k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
691
59.7k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
692
693
59.7k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
694
126
    ERREXIT(cinfo, JERR_PPM_NOT);
695
59.7k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
696
973
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
697
698
59.7k
  cinfo->image_width = (JDIMENSION)w;
699
59.7k
  cinfo->image_height = (JDIMENSION)h;
700
59.7k
  source->maxval = maxval;
701
702
  /* initialize flags to most common settings */
703
59.7k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
704
59.7k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
705
59.7k
  need_rescale = TRUE;          /* do we need a rescale array? */
706
707
59.7k
  switch (c) {
708
4.54k
  case '2':                     /* it's a text-format PGM file */
709
4.54k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
710
4.54k
        cinfo->in_color_space == JCS_RGB)
711
0
      cinfo->in_color_space = JCS_GRAYSCALE;
712
4.54k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
713
4.54k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
714
649
      source->pub.get_pixel_rows = get_text_gray_row;
715
3.89k
    else if (IsExtRGB(cinfo->in_color_space))
716
3.24k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
717
649
    else if (cinfo->in_color_space == JCS_CMYK)
718
649
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
719
0
    else
720
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
721
4.54k
    need_iobuffer = FALSE;
722
4.54k
    break;
723
724
5.40k
  case '3':                     /* it's a text-format PPM file */
725
5.40k
    if (cinfo->in_color_space == JCS_UNKNOWN)
726
0
      cinfo->in_color_space = JCS_EXT_RGB;
727
5.40k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
728
5.40k
    if (IsExtRGB(cinfo->in_color_space))
729
3.86k
      source->pub.get_pixel_rows = get_text_rgb_row;
730
1.54k
    else if (cinfo->in_color_space == JCS_CMYK)
731
772
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
732
772
    else
733
772
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
734
5.40k
    need_iobuffer = FALSE;
735
5.40k
    break;
736
737
32.4k
  case '5':                     /* it's a raw-format PGM file */
738
32.4k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
739
32.4k
        cinfo->in_color_space == JCS_RGB)
740
0
      cinfo->in_color_space = JCS_GRAYSCALE;
741
32.4k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
742
32.4k
    if (maxval > 255) {
743
2.94k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
744
420
        source->pub.get_pixel_rows = get_word_gray_row;
745
2.52k
      else if (IsExtRGB(cinfo->in_color_space))
746
2.10k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
747
420
      else if (cinfo->in_color_space == JCS_CMYK)
748
420
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
749
0
      else
750
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
751
29.4k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
752
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
753
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
754
0
      source->pub.get_pixel_rows = get_raw_row;
755
0
      use_raw_buffer = TRUE;
756
0
      need_rescale = FALSE;
757
29.4k
    } else {
758
29.4k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
759
4.21k
        source->pub.get_pixel_rows = get_scaled_gray_row;
760
25.2k
      else if (IsExtRGB(cinfo->in_color_space))
761
21.0k
        source->pub.get_pixel_rows = get_gray_rgb_row;
762
4.21k
      else if (cinfo->in_color_space == JCS_CMYK)
763
4.21k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
764
0
      else
765
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
766
29.4k
    }
767
32.4k
    break;
768
769
11.8k
  case '6':                     /* it's a raw-format PPM file */
770
11.8k
    if (cinfo->in_color_space == JCS_UNKNOWN)
771
0
      cinfo->in_color_space = JCS_EXT_RGB;
772
11.8k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
773
11.8k
    if (maxval > 255) {
774
4.80k
      if (IsExtRGB(cinfo->in_color_space))
775
3.43k
        source->pub.get_pixel_rows = get_word_rgb_row;
776
1.37k
      else if (cinfo->in_color_space == JCS_CMYK)
777
686
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
778
686
      else
779
686
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
780
7.02k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
781
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
782
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
783
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
784
0
                cinfo->in_color_space == JCS_RGB)) {
785
#else
786
               cinfo->in_color_space == JCS_EXT_RGB) {
787
#endif
788
0
      source->pub.get_pixel_rows = get_raw_row;
789
0
      use_raw_buffer = TRUE;
790
0
      need_rescale = FALSE;
791
7.02k
    } else {
792
7.02k
      if (IsExtRGB(cinfo->in_color_space))
793
5.02k
        source->pub.get_pixel_rows = get_rgb_row;
794
2.00k
      else if (cinfo->in_color_space == JCS_CMYK)
795
1.00k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
796
1.00k
      else
797
1.00k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
798
7.02k
    }
799
11.8k
    break;
800
59.7k
  }
801
802
51.7k
  if (IsExtRGB(cinfo->in_color_space))
803
38.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
804
13.0k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
805
5.28k
    cinfo->input_components = 1;
806
7.74k
  else if (cinfo->in_color_space == JCS_CMYK)
807
7.74k
    cinfo->input_components = 4;
808
809
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
810
51.7k
  if (need_iobuffer) {
811
42.5k
    if (c == '6')
812
10.1k
      source->buffer_width = (size_t)w * 3 *
813
10.1k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
814
32.4k
    else
815
32.4k
      source->buffer_width = (size_t)w *
816
32.4k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
817
42.5k
    source->iobuffer = (U_CHAR *)
818
42.5k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
819
42.5k
                                  source->buffer_width);
820
42.5k
  }
821
822
  /* Create compressor input buffer. */
823
51.7k
  if (use_raw_buffer) {
824
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
825
    /* Synthesize a _JSAMPARRAY pointer structure */
826
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
827
0
    source->pub._buffer = &source->pixrow;
828
0
    source->pub.buffer_height = 1;
829
51.7k
  } else {
830
    /* Need to translate anyway, so make a separate sample buffer. */
831
51.7k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
832
51.7k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
833
51.7k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
834
51.7k
    source->pub.buffer_height = 1;
835
51.7k
  }
836
837
  /* Compute the rescaling array if required. */
838
51.7k
  if (need_rescale) {
839
51.7k
    long val, half_maxval;
840
841
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
842
51.7k
    source->rescale = (_JSAMPLE *)
843
51.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
844
51.7k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
845
51.7k
                                           sizeof(_JSAMPLE)));
846
51.7k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
847
51.7k
                                        sizeof(_JSAMPLE)));
848
51.7k
    half_maxval = maxval / 2;
849
146M
    for (val = 0; val <= (long)maxval; val++) {
850
      /* The multiplication here must be done in 32 bits to avoid overflow */
851
146M
      source->rescale[val] =
852
146M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
853
146M
                   maxval);
854
146M
    }
855
51.7k
  }
856
51.7k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
665
22.1k
{
666
22.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
667
22.1k
  int c;
668
22.1k
  unsigned int w, h, maxval;
669
22.1k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
670
671
22.1k
  if (getc(source->pub.input_file) != 'P')
672
0
    ERREXIT(cinfo, JERR_PPM_NOT);
673
674
22.1k
  c = getc(source->pub.input_file); /* subformat discriminator character */
675
676
  /* detect unsupported variants (ie, PBM) before trying to read header */
677
22.1k
  switch (c) {
678
3.17k
  case '2':                     /* it's a text-format PGM file */
679
6.80k
  case '3':                     /* it's a text-format PPM file */
680
17.2k
  case '5':                     /* it's a raw-format PGM file */
681
22.1k
  case '6':                     /* it's a raw-format PPM file */
682
22.1k
    break;
683
35
  default:
684
35
    ERREXIT(cinfo, JERR_PPM_NOT);
685
35
    break;
686
22.1k
  }
687
688
  /* fetch the remaining header info */
689
22.1k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
690
22.1k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
691
22.1k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
692
693
22.1k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
694
70
    ERREXIT(cinfo, JERR_PPM_NOT);
695
22.1k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
696
490
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
697
698
22.1k
  cinfo->image_width = (JDIMENSION)w;
699
22.1k
  cinfo->image_height = (JDIMENSION)h;
700
22.1k
  source->maxval = maxval;
701
702
  /* initialize flags to most common settings */
703
22.1k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
704
22.1k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
705
22.1k
  need_rescale = TRUE;          /* do we need a rescale array? */
706
707
22.1k
  switch (c) {
708
2.49k
  case '2':                     /* it's a text-format PGM file */
709
2.49k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
710
2.49k
        cinfo->in_color_space == JCS_RGB)
711
0
      cinfo->in_color_space = JCS_GRAYSCALE;
712
2.49k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
713
2.49k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
714
357
      source->pub.get_pixel_rows = get_text_gray_row;
715
2.14k
    else if (IsExtRGB(cinfo->in_color_space))
716
1.78k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
717
357
    else if (cinfo->in_color_space == JCS_CMYK)
718
357
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
719
0
    else
720
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
721
2.49k
    need_iobuffer = FALSE;
722
2.49k
    break;
723
724
2.84k
  case '3':                     /* it's a text-format PPM file */
725
2.84k
    if (cinfo->in_color_space == JCS_UNKNOWN)
726
0
      cinfo->in_color_space = JCS_EXT_RGB;
727
2.84k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
728
2.84k
    if (IsExtRGB(cinfo->in_color_space))
729
2.03k
      source->pub.get_pixel_rows = get_text_rgb_row;
730
814
    else if (cinfo->in_color_space == JCS_CMYK)
731
407
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
732
407
    else
733
407
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
734
2.84k
    need_iobuffer = FALSE;
735
2.84k
    break;
736
737
9.66k
  case '5':                     /* it's a raw-format PGM file */
738
9.66k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
739
9.66k
        cinfo->in_color_space == JCS_RGB)
740
0
      cinfo->in_color_space = JCS_GRAYSCALE;
741
9.66k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
742
9.66k
    if (maxval > 255) {
743
1.66k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
744
238
        source->pub.get_pixel_rows = get_word_gray_row;
745
1.42k
      else if (IsExtRGB(cinfo->in_color_space))
746
1.19k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
747
238
      else if (cinfo->in_color_space == JCS_CMYK)
748
238
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
749
0
      else
750
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
751
8.00k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
752
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
753
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
754
0
      source->pub.get_pixel_rows = get_raw_row;
755
0
      use_raw_buffer = TRUE;
756
0
      need_rescale = FALSE;
757
8.00k
    } else {
758
8.00k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
759
1.14k
        source->pub.get_pixel_rows = get_scaled_gray_row;
760
6.85k
      else if (IsExtRGB(cinfo->in_color_space))
761
5.71k
        source->pub.get_pixel_rows = get_gray_rgb_row;
762
1.14k
      else if (cinfo->in_color_space == JCS_CMYK)
763
1.14k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
764
0
      else
765
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
766
8.00k
    }
767
9.66k
    break;
768
769
4.34k
  case '6':                     /* it's a raw-format PPM file */
770
4.34k
    if (cinfo->in_color_space == JCS_UNKNOWN)
771
0
      cinfo->in_color_space = JCS_EXT_RGB;
772
4.34k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
773
4.34k
    if (maxval > 255) {
774
2.32k
      if (IsExtRGB(cinfo->in_color_space))
775
1.66k
        source->pub.get_pixel_rows = get_word_rgb_row;
776
664
      else if (cinfo->in_color_space == JCS_CMYK)
777
332
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
778
332
      else
779
332
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
780
2.32k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
781
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
782
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
783
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
784
0
                cinfo->in_color_space == JCS_RGB)) {
785
#else
786
               cinfo->in_color_space == JCS_EXT_RGB) {
787
#endif
788
0
      source->pub.get_pixel_rows = get_raw_row;
789
0
      use_raw_buffer = TRUE;
790
0
      need_rescale = FALSE;
791
2.02k
    } else {
792
2.02k
      if (IsExtRGB(cinfo->in_color_space))
793
1.44k
        source->pub.get_pixel_rows = get_rgb_row;
794
578
      else if (cinfo->in_color_space == JCS_CMYK)
795
289
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
796
289
      else
797
289
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
798
2.02k
    }
799
4.34k
    break;
800
22.1k
  }
801
802
18.3k
  if (IsExtRGB(cinfo->in_color_space))
803
13.8k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
804
4.50k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
805
1.73k
    cinfo->input_components = 1;
806
2.76k
  else if (cinfo->in_color_space == JCS_CMYK)
807
2.76k
    cinfo->input_components = 4;
808
809
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
810
18.3k
  if (need_iobuffer) {
811
13.3k
    if (c == '6')
812
3.72k
      source->buffer_width = (size_t)w * 3 *
813
3.72k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
814
9.66k
    else
815
9.66k
      source->buffer_width = (size_t)w *
816
9.66k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
817
13.3k
    source->iobuffer = (U_CHAR *)
818
13.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
819
13.3k
                                  source->buffer_width);
820
13.3k
  }
821
822
  /* Create compressor input buffer. */
823
18.3k
  if (use_raw_buffer) {
824
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
825
    /* Synthesize a _JSAMPARRAY pointer structure */
826
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
827
0
    source->pub._buffer = &source->pixrow;
828
0
    source->pub.buffer_height = 1;
829
18.3k
  } else {
830
    /* Need to translate anyway, so make a separate sample buffer. */
831
18.3k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
832
18.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
833
18.3k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
834
18.3k
    source->pub.buffer_height = 1;
835
18.3k
  }
836
837
  /* Compute the rescaling array if required. */
838
18.3k
  if (need_rescale) {
839
18.3k
    long val, half_maxval;
840
841
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
842
18.3k
    source->rescale = (_JSAMPLE *)
843
18.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
844
18.3k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
845
18.3k
                                           sizeof(_JSAMPLE)));
846
18.3k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
847
18.3k
                                        sizeof(_JSAMPLE)));
848
18.3k
    half_maxval = maxval / 2;
849
168M
    for (val = 0; val <= (long)maxval; val++) {
850
      /* The multiplication here must be done in 32 bits to avoid overflow */
851
168M
      source->rescale[val] =
852
168M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
853
168M
                   maxval);
854
168M
    }
855
18.3k
  }
856
18.3k
}
857
858
859
/*
860
 * Finish up at the end of the file.
861
 */
862
863
METHODDEF(void)
864
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
865
95.7k
{
866
  /* no work */
867
95.7k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
865
53.7k
{
866
  /* no work */
867
53.7k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
865
33.6k
{
866
  /* no work */
867
33.6k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
865
8.36k
{
866
  /* no work */
867
8.36k
}
868
869
870
/*
871
 * The module selection routine for PPM format input.
872
 */
873
874
GLOBAL(cjpeg_source_ptr)
875
_jinit_read_ppm(j_compress_ptr cinfo)
876
175k
{
877
175k
  ppm_source_ptr source;
878
879
#if BITS_IN_JSAMPLE == 8
880
93.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
881
#else
882
81.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
883
81.9k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
884
0
#endif
885
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
886
887
  /* Create module interface object */
888
175k
  source = (ppm_source_ptr)
889
175k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
890
175k
                                sizeof(ppm_source_struct));
891
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
892
175k
  source->pub.start_input = start_input_ppm;
893
175k
  source->pub.finish_input = finish_input_ppm;
894
175k
  source->pub.max_pixels = 0;
895
896
175k
  return (cjpeg_source_ptr)source;
897
175k
}
jinit_read_ppm
Line
Count
Source
876
93.7k
{
877
93.7k
  ppm_source_ptr source;
878
879
93.7k
#if BITS_IN_JSAMPLE == 8
880
93.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
881
#else
882
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
883
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
884
#endif
885
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
886
887
  /* Create module interface object */
888
93.7k
  source = (ppm_source_ptr)
889
93.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
890
93.7k
                                sizeof(ppm_source_struct));
891
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
892
93.7k
  source->pub.start_input = start_input_ppm;
893
93.7k
  source->pub.finish_input = finish_input_ppm;
894
93.7k
  source->pub.max_pixels = 0;
895
896
93.7k
  return (cjpeg_source_ptr)source;
897
93.7k
}
j12init_read_ppm
Line
Count
Source
876
59.8k
{
877
59.8k
  ppm_source_ptr source;
878
879
#if BITS_IN_JSAMPLE == 8
880
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
881
#else
882
59.8k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
883
59.8k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
884
0
#endif
885
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
886
887
  /* Create module interface object */
888
59.8k
  source = (ppm_source_ptr)
889
59.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
890
59.8k
                                sizeof(ppm_source_struct));
891
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
892
59.8k
  source->pub.start_input = start_input_ppm;
893
59.8k
  source->pub.finish_input = finish_input_ppm;
894
59.8k
  source->pub.max_pixels = 0;
895
896
59.8k
  return (cjpeg_source_ptr)source;
897
59.8k
}
j16init_read_ppm
Line
Count
Source
876
22.1k
{
877
22.1k
  ppm_source_ptr source;
878
879
#if BITS_IN_JSAMPLE == 8
880
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
881
#else
882
22.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
883
22.1k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
884
0
#endif
885
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
886
887
  /* Create module interface object */
888
22.1k
  source = (ppm_source_ptr)
889
22.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
890
22.1k
                                sizeof(ppm_source_struct));
891
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
892
22.1k
  source->pub.start_input = start_input_ppm;
893
22.1k
  source->pub.finish_input = finish_input_ppm;
894
22.1k
  source->pub.max_pixels = 0;
895
896
22.1k
  return (cjpeg_source_ptr)source;
897
22.1k
}
898
899
#endif /* defined(PPM_SUPPORTED) &&
900
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */