Coverage Report

Created: 2026-10-08 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.1.x/src/rdppm.c
Line
Count
Source
1
/*
2
 * rdppm.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * Modified 2009 by Bill Allombert, Guido Vollbeding.
7
 * libjpeg-turbo Modifications:
8
 * Copyright (C) 2015-2017, 2020-2026, D. R. Commander.
9
 * For conditions of distribution and use, see the accompanying README.ijg
10
 * file.
11
 *
12
 * This file contains routines to read input images in PPM/PGM format.
13
 * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
14
 * The PBMPLUS library is NOT required to compile this software
15
 * (but it is highly useful as a set of PPM image manipulation programs).
16
 *
17
 * These routines may need modification for non-Unix environments or
18
 * specialized applications.  As they stand, they assume input from
19
 * an ordinary stdio stream.  They further assume that reading begins
20
 * at the start of the file; start_input may need work if the
21
 * user interface has already read some data (e.g., to determine that
22
 * the file is indeed PPM format).
23
 */
24
25
#include "cmyk.h"
26
#include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
27
28
#if defined(PPM_SUPPORTED) && \
29
    (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
30
31
32
/* Portions of this code are based on the PBMPLUS library, which is:
33
**
34
** Copyright (C) 1988 by Jef Poskanzer.
35
**
36
** Permission to use, copy, modify, and distribute this software and its
37
** documentation for any purpose and without fee is hereby granted, provided
38
** that the above copyright notice appear in all copies and that both that
39
** copyright notice and this permission notice appear in supporting
40
** documentation.  This software is provided "as is" without express or
41
** implied warranty.
42
*/
43
44
45
#define ReadOK(file, buffer, len) \
46
252M
  (fread(buffer, 1, len, file) == ((size_t)(len)))
47
48
static int alpha_index[JPEG_NUMCS] = {
49
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
50
};
51
52
53
/* Private version of data source object */
54
55
typedef struct {
56
  struct cjpeg_source_struct pub; /* public fields */
57
58
  /* Usually these two pointers point to the same place: */
59
  unsigned char *iobuffer;      /* fread's I/O buffer */
60
  _JSAMPROW pixrow;             /* compressor input buffer */
61
  size_t buffer_width;          /* width of I/O buffer */
62
  _JSAMPLE *rescale;            /* => maxval-remapping array, or NULL */
63
  unsigned int maxval;
64
} ppm_source_struct;
65
66
typedef ppm_source_struct *ppm_source_ptr;
67
68
69
LOCAL(int)
70
pbm_getc(FILE *infile)
71
/* Read next char, skipping over any comments */
72
/* A comment/newline sequence is returned as a newline */
73
3.75M
{
74
3.75M
  register int ch;
75
76
3.75M
  ch = getc(infile);
77
3.75M
  if (ch == '#') {
78
811k
    do {
79
811k
      ch = getc(infile);
80
811k
    } while (ch != '\n' && ch != EOF);
81
48.5k
  }
82
3.75M
  return ch;
83
3.75M
}
rdppm-8.c:pbm_getc
Line
Count
Source
73
1.71M
{
74
1.71M
  register int ch;
75
76
1.71M
  ch = getc(infile);
77
1.71M
  if (ch == '#') {
78
298k
    do {
79
298k
      ch = getc(infile);
80
298k
    } while (ch != '\n' && ch != EOF);
81
22.9k
  }
82
1.71M
  return ch;
83
1.71M
}
rdppm-12.c:pbm_getc
Line
Count
Source
73
1.42M
{
74
1.42M
  register int ch;
75
76
1.42M
  ch = getc(infile);
77
1.42M
  if (ch == '#') {
78
337k
    do {
79
337k
      ch = getc(infile);
80
337k
    } while (ch != '\n' && ch != EOF);
81
16.2k
  }
82
1.42M
  return ch;
83
1.42M
}
rdppm-16.c:pbm_getc
Line
Count
Source
73
620k
{
74
620k
  register int ch;
75
76
620k
  ch = getc(infile);
77
620k
  if (ch == '#') {
78
175k
    do {
79
175k
      ch = getc(infile);
80
175k
    } while (ch != '\n' && ch != EOF);
81
9.33k
  }
82
620k
  return ch;
83
620k
}
84
85
86
LOCAL(unsigned int)
87
read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
88
/* Read an unsigned decimal integer from the PPM file */
89
/* Swallows one trailing character after the integer */
90
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
91
/* This should not be a problem in practice. */
92
1.61M
{
93
1.61M
  register int ch;
94
1.61M
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
1.72M
  do {
98
1.72M
    ch = pbm_getc(infile);
99
1.72M
    if (ch == EOF)
100
34.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
1.72M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
1.61M
  if (ch < '0' || ch > '9')
104
3.02k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
1.61M
  val = ch - '0';
107
2.06M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
456k
    val *= 10;
109
456k
    val += ch - '0';
110
456k
    if (val > maxval)
111
1.67k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
456k
  }
113
114
1.61M
  return val;
115
1.61M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
92
731k
{
93
731k
  register int ch;
94
731k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
783k
  do {
98
783k
    ch = pbm_getc(infile);
99
783k
    if (ch == EOF)
100
16.7k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
783k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
731k
  if (ch < '0' || ch > '9')
104
1.42k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
731k
  val = ch - '0';
107
945k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
213k
    val *= 10;
109
213k
    val += ch - '0';
110
213k
    if (val > maxval)
111
849
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
213k
  }
113
114
731k
  return val;
115
731k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
92
609k
{
93
609k
  register int ch;
94
609k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
659k
  do {
98
659k
    ch = pbm_getc(infile);
99
659k
    if (ch == EOF)
100
11.5k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
659k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
609k
  if (ch < '0' || ch > '9')
104
1.12k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
609k
  val = ch - '0';
107
779k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
170k
    val *= 10;
109
170k
    val += ch - '0';
110
170k
    if (val > maxval)
111
550
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
170k
  }
113
114
609k
  return val;
115
609k
}
rdppm-16.c:read_pbm_integer
Line
Count
Source
92
269k
{
93
269k
  register int ch;
94
269k
  register unsigned int val;
95
96
  /* Skip any leading whitespace */
97
285k
  do {
98
285k
    ch = pbm_getc(infile);
99
285k
    if (ch == EOF)
100
6.59k
      ERREXIT(cinfo, JERR_INPUT_EOF);
101
285k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
102
103
269k
  if (ch < '0' || ch > '9')
104
480
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
105
106
269k
  val = ch - '0';
107
342k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
108
72.4k
    val *= 10;
109
72.4k
    val += ch - '0';
110
72.4k
    if (val > maxval)
111
271
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
112
72.4k
  }
113
114
269k
  return val;
115
269k
}
116
117
118
/*
119
 * Read one row of pixels.
120
 *
121
 * We provide several different versions depending on input file format.
122
 * In all cases, input is scaled to cinfo->data_precision.
123
 *
124
 * A really fast path is provided for reading byte/sample raw files with
125
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U,
126
 * which is the normal case for 8-bit data.
127
 */
128
129
130
METHODDEF(JDIMENSION)
131
get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
132
/* This version is for reading text-format PGM files with any maxval */
133
21.9k
{
134
21.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
21.9k
  FILE *infile = source->pub.input_file;
136
21.9k
  register _JSAMPROW ptr;
137
21.9k
  register _JSAMPLE *rescale = source->rescale;
138
21.9k
  JDIMENSION col;
139
21.9k
  unsigned int maxval = source->maxval;
140
141
21.9k
  ptr = source->pub._buffer[0];
142
60.8k
  for (col = cinfo->image_width; col > 0; col--) {
143
38.9k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
38.9k
  }
145
21.9k
  return 1;
146
21.9k
}
rdppm-8.c:get_text_gray_row
Line
Count
Source
133
11.6k
{
134
11.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
11.6k
  FILE *infile = source->pub.input_file;
136
11.6k
  register _JSAMPROW ptr;
137
11.6k
  register _JSAMPLE *rescale = source->rescale;
138
11.6k
  JDIMENSION col;
139
11.6k
  unsigned int maxval = source->maxval;
140
141
11.6k
  ptr = source->pub._buffer[0];
142
32.2k
  for (col = cinfo->image_width; col > 0; col--) {
143
20.5k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
20.5k
  }
145
11.6k
  return 1;
146
11.6k
}
rdppm-12.c:get_text_gray_row
Line
Count
Source
133
6.77k
{
134
6.77k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
6.77k
  FILE *infile = source->pub.input_file;
136
6.77k
  register _JSAMPROW ptr;
137
6.77k
  register _JSAMPLE *rescale = source->rescale;
138
6.77k
  JDIMENSION col;
139
6.77k
  unsigned int maxval = source->maxval;
140
141
6.77k
  ptr = source->pub._buffer[0];
142
18.1k
  for (col = cinfo->image_width; col > 0; col--) {
143
11.3k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
11.3k
  }
145
6.77k
  return 1;
146
6.77k
}
rdppm-16.c:get_text_gray_row
Line
Count
Source
133
3.52k
{
134
3.52k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
135
3.52k
  FILE *infile = source->pub.input_file;
136
3.52k
  register _JSAMPROW ptr;
137
3.52k
  register _JSAMPLE *rescale = source->rescale;
138
3.52k
  JDIMENSION col;
139
3.52k
  unsigned int maxval = source->maxval;
140
141
3.52k
  ptr = source->pub._buffer[0];
142
10.4k
  for (col = cinfo->image_width; col > 0; col--) {
143
6.95k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
144
6.95k
  }
145
3.52k
  return 1;
146
3.52k
}
147
148
149
178M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
150
903M
  for (col = cinfo->image_width; col > 0; col--) { \
151
724M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
152
724M
    alpha_set_op \
153
724M
    ptr += ps; \
154
724M
  } \
155
178M
}
156
157
METHODDEF(JDIMENSION)
158
get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
159
/* This version is for reading text-format PGM files with any maxval and
160
   converting to extended RGB */
161
105k
{
162
105k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
105k
  FILE *infile = source->pub.input_file;
164
105k
  register _JSAMPROW ptr;
165
105k
  register _JSAMPLE *rescale = source->rescale;
166
105k
  JDIMENSION col;
167
105k
  unsigned int maxval = source->maxval;
168
105k
  register int rindex = rgb_red[cinfo->in_color_space];
169
105k
  register int gindex = rgb_green[cinfo->in_color_space];
170
105k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
105k
  register int aindex = alpha_index[cinfo->in_color_space];
172
105k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
105k
  ptr = source->pub._buffer[0];
175
105k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
16.8k
    if (aindex >= 0)
177
2.63k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
16.8k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
14.2k
    else
180
14.2k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
88.5k
  } else {
182
88.5k
    if (aindex >= 0)
183
14.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
88.5k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
73.9k
    else
186
73.9k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
88.5k
  }
188
105k
  return 1;
189
105k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
161
53.9k
{
162
53.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
53.9k
  FILE *infile = source->pub.input_file;
164
53.9k
  register _JSAMPROW ptr;
165
53.9k
  register _JSAMPLE *rescale = source->rescale;
166
53.9k
  JDIMENSION col;
167
53.9k
  unsigned int maxval = source->maxval;
168
53.9k
  register int rindex = rgb_red[cinfo->in_color_space];
169
53.9k
  register int gindex = rgb_green[cinfo->in_color_space];
170
53.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
53.9k
  register int aindex = alpha_index[cinfo->in_color_space];
172
53.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
53.9k
  ptr = source->pub._buffer[0];
175
53.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
10.1k
    if (aindex >= 0)
177
1.11k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
10.1k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
8.98k
    else
180
8.98k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
43.8k
  } else {
182
43.8k
    if (aindex >= 0)
183
5.79k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
43.8k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
38.0k
    else
186
38.0k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
43.8k
  }
188
53.9k
  return 1;
189
53.9k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
161
33.8k
{
162
33.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
33.8k
  FILE *infile = source->pub.input_file;
164
33.8k
  register _JSAMPROW ptr;
165
33.8k
  register _JSAMPLE *rescale = source->rescale;
166
33.8k
  JDIMENSION col;
167
33.8k
  unsigned int maxval = source->maxval;
168
33.8k
  register int rindex = rgb_red[cinfo->in_color_space];
169
33.8k
  register int gindex = rgb_green[cinfo->in_color_space];
170
33.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
33.8k
  register int aindex = alpha_index[cinfo->in_color_space];
172
33.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
33.8k
  ptr = source->pub._buffer[0];
175
33.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
4.57k
    if (aindex >= 0)
177
933
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
4.57k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
3.64k
    else
180
3.64k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
29.2k
  } else {
182
29.2k
    if (aindex >= 0)
183
5.84k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
29.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
23.4k
    else
186
23.4k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
29.2k
  }
188
33.8k
  return 1;
189
33.8k
}
rdppm-16.c:get_text_gray_rgb_row
Line
Count
Source
161
17.6k
{
162
17.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
163
17.6k
  FILE *infile = source->pub.input_file;
164
17.6k
  register _JSAMPROW ptr;
165
17.6k
  register _JSAMPLE *rescale = source->rescale;
166
17.6k
  JDIMENSION col;
167
17.6k
  unsigned int maxval = source->maxval;
168
17.6k
  register int rindex = rgb_red[cinfo->in_color_space];
169
17.6k
  register int gindex = rgb_green[cinfo->in_color_space];
170
17.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
171
17.6k
  register int aindex = alpha_index[cinfo->in_color_space];
172
17.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
173
174
17.6k
  ptr = source->pub._buffer[0];
175
17.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
176
2.21k
    if (aindex >= 0)
177
588
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
178
2.21k
                         ptr[aindex] = (_JSAMPLE)maxval;)
179
1.62k
    else
180
1.62k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
181
15.4k
  } else {
182
15.4k
    if (aindex >= 0)
183
2.93k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
184
15.4k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
185
12.4k
    else
186
12.4k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
187
15.4k
  }
188
17.6k
  return 1;
189
17.6k
}
190
191
192
METHODDEF(JDIMENSION)
193
get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
194
/* This version is for reading text-format PGM files with any maxval and
195
   converting to CMYK */
196
17.2k
{
197
17.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
17.2k
  FILE *infile = source->pub.input_file;
199
17.2k
  register _JSAMPROW ptr;
200
17.2k
  register _JSAMPLE *rescale = source->rescale;
201
17.2k
  JDIMENSION col;
202
17.2k
  unsigned int maxval = source->maxval;
203
204
17.2k
  ptr = source->pub._buffer[0];
205
17.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
11.3k
    for (col = cinfo->image_width; col > 0; col--) {
207
7.90k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
7.90k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
7.90k
      ptr += 4;
210
7.90k
    }
211
13.7k
  } else {
212
36.4k
    for (col = cinfo->image_width; col > 0; col--) {
213
22.7k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
22.7k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
22.7k
                  ptr + 1, ptr + 2, ptr + 3);
216
22.7k
      ptr += 4;
217
22.7k
    }
218
13.7k
  }
219
17.2k
  return 1;
220
17.2k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
196
6.90k
{
197
6.90k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
6.90k
  FILE *infile = source->pub.input_file;
199
6.90k
  register _JSAMPROW ptr;
200
6.90k
  register _JSAMPLE *rescale = source->rescale;
201
6.90k
  JDIMENSION col;
202
6.90k
  unsigned int maxval = source->maxval;
203
204
6.90k
  ptr = source->pub._buffer[0];
205
6.90k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
5.25k
    for (col = cinfo->image_width; col > 0; col--) {
207
3.57k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
3.57k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
3.57k
      ptr += 4;
210
3.57k
    }
211
5.22k
  } else {
212
13.9k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.69k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
8.69k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
8.69k
                  ptr + 1, ptr + 2, ptr + 3);
216
8.69k
      ptr += 4;
217
8.69k
    }
218
5.22k
  }
219
6.90k
  return 1;
220
6.90k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
196
6.77k
{
197
6.77k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
6.77k
  FILE *infile = source->pub.input_file;
199
6.77k
  register _JSAMPROW ptr;
200
6.77k
  register _JSAMPLE *rescale = source->rescale;
201
6.77k
  JDIMENSION col;
202
6.77k
  unsigned int maxval = source->maxval;
203
204
6.77k
  ptr = source->pub._buffer[0];
205
6.77k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
3.64k
    for (col = cinfo->image_width; col > 0; col--) {
207
2.53k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
2.53k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
2.53k
      ptr += 4;
210
2.53k
    }
211
5.66k
  } else {
212
14.5k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.86k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
8.86k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
8.86k
                  ptr + 1, ptr + 2, ptr + 3);
216
8.86k
      ptr += 4;
217
8.86k
    }
218
5.66k
  }
219
6.77k
  return 1;
220
6.77k
}
rdppm-16.c:get_text_gray_cmyk_row
Line
Count
Source
196
3.52k
{
197
3.52k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
198
3.52k
  FILE *infile = source->pub.input_file;
199
3.52k
  register _JSAMPROW ptr;
200
3.52k
  register _JSAMPLE *rescale = source->rescale;
201
3.52k
  JDIMENSION col;
202
3.52k
  unsigned int maxval = source->maxval;
203
204
3.52k
  ptr = source->pub._buffer[0];
205
3.52k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
206
2.42k
    for (col = cinfo->image_width; col > 0; col--) {
207
1.79k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
208
1.79k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
209
1.79k
      ptr += 4;
210
1.79k
    }
211
2.89k
  } else {
212
8.05k
    for (col = cinfo->image_width; col > 0; col--) {
213
5.15k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
214
5.15k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
215
5.15k
                  ptr + 1, ptr + 2, ptr + 3);
216
5.15k
      ptr += 4;
217
5.15k
    }
218
2.89k
  }
219
3.52k
  return 1;
220
3.52k
}
221
222
223
9.16M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
224
85.2M
  for (col = cinfo->image_width; col > 0; col--) { \
225
76.0M
    ptr[rindex] = read_op; \
226
76.0M
    ptr[gindex] = read_op; \
227
76.0M
    ptr[bindex] = read_op; \
228
76.0M
    alpha_set_op \
229
76.0M
    ptr += ps; \
230
76.0M
  } \
231
9.16M
}
232
233
METHODDEF(JDIMENSION)
234
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
235
/* This version is for reading text-format PPM files with any maxval */
236
132k
{
237
132k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
132k
  FILE *infile = source->pub.input_file;
239
132k
  register _JSAMPROW ptr;
240
132k
  register _JSAMPLE *rescale = source->rescale;
241
132k
  JDIMENSION col;
242
132k
  unsigned int maxval = source->maxval;
243
132k
  register int rindex = rgb_red[cinfo->in_color_space];
244
132k
  register int gindex = rgb_green[cinfo->in_color_space];
245
132k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
132k
  register int aindex = alpha_index[cinfo->in_color_space];
247
132k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
132k
  ptr = source->pub._buffer[0];
250
132k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
40.1k
    if (aindex >= 0)
252
6.20k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
40.1k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
33.9k
    else
255
33.9k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
92.0k
  } else {
257
92.0k
    if (aindex >= 0)
258
16.3k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
92.0k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
75.6k
    else
261
75.6k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
92.0k
  }
263
132k
  return 1;
264
132k
}
rdppm-8.c:get_text_rgb_row
Line
Count
Source
236
56.1k
{
237
56.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
56.1k
  FILE *infile = source->pub.input_file;
239
56.1k
  register _JSAMPROW ptr;
240
56.1k
  register _JSAMPLE *rescale = source->rescale;
241
56.1k
  JDIMENSION col;
242
56.1k
  unsigned int maxval = source->maxval;
243
56.1k
  register int rindex = rgb_red[cinfo->in_color_space];
244
56.1k
  register int gindex = rgb_green[cinfo->in_color_space];
245
56.1k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
56.1k
  register int aindex = alpha_index[cinfo->in_color_space];
247
56.1k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
56.1k
  ptr = source->pub._buffer[0];
250
56.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
13.3k
    if (aindex >= 0)
252
1.28k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
13.3k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
12.0k
    else
255
12.0k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
42.7k
  } else {
257
42.7k
    if (aindex >= 0)
258
6.10k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
42.7k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
36.6k
    else
261
36.6k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
42.7k
  }
263
56.1k
  return 1;
264
56.1k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
236
50.3k
{
237
50.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
50.3k
  FILE *infile = source->pub.input_file;
239
50.3k
  register _JSAMPROW ptr;
240
50.3k
  register _JSAMPLE *rescale = source->rescale;
241
50.3k
  JDIMENSION col;
242
50.3k
  unsigned int maxval = source->maxval;
243
50.3k
  register int rindex = rgb_red[cinfo->in_color_space];
244
50.3k
  register int gindex = rgb_green[cinfo->in_color_space];
245
50.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
50.3k
  register int aindex = alpha_index[cinfo->in_color_space];
247
50.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
50.3k
  ptr = source->pub._buffer[0];
250
50.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
22.4k
    if (aindex >= 0)
252
4.47k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
22.4k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
17.9k
    else
255
17.9k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
27.8k
  } else {
257
27.8k
    if (aindex >= 0)
258
5.59k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
27.8k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
22.2k
    else
261
22.2k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
27.8k
  }
263
50.3k
  return 1;
264
50.3k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
236
25.7k
{
237
25.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
238
25.7k
  FILE *infile = source->pub.input_file;
239
25.7k
  register _JSAMPROW ptr;
240
25.7k
  register _JSAMPLE *rescale = source->rescale;
241
25.7k
  JDIMENSION col;
242
25.7k
  unsigned int maxval = source->maxval;
243
25.7k
  register int rindex = rgb_red[cinfo->in_color_space];
244
25.7k
  register int gindex = rgb_green[cinfo->in_color_space];
245
25.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
246
25.7k
  register int aindex = alpha_index[cinfo->in_color_space];
247
25.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
248
249
25.7k
  ptr = source->pub._buffer[0];
250
25.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
251
4.31k
    if (aindex >= 0)
252
451
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
253
4.31k
                    ptr[aindex] = (_JSAMPLE)maxval;)
254
3.86k
    else
255
3.86k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
256
21.4k
  } else {
257
21.4k
    if (aindex >= 0)
258
4.70k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
259
21.4k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
260
16.7k
    else
261
16.7k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
262
21.4k
  }
263
25.7k
  return 1;
264
25.7k
}
265
266
267
METHODDEF(JDIMENSION)
268
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
269
/* This version is for reading text-format PPM files with any maxval and
270
   converting to CMYK */
271
22.5k
{
272
22.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
22.5k
  FILE *infile = source->pub.input_file;
274
22.5k
  register _JSAMPROW ptr;
275
22.5k
  register _JSAMPLE *rescale = source->rescale;
276
22.5k
  JDIMENSION col;
277
22.5k
  unsigned int maxval = source->maxval;
278
279
22.5k
  ptr = source->pub._buffer[0];
280
22.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
27.3k
    for (col = cinfo->image_width; col > 0; col--) {
282
18.8k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
18.8k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
18.8k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
18.8k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
18.8k
      ptr += 4;
287
18.8k
    }
288
14.1k
  } else {
289
38.9k
    for (col = cinfo->image_width; col > 0; col--) {
290
24.8k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
24.8k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
24.8k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
24.8k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
24.8k
                  ptr + 2, ptr + 3);
295
24.8k
      ptr += 4;
296
24.8k
    }
297
14.1k
  }
298
22.5k
  return 1;
299
22.5k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
271
7.38k
{
272
7.38k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
7.38k
  FILE *infile = source->pub.input_file;
274
7.38k
  register _JSAMPROW ptr;
275
7.38k
  register _JSAMPLE *rescale = source->rescale;
276
7.38k
  JDIMENSION col;
277
7.38k
  unsigned int maxval = source->maxval;
278
279
7.38k
  ptr = source->pub._buffer[0];
280
7.38k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
6.70k
    for (col = cinfo->image_width; col > 0; col--) {
282
4.72k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
4.72k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
4.72k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
4.72k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
4.72k
      ptr += 4;
287
4.72k
    }
288
5.40k
  } else {
289
15.4k
    for (col = cinfo->image_width; col > 0; col--) {
290
10.0k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
10.0k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
10.0k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
10.0k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
10.0k
                  ptr + 2, ptr + 3);
295
10.0k
      ptr += 4;
296
10.0k
    }
297
5.40k
  }
298
7.38k
  return 1;
299
7.38k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
271
10.0k
{
272
10.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
10.0k
  FILE *infile = source->pub.input_file;
274
10.0k
  register _JSAMPROW ptr;
275
10.0k
  register _JSAMPLE *rescale = source->rescale;
276
10.0k
  JDIMENSION col;
277
10.0k
  unsigned int maxval = source->maxval;
278
279
10.0k
  ptr = source->pub._buffer[0];
280
10.0k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
16.0k
    for (col = cinfo->image_width; col > 0; col--) {
282
11.1k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
11.1k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
11.1k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
11.1k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
11.1k
      ptr += 4;
287
11.1k
    }
288
5.15k
  } else {
289
14.2k
    for (col = cinfo->image_width; col > 0; col--) {
290
9.08k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
9.08k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
9.08k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
9.08k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
9.08k
                  ptr + 2, ptr + 3);
295
9.08k
      ptr += 4;
296
9.08k
    }
297
5.15k
  }
298
10.0k
  return 1;
299
10.0k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
271
5.15k
{
272
5.15k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
273
5.15k
  FILE *infile = source->pub.input_file;
274
5.15k
  register _JSAMPROW ptr;
275
5.15k
  register _JSAMPLE *rescale = source->rescale;
276
5.15k
  JDIMENSION col;
277
5.15k
  unsigned int maxval = source->maxval;
278
279
5.15k
  ptr = source->pub._buffer[0];
280
5.15k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
281
4.54k
    for (col = cinfo->image_width; col > 0; col--) {
282
2.94k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
283
2.94k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
284
2.94k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
285
2.94k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
286
2.94k
      ptr += 4;
287
2.94k
    }
288
3.55k
  } else {
289
9.30k
    for (col = cinfo->image_width; col > 0; col--) {
290
5.75k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
291
5.75k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
292
5.75k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
293
5.75k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
294
5.75k
                  ptr + 2, ptr + 3);
295
5.75k
      ptr += 4;
296
5.75k
    }
297
3.55k
  }
298
5.15k
  return 1;
299
5.15k
}
300
301
302
METHODDEF(JDIMENSION)
303
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
304
/* This version is for reading raw-byte-format PGM files with any maxval */
305
33.8M
{
306
33.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
33.8M
  register _JSAMPROW ptr;
308
33.8M
  register unsigned char *bufferptr;
309
33.8M
  register _JSAMPLE *rescale = source->rescale;
310
33.8M
  JDIMENSION col;
311
312
33.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
1.34k
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
33.8M
  ptr = source->pub._buffer[0];
315
33.8M
  bufferptr = source->iobuffer;
316
174M
  for (col = cinfo->image_width; col > 0; col--) {
317
140M
    *ptr++ = rescale[*bufferptr++];
318
140M
  }
319
33.8M
  return 1;
320
33.8M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
305
16.6M
{
306
16.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
16.6M
  register _JSAMPROW ptr;
308
16.6M
  register unsigned char *bufferptr;
309
16.6M
  register _JSAMPLE *rescale = source->rescale;
310
16.6M
  JDIMENSION col;
311
312
16.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
919
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
16.6M
  ptr = source->pub._buffer[0];
315
16.6M
  bufferptr = source->iobuffer;
316
75.1M
  for (col = cinfo->image_width; col > 0; col--) {
317
58.4M
    *ptr++ = rescale[*bufferptr++];
318
58.4M
  }
319
16.6M
  return 1;
320
16.6M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
305
13.0M
{
306
13.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
13.0M
  register _JSAMPROW ptr;
308
13.0M
  register unsigned char *bufferptr;
309
13.0M
  register _JSAMPLE *rescale = source->rescale;
310
13.0M
  JDIMENSION col;
311
312
13.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
289
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
13.0M
  ptr = source->pub._buffer[0];
315
13.0M
  bufferptr = source->iobuffer;
316
73.1M
  for (col = cinfo->image_width; col > 0; col--) {
317
60.1M
    *ptr++ = rescale[*bufferptr++];
318
60.1M
  }
319
13.0M
  return 1;
320
13.0M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
305
4.12M
{
306
4.12M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
307
4.12M
  register _JSAMPROW ptr;
308
4.12M
  register unsigned char *bufferptr;
309
4.12M
  register _JSAMPLE *rescale = source->rescale;
310
4.12M
  JDIMENSION col;
311
312
4.12M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
313
132
    ERREXIT(cinfo, JERR_INPUT_EOF);
314
4.12M
  ptr = source->pub._buffer[0];
315
4.12M
  bufferptr = source->iobuffer;
316
25.9M
  for (col = cinfo->image_width; col > 0; col--) {
317
21.7M
    *ptr++ = rescale[*bufferptr++];
318
21.7M
  }
319
4.12M
  return 1;
320
4.12M
}
321
322
323
METHODDEF(JDIMENSION)
324
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
325
/* This version is for reading raw-byte-format PGM files with any maxval
326
   and converting to extended RGB */
327
178M
{
328
178M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
178M
  register _JSAMPROW ptr;
330
178M
  register unsigned char *bufferptr;
331
178M
  register _JSAMPLE *rescale = source->rescale;
332
178M
  JDIMENSION col;
333
178M
  unsigned int maxval = source->maxval;
334
178M
  register int rindex = rgb_red[cinfo->in_color_space];
335
178M
  register int gindex = rgb_green[cinfo->in_color_space];
336
178M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
178M
  register int aindex = alpha_index[cinfo->in_color_space];
338
178M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
178M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
5.33k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
178M
  ptr = source->pub._buffer[0];
343
178M
  bufferptr = source->iobuffer;
344
178M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
8.78M
    if (aindex >= 0)
346
607k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
8.17M
    else
348
8.17M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
169M
  } else {
350
169M
    if (aindex >= 0)
351
24.9M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
169M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
144M
    else
354
144M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
169M
  }
356
178M
  return 1;
357
178M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
327
92.2M
{
328
92.2M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
92.2M
  register _JSAMPROW ptr;
330
92.2M
  register unsigned char *bufferptr;
331
92.2M
  register _JSAMPLE *rescale = source->rescale;
332
92.2M
  JDIMENSION col;
333
92.2M
  unsigned int maxval = source->maxval;
334
92.2M
  register int rindex = rgb_red[cinfo->in_color_space];
335
92.2M
  register int gindex = rgb_green[cinfo->in_color_space];
336
92.2M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
92.2M
  register int aindex = alpha_index[cinfo->in_color_space];
338
92.2M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
92.2M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
3.23k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
92.2M
  ptr = source->pub._buffer[0];
343
92.2M
  bufferptr = source->iobuffer;
344
92.2M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
8.78M
    if (aindex >= 0)
346
607k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
8.17M
    else
348
8.17M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
83.4M
  } else {
350
83.4M
    if (aindex >= 0)
351
7.69M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
83.4M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
75.7M
    else
354
75.7M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
83.4M
  }
356
92.2M
  return 1;
357
92.2M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
327
65.4M
{
328
65.4M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
65.4M
  register _JSAMPROW ptr;
330
65.4M
  register unsigned char *bufferptr;
331
65.4M
  register _JSAMPLE *rescale = source->rescale;
332
65.4M
  JDIMENSION col;
333
65.4M
  unsigned int maxval = source->maxval;
334
65.4M
  register int rindex = rgb_red[cinfo->in_color_space];
335
65.4M
  register int gindex = rgb_green[cinfo->in_color_space];
336
65.4M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
65.4M
  register int aindex = alpha_index[cinfo->in_color_space];
338
65.4M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
65.4M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
1.44k
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
65.4M
  ptr = source->pub._buffer[0];
343
65.4M
  bufferptr = source->iobuffer;
344
65.4M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
0
    if (aindex >= 0)
346
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
0
    else
348
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
65.4M
  } else {
350
65.4M
    if (aindex >= 0)
351
13.0M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
65.4M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
52.3M
    else
354
52.3M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
65.4M
  }
356
65.4M
  return 1;
357
65.4M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
327
20.6M
{
328
20.6M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
329
20.6M
  register _JSAMPROW ptr;
330
20.6M
  register unsigned char *bufferptr;
331
20.6M
  register _JSAMPLE *rescale = source->rescale;
332
20.6M
  JDIMENSION col;
333
20.6M
  unsigned int maxval = source->maxval;
334
20.6M
  register int rindex = rgb_red[cinfo->in_color_space];
335
20.6M
  register int gindex = rgb_green[cinfo->in_color_space];
336
20.6M
  register int bindex = rgb_blue[cinfo->in_color_space];
337
20.6M
  register int aindex = alpha_index[cinfo->in_color_space];
338
20.6M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
339
340
20.6M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
341
660
    ERREXIT(cinfo, JERR_INPUT_EOF);
342
20.6M
  ptr = source->pub._buffer[0];
343
20.6M
  bufferptr = source->iobuffer;
344
20.6M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
345
0
    if (aindex >= 0)
346
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
347
0
    else
348
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
349
20.6M
  } else {
350
20.6M
    if (aindex >= 0)
351
4.12M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++],
352
20.6M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
353
16.5M
    else
354
16.5M
      GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {})
355
20.6M
  }
356
20.6M
  return 1;
357
20.6M
}
358
359
360
METHODDEF(JDIMENSION)
361
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
362
/* This version is for reading raw-byte-format PGM files with any maxval
363
   and converting to CMYK */
364
25.5M
{
365
25.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
25.5M
  register _JSAMPROW ptr;
367
25.5M
  register unsigned char *bufferptr;
368
25.5M
  register _JSAMPLE *rescale = source->rescale;
369
25.5M
  JDIMENSION col;
370
25.5M
  unsigned int maxval = source->maxval;
371
372
25.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
868
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
25.5M
  ptr = source->pub._buffer[0];
375
25.5M
  bufferptr = source->iobuffer;
376
25.5M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
4.47M
    for (col = cinfo->image_width; col > 0; col--) {
378
3.47M
      _JSAMPLE gray = *bufferptr++;
379
3.47M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
3.47M
      ptr += 4;
381
3.47M
    }
382
24.5M
  } else {
383
142M
    for (col = cinfo->image_width; col > 0; col--) {
384
118M
      _JSAMPLE gray = rescale[*bufferptr++];
385
118M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
118M
                  ptr + 1, ptr + 2, ptr + 3);
387
118M
      ptr += 4;
388
118M
    }
389
24.5M
  }
390
25.5M
  return 1;
391
25.5M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
364
8.30M
{
365
8.30M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
8.30M
  register _JSAMPROW ptr;
367
8.30M
  register unsigned char *bufferptr;
368
8.30M
  register _JSAMPLE *rescale = source->rescale;
369
8.30M
  JDIMENSION col;
370
8.30M
  unsigned int maxval = source->maxval;
371
372
8.30M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
447
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
8.30M
  ptr = source->pub._buffer[0];
375
8.30M
  bufferptr = source->iobuffer;
376
8.30M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
4.47M
    for (col = cinfo->image_width; col > 0; col--) {
378
3.47M
      _JSAMPLE gray = *bufferptr++;
379
3.47M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
3.47M
      ptr += 4;
381
3.47M
    }
382
7.29M
  } else {
383
43.8M
    for (col = cinfo->image_width; col > 0; col--) {
384
36.5M
      _JSAMPLE gray = rescale[*bufferptr++];
385
36.5M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
36.5M
                  ptr + 1, ptr + 2, ptr + 3);
387
36.5M
      ptr += 4;
388
36.5M
    }
389
7.29M
  }
390
8.30M
  return 1;
391
8.30M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
364
13.0M
{
365
13.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
13.0M
  register _JSAMPROW ptr;
367
13.0M
  register unsigned char *bufferptr;
368
13.0M
  register _JSAMPLE *rescale = source->rescale;
369
13.0M
  JDIMENSION col;
370
13.0M
  unsigned int maxval = source->maxval;
371
372
13.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
289
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
13.0M
  ptr = source->pub._buffer[0];
375
13.0M
  bufferptr = source->iobuffer;
376
13.0M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
0
    for (col = cinfo->image_width; col > 0; col--) {
378
0
      _JSAMPLE gray = *bufferptr++;
379
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
0
      ptr += 4;
381
0
    }
382
13.0M
  } else {
383
73.1M
    for (col = cinfo->image_width; col > 0; col--) {
384
60.1M
      _JSAMPLE gray = rescale[*bufferptr++];
385
60.1M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
60.1M
                  ptr + 1, ptr + 2, ptr + 3);
387
60.1M
      ptr += 4;
388
60.1M
    }
389
13.0M
  }
390
13.0M
  return 1;
391
13.0M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
364
4.12M
{
365
4.12M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
366
4.12M
  register _JSAMPROW ptr;
367
4.12M
  register unsigned char *bufferptr;
368
4.12M
  register _JSAMPLE *rescale = source->rescale;
369
4.12M
  JDIMENSION col;
370
4.12M
  unsigned int maxval = source->maxval;
371
372
4.12M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
373
132
    ERREXIT(cinfo, JERR_INPUT_EOF);
374
4.12M
  ptr = source->pub._buffer[0];
375
4.12M
  bufferptr = source->iobuffer;
376
4.12M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
377
0
    for (col = cinfo->image_width; col > 0; col--) {
378
0
      _JSAMPLE gray = *bufferptr++;
379
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
380
0
      ptr += 4;
381
0
    }
382
4.12M
  } else {
383
25.9M
    for (col = cinfo->image_width; col > 0; col--) {
384
21.7M
      _JSAMPLE gray = rescale[*bufferptr++];
385
21.7M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
386
21.7M
                  ptr + 1, ptr + 2, ptr + 3);
387
21.7M
      ptr += 4;
388
21.7M
    }
389
4.12M
  }
390
4.12M
  return 1;
391
4.12M
}
392
393
394
METHODDEF(JDIMENSION)
395
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
396
/* This version is for reading raw-byte-format PPM files with any maxval */
397
9.03M
{
398
9.03M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
9.03M
  register _JSAMPROW ptr;
400
9.03M
  register unsigned char *bufferptr;
401
9.03M
  register _JSAMPLE *rescale = source->rescale;
402
9.03M
  JDIMENSION col;
403
9.03M
  unsigned int maxval = source->maxval;
404
9.03M
  register int rindex = rgb_red[cinfo->in_color_space];
405
9.03M
  register int gindex = rgb_green[cinfo->in_color_space];
406
9.03M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
9.03M
  register int aindex = alpha_index[cinfo->in_color_space];
408
9.03M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
9.03M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
7.19k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
9.03M
  ptr = source->pub._buffer[0];
413
9.03M
  bufferptr = source->iobuffer;
414
9.03M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
180k
    if (aindex >= 0)
416
44.3k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
135k
    else
418
135k
      RGB_READ_LOOP(*bufferptr++, {})
419
8.85M
  } else {
420
8.85M
    if (aindex >= 0)
421
1.74M
      RGB_READ_LOOP(rescale[*bufferptr++],
422
8.85M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
7.11M
    else
424
7.11M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
8.85M
  }
426
9.03M
  return 1;
427
9.03M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
397
1.77M
{
398
1.77M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
1.77M
  register _JSAMPROW ptr;
400
1.77M
  register unsigned char *bufferptr;
401
1.77M
  register _JSAMPLE *rescale = source->rescale;
402
1.77M
  JDIMENSION col;
403
1.77M
  unsigned int maxval = source->maxval;
404
1.77M
  register int rindex = rgb_red[cinfo->in_color_space];
405
1.77M
  register int gindex = rgb_green[cinfo->in_color_space];
406
1.77M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
1.77M
  register int aindex = alpha_index[cinfo->in_color_space];
408
1.77M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
1.77M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
4.18k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
1.77M
  ptr = source->pub._buffer[0];
413
1.77M
  bufferptr = source->iobuffer;
414
1.77M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
180k
    if (aindex >= 0)
416
44.3k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
135k
    else
418
135k
      RGB_READ_LOOP(*bufferptr++, {})
419
1.59M
  } else {
420
1.59M
    if (aindex >= 0)
421
290k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
1.59M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
1.30M
    else
424
1.30M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
1.59M
  }
426
1.77M
  return 1;
427
1.77M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
397
7.12M
{
398
7.12M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
7.12M
  register _JSAMPROW ptr;
400
7.12M
  register unsigned char *bufferptr;
401
7.12M
  register _JSAMPLE *rescale = source->rescale;
402
7.12M
  JDIMENSION col;
403
7.12M
  unsigned int maxval = source->maxval;
404
7.12M
  register int rindex = rgb_red[cinfo->in_color_space];
405
7.12M
  register int gindex = rgb_green[cinfo->in_color_space];
406
7.12M
  register int bindex = rgb_blue[cinfo->in_color_space];
407
7.12M
  register int aindex = alpha_index[cinfo->in_color_space];
408
7.12M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
7.12M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
1.97k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
7.12M
  ptr = source->pub._buffer[0];
413
7.12M
  bufferptr = source->iobuffer;
414
7.12M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
0
    if (aindex >= 0)
416
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
0
    else
418
0
      RGB_READ_LOOP(*bufferptr++, {})
419
7.12M
  } else {
420
7.12M
    if (aindex >= 0)
421
1.42M
      RGB_READ_LOOP(rescale[*bufferptr++],
422
7.12M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
5.70M
    else
424
5.70M
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
7.12M
  }
426
7.12M
  return 1;
427
7.12M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
397
127k
{
398
127k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
399
127k
  register _JSAMPROW ptr;
400
127k
  register unsigned char *bufferptr;
401
127k
  register _JSAMPLE *rescale = source->rescale;
402
127k
  JDIMENSION col;
403
127k
  unsigned int maxval = source->maxval;
404
127k
  register int rindex = rgb_red[cinfo->in_color_space];
405
127k
  register int gindex = rgb_green[cinfo->in_color_space];
406
127k
  register int bindex = rgb_blue[cinfo->in_color_space];
407
127k
  register int aindex = alpha_index[cinfo->in_color_space];
408
127k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
409
410
127k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
411
1.03k
    ERREXIT(cinfo, JERR_INPUT_EOF);
412
127k
  ptr = source->pub._buffer[0];
413
127k
  bufferptr = source->iobuffer;
414
127k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
415
0
    if (aindex >= 0)
416
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
417
0
    else
418
0
      RGB_READ_LOOP(*bufferptr++, {})
419
127k
  } else {
420
127k
    if (aindex >= 0)
421
25.2k
      RGB_READ_LOOP(rescale[*bufferptr++],
422
127k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
423
102k
    else
424
102k
      RGB_READ_LOOP(rescale[*bufferptr++], {})
425
127k
  }
426
127k
  return 1;
427
127k
}
428
429
430
METHODDEF(JDIMENSION)
431
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
432
/* This version is for reading raw-byte-format PPM files with any maxval and
433
   converting to CMYK */
434
1.78M
{
435
1.78M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
1.78M
  register _JSAMPROW ptr;
437
1.78M
  register unsigned char *bufferptr;
438
1.78M
  register _JSAMPLE *rescale = source->rescale;
439
1.78M
  JDIMENSION col;
440
1.78M
  unsigned int maxval = source->maxval;
441
442
1.78M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
1.23k
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
1.78M
  ptr = source->pub._buffer[0];
445
1.78M
  bufferptr = source->iobuffer;
446
1.78M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
640k
    for (col = cinfo->image_width; col > 0; col--) {
448
472k
      _JSAMPLE r = *bufferptr++;
449
472k
      _JSAMPLE g = *bufferptr++;
450
472k
      _JSAMPLE b = *bufferptr++;
451
472k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
472k
      ptr += 4;
453
472k
    }
454
1.61M
  } else {
455
15.9M
    for (col = cinfo->image_width; col > 0; col--) {
456
14.3M
      _JSAMPLE r = rescale[*bufferptr++];
457
14.3M
      _JSAMPLE g = rescale[*bufferptr++];
458
14.3M
      _JSAMPLE b = rescale[*bufferptr++];
459
14.3M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
14.3M
                  ptr + 2, ptr + 3);
461
14.3M
      ptr += 4;
462
14.3M
    }
463
1.61M
  }
464
1.78M
  return 1;
465
1.78M
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
434
335k
{
435
335k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
335k
  register _JSAMPROW ptr;
437
335k
  register unsigned char *bufferptr;
438
335k
  register _JSAMPLE *rescale = source->rescale;
439
335k
  JDIMENSION col;
440
335k
  unsigned int maxval = source->maxval;
441
442
335k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
635
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
335k
  ptr = source->pub._buffer[0];
445
335k
  bufferptr = source->iobuffer;
446
335k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
640k
    for (col = cinfo->image_width; col > 0; col--) {
448
472k
      _JSAMPLE r = *bufferptr++;
449
472k
      _JSAMPLE g = *bufferptr++;
450
472k
      _JSAMPLE b = *bufferptr++;
451
472k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
472k
      ptr += 4;
453
472k
    }
454
168k
  } else {
455
1.39M
    for (col = cinfo->image_width; col > 0; col--) {
456
1.22M
      _JSAMPLE r = rescale[*bufferptr++];
457
1.22M
      _JSAMPLE g = rescale[*bufferptr++];
458
1.22M
      _JSAMPLE b = rescale[*bufferptr++];
459
1.22M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
1.22M
                  ptr + 2, ptr + 3);
461
1.22M
      ptr += 4;
462
1.22M
    }
463
167k
  }
464
335k
  return 1;
465
335k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
434
1.42M
{
435
1.42M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
1.42M
  register _JSAMPROW ptr;
437
1.42M
  register unsigned char *bufferptr;
438
1.42M
  register _JSAMPLE *rescale = source->rescale;
439
1.42M
  JDIMENSION col;
440
1.42M
  unsigned int maxval = source->maxval;
441
442
1.42M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
395
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
1.42M
  ptr = source->pub._buffer[0];
445
1.42M
  bufferptr = source->iobuffer;
446
1.42M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
0
    for (col = cinfo->image_width; col > 0; col--) {
448
0
      _JSAMPLE r = *bufferptr++;
449
0
      _JSAMPLE g = *bufferptr++;
450
0
      _JSAMPLE b = *bufferptr++;
451
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
0
      ptr += 4;
453
0
    }
454
1.42M
  } else {
455
11.6M
    for (col = cinfo->image_width; col > 0; col--) {
456
10.2M
      _JSAMPLE r = rescale[*bufferptr++];
457
10.2M
      _JSAMPLE g = rescale[*bufferptr++];
458
10.2M
      _JSAMPLE b = rescale[*bufferptr++];
459
10.2M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
10.2M
                  ptr + 2, ptr + 3);
461
10.2M
      ptr += 4;
462
10.2M
    }
463
1.42M
  }
464
1.42M
  return 1;
465
1.42M
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
434
25.4k
{
435
25.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
436
25.4k
  register _JSAMPROW ptr;
437
25.4k
  register unsigned char *bufferptr;
438
25.4k
  register _JSAMPLE *rescale = source->rescale;
439
25.4k
  JDIMENSION col;
440
25.4k
  unsigned int maxval = source->maxval;
441
442
25.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
443
206
    ERREXIT(cinfo, JERR_INPUT_EOF);
444
25.4k
  ptr = source->pub._buffer[0];
445
25.4k
  bufferptr = source->iobuffer;
446
25.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
447
0
    for (col = cinfo->image_width; col > 0; col--) {
448
0
      _JSAMPLE r = *bufferptr++;
449
0
      _JSAMPLE g = *bufferptr++;
450
0
      _JSAMPLE b = *bufferptr++;
451
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
452
0
      ptr += 4;
453
0
    }
454
25.4k
  } else {
455
2.94M
    for (col = cinfo->image_width; col > 0; col--) {
456
2.92M
      _JSAMPLE r = rescale[*bufferptr++];
457
2.92M
      _JSAMPLE g = rescale[*bufferptr++];
458
2.92M
      _JSAMPLE b = rescale[*bufferptr++];
459
2.92M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
460
2.92M
                  ptr + 2, ptr + 3);
461
2.92M
      ptr += 4;
462
2.92M
    }
463
25.4k
  }
464
25.4k
  return 1;
465
25.4k
}
466
467
468
#if BITS_IN_JSAMPLE == 8
469
470
METHODDEF(JDIMENSION)
471
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
472
/* This version is for reading raw-byte-format files with
473
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
474
 * In this case we just read right into the _JSAMPLE buffer!
475
 * Note that same code works for PPM and PGM files.
476
 */
477
1.86M
{
478
1.86M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
479
480
1.86M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
481
395
    ERREXIT(cinfo, JERR_INPUT_EOF);
482
1.86M
  return 1;
483
1.86M
}
484
485
#endif
486
487
488
METHODDEF(JDIMENSION)
489
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
490
/* This version is for reading raw-word-format PGM files with any maxval */
491
228k
{
492
228k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
228k
  register _JSAMPROW ptr;
494
228k
  register unsigned char *bufferptr;
495
228k
  register _JSAMPLE *rescale = source->rescale;
496
228k
  JDIMENSION col;
497
228k
  unsigned int maxval = source->maxval;
498
499
228k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
1.01k
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
228k
  ptr = source->pub._buffer[0];
502
228k
  bufferptr = source->iobuffer;
503
573k
  for (col = cinfo->image_width; col > 0; col--) {
504
345k
    register unsigned int temp;
505
345k
    temp  = (*bufferptr++) << 8;
506
345k
    temp |= (*bufferptr++);
507
345k
    if (temp > maxval)
508
680
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
345k
    *ptr++ = rescale[temp];
510
345k
  }
511
228k
  return 1;
512
228k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
491
14.7k
{
492
14.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
14.7k
  register _JSAMPROW ptr;
494
14.7k
  register unsigned char *bufferptr;
495
14.7k
  register _JSAMPLE *rescale = source->rescale;
496
14.7k
  JDIMENSION col;
497
14.7k
  unsigned int maxval = source->maxval;
498
499
14.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
493
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
14.7k
  ptr = source->pub._buffer[0];
502
14.7k
  bufferptr = source->iobuffer;
503
82.5k
  for (col = cinfo->image_width; col > 0; col--) {
504
67.7k
    register unsigned int temp;
505
67.7k
    temp  = (*bufferptr++) << 8;
506
67.7k
    temp |= (*bufferptr++);
507
67.7k
    if (temp > maxval)
508
342
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
67.7k
    *ptr++ = rescale[temp];
510
67.7k
  }
511
14.7k
  return 1;
512
14.7k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
491
186k
{
492
186k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
186k
  register _JSAMPROW ptr;
494
186k
  register unsigned char *bufferptr;
495
186k
  register _JSAMPLE *rescale = source->rescale;
496
186k
  JDIMENSION col;
497
186k
  unsigned int maxval = source->maxval;
498
499
186k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
325
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
186k
  ptr = source->pub._buffer[0];
502
186k
  bufferptr = source->iobuffer;
503
386k
  for (col = cinfo->image_width; col > 0; col--) {
504
200k
    register unsigned int temp;
505
200k
    temp  = (*bufferptr++) << 8;
506
200k
    temp |= (*bufferptr++);
507
200k
    if (temp > maxval)
508
262
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
200k
    *ptr++ = rescale[temp];
510
200k
  }
511
186k
  return 1;
512
186k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
491
26.9k
{
492
26.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
493
26.9k
  register _JSAMPROW ptr;
494
26.9k
  register unsigned char *bufferptr;
495
26.9k
  register _JSAMPLE *rescale = source->rescale;
496
26.9k
  JDIMENSION col;
497
26.9k
  unsigned int maxval = source->maxval;
498
499
26.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
500
200
    ERREXIT(cinfo, JERR_INPUT_EOF);
501
26.9k
  ptr = source->pub._buffer[0];
502
26.9k
  bufferptr = source->iobuffer;
503
104k
  for (col = cinfo->image_width; col > 0; col--) {
504
77.3k
    register unsigned int temp;
505
77.3k
    temp  = (*bufferptr++) << 8;
506
77.3k
    temp |= (*bufferptr++);
507
77.3k
    if (temp > maxval)
508
76
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
509
77.3k
    *ptr++ = rescale[temp];
510
77.3k
  }
511
26.9k
  return 1;
512
26.9k
}
513
514
515
METHODDEF(JDIMENSION)
516
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
517
/* This version is for reading raw-word-format PGM files with any maxval */
518
1.13M
{
519
1.13M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
1.13M
  register _JSAMPROW ptr;
521
1.13M
  register unsigned char *bufferptr;
522
1.13M
  register _JSAMPLE *rescale = source->rescale;
523
1.13M
  JDIMENSION col;
524
1.13M
  unsigned int maxval = source->maxval;
525
1.13M
  register int rindex = rgb_red[cinfo->in_color_space];
526
1.13M
  register int gindex = rgb_green[cinfo->in_color_space];
527
1.13M
  register int bindex = rgb_blue[cinfo->in_color_space];
528
1.13M
  register int aindex = alpha_index[cinfo->in_color_space];
529
1.13M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
1.13M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
4.42k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
1.13M
  ptr = source->pub._buffer[0];
534
1.13M
  bufferptr = source->iobuffer;
535
2.85M
  for (col = cinfo->image_width; col > 0; col--) {
536
1.72M
    register unsigned int temp;
537
1.72M
    temp  = (*bufferptr++) << 8;
538
1.72M
    temp |= (*bufferptr++);
539
1.72M
    if (temp > maxval)
540
2.83k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
1.72M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
1.72M
    if (aindex >= 0)
543
301k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
1.72M
    ptr += ps;
545
1.72M
  }
546
1.13M
  return 1;
547
1.13M
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
518
68.6k
{
519
68.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
68.6k
  register _JSAMPROW ptr;
521
68.6k
  register unsigned char *bufferptr;
522
68.6k
  register _JSAMPLE *rescale = source->rescale;
523
68.6k
  JDIMENSION col;
524
68.6k
  unsigned int maxval = source->maxval;
525
68.6k
  register int rindex = rgb_red[cinfo->in_color_space];
526
68.6k
  register int gindex = rgb_green[cinfo->in_color_space];
527
68.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
68.6k
  register int aindex = alpha_index[cinfo->in_color_space];
529
68.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
68.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.79k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
68.6k
  ptr = source->pub._buffer[0];
534
68.6k
  bufferptr = source->iobuffer;
535
400k
  for (col = cinfo->image_width; col > 0; col--) {
536
331k
    register unsigned int temp;
537
331k
    temp  = (*bufferptr++) << 8;
538
331k
    temp |= (*bufferptr++);
539
331k
    if (temp > maxval)
540
1.14k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
331k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
331k
    if (aindex >= 0)
543
23.3k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
331k
    ptr += ps;
545
331k
  }
546
68.6k
  return 1;
547
68.6k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
518
931k
{
519
931k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
931k
  register _JSAMPROW ptr;
521
931k
  register unsigned char *bufferptr;
522
931k
  register _JSAMPLE *rescale = source->rescale;
523
931k
  JDIMENSION col;
524
931k
  unsigned int maxval = source->maxval;
525
931k
  register int rindex = rgb_red[cinfo->in_color_space];
526
931k
  register int gindex = rgb_green[cinfo->in_color_space];
527
931k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
931k
  register int aindex = alpha_index[cinfo->in_color_space];
529
931k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
931k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.62k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
931k
  ptr = source->pub._buffer[0];
534
931k
  bufferptr = source->iobuffer;
535
1.93M
  for (col = cinfo->image_width; col > 0; col--) {
536
1.00M
    register unsigned int temp;
537
1.00M
    temp  = (*bufferptr++) << 8;
538
1.00M
    temp |= (*bufferptr++);
539
1.00M
    if (temp > maxval)
540
1.31k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
1.00M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
1.00M
    if (aindex >= 0)
543
200k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
1.00M
    ptr += ps;
545
1.00M
  }
546
931k
  return 1;
547
931k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
518
134k
{
519
134k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
520
134k
  register _JSAMPROW ptr;
521
134k
  register unsigned char *bufferptr;
522
134k
  register _JSAMPLE *rescale = source->rescale;
523
134k
  JDIMENSION col;
524
134k
  unsigned int maxval = source->maxval;
525
134k
  register int rindex = rgb_red[cinfo->in_color_space];
526
134k
  register int gindex = rgb_green[cinfo->in_color_space];
527
134k
  register int bindex = rgb_blue[cinfo->in_color_space];
528
134k
  register int aindex = alpha_index[cinfo->in_color_space];
529
134k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
530
531
134k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
532
1.00k
    ERREXIT(cinfo, JERR_INPUT_EOF);
533
134k
  ptr = source->pub._buffer[0];
534
134k
  bufferptr = source->iobuffer;
535
521k
  for (col = cinfo->image_width; col > 0; col--) {
536
386k
    register unsigned int temp;
537
386k
    temp  = (*bufferptr++) << 8;
538
386k
    temp |= (*bufferptr++);
539
386k
    if (temp > maxval)
540
380
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
541
386k
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
542
386k
    if (aindex >= 0)
543
77.2k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
544
386k
    ptr += ps;
545
386k
  }
546
134k
  return 1;
547
134k
}
548
549
550
METHODDEF(JDIMENSION)
551
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
552
/* This version is for reading raw-word-format PGM files with any maxval */
553
223k
{
554
223k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
223k
  register _JSAMPROW ptr;
556
223k
  register unsigned char *bufferptr;
557
223k
  register _JSAMPLE *rescale = source->rescale;
558
223k
  JDIMENSION col;
559
223k
  unsigned int maxval = source->maxval;
560
561
223k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
777
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
223k
  ptr = source->pub._buffer[0];
564
223k
  bufferptr = source->iobuffer;
565
223k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
95.9k
    for (col = cinfo->image_width; col > 0; col--) {
567
72.1k
      register unsigned int gray;
568
72.1k
      gray  = (*bufferptr++) << 8;
569
72.1k
      gray |= (*bufferptr++);
570
72.1k
      if (gray > maxval)
571
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
72.1k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
72.1k
                  ptr + 1, ptr + 2, ptr + 3);
574
72.1k
      ptr += 4;
575
72.1k
    }
576
199k
  } else {
577
429k
    for (col = cinfo->image_width; col > 0; col--) {
578
229k
      register unsigned int temp;
579
229k
      _JSAMPLE gray;
580
229k
      temp  = (*bufferptr++) << 8;
581
229k
      temp |= (*bufferptr++);
582
229k
      if (temp > maxval)
583
411
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
229k
      gray = rescale[temp];
585
229k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
229k
                  ptr + 1, ptr + 2, ptr + 3);
587
229k
      ptr += 4;
588
229k
    }
589
199k
  }
590
223k
  return 1;
591
223k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
553
10.4k
{
554
10.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
10.4k
  register _JSAMPROW ptr;
556
10.4k
  register unsigned char *bufferptr;
557
10.4k
  register _JSAMPLE *rescale = source->rescale;
558
10.4k
  JDIMENSION col;
559
10.4k
  unsigned int maxval = source->maxval;
560
561
10.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
252
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
10.4k
  ptr = source->pub._buffer[0];
564
10.4k
  bufferptr = source->iobuffer;
565
10.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
0
    for (col = cinfo->image_width; col > 0; col--) {
567
0
      register unsigned int gray;
568
0
      gray  = (*bufferptr++) << 8;
569
0
      gray |= (*bufferptr++);
570
0
      if (gray > maxval)
571
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
0
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
0
                  ptr + 1, ptr + 2, ptr + 3);
574
0
      ptr += 4;
575
0
    }
576
10.4k
  } else {
577
34.0k
    for (col = cinfo->image_width; col > 0; col--) {
578
23.5k
      register unsigned int temp;
579
23.5k
      _JSAMPLE gray;
580
23.5k
      temp  = (*bufferptr++) << 8;
581
23.5k
      temp |= (*bufferptr++);
582
23.5k
      if (temp > maxval)
583
159
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
23.5k
      gray = rescale[temp];
585
23.5k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
23.5k
                  ptr + 1, ptr + 2, ptr + 3);
587
23.5k
      ptr += 4;
588
23.5k
    }
589
10.4k
  }
590
10.4k
  return 1;
591
10.4k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
553
186k
{
554
186k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
186k
  register _JSAMPROW ptr;
556
186k
  register unsigned char *bufferptr;
557
186k
  register _JSAMPLE *rescale = source->rescale;
558
186k
  JDIMENSION col;
559
186k
  unsigned int maxval = source->maxval;
560
561
186k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
325
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
186k
  ptr = source->pub._buffer[0];
564
186k
  bufferptr = source->iobuffer;
565
186k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
6.38k
    for (col = cinfo->image_width; col > 0; col--) {
567
4.20k
      register unsigned int gray;
568
4.20k
      gray  = (*bufferptr++) << 8;
569
4.20k
      gray |= (*bufferptr++);
570
4.20k
      if (gray > maxval)
571
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
4.20k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
4.20k
                  ptr + 1, ptr + 2, ptr + 3);
574
4.20k
      ptr += 4;
575
4.20k
    }
576
184k
  } else {
577
380k
    for (col = cinfo->image_width; col > 0; col--) {
578
196k
      register unsigned int temp;
579
196k
      _JSAMPLE gray;
580
196k
      temp  = (*bufferptr++) << 8;
581
196k
      temp |= (*bufferptr++);
582
196k
      if (temp > maxval)
583
176
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
196k
      gray = rescale[temp];
585
196k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
196k
                  ptr + 1, ptr + 2, ptr + 3);
587
196k
      ptr += 4;
588
196k
    }
589
184k
  }
590
186k
  return 1;
591
186k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
553
26.9k
{
554
26.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
555
26.9k
  register _JSAMPROW ptr;
556
26.9k
  register unsigned char *bufferptr;
557
26.9k
  register _JSAMPLE *rescale = source->rescale;
558
26.9k
  JDIMENSION col;
559
26.9k
  unsigned int maxval = source->maxval;
560
561
26.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
562
200
    ERREXIT(cinfo, JERR_INPUT_EOF);
563
26.9k
  ptr = source->pub._buffer[0];
564
26.9k
  bufferptr = source->iobuffer;
565
26.9k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
566
89.6k
    for (col = cinfo->image_width; col > 0; col--) {
567
67.9k
      register unsigned int gray;
568
67.9k
      gray  = (*bufferptr++) << 8;
569
67.9k
      gray |= (*bufferptr++);
570
67.9k
      if (gray > maxval)
571
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
572
67.9k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
573
67.9k
                  ptr + 1, ptr + 2, ptr + 3);
574
67.9k
      ptr += 4;
575
67.9k
    }
576
21.6k
  } else {
577
14.6k
    for (col = cinfo->image_width; col > 0; col--) {
578
9.37k
      register unsigned int temp;
579
9.37k
      _JSAMPLE gray;
580
9.37k
      temp  = (*bufferptr++) << 8;
581
9.37k
      temp |= (*bufferptr++);
582
9.37k
      if (temp > maxval)
583
76
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
584
9.37k
      gray = rescale[temp];
585
9.37k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
586
9.37k
                  ptr + 1, ptr + 2, ptr + 3);
587
9.37k
      ptr += 4;
588
9.37k
    }
589
5.32k
  }
590
26.9k
  return 1;
591
26.9k
}
592
593
594
METHODDEF(JDIMENSION)
595
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
596
/* This version is for reading raw-word-format PPM files with any maxval */
597
146k
{
598
146k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
146k
  register _JSAMPROW ptr;
600
146k
  register unsigned char *bufferptr;
601
146k
  register _JSAMPLE *rescale = source->rescale;
602
146k
  JDIMENSION col;
603
146k
  unsigned int maxval = source->maxval;
604
146k
  register int rindex = rgb_red[cinfo->in_color_space];
605
146k
  register int gindex = rgb_green[cinfo->in_color_space];
606
146k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
146k
  register int aindex = alpha_index[cinfo->in_color_space];
608
146k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
146k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
5.63k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
146k
  ptr = source->pub._buffer[0];
613
146k
  bufferptr = source->iobuffer;
614
499k
  for (col = cinfo->image_width; col > 0; col--) {
615
353k
    register unsigned int temp;
616
353k
    temp  = (*bufferptr++) << 8;
617
353k
    temp |= (*bufferptr++);
618
353k
    if (temp > maxval)
619
2.03k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
353k
    ptr[rindex] = rescale[temp];
621
353k
    temp  = (*bufferptr++) << 8;
622
353k
    temp |= (*bufferptr++);
623
353k
    if (temp > maxval)
624
1.81k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
353k
    ptr[gindex] = rescale[temp];
626
353k
    temp  = (*bufferptr++) << 8;
627
353k
    temp |= (*bufferptr++);
628
353k
    if (temp > maxval)
629
1.86k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
353k
    ptr[bindex] = rescale[temp];
631
353k
    if (aindex >= 0)
632
65.6k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
353k
    ptr += ps;
634
353k
  }
635
146k
  return 1;
636
146k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
597
53.5k
{
598
53.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
53.5k
  register _JSAMPROW ptr;
600
53.5k
  register unsigned char *bufferptr;
601
53.5k
  register _JSAMPLE *rescale = source->rescale;
602
53.5k
  JDIMENSION col;
603
53.5k
  unsigned int maxval = source->maxval;
604
53.5k
  register int rindex = rgb_red[cinfo->in_color_space];
605
53.5k
  register int gindex = rgb_green[cinfo->in_color_space];
606
53.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
53.5k
  register int aindex = alpha_index[cinfo->in_color_space];
608
53.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
53.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
2.03k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
53.5k
  ptr = source->pub._buffer[0];
613
53.5k
  bufferptr = source->iobuffer;
614
138k
  for (col = cinfo->image_width; col > 0; col--) {
615
84.6k
    register unsigned int temp;
616
84.6k
    temp  = (*bufferptr++) << 8;
617
84.6k
    temp |= (*bufferptr++);
618
84.6k
    if (temp > maxval)
619
764
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
84.6k
    ptr[rindex] = rescale[temp];
621
84.6k
    temp  = (*bufferptr++) << 8;
622
84.6k
    temp |= (*bufferptr++);
623
84.6k
    if (temp > maxval)
624
732
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
84.6k
    ptr[gindex] = rescale[temp];
626
84.6k
    temp  = (*bufferptr++) << 8;
627
84.6k
    temp |= (*bufferptr++);
628
84.6k
    if (temp > maxval)
629
749
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
84.6k
    ptr[bindex] = rescale[temp];
631
84.6k
    if (aindex >= 0)
632
12.5k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
84.6k
    ptr += ps;
634
84.6k
  }
635
53.5k
  return 1;
636
53.5k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
597
60.7k
{
598
60.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
60.7k
  register _JSAMPROW ptr;
600
60.7k
  register unsigned char *bufferptr;
601
60.7k
  register _JSAMPLE *rescale = source->rescale;
602
60.7k
  JDIMENSION col;
603
60.7k
  unsigned int maxval = source->maxval;
604
60.7k
  register int rindex = rgb_red[cinfo->in_color_space];
605
60.7k
  register int gindex = rgb_green[cinfo->in_color_space];
606
60.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
60.7k
  register int aindex = alpha_index[cinfo->in_color_space];
608
60.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
60.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
2.28k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
60.7k
  ptr = source->pub._buffer[0];
613
60.7k
  bufferptr = source->iobuffer;
614
173k
  for (col = cinfo->image_width; col > 0; col--) {
615
113k
    register unsigned int temp;
616
113k
    temp  = (*bufferptr++) << 8;
617
113k
    temp |= (*bufferptr++);
618
113k
    if (temp > maxval)
619
960
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
113k
    ptr[rindex] = rescale[temp];
621
113k
    temp  = (*bufferptr++) << 8;
622
113k
    temp |= (*bufferptr++);
623
113k
    if (temp > maxval)
624
825
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
113k
    ptr[gindex] = rescale[temp];
626
113k
    temp  = (*bufferptr++) << 8;
627
113k
    temp |= (*bufferptr++);
628
113k
    if (temp > maxval)
629
860
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
113k
    ptr[bindex] = rescale[temp];
631
113k
    if (aindex >= 0)
632
22.0k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
113k
    ptr += ps;
634
113k
  }
635
60.7k
  return 1;
636
60.7k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
597
31.9k
{
598
31.9k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
599
31.9k
  register _JSAMPROW ptr;
600
31.9k
  register unsigned char *bufferptr;
601
31.9k
  register _JSAMPLE *rescale = source->rescale;
602
31.9k
  JDIMENSION col;
603
31.9k
  unsigned int maxval = source->maxval;
604
31.9k
  register int rindex = rgb_red[cinfo->in_color_space];
605
31.9k
  register int gindex = rgb_green[cinfo->in_color_space];
606
31.9k
  register int bindex = rgb_blue[cinfo->in_color_space];
607
31.9k
  register int aindex = alpha_index[cinfo->in_color_space];
608
31.9k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
609
610
31.9k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
611
1.32k
    ERREXIT(cinfo, JERR_INPUT_EOF);
612
31.9k
  ptr = source->pub._buffer[0];
613
31.9k
  bufferptr = source->iobuffer;
614
187k
  for (col = cinfo->image_width; col > 0; col--) {
615
155k
    register unsigned int temp;
616
155k
    temp  = (*bufferptr++) << 8;
617
155k
    temp |= (*bufferptr++);
618
155k
    if (temp > maxval)
619
310
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
620
155k
    ptr[rindex] = rescale[temp];
621
155k
    temp  = (*bufferptr++) << 8;
622
155k
    temp |= (*bufferptr++);
623
155k
    if (temp > maxval)
624
260
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
625
155k
    ptr[gindex] = rescale[temp];
626
155k
    temp  = (*bufferptr++) << 8;
627
155k
    temp |= (*bufferptr++);
628
155k
    if (temp > maxval)
629
255
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
630
155k
    ptr[bindex] = rescale[temp];
631
155k
    if (aindex >= 0)
632
30.9k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
633
155k
    ptr += ps;
634
155k
  }
635
31.9k
  return 1;
636
31.9k
}
637
638
639
METHODDEF(JDIMENSION)
640
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
641
/* This version is for reading raw-word-format PPM files with any maxval */
642
26.6k
{
643
26.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
26.6k
  register _JSAMPROW ptr;
645
26.6k
  register unsigned char *bufferptr;
646
26.6k
  register _JSAMPLE *rescale = source->rescale;
647
26.6k
  JDIMENSION col;
648
26.6k
  unsigned int maxval = source->maxval;
649
650
26.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
1.01k
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
26.6k
  ptr = source->pub._buffer[0];
653
26.6k
  bufferptr = source->iobuffer;
654
26.6k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
40.6k
    for (col = cinfo->image_width; col > 0; col--) {
656
34.0k
      register unsigned int r, g, b;
657
34.0k
      r  = (*bufferptr++) << 8;
658
34.0k
      r |= (*bufferptr++);
659
34.0k
      if (r > maxval)
660
68
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
34.0k
      g  = (*bufferptr++) << 8;
662
34.0k
      g |= (*bufferptr++);
663
34.0k
      if (g > maxval)
664
72
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
34.0k
      b  = (*bufferptr++) << 8;
666
34.0k
      b |= (*bufferptr++);
667
34.0k
      if (b > maxval)
668
79
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
34.0k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
34.0k
                  ptr + 2, ptr + 3);
671
34.0k
      ptr += 4;
672
34.0k
    }
673
20.0k
  } else {
674
52.7k
    for (col = cinfo->image_width; col > 0; col--) {
675
32.6k
      register unsigned int r, g, b;
676
32.6k
      r  = (*bufferptr++) << 8;
677
32.6k
      r |= (*bufferptr++);
678
32.6k
      if (r > maxval)
679
309
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
32.6k
      g  = (*bufferptr++) << 8;
681
32.6k
      g |= (*bufferptr++);
682
32.6k
      if (g > maxval)
683
244
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
32.6k
      b  = (*bufferptr++) << 8;
685
32.6k
      b |= (*bufferptr++);
686
32.6k
      if (b > maxval)
687
236
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
32.6k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
32.6k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
32.6k
      ptr += 4;
691
32.6k
    }
692
20.0k
  }
693
26.6k
  return 1;
694
26.6k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
642
8.15k
{
643
8.15k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
8.15k
  register _JSAMPROW ptr;
645
8.15k
  register unsigned char *bufferptr;
646
8.15k
  register _JSAMPLE *rescale = source->rescale;
647
8.15k
  JDIMENSION col;
648
8.15k
  unsigned int maxval = source->maxval;
649
650
8.15k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
296
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
8.15k
  ptr = source->pub._buffer[0];
653
8.15k
  bufferptr = source->iobuffer;
654
8.15k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
0
    for (col = cinfo->image_width; col > 0; col--) {
656
0
      register unsigned int r, g, b;
657
0
      r  = (*bufferptr++) << 8;
658
0
      r |= (*bufferptr++);
659
0
      if (r > maxval)
660
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
0
      g  = (*bufferptr++) << 8;
662
0
      g |= (*bufferptr++);
663
0
      if (g > maxval)
664
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
0
      b  = (*bufferptr++) << 8;
666
0
      b |= (*bufferptr++);
667
0
      if (b > maxval)
668
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
0
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
0
                  ptr + 2, ptr + 3);
671
0
      ptr += 4;
672
0
    }
673
8.15k
  } else {
674
21.0k
    for (col = cinfo->image_width; col > 0; col--) {
675
12.9k
      register unsigned int r, g, b;
676
12.9k
      r  = (*bufferptr++) << 8;
677
12.9k
      r |= (*bufferptr++);
678
12.9k
      if (r > maxval)
679
123
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
12.9k
      g  = (*bufferptr++) << 8;
681
12.9k
      g |= (*bufferptr++);
682
12.9k
      if (g > maxval)
683
99
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
12.9k
      b  = (*bufferptr++) << 8;
685
12.9k
      b |= (*bufferptr++);
686
12.9k
      if (b > maxval)
687
92
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
12.9k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
12.9k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
12.9k
      ptr += 4;
691
12.9k
    }
692
8.15k
  }
693
8.15k
  return 1;
694
8.15k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
642
12.1k
{
643
12.1k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
12.1k
  register _JSAMPROW ptr;
645
12.1k
  register unsigned char *bufferptr;
646
12.1k
  register _JSAMPLE *rescale = source->rescale;
647
12.1k
  JDIMENSION col;
648
12.1k
  unsigned int maxval = source->maxval;
649
650
12.1k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
456
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
12.1k
  ptr = source->pub._buffer[0];
653
12.1k
  bufferptr = source->iobuffer;
654
12.1k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
12.3k
    for (col = cinfo->image_width; col > 0; col--) {
656
8.29k
      register unsigned int r, g, b;
657
8.29k
      r  = (*bufferptr++) << 8;
658
8.29k
      r |= (*bufferptr++);
659
8.29k
      if (r > maxval)
660
68
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
8.29k
      g  = (*bufferptr++) << 8;
662
8.29k
      g |= (*bufferptr++);
663
8.29k
      if (g > maxval)
664
72
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
8.29k
      b  = (*bufferptr++) << 8;
666
8.29k
      b |= (*bufferptr++);
667
8.29k
      if (b > maxval)
668
79
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
8.29k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
8.29k
                  ptr + 2, ptr + 3);
671
8.29k
      ptr += 4;
672
8.29k
    }
673
8.06k
  } else {
674
22.3k
    for (col = cinfo->image_width; col > 0; col--) {
675
14.3k
      register unsigned int r, g, b;
676
14.3k
      r  = (*bufferptr++) << 8;
677
14.3k
      r |= (*bufferptr++);
678
14.3k
      if (r > maxval)
679
124
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
14.3k
      g  = (*bufferptr++) << 8;
681
14.3k
      g |= (*bufferptr++);
682
14.3k
      if (g > maxval)
683
93
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
14.3k
      b  = (*bufferptr++) << 8;
685
14.3k
      b |= (*bufferptr++);
686
14.3k
      if (b > maxval)
687
93
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
14.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
14.3k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
14.3k
      ptr += 4;
691
14.3k
    }
692
8.06k
  }
693
12.1k
  return 1;
694
12.1k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
642
6.39k
{
643
6.39k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
644
6.39k
  register _JSAMPROW ptr;
645
6.39k
  register unsigned char *bufferptr;
646
6.39k
  register _JSAMPLE *rescale = source->rescale;
647
6.39k
  JDIMENSION col;
648
6.39k
  unsigned int maxval = source->maxval;
649
650
6.39k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
651
264
    ERREXIT(cinfo, JERR_INPUT_EOF);
652
6.39k
  ptr = source->pub._buffer[0];
653
6.39k
  bufferptr = source->iobuffer;
654
6.39k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
655
28.2k
    for (col = cinfo->image_width; col > 0; col--) {
656
25.7k
      register unsigned int r, g, b;
657
25.7k
      r  = (*bufferptr++) << 8;
658
25.7k
      r |= (*bufferptr++);
659
25.7k
      if (r > maxval)
660
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
661
25.7k
      g  = (*bufferptr++) << 8;
662
25.7k
      g |= (*bufferptr++);
663
25.7k
      if (g > maxval)
664
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
665
25.7k
      b  = (*bufferptr++) << 8;
666
25.7k
      b |= (*bufferptr++);
667
25.7k
      if (b > maxval)
668
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
669
25.7k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
670
25.7k
                  ptr + 2, ptr + 3);
671
25.7k
      ptr += 4;
672
25.7k
    }
673
3.83k
  } else {
674
9.25k
    for (col = cinfo->image_width; col > 0; col--) {
675
5.42k
      register unsigned int r, g, b;
676
5.42k
      r  = (*bufferptr++) << 8;
677
5.42k
      r |= (*bufferptr++);
678
5.42k
      if (r > maxval)
679
62
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
680
5.42k
      g  = (*bufferptr++) << 8;
681
5.42k
      g |= (*bufferptr++);
682
5.42k
      if (g > maxval)
683
52
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
684
5.42k
      b  = (*bufferptr++) << 8;
685
5.42k
      b |= (*bufferptr++);
686
5.42k
      if (b > maxval)
687
51
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
688
5.42k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
689
5.42k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
690
5.42k
      ptr += 4;
691
5.42k
    }
692
3.83k
  }
693
6.39k
  return 1;
694
6.39k
}
695
696
697
/*
698
 * Read the file header; return image size and component count.
699
 */
700
701
METHODDEF(void)
702
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
703
173k
{
704
173k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
173k
  int c;
706
173k
  unsigned int w, h, maxval;
707
173k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
173k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
173k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
173k
  switch (c) {
716
17.9k
  case '2':                     /* it's a text-format PGM file */
717
38.0k
  case '3':                     /* it's a text-format PPM file */
718
132k
  case '5':                     /* it's a raw-format PGM file */
719
173k
  case '6':                     /* it's a raw-format PPM file */
720
173k
    break;
721
537
  default:
722
537
    ERREXIT(cinfo, JERR_PPM_NOT);
723
537
    break;
724
173k
  }
725
726
  /* fetch the remaining header info */
727
173k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
173k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
173k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
173k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
402
    ERREXIT(cinfo, JERR_PPM_NOT);
733
173k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
199
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
173k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
2.56k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
173k
  cinfo->image_width = (JDIMENSION)w;
739
173k
  cinfo->image_height = (JDIMENSION)h;
740
173k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
173k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
173k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
173k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
173k
  switch (c) {
748
13.4k
  case '2':                     /* it's a text-format PGM file */
749
13.4k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
13.4k
        cinfo->in_color_space == JCS_RGB)
751
220
      cinfo->in_color_space = JCS_GRAYSCALE;
752
13.4k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
13.4k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
2.13k
      source->pub.get_pixel_rows = get_text_gray_row;
755
11.2k
    else if (IsExtRGB(cinfo->in_color_space))
756
9.59k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
1.68k
    else if (cinfo->in_color_space == JCS_CMYK)
758
1.68k
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
13.4k
    need_iobuffer = FALSE;
762
13.4k
    break;
763
764
15.9k
  case '3':                     /* it's a text-format PPM file */
765
15.9k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
15.9k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
15.9k
    if (IsExtRGB(cinfo->in_color_space))
769
11.6k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
4.27k
    else if (cinfo->in_color_space == JCS_CMYK)
771
2.00k
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
2.26k
    else
773
2.26k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
15.9k
    need_iobuffer = FALSE;
775
15.9k
    break;
776
777
89.2k
  case '5':                     /* it's a raw-format PGM file */
778
89.2k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
89.2k
        cinfo->in_color_space == JCS_RGB)
780
872
      cinfo->in_color_space = JCS_GRAYSCALE;
781
89.2k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
89.2k
    if (maxval > 255) {
783
11.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
1.93k
        source->pub.get_pixel_rows = get_word_gray_row;
785
9.84k
      else if (IsExtRGB(cinfo->in_color_space))
786
8.36k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
1.48k
      else if (cinfo->in_color_space == JCS_CMYK)
788
1.48k
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
44.5k
    } else if (maxval <= _MAXJSAMPLE &&
793
44.5k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
4.63k
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
786
      source->pub.get_pixel_rows = get_raw_row;
796
786
      use_raw_buffer = TRUE;
797
786
      need_rescale = FALSE;
798
#endif
799
76.7k
    } else {
800
76.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
11.2k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
65.5k
      else if (IsExtRGB(cinfo->in_color_space))
803
56.9k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
8.61k
      else if (cinfo->in_color_space == JCS_CMYK)
805
8.61k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
76.7k
    }
809
89.2k
    break;
810
811
37.3k
  case '6':                     /* it's a raw-format PPM file */
812
37.3k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
37.3k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
37.3k
    if (maxval > 255) {
816
16.4k
      if (IsExtRGB(cinfo->in_color_space))
817
11.9k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
4.47k
      else if (cinfo->in_color_space == JCS_CMYK)
819
2.14k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
2.33k
      else
821
2.33k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
11.7k
    } else if (maxval <= _MAXJSAMPLE &&
824
11.7k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
2.04k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
2.04k
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
1.78k
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
313
      source->pub.get_pixel_rows = get_raw_row;
832
313
      use_raw_buffer = TRUE;
833
313
      need_rescale = FALSE;
834
#endif
835
20.5k
    } else {
836
20.5k
      if (IsExtRGB(cinfo->in_color_space))
837
15.0k
        source->pub.get_pixel_rows = get_rgb_row;
838
5.53k
      else if (cinfo->in_color_space == JCS_CMYK)
839
2.54k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
2.98k
      else
841
2.98k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
20.5k
    }
843
37.3k
    break;
844
173k
  }
845
846
148k
  if (IsExtRGB(cinfo->in_color_space))
847
113k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
34.5k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
16.0k
    cinfo->input_components = 1;
850
18.4k
  else if (cinfo->in_color_space == JCS_CMYK)
851
18.4k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
148k
  if (need_iobuffer) {
855
121k
    if (c == '6')
856
31.9k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
89.2k
    else
858
89.2k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
121k
    source->iobuffer = (unsigned char *)
860
121k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
121k
                                  source->buffer_width);
862
121k
  }
863
864
  /* Create compressor input buffer. */
865
148k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
1.09k
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
1.09k
    source->pub._buffer = &source->pixrow;
870
1.09k
    source->pub.buffer_height = 1;
871
147k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
147k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
147k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
147k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
147k
    source->pub.buffer_height = 1;
877
147k
  }
878
879
  /* Compute the rescaling array if required. */
880
148k
  if (need_rescale) {
881
147k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
147k
    source->rescale = (_JSAMPLE *)
885
147k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
147k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
147k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
147k
    half_maxval = (size_t)maxval / 2;
889
523M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
523M
      source->rescale[val] =
892
523M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
523M
                   maxval);
894
523M
    }
895
147k
  }
896
148k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
703
89.0k
{
704
89.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
89.0k
  int c;
706
89.0k
  unsigned int w, h, maxval;
707
89.0k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
89.0k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
89.0k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
89.0k
  switch (c) {
716
8.53k
  case '2':                     /* it's a text-format PGM file */
717
17.8k
  case '3':                     /* it's a text-format PPM file */
718
69.5k
  case '5':                     /* it's a raw-format PGM file */
719
88.8k
  case '6':                     /* it's a raw-format PPM file */
720
88.8k
    break;
721
257
  default:
722
257
    ERREXIT(cinfo, JERR_PPM_NOT);
723
257
    break;
724
89.0k
  }
725
726
  /* fetch the remaining header info */
727
88.8k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
88.8k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
88.8k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
88.8k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
199
    ERREXIT(cinfo, JERR_PPM_NOT);
733
88.8k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
101
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
88.8k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.11k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
88.8k
  cinfo->image_width = (JDIMENSION)w;
739
88.8k
  cinfo->image_height = (JDIMENSION)h;
740
88.8k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
88.8k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
88.8k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
88.8k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
88.8k
  switch (c) {
748
6.17k
  case '2':                     /* it's a text-format PGM file */
749
6.17k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
6.17k
        cinfo->in_color_space == JCS_RGB)
751
220
      cinfo->in_color_space = JCS_GRAYSCALE;
752
6.17k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
6.17k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
1.10k
      source->pub.get_pixel_rows = get_text_gray_row;
755
5.06k
    else if (IsExtRGB(cinfo->in_color_space))
756
4.42k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
646
    else if (cinfo->in_color_space == JCS_CMYK)
758
646
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
6.17k
    need_iobuffer = FALSE;
762
6.17k
    break;
763
764
7.43k
  case '3':                     /* it's a text-format PPM file */
765
7.43k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
7.43k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
7.43k
    if (IsExtRGB(cinfo->in_color_space))
769
5.59k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.83k
    else if (cinfo->in_color_space == JCS_CMYK)
771
790
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
1.04k
    else
773
1.04k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
7.43k
    need_iobuffer = FALSE;
775
7.43k
    break;
776
777
49.0k
  case '5':                     /* it's a raw-format PGM file */
778
49.0k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
49.0k
        cinfo->in_color_space == JCS_RGB)
780
872
      cinfo->in_color_space = JCS_GRAYSCALE;
781
49.0k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
49.0k
    if (maxval > 255) {
783
4.45k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
890
        source->pub.get_pixel_rows = get_word_gray_row;
785
3.56k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.13k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
438
      else if (cinfo->in_color_space == JCS_CMYK)
788
438
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
4.45k
#if BITS_IN_JSAMPLE == 8
792
44.5k
    } else if (maxval <= _MAXJSAMPLE &&
793
44.5k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
4.63k
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
786
      source->pub.get_pixel_rows = get_raw_row;
796
786
      use_raw_buffer = TRUE;
797
786
      need_rescale = FALSE;
798
786
#endif
799
43.7k
    } else {
800
43.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
6.49k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
37.2k
      else if (IsExtRGB(cinfo->in_color_space))
803
33.3k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
3.90k
      else if (cinfo->in_color_space == JCS_CMYK)
805
3.90k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
43.7k
    }
809
49.0k
    break;
810
811
17.6k
  case '6':                     /* it's a raw-format PPM file */
812
17.6k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
17.6k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
17.6k
    if (maxval > 255) {
816
5.87k
      if (IsExtRGB(cinfo->in_color_space))
817
4.42k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
1.45k
      else if (cinfo->in_color_space == JCS_CMYK)
819
634
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
818
      else
821
818
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
5.87k
#if BITS_IN_JSAMPLE == 8
823
11.7k
    } else if (maxval <= _MAXJSAMPLE &&
824
11.7k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
2.04k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
2.04k
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
1.78k
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
313
      source->pub.get_pixel_rows = get_raw_row;
832
313
      use_raw_buffer = TRUE;
833
313
      need_rescale = FALSE;
834
313
#endif
835
11.4k
    } else {
836
11.4k
      if (IsExtRGB(cinfo->in_color_space))
837
8.50k
        source->pub.get_pixel_rows = get_rgb_row;
838
2.93k
      else if (cinfo->in_color_space == JCS_CMYK)
839
1.24k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
1.68k
      else
841
1.68k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
11.4k
    }
843
17.6k
    break;
844
88.8k
  }
845
846
76.7k
  if (IsExtRGB(cinfo->in_color_space))
847
59.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
16.9k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
9.27k
    cinfo->input_components = 1;
850
7.66k
  else if (cinfo->in_color_space == JCS_CMYK)
851
7.66k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
76.7k
  if (need_iobuffer) {
855
64.1k
    if (c == '6')
856
15.1k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
49.0k
    else
858
49.0k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
64.1k
    source->iobuffer = (unsigned char *)
860
64.1k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
64.1k
                                  source->buffer_width);
862
64.1k
  }
863
864
  /* Create compressor input buffer. */
865
76.7k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
1.09k
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
1.09k
    source->pub._buffer = &source->pixrow;
870
1.09k
    source->pub.buffer_height = 1;
871
75.6k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
75.6k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
75.6k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
75.6k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
75.6k
    source->pub.buffer_height = 1;
877
75.6k
  }
878
879
  /* Compute the rescaling array if required. */
880
76.7k
  if (need_rescale) {
881
75.6k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
75.6k
    source->rescale = (_JSAMPLE *)
885
75.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
75.6k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
75.6k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
75.6k
    half_maxval = (size_t)maxval / 2;
889
129M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
129M
      source->rescale[val] =
892
129M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
129M
                   maxval);
894
129M
    }
895
75.6k
  }
896
76.7k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
703
60.3k
{
704
60.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
60.3k
  int c;
706
60.3k
  unsigned int w, h, maxval;
707
60.3k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
60.3k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
60.3k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
60.3k
  switch (c) {
716
6.20k
  case '2':                     /* it's a text-format PGM file */
717
13.0k
  case '3':                     /* it's a text-format PPM file */
718
44.9k
  case '5':                     /* it's a raw-format PGM file */
719
60.1k
  case '6':                     /* it's a raw-format PPM file */
720
60.1k
    break;
721
217
  default:
722
217
    ERREXIT(cinfo, JERR_PPM_NOT);
723
217
    break;
724
60.3k
  }
725
726
  /* fetch the remaining header info */
727
60.1k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
60.1k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
60.1k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
60.1k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
133
    ERREXIT(cinfo, JERR_PPM_NOT);
733
60.1k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
56
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
60.1k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
973
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
60.1k
  cinfo->image_width = (JDIMENSION)w;
739
60.1k
  cinfo->image_height = (JDIMENSION)h;
740
60.1k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
60.1k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
60.1k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
60.1k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
60.1k
  switch (c) {
748
4.59k
  case '2':                     /* it's a text-format PGM file */
749
4.59k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
4.59k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
4.59k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
4.59k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
656
      source->pub.get_pixel_rows = get_text_gray_row;
755
3.93k
    else if (IsExtRGB(cinfo->in_color_space))
756
3.28k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
656
    else if (cinfo->in_color_space == JCS_CMYK)
758
656
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
4.59k
    need_iobuffer = FALSE;
762
4.59k
    break;
763
764
5.42k
  case '3':                     /* it's a text-format PPM file */
765
5.42k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
5.42k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
5.42k
    if (IsExtRGB(cinfo->in_color_space))
769
3.87k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.55k
    else if (cinfo->in_color_space == JCS_CMYK)
771
775
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
775
    else
773
775
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
5.42k
    need_iobuffer = FALSE;
775
5.42k
    break;
776
777
30.2k
  case '5':                     /* it's a raw-format PGM file */
778
30.2k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
30.2k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
30.2k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
30.2k
    if (maxval > 255) {
783
4.77k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
682
        source->pub.get_pixel_rows = get_word_gray_row;
785
4.09k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.41k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
682
      else if (cinfo->in_color_space == JCS_CMYK)
788
682
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
    } else if (maxval <= _MAXJSAMPLE &&
793
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
      source->pub.get_pixel_rows = get_raw_row;
796
      use_raw_buffer = TRUE;
797
      need_rescale = FALSE;
798
#endif
799
25.5k
    } else {
800
25.5k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
3.64k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
21.8k
      else if (IsExtRGB(cinfo->in_color_space))
803
18.2k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
3.64k
      else if (cinfo->in_color_space == JCS_CMYK)
805
3.64k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
25.5k
    }
809
30.2k
    break;
810
811
13.9k
  case '6':                     /* it's a raw-format PPM file */
812
13.9k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
13.9k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
13.9k
    if (maxval > 255) {
816
7.28k
      if (IsExtRGB(cinfo->in_color_space))
817
5.20k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
2.08k
      else if (cinfo->in_color_space == JCS_CMYK)
819
1.04k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
1.04k
      else
821
1.04k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
    } else if (maxval <= _MAXJSAMPLE &&
824
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
      source->pub.get_pixel_rows = get_raw_row;
832
      use_raw_buffer = TRUE;
833
      need_rescale = FALSE;
834
#endif
835
7.28k
    } else {
836
6.62k
      if (IsExtRGB(cinfo->in_color_space))
837
4.73k
        source->pub.get_pixel_rows = get_rgb_row;
838
1.89k
      else if (cinfo->in_color_space == JCS_CMYK)
839
946
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
946
      else
841
946
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
6.62k
    }
843
13.9k
    break;
844
60.1k
  }
845
846
51.4k
  if (IsExtRGB(cinfo->in_color_space))
847
38.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
12.7k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
4.98k
    cinfo->input_components = 1;
850
7.74k
  else if (cinfo->in_color_space == JCS_CMYK)
851
7.74k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
51.4k
  if (need_iobuffer) {
855
42.2k
    if (c == '6')
856
11.9k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
30.2k
    else
858
30.2k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
42.2k
    source->iobuffer = (unsigned char *)
860
42.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
42.2k
                                  source->buffer_width);
862
42.2k
  }
863
864
  /* Create compressor input buffer. */
865
51.4k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
0
    source->pub._buffer = &source->pixrow;
870
0
    source->pub.buffer_height = 1;
871
51.4k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
51.4k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
51.4k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
51.4k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
51.4k
    source->pub.buffer_height = 1;
877
51.4k
  }
878
879
  /* Compute the rescaling array if required. */
880
51.4k
  if (need_rescale) {
881
51.4k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
51.4k
    source->rescale = (_JSAMPLE *)
885
51.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
51.4k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
51.4k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
51.4k
    half_maxval = (size_t)maxval / 2;
889
118M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
118M
      source->rescale[val] =
892
118M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
118M
                   maxval);
894
118M
    }
895
51.4k
  }
896
51.4k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
703
24.4k
{
704
24.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
705
24.4k
  int c;
706
24.4k
  unsigned int w, h, maxval;
707
24.4k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
708
709
24.4k
  if (getc(source->pub.input_file) != 'P')
710
0
    ERREXIT(cinfo, JERR_PPM_NOT);
711
712
24.4k
  c = getc(source->pub.input_file); /* subformat discriminator character */
713
714
  /* detect unsupported variants (ie, PBM) before trying to read header */
715
24.4k
  switch (c) {
716
3.19k
  case '2':                     /* it's a text-format PGM file */
717
7.15k
  case '3':                     /* it's a text-format PPM file */
718
17.9k
  case '5':                     /* it's a raw-format PGM file */
719
24.4k
  case '6':                     /* it's a raw-format PPM file */
720
24.4k
    break;
721
63
  default:
722
63
    ERREXIT(cinfo, JERR_PPM_NOT);
723
63
    break;
724
24.4k
  }
725
726
  /* fetch the remaining header info */
727
24.4k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
728
24.4k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
729
24.4k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
731
24.4k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
732
70
    ERREXIT(cinfo, JERR_PPM_NOT);
733
24.4k
  if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION)
734
42
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION);
735
24.4k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
469
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
24.4k
  cinfo->image_width = (JDIMENSION)w;
739
24.4k
  cinfo->image_height = (JDIMENSION)h;
740
24.4k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
24.4k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
24.4k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
24.4k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
24.4k
  switch (c) {
748
2.64k
  case '2':                     /* it's a text-format PGM file */
749
2.64k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
2.64k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
2.64k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
2.64k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
378
      source->pub.get_pixel_rows = get_text_gray_row;
755
2.26k
    else if (IsExtRGB(cinfo->in_color_space))
756
1.89k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
378
    else if (cinfo->in_color_space == JCS_CMYK)
758
378
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
2.64k
    need_iobuffer = FALSE;
762
2.64k
    break;
763
764
3.10k
  case '3':                     /* it's a text-format PPM file */
765
3.10k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
3.10k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
3.10k
    if (IsExtRGB(cinfo->in_color_space))
769
2.21k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
886
    else if (cinfo->in_color_space == JCS_CMYK)
771
443
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
443
    else
773
443
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
3.10k
    need_iobuffer = FALSE;
775
3.10k
    break;
776
777
9.98k
  case '5':                     /* it's a raw-format PGM file */
778
9.98k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
9.98k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
9.98k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
9.98k
    if (maxval > 255) {
783
2.54k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
364
        source->pub.get_pixel_rows = get_word_gray_row;
785
2.18k
      else if (IsExtRGB(cinfo->in_color_space))
786
1.82k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
364
      else if (cinfo->in_color_space == JCS_CMYK)
788
364
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
#if BITS_IN_JSAMPLE == 8
792
    } else if (maxval <= _MAXJSAMPLE &&
793
               maxval == ((1U << cinfo->data_precision) - 1U) &&
794
               cinfo->in_color_space == JCS_GRAYSCALE) {
795
      source->pub.get_pixel_rows = get_raw_row;
796
      use_raw_buffer = TRUE;
797
      need_rescale = FALSE;
798
#endif
799
7.43k
    } else {
800
7.43k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
801
1.06k
        source->pub.get_pixel_rows = get_scaled_gray_row;
802
6.37k
      else if (IsExtRGB(cinfo->in_color_space))
803
5.31k
        source->pub.get_pixel_rows = get_gray_rgb_row;
804
1.06k
      else if (cinfo->in_color_space == JCS_CMYK)
805
1.06k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
806
0
      else
807
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
808
7.43k
    }
809
9.98k
    break;
810
811
5.77k
  case '6':                     /* it's a raw-format PPM file */
812
5.77k
    if (cinfo->in_color_space == JCS_UNKNOWN)
813
0
      cinfo->in_color_space = JCS_EXT_RGB;
814
5.77k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
815
5.77k
    if (maxval > 255) {
816
3.29k
      if (IsExtRGB(cinfo->in_color_space))
817
2.35k
        source->pub.get_pixel_rows = get_word_rgb_row;
818
942
      else if (cinfo->in_color_space == JCS_CMYK)
819
471
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
820
471
      else
821
471
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
822
#if BITS_IN_JSAMPLE == 8
823
    } else if (maxval <= _MAXJSAMPLE &&
824
               maxval == ((1U << cinfo->data_precision) - 1U) &&
825
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
826
               (cinfo->in_color_space == JCS_EXT_RGB ||
827
                cinfo->in_color_space == JCS_RGB)) {
828
#else
829
               cinfo->in_color_space == JCS_EXT_RGB) {
830
#endif
831
      source->pub.get_pixel_rows = get_raw_row;
832
      use_raw_buffer = TRUE;
833
      need_rescale = FALSE;
834
#endif
835
3.29k
    } else {
836
2.47k
      if (IsExtRGB(cinfo->in_color_space))
837
1.77k
        source->pub.get_pixel_rows = get_rgb_row;
838
708
      else if (cinfo->in_color_space == JCS_CMYK)
839
354
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
840
354
      else
841
354
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
842
2.47k
    }
843
5.77k
    break;
844
24.4k
  }
845
846
20.2k
  if (IsExtRGB(cinfo->in_color_space))
847
15.3k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
848
4.87k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
849
1.80k
    cinfo->input_components = 1;
850
3.07k
  else if (cinfo->in_color_space == JCS_CMYK)
851
3.07k
    cinfo->input_components = 4;
852
853
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
854
20.2k
  if (need_iobuffer) {
855
14.9k
    if (c == '6')
856
4.95k
      source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2);
857
9.98k
    else
858
9.98k
      source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2);
859
14.9k
    source->iobuffer = (unsigned char *)
860
14.9k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
861
14.9k
                                  source->buffer_width);
862
14.9k
  }
863
864
  /* Create compressor input buffer. */
865
20.2k
  if (use_raw_buffer) {
866
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
867
    /* Synthesize a _JSAMPARRAY pointer structure */
868
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
869
0
    source->pub._buffer = &source->pixrow;
870
0
    source->pub.buffer_height = 1;
871
20.2k
  } else {
872
    /* Need to translate anyway, so make a separate sample buffer. */
873
20.2k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
874
20.2k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
875
20.2k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
876
20.2k
    source->pub.buffer_height = 1;
877
20.2k
  }
878
879
  /* Compute the rescaling array if required. */
880
20.2k
  if (need_rescale) {
881
20.2k
    size_t val, half_maxval;
882
883
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
884
20.2k
    source->rescale = (_JSAMPLE *)
885
20.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
886
20.2k
                                  (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
887
20.2k
    memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE));
888
20.2k
    half_maxval = (size_t)maxval / 2;
889
275M
    for (val = 0; val <= (size_t)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
275M
      source->rescale[val] =
892
275M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
275M
                   maxval);
894
275M
    }
895
20.2k
  }
896
20.2k
}
897
898
899
/*
900
 * Finish up at the end of the file.
901
 */
902
903
METHODDEF(void)
904
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
905
127k
{
906
  /* no work */
907
127k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
905
67.3k
{
906
  /* no work */
907
67.3k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
905
43.9k
{
906
  /* no work */
907
43.9k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
905
16.2k
{
906
  /* no work */
907
16.2k
}
908
909
910
/*
911
 * The module selection routine for PPM format input.
912
 */
913
914
GLOBAL(cjpeg_source_ptr)
915
_jinit_read_ppm(j_compress_ptr cinfo)
916
173k
{
917
173k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
89.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
84.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
84.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
173k
  source = (ppm_source_ptr)
929
173k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
173k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
173k
  source->pub.start_input = start_input_ppm;
933
173k
  source->pub.finish_input = finish_input_ppm;
934
173k
  source->pub.max_pixels = 0;
935
936
173k
  return (cjpeg_source_ptr)source;
937
173k
}
jinit_read_ppm
Line
Count
Source
916
89.0k
{
917
89.0k
  ppm_source_ptr source;
918
919
89.0k
#if BITS_IN_JSAMPLE == 8
920
89.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
89.0k
  source = (ppm_source_ptr)
929
89.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
89.0k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
89.0k
  source->pub.start_input = start_input_ppm;
933
89.0k
  source->pub.finish_input = finish_input_ppm;
934
89.0k
  source->pub.max_pixels = 0;
935
936
89.0k
  return (cjpeg_source_ptr)source;
937
89.0k
}
j12init_read_ppm
Line
Count
Source
916
60.3k
{
917
60.3k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
60.3k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
60.3k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
60.3k
  source = (ppm_source_ptr)
929
60.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
60.3k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
60.3k
  source->pub.start_input = start_input_ppm;
933
60.3k
  source->pub.finish_input = finish_input_ppm;
934
60.3k
  source->pub.max_pixels = 0;
935
936
60.3k
  return (cjpeg_source_ptr)source;
937
60.3k
}
j16init_read_ppm
Line
Count
Source
916
24.4k
{
917
24.4k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
24.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
24.4k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
24.4k
  source = (ppm_source_ptr)
929
24.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
24.4k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
24.4k
  source->pub.start_input = start_input_ppm;
933
24.4k
  source->pub.finish_input = finish_input_ppm;
934
24.4k
  source->pub.max_pixels = 0;
935
936
24.4k
  return (cjpeg_source_ptr)source;
937
24.4k
}
938
939
#endif /* defined(PPM_SUPPORTED) &&
940
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */