Coverage Report

Created: 2026-03-12 08:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/rdppm.c
Line
Count
Source
1
/*
2
 * rdppm.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
6
 * Modified 2009 by Bill Allombert, Guido Vollbeding.
7
 * libjpeg-turbo Modifications:
8
 * Copyright (C) 2015-2017, 2020-2025, D. R. Commander.
9
 * For conditions of distribution and use, see the accompanying README.ijg
10
 * file.
11
 *
12
 * This file contains routines to read input images in PPM/PGM format.
13
 * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
14
 * The PBMPLUS library is NOT required to compile this software
15
 * (but it is highly useful as a set of PPM image manipulation programs).
16
 *
17
 * These routines may need modification for non-Unix environments or
18
 * specialized applications.  As they stand, they assume input from
19
 * an ordinary stdio stream.  They further assume that reading begins
20
 * at the start of the file; start_input may need work if the
21
 * user interface has already read some data (e.g., to determine that
22
 * the file is indeed PPM format).
23
 */
24
25
#include "cmyk.h"
26
#include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
27
28
#if defined(PPM_SUPPORTED) && \
29
    (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
30
31
32
/* Portions of this code are based on the PBMPLUS library, which is:
33
**
34
** Copyright (C) 1988 by Jef Poskanzer.
35
**
36
** Permission to use, copy, modify, and distribute this software and its
37
** documentation for any purpose and without fee is hereby granted, provided
38
** that the above copyright notice appear in all copies and that both that
39
** copyright notice and this permission notice appear in supporting
40
** documentation.  This software is provided "as is" without express or
41
** implied warranty.
42
*/
43
44
45
/* Macros to deal with unsigned chars as efficiently as compiler allows */
46
47
typedef unsigned char U_CHAR;
48
345M
#define UCH(x)  ((int)(x))
49
50
51
#define ReadOK(file, buffer, len) \
52
320M
  (fread(buffer, 1, len, file) == ((size_t)(len)))
53
54
static int alpha_index[JPEG_NUMCS] = {
55
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
56
};
57
58
59
/* Private version of data source object */
60
61
typedef struct {
62
  struct cjpeg_source_struct pub; /* public fields */
63
64
  /* Usually these two pointers point to the same place: */
65
  U_CHAR *iobuffer;             /* fread's I/O buffer */
66
  _JSAMPROW pixrow;             /* compressor input buffer */
67
  size_t buffer_width;          /* width of I/O buffer */
68
  _JSAMPLE *rescale;            /* => maxval-remapping array, or NULL */
69
  unsigned int maxval;
70
} ppm_source_struct;
71
72
typedef ppm_source_struct *ppm_source_ptr;
73
74
75
LOCAL(int)
76
pbm_getc(FILE *infile)
77
/* Read next char, skipping over any comments */
78
/* A comment/newline sequence is returned as a newline */
79
3.76M
{
80
3.76M
  register int ch;
81
82
3.76M
  ch = getc(infile);
83
3.76M
  if (ch == '#') {
84
748k
    do {
85
748k
      ch = getc(infile);
86
748k
    } while (ch != '\n' && ch != EOF);
87
47.5k
  }
88
3.76M
  return ch;
89
3.76M
}
rdppm-8.c:pbm_getc
Line
Count
Source
79
1.78M
{
80
1.78M
  register int ch;
81
82
1.78M
  ch = getc(infile);
83
1.78M
  if (ch == '#') {
84
343k
    do {
85
343k
      ch = getc(infile);
86
343k
    } while (ch != '\n' && ch != EOF);
87
23.8k
  }
88
1.78M
  return ch;
89
1.78M
}
rdppm-12.c:pbm_getc
Line
Count
Source
79
1.34M
{
80
1.34M
  register int ch;
81
82
1.34M
  ch = getc(infile);
83
1.34M
  if (ch == '#') {
84
303k
    do {
85
303k
      ch = getc(infile);
86
303k
    } while (ch != '\n' && ch != EOF);
87
15.2k
  }
88
1.34M
  return ch;
89
1.34M
}
rdppm-16.c:pbm_getc
Line
Count
Source
79
638k
{
80
638k
  register int ch;
81
82
638k
  ch = getc(infile);
83
638k
  if (ch == '#') {
84
101k
    do {
85
101k
      ch = getc(infile);
86
101k
    } while (ch != '\n' && ch != EOF);
87
8.44k
  }
88
638k
  return ch;
89
638k
}
90
91
92
LOCAL(unsigned int)
93
read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
94
/* Read an unsigned decimal integer from the PPM file */
95
/* Swallows one trailing character after the integer */
96
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
97
/* This should not be a problem in practice. */
98
1.59M
{
99
1.59M
  register int ch;
100
1.59M
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
1.69M
  do {
104
1.69M
    ch = pbm_getc(infile);
105
1.69M
    if (ch == EOF)
106
34.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
1.69M
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
1.59M
  if (ch < '0' || ch > '9')
110
3.52k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
1.59M
  val = ch - '0';
113
2.10M
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
508k
    val *= 10;
115
508k
    val += ch - '0';
116
508k
    if (val > maxval)
117
1.73k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
508k
  }
119
120
1.59M
  return val;
121
1.59M
}
rdppm-8.c:read_pbm_integer
Line
Count
Source
98
761k
{
99
761k
  register int ch;
100
761k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
808k
  do {
104
808k
    ch = pbm_getc(infile);
105
808k
    if (ch == EOF)
106
16.8k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
808k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
761k
  if (ch < '0' || ch > '9')
110
1.52k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
761k
  val = ch - '0';
113
993k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
232k
    val *= 10;
115
232k
    val += ch - '0';
116
232k
    if (val > maxval)
117
860
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
232k
  }
119
120
761k
  return val;
121
761k
}
rdppm-12.c:read_pbm_integer
Line
Count
Source
98
559k
{
99
559k
  register int ch;
100
559k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
597k
  do {
104
597k
    ch = pbm_getc(infile);
105
597k
    if (ch == EOF)
106
11.5k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
597k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
559k
  if (ch < '0' || ch > '9')
110
1.44k
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
559k
  val = ch - '0';
113
758k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
198k
    val *= 10;
115
198k
    val += ch - '0';
116
198k
    if (val > maxval)
117
593
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
198k
  }
119
120
559k
  return val;
121
559k
}
rdppm-16.c:read_pbm_integer
Line
Count
Source
98
274k
{
99
274k
  register int ch;
100
274k
  register unsigned int val;
101
102
  /* Skip any leading whitespace */
103
292k
  do {
104
292k
    ch = pbm_getc(infile);
105
292k
    if (ch == EOF)
106
6.49k
      ERREXIT(cinfo, JERR_INPUT_EOF);
107
292k
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
108
109
274k
  if (ch < '0' || ch > '9')
110
553
    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
111
112
274k
  val = ch - '0';
113
352k
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
114
77.9k
    val *= 10;
115
77.9k
    val += ch - '0';
116
77.9k
    if (val > maxval)
117
277
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
118
77.9k
  }
119
120
274k
  return val;
121
274k
}
122
123
124
/*
125
 * Read one row of pixels.
126
 *
127
 * We provide several different versions depending on input file format.
128
 * In all cases, input is scaled to cinfo->data_precision.
129
 *
130
 * A really fast path is provided for reading byte/sample raw files with
131
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U,
132
 * which is the normal case for 8-bit data.
133
 */
134
135
136
METHODDEF(JDIMENSION)
137
get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
138
/* This version is for reading text-format PGM files with any maxval */
139
22.2k
{
140
22.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
22.2k
  FILE *infile = source->pub.input_file;
142
22.2k
  register _JSAMPROW ptr;
143
22.2k
  register _JSAMPLE *rescale = source->rescale;
144
22.2k
  JDIMENSION col;
145
22.2k
  unsigned int maxval = source->maxval;
146
147
22.2k
  ptr = source->pub._buffer[0];
148
61.4k
  for (col = cinfo->image_width; col > 0; col--) {
149
39.1k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
39.1k
  }
151
22.2k
  return 1;
152
22.2k
}
rdppm-8.c:get_text_gray_row
Line
Count
Source
139
11.5k
{
140
11.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
11.5k
  FILE *infile = source->pub.input_file;
142
11.5k
  register _JSAMPROW ptr;
143
11.5k
  register _JSAMPLE *rescale = source->rescale;
144
11.5k
  JDIMENSION col;
145
11.5k
  unsigned int maxval = source->maxval;
146
147
11.5k
  ptr = source->pub._buffer[0];
148
32.0k
  for (col = cinfo->image_width; col > 0; col--) {
149
20.4k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
20.4k
  }
151
11.5k
  return 1;
152
11.5k
}
rdppm-12.c:get_text_gray_row
Line
Count
Source
139
6.71k
{
140
6.71k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
6.71k
  FILE *infile = source->pub.input_file;
142
6.71k
  register _JSAMPROW ptr;
143
6.71k
  register _JSAMPLE *rescale = source->rescale;
144
6.71k
  JDIMENSION col;
145
6.71k
  unsigned int maxval = source->maxval;
146
147
6.71k
  ptr = source->pub._buffer[0];
148
18.5k
  for (col = cinfo->image_width; col > 0; col--) {
149
11.8k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
11.8k
  }
151
6.71k
  return 1;
152
6.71k
}
rdppm-16.c:get_text_gray_row
Line
Count
Source
139
3.95k
{
140
3.95k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
141
3.95k
  FILE *infile = source->pub.input_file;
142
3.95k
  register _JSAMPROW ptr;
143
3.95k
  register _JSAMPLE *rescale = source->rescale;
144
3.95k
  JDIMENSION col;
145
3.95k
  unsigned int maxval = source->maxval;
146
147
3.95k
  ptr = source->pub._buffer[0];
148
10.8k
  for (col = cinfo->image_width; col > 0; col--) {
149
6.86k
    *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
150
6.86k
  }
151
3.95k
  return 1;
152
3.95k
}
153
154
155
229M
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
156
1.01G
  for (col = cinfo->image_width; col > 0; col--) { \
157
789M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
158
789M
    alpha_set_op \
159
789M
    ptr += ps; \
160
789M
  } \
161
229M
}
162
163
METHODDEF(JDIMENSION)
164
get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
165
/* This version is for reading text-format PGM files with any maxval and
166
   converting to extended RGB */
167
107k
{
168
107k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
107k
  FILE *infile = source->pub.input_file;
170
107k
  register _JSAMPROW ptr;
171
107k
  register _JSAMPLE *rescale = source->rescale;
172
107k
  JDIMENSION col;
173
107k
  unsigned int maxval = source->maxval;
174
107k
  register int rindex = rgb_red[cinfo->in_color_space];
175
107k
  register int gindex = rgb_green[cinfo->in_color_space];
176
107k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
107k
  register int aindex = alpha_index[cinfo->in_color_space];
178
107k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
107k
  ptr = source->pub._buffer[0];
181
107k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
20.4k
    if (aindex >= 0)
183
2.97k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
20.4k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
17.4k
    else
186
17.4k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
87.3k
  } else {
188
87.3k
    if (aindex >= 0)
189
14.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
87.3k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
72.8k
    else
192
72.8k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
87.3k
  }
194
107k
  return 1;
195
107k
}
rdppm-8.c:get_text_gray_rgb_row
Line
Count
Source
167
54.4k
{
168
54.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
54.4k
  FILE *infile = source->pub.input_file;
170
54.4k
  register _JSAMPROW ptr;
171
54.4k
  register _JSAMPLE *rescale = source->rescale;
172
54.4k
  JDIMENSION col;
173
54.4k
  unsigned int maxval = source->maxval;
174
54.4k
  register int rindex = rgb_red[cinfo->in_color_space];
175
54.4k
  register int gindex = rgb_green[cinfo->in_color_space];
176
54.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
54.4k
  register int aindex = alpha_index[cinfo->in_color_space];
178
54.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
54.4k
  ptr = source->pub._buffer[0];
181
54.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
9.40k
    if (aindex >= 0)
183
984
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
9.40k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
8.42k
    else
186
8.42k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
45.0k
  } else {
188
45.0k
    if (aindex >= 0)
189
5.86k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
45.0k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
39.1k
    else
192
39.1k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
45.0k
  }
194
54.4k
  return 1;
195
54.4k
}
rdppm-12.c:get_text_gray_rgb_row
Line
Count
Source
167
33.5k
{
168
33.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
33.5k
  FILE *infile = source->pub.input_file;
170
33.5k
  register _JSAMPROW ptr;
171
33.5k
  register _JSAMPLE *rescale = source->rescale;
172
33.5k
  JDIMENSION col;
173
33.5k
  unsigned int maxval = source->maxval;
174
33.5k
  register int rindex = rgb_red[cinfo->in_color_space];
175
33.5k
  register int gindex = rgb_green[cinfo->in_color_space];
176
33.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
33.5k
  register int aindex = alpha_index[cinfo->in_color_space];
178
33.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
33.5k
  ptr = source->pub._buffer[0];
181
33.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
8.38k
    if (aindex >= 0)
183
1.54k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
8.38k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
6.83k
    else
186
6.83k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
25.2k
  } else {
188
25.2k
    if (aindex >= 0)
189
5.17k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
25.2k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
20.0k
    else
192
20.0k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
25.2k
  }
194
33.5k
  return 1;
195
33.5k
}
rdppm-16.c:get_text_gray_rgb_row
Line
Count
Source
167
19.7k
{
168
19.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
169
19.7k
  FILE *infile = source->pub.input_file;
170
19.7k
  register _JSAMPROW ptr;
171
19.7k
  register _JSAMPLE *rescale = source->rescale;
172
19.7k
  JDIMENSION col;
173
19.7k
  unsigned int maxval = source->maxval;
174
19.7k
  register int rindex = rgb_red[cinfo->in_color_space];
175
19.7k
  register int gindex = rgb_green[cinfo->in_color_space];
176
19.7k
  register int bindex = rgb_blue[cinfo->in_color_space];
177
19.7k
  register int aindex = alpha_index[cinfo->in_color_space];
178
19.7k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
179
180
19.7k
  ptr = source->pub._buffer[0];
181
19.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
182
2.68k
    if (aindex >= 0)
183
443
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
184
2.68k
                         ptr[aindex] = (_JSAMPLE)maxval;)
185
2.23k
    else
186
2.23k
      GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
187
17.0k
  } else {
188
17.0k
    if (aindex >= 0)
189
3.51k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
190
17.0k
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
191
13.5k
    else
192
13.5k
      GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
193
17.0k
  }
194
19.7k
  return 1;
195
19.7k
}
196
197
198
METHODDEF(JDIMENSION)
199
get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
200
/* This version is for reading text-format PGM files with any maxval and
201
   converting to CMYK */
202
17.5k
{
203
17.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
17.5k
  FILE *infile = source->pub.input_file;
205
17.5k
  register _JSAMPROW ptr;
206
17.5k
  register _JSAMPLE *rescale = source->rescale;
207
17.5k
  JDIMENSION col;
208
17.5k
  unsigned int maxval = source->maxval;
209
210
17.5k
  ptr = source->pub._buffer[0];
211
17.5k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
13.3k
    for (col = cinfo->image_width; col > 0; col--) {
213
8.67k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
8.67k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
8.67k
      ptr += 4;
216
8.67k
    }
217
12.8k
  } else {
218
35.2k
    for (col = cinfo->image_width; col > 0; col--) {
219
22.4k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
22.4k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
22.4k
                  ptr + 1, ptr + 2, ptr + 3);
222
22.4k
      ptr += 4;
223
22.4k
    }
224
12.8k
  }
225
17.5k
  return 1;
226
17.5k
}
rdppm-8.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.85k
{
203
6.85k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.85k
  FILE *infile = source->pub.input_file;
205
6.85k
  register _JSAMPROW ptr;
206
6.85k
  register _JSAMPLE *rescale = source->rescale;
207
6.85k
  JDIMENSION col;
208
6.85k
  unsigned int maxval = source->maxval;
209
210
6.85k
  ptr = source->pub._buffer[0];
211
6.85k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
4.80k
    for (col = cinfo->image_width; col > 0; col--) {
213
3.18k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
3.18k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
3.18k
      ptr += 4;
216
3.18k
    }
217
5.23k
  } else {
218
14.4k
    for (col = cinfo->image_width; col > 0; col--) {
219
9.19k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
9.19k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
9.19k
                  ptr + 1, ptr + 2, ptr + 3);
222
9.19k
      ptr += 4;
223
9.19k
    }
224
5.23k
  }
225
6.85k
  return 1;
226
6.85k
}
rdppm-12.c:get_text_gray_cmyk_row
Line
Count
Source
202
6.71k
{
203
6.71k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
6.71k
  FILE *infile = source->pub.input_file;
205
6.71k
  register _JSAMPROW ptr;
206
6.71k
  register _JSAMPLE *rescale = source->rescale;
207
6.71k
  JDIMENSION col;
208
6.71k
  unsigned int maxval = source->maxval;
209
210
6.71k
  ptr = source->pub._buffer[0];
211
6.71k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
5.96k
    for (col = cinfo->image_width; col > 0; col--) {
213
3.83k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
3.83k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
3.83k
      ptr += 4;
216
3.83k
    }
217
4.58k
  } else {
218
12.6k
    for (col = cinfo->image_width; col > 0; col--) {
219
8.01k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
8.01k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
8.01k
                  ptr + 1, ptr + 2, ptr + 3);
222
8.01k
      ptr += 4;
223
8.01k
    }
224
4.58k
  }
225
6.71k
  return 1;
226
6.71k
}
rdppm-16.c:get_text_gray_cmyk_row
Line
Count
Source
202
3.95k
{
203
3.95k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
204
3.95k
  FILE *infile = source->pub.input_file;
205
3.95k
  register _JSAMPROW ptr;
206
3.95k
  register _JSAMPLE *rescale = source->rescale;
207
3.95k
  JDIMENSION col;
208
3.95k
  unsigned int maxval = source->maxval;
209
210
3.95k
  ptr = source->pub._buffer[0];
211
3.95k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
212
2.59k
    for (col = cinfo->image_width; col > 0; col--) {
213
1.65k
      _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
214
1.65k
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
215
1.65k
      ptr += 4;
216
1.65k
    }
217
3.01k
  } else {
218
8.22k
    for (col = cinfo->image_width; col > 0; col--) {
219
5.20k
      _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
220
5.20k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
221
5.20k
                  ptr + 1, ptr + 2, ptr + 3);
222
5.20k
      ptr += 4;
223
5.20k
    }
224
3.01k
  }
225
3.95k
  return 1;
226
3.95k
}
227
228
229
9.98M
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
230
88.4M
  for (col = cinfo->image_width; col > 0; col--) { \
231
78.4M
    ptr[rindex] = read_op; \
232
78.4M
    ptr[gindex] = read_op; \
233
78.4M
    ptr[bindex] = read_op; \
234
78.4M
    alpha_set_op \
235
78.4M
    ptr += ps; \
236
78.4M
  } \
237
9.98M
}
238
239
METHODDEF(JDIMENSION)
240
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
241
/* This version is for reading text-format PPM files with any maxval */
242
124k
{
243
124k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
124k
  FILE *infile = source->pub.input_file;
245
124k
  register _JSAMPROW ptr;
246
124k
  register _JSAMPLE *rescale = source->rescale;
247
124k
  JDIMENSION col;
248
124k
  unsigned int maxval = source->maxval;
249
124k
  register int rindex = rgb_red[cinfo->in_color_space];
250
124k
  register int gindex = rgb_green[cinfo->in_color_space];
251
124k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
124k
  register int aindex = alpha_index[cinfo->in_color_space];
253
124k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
124k
  ptr = source->pub._buffer[0];
256
124k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
23.5k
    if (aindex >= 0)
258
3.15k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
23.5k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
20.3k
    else
261
20.3k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
100k
  } else {
263
100k
    if (aindex >= 0)
264
17.6k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
100k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
83.0k
    else
267
83.0k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
100k
  }
269
124k
  return 1;
270
124k
}
rdppm-8.c:get_text_rgb_row
Line
Count
Source
242
61.0k
{
243
61.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
61.0k
  FILE *infile = source->pub.input_file;
245
61.0k
  register _JSAMPROW ptr;
246
61.0k
  register _JSAMPLE *rescale = source->rescale;
247
61.0k
  JDIMENSION col;
248
61.0k
  unsigned int maxval = source->maxval;
249
61.0k
  register int rindex = rgb_red[cinfo->in_color_space];
250
61.0k
  register int gindex = rgb_green[cinfo->in_color_space];
251
61.0k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
61.0k
  register int aindex = alpha_index[cinfo->in_color_space];
253
61.0k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
61.0k
  ptr = source->pub._buffer[0];
256
61.0k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
12.5k
    if (aindex >= 0)
258
1.39k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
12.5k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
11.1k
    else
261
11.1k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
48.4k
  } else {
263
48.4k
    if (aindex >= 0)
264
6.80k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
48.4k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
41.6k
    else
267
41.6k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
48.4k
  }
269
61.0k
  return 1;
270
61.0k
}
rdppm-12.c:get_text_rgb_row
Line
Count
Source
242
37.3k
{
243
37.3k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
37.3k
  FILE *infile = source->pub.input_file;
245
37.3k
  register _JSAMPROW ptr;
246
37.3k
  register _JSAMPLE *rescale = source->rescale;
247
37.3k
  JDIMENSION col;
248
37.3k
  unsigned int maxval = source->maxval;
249
37.3k
  register int rindex = rgb_red[cinfo->in_color_space];
250
37.3k
  register int gindex = rgb_green[cinfo->in_color_space];
251
37.3k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
37.3k
  register int aindex = alpha_index[cinfo->in_color_space];
253
37.3k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
37.3k
  ptr = source->pub._buffer[0];
256
37.3k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
7.61k
    if (aindex >= 0)
258
1.30k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
7.61k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
6.30k
    else
261
6.30k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
29.7k
  } else {
263
29.7k
    if (aindex >= 0)
264
6.16k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
29.7k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
23.5k
    else
267
23.5k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
29.7k
  }
269
37.3k
  return 1;
270
37.3k
}
rdppm-16.c:get_text_rgb_row
Line
Count
Source
242
25.8k
{
243
25.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
244
25.8k
  FILE *infile = source->pub.input_file;
245
25.8k
  register _JSAMPROW ptr;
246
25.8k
  register _JSAMPLE *rescale = source->rescale;
247
25.8k
  JDIMENSION col;
248
25.8k
  unsigned int maxval = source->maxval;
249
25.8k
  register int rindex = rgb_red[cinfo->in_color_space];
250
25.8k
  register int gindex = rgb_green[cinfo->in_color_space];
251
25.8k
  register int bindex = rgb_blue[cinfo->in_color_space];
252
25.8k
  register int aindex = alpha_index[cinfo->in_color_space];
253
25.8k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
254
255
25.8k
  ptr = source->pub._buffer[0];
256
25.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
257
3.34k
    if (aindex >= 0)
258
455
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
259
3.34k
                    ptr[aindex] = (_JSAMPLE)maxval;)
260
2.89k
    else
261
2.89k
      RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
262
22.5k
  } else {
263
22.5k
    if (aindex >= 0)
264
4.72k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
265
22.5k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
266
17.8k
    else
267
17.8k
      RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
268
22.5k
  }
269
25.8k
  return 1;
270
25.8k
}
271
272
273
METHODDEF(JDIMENSION)
274
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
275
/* This version is for reading text-format PPM files with any maxval and
276
   converting to CMYK */
277
20.8k
{
278
20.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
20.8k
  FILE *infile = source->pub.input_file;
280
20.8k
  register _JSAMPROW ptr;
281
20.8k
  register _JSAMPLE *rescale = source->rescale;
282
20.8k
  JDIMENSION col;
283
20.8k
  unsigned int maxval = source->maxval;
284
285
20.8k
  ptr = source->pub._buffer[0];
286
20.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
20.6k
    for (col = cinfo->image_width; col > 0; col--) {
288
14.4k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
14.4k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
14.4k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
14.4k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
14.4k
      ptr += 4;
293
14.4k
    }
294
14.6k
  } else {
295
41.4k
    for (col = cinfo->image_width; col > 0; col--) {
296
26.8k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
26.8k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
26.8k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
26.8k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
26.8k
                  ptr + 2, ptr + 3);
301
26.8k
      ptr += 4;
302
26.8k
    }
303
14.6k
  }
304
20.8k
  return 1;
305
20.8k
}
rdppm-8.c:get_text_rgb_cmyk_row
Line
Count
Source
277
8.20k
{
278
8.20k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
8.20k
  FILE *infile = source->pub.input_file;
280
8.20k
  register _JSAMPROW ptr;
281
8.20k
  register _JSAMPLE *rescale = source->rescale;
282
8.20k
  JDIMENSION col;
283
8.20k
  unsigned int maxval = source->maxval;
284
285
8.20k
  ptr = source->pub._buffer[0];
286
8.20k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
8.34k
    for (col = cinfo->image_width; col > 0; col--) {
288
5.49k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
5.49k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
5.49k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
5.49k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
5.49k
      ptr += 4;
293
5.49k
    }
294
5.35k
  } else {
295
15.7k
    for (col = cinfo->image_width; col > 0; col--) {
296
10.3k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.3k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
10.3k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
10.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
10.3k
                  ptr + 2, ptr + 3);
301
10.3k
      ptr += 4;
302
10.3k
    }
303
5.35k
  }
304
8.20k
  return 1;
305
8.20k
}
rdppm-12.c:get_text_rgb_cmyk_row
Line
Count
Source
277
7.46k
{
278
7.46k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
7.46k
  FILE *infile = source->pub.input_file;
280
7.46k
  register _JSAMPROW ptr;
281
7.46k
  register _JSAMPLE *rescale = source->rescale;
282
7.46k
  JDIMENSION col;
283
7.46k
  unsigned int maxval = source->maxval;
284
285
7.46k
  ptr = source->pub._buffer[0];
286
7.46k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
8.42k
    for (col = cinfo->image_width; col > 0; col--) {
288
6.23k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
6.23k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
6.23k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
6.23k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
6.23k
      ptr += 4;
293
6.23k
    }
294
5.27k
  } else {
295
15.5k
    for (col = cinfo->image_width; col > 0; col--) {
296
10.3k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
10.3k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
10.3k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
10.3k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
10.3k
                  ptr + 2, ptr + 3);
301
10.3k
      ptr += 4;
302
10.3k
    }
303
5.27k
  }
304
7.46k
  return 1;
305
7.46k
}
rdppm-16.c:get_text_rgb_cmyk_row
Line
Count
Source
277
5.17k
{
278
5.17k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
279
5.17k
  FILE *infile = source->pub.input_file;
280
5.17k
  register _JSAMPROW ptr;
281
5.17k
  register _JSAMPLE *rescale = source->rescale;
282
5.17k
  JDIMENSION col;
283
5.17k
  unsigned int maxval = source->maxval;
284
285
5.17k
  ptr = source->pub._buffer[0];
286
5.17k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
287
3.88k
    for (col = cinfo->image_width; col > 0; col--) {
288
2.69k
      _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
289
2.69k
      _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
290
2.69k
      _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
291
2.69k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
292
2.69k
      ptr += 4;
293
2.69k
    }
294
3.98k
  } else {
295
10.1k
    for (col = cinfo->image_width; col > 0; col--) {
296
6.16k
      _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
297
6.16k
      _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
298
6.16k
      _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
299
6.16k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
300
6.16k
                  ptr + 2, ptr + 3);
301
6.16k
      ptr += 4;
302
6.16k
    }
303
3.98k
  }
304
5.17k
  return 1;
305
5.17k
}
306
307
308
METHODDEF(JDIMENSION)
309
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
310
/* This version is for reading raw-byte-format PGM files with any maxval */
311
43.8M
{
312
43.8M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
43.8M
  register _JSAMPROW ptr;
314
43.8M
  register U_CHAR *bufferptr;
315
43.8M
  register _JSAMPLE *rescale = source->rescale;
316
43.8M
  JDIMENSION col;
317
318
43.8M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
1.19k
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
43.8M
  ptr = source->pub._buffer[0];
321
43.8M
  bufferptr = source->iobuffer;
322
198M
  for (col = cinfo->image_width; col > 0; col--) {
323
154M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
154M
  }
325
43.8M
  return 1;
326
43.8M
}
rdppm-8.c:get_scaled_gray_row
Line
Count
Source
311
21.9M
{
312
21.9M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
21.9M
  register _JSAMPROW ptr;
314
21.9M
  register U_CHAR *bufferptr;
315
21.9M
  register _JSAMPLE *rescale = source->rescale;
316
21.9M
  JDIMENSION col;
317
318
21.9M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
793
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
21.9M
  ptr = source->pub._buffer[0];
321
21.9M
  bufferptr = source->iobuffer;
322
87.5M
  for (col = cinfo->image_width; col > 0; col--) {
323
65.5M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
65.5M
  }
325
21.9M
  return 1;
326
21.9M
}
rdppm-12.c:get_scaled_gray_row
Line
Count
Source
311
17.0M
{
312
17.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
17.0M
  register _JSAMPROW ptr;
314
17.0M
  register U_CHAR *bufferptr;
315
17.0M
  register _JSAMPLE *rescale = source->rescale;
316
17.0M
  JDIMENSION col;
317
318
17.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
274
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
17.0M
  ptr = source->pub._buffer[0];
321
17.0M
  bufferptr = source->iobuffer;
322
77.4M
  for (col = cinfo->image_width; col > 0; col--) {
323
60.3M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
60.3M
  }
325
17.0M
  return 1;
326
17.0M
}
rdppm-16.c:get_scaled_gray_row
Line
Count
Source
311
4.80M
{
312
4.80M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
313
4.80M
  register _JSAMPROW ptr;
314
4.80M
  register U_CHAR *bufferptr;
315
4.80M
  register _JSAMPLE *rescale = source->rescale;
316
4.80M
  JDIMENSION col;
317
318
4.80M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
319
131
    ERREXIT(cinfo, JERR_INPUT_EOF);
320
4.80M
  ptr = source->pub._buffer[0];
321
4.80M
  bufferptr = source->iobuffer;
322
33.2M
  for (col = cinfo->image_width; col > 0; col--) {
323
28.4M
    *ptr++ = rescale[UCH(*bufferptr++)];
324
28.4M
  }
325
4.80M
  return 1;
326
4.80M
}
327
328
329
METHODDEF(JDIMENSION)
330
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
331
/* This version is for reading raw-byte-format PGM files with any maxval
332
   and converting to extended RGB */
333
229M
{
334
229M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
229M
  register _JSAMPROW ptr;
336
229M
  register U_CHAR *bufferptr;
337
229M
  register _JSAMPLE *rescale = source->rescale;
338
229M
  JDIMENSION col;
339
229M
  unsigned int maxval = source->maxval;
340
229M
  register int rindex = rgb_red[cinfo->in_color_space];
341
229M
  register int gindex = rgb_green[cinfo->in_color_space];
342
229M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
229M
  register int aindex = alpha_index[cinfo->in_color_space];
344
229M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
229M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
5.06k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
229M
  ptr = source->pub._buffer[0];
349
229M
  bufferptr = source->iobuffer;
350
229M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
10.9M
    if (aindex >= 0)
352
367k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
10.5M
    else
354
10.5M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
218M
  } else {
356
218M
    if (aindex >= 0)
357
32.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
218M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
186M
    else
360
186M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
218M
  }
362
229M
  return 1;
363
229M
}
rdppm-8.c:get_gray_rgb_row
Line
Count
Source
333
120M
{
334
120M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
120M
  register _JSAMPROW ptr;
336
120M
  register U_CHAR *bufferptr;
337
120M
  register _JSAMPLE *rescale = source->rescale;
338
120M
  JDIMENSION col;
339
120M
  unsigned int maxval = source->maxval;
340
120M
  register int rindex = rgb_red[cinfo->in_color_space];
341
120M
  register int gindex = rgb_green[cinfo->in_color_space];
342
120M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
120M
  register int aindex = alpha_index[cinfo->in_color_space];
344
120M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
120M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
3.03k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
120M
  ptr = source->pub._buffer[0];
349
120M
  bufferptr = source->iobuffer;
350
120M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
10.9M
    if (aindex >= 0)
352
367k
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
10.5M
    else
354
10.5M
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
109M
  } else {
356
109M
    if (aindex >= 0)
357
10.2M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
109M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
99.3M
    else
360
99.3M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
109M
  }
362
120M
  return 1;
363
120M
}
rdppm-12.c:get_gray_rgb_row
Line
Count
Source
333
85.0M
{
334
85.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
85.0M
  register _JSAMPROW ptr;
336
85.0M
  register U_CHAR *bufferptr;
337
85.0M
  register _JSAMPLE *rescale = source->rescale;
338
85.0M
  JDIMENSION col;
339
85.0M
  unsigned int maxval = source->maxval;
340
85.0M
  register int rindex = rgb_red[cinfo->in_color_space];
341
85.0M
  register int gindex = rgb_green[cinfo->in_color_space];
342
85.0M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
85.0M
  register int aindex = alpha_index[cinfo->in_color_space];
344
85.0M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
85.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
1.37k
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
85.0M
  ptr = source->pub._buffer[0];
349
85.0M
  bufferptr = source->iobuffer;
350
85.0M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
0
    if (aindex >= 0)
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
0
    else
354
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
85.0M
  } else {
356
85.0M
    if (aindex >= 0)
357
17.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
85.0M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
68.0M
    else
360
68.0M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
85.0M
  }
362
85.0M
  return 1;
363
85.0M
}
rdppm-16.c:get_gray_rgb_row
Line
Count
Source
333
24.0M
{
334
24.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
335
24.0M
  register _JSAMPROW ptr;
336
24.0M
  register U_CHAR *bufferptr;
337
24.0M
  register _JSAMPLE *rescale = source->rescale;
338
24.0M
  JDIMENSION col;
339
24.0M
  unsigned int maxval = source->maxval;
340
24.0M
  register int rindex = rgb_red[cinfo->in_color_space];
341
24.0M
  register int gindex = rgb_green[cinfo->in_color_space];
342
24.0M
  register int bindex = rgb_blue[cinfo->in_color_space];
343
24.0M
  register int aindex = alpha_index[cinfo->in_color_space];
344
24.0M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
345
346
24.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
347
655
    ERREXIT(cinfo, JERR_INPUT_EOF);
348
24.0M
  ptr = source->pub._buffer[0];
349
24.0M
  bufferptr = source->iobuffer;
350
24.0M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
351
0
    if (aindex >= 0)
352
0
      GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
353
0
    else
354
0
      GRAY_RGB_READ_LOOP(*bufferptr++, {})
355
24.0M
  } else {
356
24.0M
    if (aindex >= 0)
357
4.80M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
358
24.0M
                         ptr[aindex] = (1 << cinfo->data_precision) - 1;)
359
19.2M
    else
360
19.2M
      GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
361
24.0M
  }
362
24.0M
  return 1;
363
24.0M
}
364
365
366
METHODDEF(JDIMENSION)
367
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
368
/* This version is for reading raw-byte-format PGM files with any maxval
369
   and converting to CMYK */
370
32.3M
{
371
32.3M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
32.3M
  register _JSAMPROW ptr;
373
32.3M
  register U_CHAR *bufferptr;
374
32.3M
  register _JSAMPLE *rescale = source->rescale;
375
32.3M
  JDIMENSION col;
376
32.3M
  unsigned int maxval = source->maxval;
377
378
32.3M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
840
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
32.3M
  ptr = source->pub._buffer[0];
381
32.3M
  bufferptr = source->iobuffer;
382
32.3M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
3.48M
    for (col = cinfo->image_width; col > 0; col--) {
384
2.93M
      _JSAMPLE gray = *bufferptr++;
385
2.93M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
2.93M
      ptr += 4;
387
2.93M
    }
388
31.8M
  } else {
389
161M
    for (col = cinfo->image_width; col > 0; col--) {
390
129M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
129M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
129M
                  ptr + 1, ptr + 2, ptr + 3);
393
129M
      ptr += 4;
394
129M
    }
395
31.8M
  }
396
32.3M
  return 1;
397
32.3M
}
rdppm-8.c:get_gray_cmyk_row
Line
Count
Source
370
10.5M
{
371
10.5M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
10.5M
  register _JSAMPROW ptr;
373
10.5M
  register U_CHAR *bufferptr;
374
10.5M
  register _JSAMPLE *rescale = source->rescale;
375
10.5M
  JDIMENSION col;
376
10.5M
  unsigned int maxval = source->maxval;
377
378
10.5M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
435
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
10.5M
  ptr = source->pub._buffer[0];
381
10.5M
  bufferptr = source->iobuffer;
382
10.5M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
3.48M
    for (col = cinfo->image_width; col > 0; col--) {
384
2.93M
      _JSAMPLE gray = *bufferptr++;
385
2.93M
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
2.93M
      ptr += 4;
387
2.93M
    }
388
10.0M
  } else {
389
50.5M
    for (col = cinfo->image_width; col > 0; col--) {
390
40.5M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
40.5M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
40.5M
                  ptr + 1, ptr + 2, ptr + 3);
393
40.5M
      ptr += 4;
394
40.5M
    }
395
10.0M
  }
396
10.5M
  return 1;
397
10.5M
}
rdppm-12.c:get_gray_cmyk_row
Line
Count
Source
370
17.0M
{
371
17.0M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
17.0M
  register _JSAMPROW ptr;
373
17.0M
  register U_CHAR *bufferptr;
374
17.0M
  register _JSAMPLE *rescale = source->rescale;
375
17.0M
  JDIMENSION col;
376
17.0M
  unsigned int maxval = source->maxval;
377
378
17.0M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
274
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
17.0M
  ptr = source->pub._buffer[0];
381
17.0M
  bufferptr = source->iobuffer;
382
17.0M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
0
    for (col = cinfo->image_width; col > 0; col--) {
384
0
      _JSAMPLE gray = *bufferptr++;
385
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
0
      ptr += 4;
387
0
    }
388
17.0M
  } else {
389
77.4M
    for (col = cinfo->image_width; col > 0; col--) {
390
60.3M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
60.3M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
60.3M
                  ptr + 1, ptr + 2, ptr + 3);
393
60.3M
      ptr += 4;
394
60.3M
    }
395
17.0M
  }
396
17.0M
  return 1;
397
17.0M
}
rdppm-16.c:get_gray_cmyk_row
Line
Count
Source
370
4.80M
{
371
4.80M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
372
4.80M
  register _JSAMPROW ptr;
373
4.80M
  register U_CHAR *bufferptr;
374
4.80M
  register _JSAMPLE *rescale = source->rescale;
375
4.80M
  JDIMENSION col;
376
4.80M
  unsigned int maxval = source->maxval;
377
378
4.80M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
379
131
    ERREXIT(cinfo, JERR_INPUT_EOF);
380
4.80M
  ptr = source->pub._buffer[0];
381
4.80M
  bufferptr = source->iobuffer;
382
4.80M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
383
0
    for (col = cinfo->image_width; col > 0; col--) {
384
0
      _JSAMPLE gray = *bufferptr++;
385
0
      rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
386
0
      ptr += 4;
387
0
    }
388
4.80M
  } else {
389
33.2M
    for (col = cinfo->image_width; col > 0; col--) {
390
28.4M
      _JSAMPLE gray = rescale[UCH(*bufferptr++)];
391
28.4M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
392
28.4M
                  ptr + 1, ptr + 2, ptr + 3);
393
28.4M
      ptr += 4;
394
28.4M
    }
395
4.80M
  }
396
4.80M
  return 1;
397
4.80M
}
398
399
400
METHODDEF(JDIMENSION)
401
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
402
/* This version is for reading raw-byte-format PPM files with any maxval */
403
9.85M
{
404
9.85M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
9.85M
  register _JSAMPROW ptr;
406
9.85M
  register U_CHAR *bufferptr;
407
9.85M
  register _JSAMPLE *rescale = source->rescale;
408
9.85M
  JDIMENSION col;
409
9.85M
  unsigned int maxval = source->maxval;
410
9.85M
  register int rindex = rgb_red[cinfo->in_color_space];
411
9.85M
  register int gindex = rgb_green[cinfo->in_color_space];
412
9.85M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
9.85M
  register int aindex = alpha_index[cinfo->in_color_space];
414
9.85M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
9.85M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
7.23k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
9.85M
  ptr = source->pub._buffer[0];
419
9.85M
  bufferptr = source->iobuffer;
420
9.85M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
73.4k
    if (aindex >= 0)
422
9.70k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
63.7k
    else
424
63.7k
      RGB_READ_LOOP(*bufferptr++, {})
425
9.78M
  } else {
426
9.78M
    if (aindex >= 0)
427
1.92M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
9.78M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
7.85M
    else
430
7.85M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
9.78M
  }
432
9.85M
  return 1;
433
9.85M
}
rdppm-8.c:get_rgb_row
Line
Count
Source
403
2.14M
{
404
2.14M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
2.14M
  register _JSAMPROW ptr;
406
2.14M
  register U_CHAR *bufferptr;
407
2.14M
  register _JSAMPLE *rescale = source->rescale;
408
2.14M
  JDIMENSION col;
409
2.14M
  unsigned int maxval = source->maxval;
410
2.14M
  register int rindex = rgb_red[cinfo->in_color_space];
411
2.14M
  register int gindex = rgb_green[cinfo->in_color_space];
412
2.14M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
2.14M
  register int aindex = alpha_index[cinfo->in_color_space];
414
2.14M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
2.14M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
4.21k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
2.14M
  ptr = source->pub._buffer[0];
419
2.14M
  bufferptr = source->iobuffer;
420
2.14M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
73.4k
    if (aindex >= 0)
422
9.70k
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
63.7k
    else
424
63.7k
      RGB_READ_LOOP(*bufferptr++, {})
425
2.07M
  } else {
426
2.07M
    if (aindex >= 0)
427
387k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
2.07M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
1.68M
    else
430
1.68M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
2.07M
  }
432
2.14M
  return 1;
433
2.14M
}
rdppm-12.c:get_rgb_row
Line
Count
Source
403
7.58M
{
404
7.58M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
7.58M
  register _JSAMPROW ptr;
406
7.58M
  register U_CHAR *bufferptr;
407
7.58M
  register _JSAMPLE *rescale = source->rescale;
408
7.58M
  JDIMENSION col;
409
7.58M
  unsigned int maxval = source->maxval;
410
7.58M
  register int rindex = rgb_red[cinfo->in_color_space];
411
7.58M
  register int gindex = rgb_green[cinfo->in_color_space];
412
7.58M
  register int bindex = rgb_blue[cinfo->in_color_space];
413
7.58M
  register int aindex = alpha_index[cinfo->in_color_space];
414
7.58M
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
7.58M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
1.98k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
7.58M
  ptr = source->pub._buffer[0];
419
7.58M
  bufferptr = source->iobuffer;
420
7.58M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
0
    if (aindex >= 0)
422
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
0
    else
424
0
      RGB_READ_LOOP(*bufferptr++, {})
425
7.58M
  } else {
426
7.58M
    if (aindex >= 0)
427
1.51M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
7.58M
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
6.06M
    else
430
6.06M
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
7.58M
  }
432
7.58M
  return 1;
433
7.58M
}
rdppm-16.c:get_rgb_row
Line
Count
Source
403
128k
{
404
128k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
405
128k
  register _JSAMPROW ptr;
406
128k
  register U_CHAR *bufferptr;
407
128k
  register _JSAMPLE *rescale = source->rescale;
408
128k
  JDIMENSION col;
409
128k
  unsigned int maxval = source->maxval;
410
128k
  register int rindex = rgb_red[cinfo->in_color_space];
411
128k
  register int gindex = rgb_green[cinfo->in_color_space];
412
128k
  register int bindex = rgb_blue[cinfo->in_color_space];
413
128k
  register int aindex = alpha_index[cinfo->in_color_space];
414
128k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
415
416
128k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
417
1.03k
    ERREXIT(cinfo, JERR_INPUT_EOF);
418
128k
  ptr = source->pub._buffer[0];
419
128k
  bufferptr = source->iobuffer;
420
128k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
421
0
    if (aindex >= 0)
422
0
      RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
423
0
    else
424
0
      RGB_READ_LOOP(*bufferptr++, {})
425
128k
  } else {
426
128k
    if (aindex >= 0)
427
25.5k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
428
128k
                    ptr[aindex] = (1 << cinfo->data_precision) - 1;)
429
103k
    else
430
103k
      RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
431
128k
  }
432
128k
  return 1;
433
128k
}
434
435
436
METHODDEF(JDIMENSION)
437
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
438
/* This version is for reading raw-byte-format PPM files with any maxval and
439
   converting to CMYK */
440
1.94M
{
441
1.94M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
1.94M
  register _JSAMPROW ptr;
443
1.94M
  register U_CHAR *bufferptr;
444
1.94M
  register _JSAMPLE *rescale = source->rescale;
445
1.94M
  JDIMENSION col;
446
1.94M
  unsigned int maxval = source->maxval;
447
448
1.94M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
1.24k
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
1.94M
  ptr = source->pub._buffer[0];
451
1.94M
  bufferptr = source->iobuffer;
452
1.94M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
585k
    for (col = cinfo->image_width; col > 0; col--) {
454
572k
      _JSAMPLE r = *bufferptr++;
455
572k
      _JSAMPLE g = *bufferptr++;
456
572k
      _JSAMPLE b = *bufferptr++;
457
572k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
572k
      ptr += 4;
459
572k
    }
460
1.92M
  } else {
461
16.9M
    for (col = cinfo->image_width; col > 0; col--) {
462
14.9M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
14.9M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
14.9M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
14.9M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
14.9M
                  ptr + 2, ptr + 3);
467
14.9M
      ptr += 4;
468
14.9M
    }
469
1.92M
  }
470
1.94M
  return 1;
471
1.94M
}
rdppm-8.c:get_rgb_cmyk_row
Line
Count
Source
440
397k
{
441
397k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
397k
  register _JSAMPROW ptr;
443
397k
  register U_CHAR *bufferptr;
444
397k
  register _JSAMPLE *rescale = source->rescale;
445
397k
  JDIMENSION col;
446
397k
  unsigned int maxval = source->maxval;
447
448
397k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
646
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
397k
  ptr = source->pub._buffer[0];
451
397k
  bufferptr = source->iobuffer;
452
397k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
585k
    for (col = cinfo->image_width; col > 0; col--) {
454
572k
      _JSAMPLE r = *bufferptr++;
455
572k
      _JSAMPLE g = *bufferptr++;
456
572k
      _JSAMPLE b = *bufferptr++;
457
572k
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
572k
      ptr += 4;
459
572k
    }
460
384k
  } else {
461
1.70M
    for (col = cinfo->image_width; col > 0; col--) {
462
1.32M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
1.32M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
1.32M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
1.32M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
1.32M
                  ptr + 2, ptr + 3);
467
1.32M
      ptr += 4;
468
1.32M
    }
469
384k
  }
470
397k
  return 1;
471
397k
}
rdppm-12.c:get_rgb_cmyk_row
Line
Count
Source
440
1.51M
{
441
1.51M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
1.51M
  register _JSAMPROW ptr;
443
1.51M
  register U_CHAR *bufferptr;
444
1.51M
  register _JSAMPLE *rescale = source->rescale;
445
1.51M
  JDIMENSION col;
446
1.51M
  unsigned int maxval = source->maxval;
447
448
1.51M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
397
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
1.51M
  ptr = source->pub._buffer[0];
451
1.51M
  bufferptr = source->iobuffer;
452
1.51M
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
0
    for (col = cinfo->image_width; col > 0; col--) {
454
0
      _JSAMPLE r = *bufferptr++;
455
0
      _JSAMPLE g = *bufferptr++;
456
0
      _JSAMPLE b = *bufferptr++;
457
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
0
      ptr += 4;
459
0
    }
460
1.51M
  } else {
461
14.0M
    for (col = cinfo->image_width; col > 0; col--) {
462
12.5M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
12.5M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
12.5M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
12.5M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
12.5M
                  ptr + 2, ptr + 3);
467
12.5M
      ptr += 4;
468
12.5M
    }
469
1.51M
  }
470
1.51M
  return 1;
471
1.51M
}
rdppm-16.c:get_rgb_cmyk_row
Line
Count
Source
440
25.7k
{
441
25.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
442
25.7k
  register _JSAMPROW ptr;
443
25.7k
  register U_CHAR *bufferptr;
444
25.7k
  register _JSAMPLE *rescale = source->rescale;
445
25.7k
  JDIMENSION col;
446
25.7k
  unsigned int maxval = source->maxval;
447
448
25.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
449
206
    ERREXIT(cinfo, JERR_INPUT_EOF);
450
25.7k
  ptr = source->pub._buffer[0];
451
25.7k
  bufferptr = source->iobuffer;
452
25.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
453
0
    for (col = cinfo->image_width; col > 0; col--) {
454
0
      _JSAMPLE r = *bufferptr++;
455
0
      _JSAMPLE g = *bufferptr++;
456
0
      _JSAMPLE b = *bufferptr++;
457
0
      rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
458
0
      ptr += 4;
459
0
    }
460
25.7k
  } else {
461
1.12M
    for (col = cinfo->image_width; col > 0; col--) {
462
1.09M
      _JSAMPLE r = rescale[UCH(*bufferptr++)];
463
1.09M
      _JSAMPLE g = rescale[UCH(*bufferptr++)];
464
1.09M
      _JSAMPLE b = rescale[UCH(*bufferptr++)];
465
1.09M
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1,
466
1.09M
                  ptr + 2, ptr + 3);
467
1.09M
      ptr += 4;
468
1.09M
    }
469
25.7k
  }
470
25.7k
  return 1;
471
25.7k
}
472
473
474
METHODDEF(JDIMENSION)
475
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
476
/* This version is for reading raw-byte-format files with
477
 * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
478
 * In this case we just read right into the _JSAMPLE buffer!
479
 * Note that same code works for PPM and PGM files.
480
 */
481
2.13M
{
482
2.13M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
483
484
2.13M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
485
420
    ERREXIT(cinfo, JERR_INPUT_EOF);
486
2.13M
  return 1;
487
2.13M
}
rdppm-8.c:get_raw_row
Line
Count
Source
481
2.13M
{
482
2.13M
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
483
484
2.13M
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
485
420
    ERREXIT(cinfo, JERR_INPUT_EOF);
486
2.13M
  return 1;
487
2.13M
}
Unexecuted instantiation: rdppm-12.c:get_raw_row
Unexecuted instantiation: rdppm-16.c:get_raw_row
488
489
490
METHODDEF(JDIMENSION)
491
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
492
/* This version is for reading raw-word-format PGM files with any maxval */
493
136k
{
494
136k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
136k
  register _JSAMPROW ptr;
496
136k
  register U_CHAR *bufferptr;
497
136k
  register _JSAMPLE *rescale = source->rescale;
498
136k
  JDIMENSION col;
499
136k
  unsigned int maxval = source->maxval;
500
501
136k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
1.10k
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
136k
  ptr = source->pub._buffer[0];
504
136k
  bufferptr = source->iobuffer;
505
1.03M
  for (col = cinfo->image_width; col > 0; col--) {
506
900k
    register unsigned int temp;
507
900k
    temp  = UCH(*bufferptr++) << 8;
508
900k
    temp |= UCH(*bufferptr++);
509
900k
    if (temp > maxval)
510
719
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
900k
    *ptr++ = rescale[temp];
512
900k
  }
513
136k
  return 1;
514
136k
}
rdppm-8.c:get_word_gray_row
Line
Count
Source
493
14.0k
{
494
14.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
14.0k
  register _JSAMPROW ptr;
496
14.0k
  register U_CHAR *bufferptr;
497
14.0k
  register _JSAMPLE *rescale = source->rescale;
498
14.0k
  JDIMENSION col;
499
14.0k
  unsigned int maxval = source->maxval;
500
501
14.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
517
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
14.0k
  ptr = source->pub._buffer[0];
504
14.0k
  bufferptr = source->iobuffer;
505
229k
  for (col = cinfo->image_width; col > 0; col--) {
506
215k
    register unsigned int temp;
507
215k
    temp  = UCH(*bufferptr++) << 8;
508
215k
    temp |= UCH(*bufferptr++);
509
215k
    if (temp > maxval)
510
347
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
215k
    *ptr++ = rescale[temp];
512
215k
  }
513
14.0k
  return 1;
514
14.0k
}
rdppm-12.c:get_word_gray_row
Line
Count
Source
493
90.4k
{
494
90.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
90.4k
  register _JSAMPROW ptr;
496
90.4k
  register U_CHAR *bufferptr;
497
90.4k
  register _JSAMPLE *rescale = source->rescale;
498
90.4k
  JDIMENSION col;
499
90.4k
  unsigned int maxval = source->maxval;
500
501
90.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
363
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
90.4k
  ptr = source->pub._buffer[0];
504
90.4k
  bufferptr = source->iobuffer;
505
354k
  for (col = cinfo->image_width; col > 0; col--) {
506
263k
    register unsigned int temp;
507
263k
    temp  = UCH(*bufferptr++) << 8;
508
263k
    temp |= UCH(*bufferptr++);
509
263k
    if (temp > maxval)
510
295
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
263k
    *ptr++ = rescale[temp];
512
263k
  }
513
90.4k
  return 1;
514
90.4k
}
rdppm-16.c:get_word_gray_row
Line
Count
Source
493
31.7k
{
494
31.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
495
31.7k
  register _JSAMPROW ptr;
496
31.7k
  register U_CHAR *bufferptr;
497
31.7k
  register _JSAMPLE *rescale = source->rescale;
498
31.7k
  JDIMENSION col;
499
31.7k
  unsigned int maxval = source->maxval;
500
501
31.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
502
220
    ERREXIT(cinfo, JERR_INPUT_EOF);
503
31.7k
  ptr = source->pub._buffer[0];
504
31.7k
  bufferptr = source->iobuffer;
505
453k
  for (col = cinfo->image_width; col > 0; col--) {
506
421k
    register unsigned int temp;
507
421k
    temp  = UCH(*bufferptr++) << 8;
508
421k
    temp |= UCH(*bufferptr++);
509
421k
    if (temp > maxval)
510
77
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
511
421k
    *ptr++ = rescale[temp];
512
421k
  }
513
31.7k
  return 1;
514
31.7k
}
515
516
517
METHODDEF(JDIMENSION)
518
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
519
/* This version is for reading raw-word-format PGM files with any maxval */
520
676k
{
521
676k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
676k
  register _JSAMPROW ptr;
523
676k
  register U_CHAR *bufferptr;
524
676k
  register _JSAMPLE *rescale = source->rescale;
525
676k
  JDIMENSION col;
526
676k
  unsigned int maxval = source->maxval;
527
676k
  register int rindex = rgb_red[cinfo->in_color_space];
528
676k
  register int gindex = rgb_green[cinfo->in_color_space];
529
676k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
676k
  register int aindex = alpha_index[cinfo->in_color_space];
531
676k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
676k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
4.73k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
676k
  ptr = source->pub._buffer[0];
536
676k
  bufferptr = source->iobuffer;
537
5.17M
  for (col = cinfo->image_width; col > 0; col--) {
538
4.49M
    register unsigned int temp;
539
4.49M
    temp  = UCH(*bufferptr++) << 8;
540
4.49M
    temp |= UCH(*bufferptr++);
541
4.49M
    if (temp > maxval)
542
2.97k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
4.49M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
4.49M
    if (aindex >= 0)
545
861k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
4.49M
    ptr += ps;
547
4.49M
  }
548
676k
  return 1;
549
676k
}
rdppm-8.c:get_word_gray_rgb_row
Line
Count
Source
520
65.4k
{
521
65.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
65.4k
  register _JSAMPROW ptr;
523
65.4k
  register U_CHAR *bufferptr;
524
65.4k
  register _JSAMPLE *rescale = source->rescale;
525
65.4k
  JDIMENSION col;
526
65.4k
  unsigned int maxval = source->maxval;
527
65.4k
  register int rindex = rgb_red[cinfo->in_color_space];
528
65.4k
  register int gindex = rgb_green[cinfo->in_color_space];
529
65.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
65.4k
  register int aindex = alpha_index[cinfo->in_color_space];
531
65.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
65.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.81k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
65.4k
  ptr = source->pub._buffer[0];
536
65.4k
  bufferptr = source->iobuffer;
537
1.13M
  for (col = cinfo->image_width; col > 0; col--) {
538
1.07M
    register unsigned int temp;
539
1.07M
    temp  = UCH(*bufferptr++) << 8;
540
1.07M
    temp |= UCH(*bufferptr++);
541
1.07M
    if (temp > maxval)
542
1.11k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
1.07M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
1.07M
    if (aindex >= 0)
545
177k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
1.07M
    ptr += ps;
547
1.07M
  }
548
65.4k
  return 1;
549
65.4k
}
rdppm-12.c:get_word_gray_rgb_row
Line
Count
Source
520
452k
{
521
452k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
452k
  register _JSAMPROW ptr;
523
452k
  register U_CHAR *bufferptr;
524
452k
  register _JSAMPLE *rescale = source->rescale;
525
452k
  JDIMENSION col;
526
452k
  unsigned int maxval = source->maxval;
527
452k
  register int rindex = rgb_red[cinfo->in_color_space];
528
452k
  register int gindex = rgb_green[cinfo->in_color_space];
529
452k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
452k
  register int aindex = alpha_index[cinfo->in_color_space];
531
452k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
452k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.81k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
452k
  ptr = source->pub._buffer[0];
536
452k
  bufferptr = source->iobuffer;
537
1.77M
  for (col = cinfo->image_width; col > 0; col--) {
538
1.31M
    register unsigned int temp;
539
1.31M
    temp  = UCH(*bufferptr++) << 8;
540
1.31M
    temp |= UCH(*bufferptr++);
541
1.31M
    if (temp > maxval)
542
1.47k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
1.31M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
1.31M
    if (aindex >= 0)
545
263k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
1.31M
    ptr += ps;
547
1.31M
  }
548
452k
  return 1;
549
452k
}
rdppm-16.c:get_word_gray_rgb_row
Line
Count
Source
520
158k
{
521
158k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
522
158k
  register _JSAMPROW ptr;
523
158k
  register U_CHAR *bufferptr;
524
158k
  register _JSAMPLE *rescale = source->rescale;
525
158k
  JDIMENSION col;
526
158k
  unsigned int maxval = source->maxval;
527
158k
  register int rindex = rgb_red[cinfo->in_color_space];
528
158k
  register int gindex = rgb_green[cinfo->in_color_space];
529
158k
  register int bindex = rgb_blue[cinfo->in_color_space];
530
158k
  register int aindex = alpha_index[cinfo->in_color_space];
531
158k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
532
533
158k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
534
1.10k
    ERREXIT(cinfo, JERR_INPUT_EOF);
535
158k
  ptr = source->pub._buffer[0];
536
158k
  bufferptr = source->iobuffer;
537
2.26M
  for (col = cinfo->image_width; col > 0; col--) {
538
2.10M
    register unsigned int temp;
539
2.10M
    temp  = UCH(*bufferptr++) << 8;
540
2.10M
    temp |= UCH(*bufferptr++);
541
2.10M
    if (temp > maxval)
542
385
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
543
2.10M
    ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
544
2.10M
    if (aindex >= 0)
545
421k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
546
2.10M
    ptr += ps;
547
2.10M
  }
548
158k
  return 1;
549
158k
}
550
551
552
METHODDEF(JDIMENSION)
553
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
554
/* This version is for reading raw-word-format PGM files with any maxval */
555
132k
{
556
132k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
132k
  register _JSAMPROW ptr;
558
132k
  register U_CHAR *bufferptr;
559
132k
  register _JSAMPLE *rescale = source->rescale;
560
132k
  JDIMENSION col;
561
132k
  unsigned int maxval = source->maxval;
562
563
132k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
841
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
132k
  ptr = source->pub._buffer[0];
566
132k
  bufferptr = source->iobuffer;
567
132k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
444k
    for (col = cinfo->image_width; col > 0; col--) {
569
413k
      register unsigned int gray;
570
413k
      gray  = UCH(*bufferptr++) << 8;
571
413k
      gray |= UCH(*bufferptr++);
572
413k
      if (gray > maxval)
573
114
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
413k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
413k
                  ptr + 1, ptr + 2, ptr + 3);
576
413k
      ptr += 4;
577
413k
    }
578
102k
  } else {
579
550k
    for (col = cinfo->image_width; col > 0; col--) {
580
448k
      register unsigned int temp;
581
448k
      _JSAMPLE gray;
582
448k
      temp  = UCH(*bufferptr++) << 8;
583
448k
      temp |= UCH(*bufferptr++);
584
448k
      if (temp > maxval)
585
416
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
448k
      gray = rescale[temp];
587
448k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
448k
                  ptr + 1, ptr + 2, ptr + 3);
589
448k
      ptr += 4;
590
448k
    }
591
102k
  }
592
132k
  return 1;
593
132k
}
rdppm-8.c:get_word_gray_cmyk_row
Line
Count
Source
555
10.2k
{
556
10.2k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
10.2k
  register _JSAMPROW ptr;
558
10.2k
  register U_CHAR *bufferptr;
559
10.2k
  register _JSAMPLE *rescale = source->rescale;
560
10.2k
  JDIMENSION col;
561
10.2k
  unsigned int maxval = source->maxval;
562
563
10.2k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
258
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
10.2k
  ptr = source->pub._buffer[0];
566
10.2k
  bufferptr = source->iobuffer;
567
10.2k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
0
    for (col = cinfo->image_width; col > 0; col--) {
569
0
      register unsigned int gray;
570
0
      gray  = UCH(*bufferptr++) << 8;
571
0
      gray |= UCH(*bufferptr++);
572
0
      if (gray > maxval)
573
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
0
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
0
                  ptr + 1, ptr + 2, ptr + 3);
576
0
      ptr += 4;
577
0
    }
578
10.2k
  } else {
579
187k
    for (col = cinfo->image_width; col > 0; col--) {
580
177k
      register unsigned int temp;
581
177k
      _JSAMPLE gray;
582
177k
      temp  = UCH(*bufferptr++) << 8;
583
177k
      temp |= UCH(*bufferptr++);
584
177k
      if (temp > maxval)
585
158
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
177k
      gray = rescale[temp];
587
177k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
177k
                  ptr + 1, ptr + 2, ptr + 3);
589
177k
      ptr += 4;
590
177k
    }
591
10.2k
  }
592
10.2k
  return 1;
593
10.2k
}
rdppm-12.c:get_word_gray_cmyk_row
Line
Count
Source
555
90.4k
{
556
90.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
90.4k
  register _JSAMPROW ptr;
558
90.4k
  register U_CHAR *bufferptr;
559
90.4k
  register _JSAMPLE *rescale = source->rescale;
560
90.4k
  JDIMENSION col;
561
90.4k
  unsigned int maxval = source->maxval;
562
563
90.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
363
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
90.4k
  ptr = source->pub._buffer[0];
566
90.4k
  bufferptr = source->iobuffer;
567
90.4k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
6.80k
    for (col = cinfo->image_width; col > 0; col--) {
569
4.53k
      register unsigned int gray;
570
4.53k
      gray  = UCH(*bufferptr++) << 8;
571
4.53k
      gray |= UCH(*bufferptr++);
572
4.53k
      if (gray > maxval)
573
114
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
4.53k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
4.53k
                  ptr + 1, ptr + 2, ptr + 3);
576
4.53k
      ptr += 4;
577
4.53k
    }
578
88.1k
  } else {
579
347k
    for (col = cinfo->image_width; col > 0; col--) {
580
259k
      register unsigned int temp;
581
259k
      _JSAMPLE gray;
582
259k
      temp  = UCH(*bufferptr++) << 8;
583
259k
      temp |= UCH(*bufferptr++);
584
259k
      if (temp > maxval)
585
181
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
259k
      gray = rescale[temp];
587
259k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
259k
                  ptr + 1, ptr + 2, ptr + 3);
589
259k
      ptr += 4;
590
259k
    }
591
88.1k
  }
592
90.4k
  return 1;
593
90.4k
}
rdppm-16.c:get_word_gray_cmyk_row
Line
Count
Source
555
31.7k
{
556
31.7k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
557
31.7k
  register _JSAMPROW ptr;
558
31.7k
  register U_CHAR *bufferptr;
559
31.7k
  register _JSAMPLE *rescale = source->rescale;
560
31.7k
  JDIMENSION col;
561
31.7k
  unsigned int maxval = source->maxval;
562
563
31.7k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
564
220
    ERREXIT(cinfo, JERR_INPUT_EOF);
565
31.7k
  ptr = source->pub._buffer[0];
566
31.7k
  bufferptr = source->iobuffer;
567
31.7k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
568
437k
    for (col = cinfo->image_width; col > 0; col--) {
569
409k
      register unsigned int gray;
570
409k
      gray  = UCH(*bufferptr++) << 8;
571
409k
      gray |= UCH(*bufferptr++);
572
409k
      if (gray > maxval)
573
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
574
409k
      rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr,
575
409k
                  ptr + 1, ptr + 2, ptr + 3);
576
409k
      ptr += 4;
577
409k
    }
578
28.0k
  } else {
579
15.9k
    for (col = cinfo->image_width; col > 0; col--) {
580
12.2k
      register unsigned int temp;
581
12.2k
      _JSAMPLE gray;
582
12.2k
      temp  = UCH(*bufferptr++) << 8;
583
12.2k
      temp |= UCH(*bufferptr++);
584
12.2k
      if (temp > maxval)
585
77
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
586
12.2k
      gray = rescale[temp];
587
12.2k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr,
588
12.2k
                  ptr + 1, ptr + 2, ptr + 3);
589
12.2k
      ptr += 4;
590
12.2k
    }
591
3.69k
  }
592
31.7k
  return 1;
593
31.7k
}
594
595
596
METHODDEF(JDIMENSION)
597
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
598
/* This version is for reading raw-word-format PPM files with any maxval */
599
150k
{
600
150k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
150k
  register _JSAMPROW ptr;
602
150k
  register U_CHAR *bufferptr;
603
150k
  register _JSAMPLE *rescale = source->rescale;
604
150k
  JDIMENSION col;
605
150k
  unsigned int maxval = source->maxval;
606
150k
  register int rindex = rgb_red[cinfo->in_color_space];
607
150k
  register int gindex = rgb_green[cinfo->in_color_space];
608
150k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
150k
  register int aindex = alpha_index[cinfo->in_color_space];
610
150k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
150k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
5.87k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
150k
  ptr = source->pub._buffer[0];
615
150k
  bufferptr = source->iobuffer;
616
734k
  for (col = cinfo->image_width; col > 0; col--) {
617
583k
    register unsigned int temp;
618
583k
    temp  = UCH(*bufferptr++) << 8;
619
583k
    temp |= UCH(*bufferptr++);
620
583k
    if (temp > maxval)
621
2.29k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
583k
    ptr[rindex] = rescale[temp];
623
583k
    temp  = UCH(*bufferptr++) << 8;
624
583k
    temp |= UCH(*bufferptr++);
625
583k
    if (temp > maxval)
626
1.98k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
583k
    ptr[gindex] = rescale[temp];
628
583k
    temp  = UCH(*bufferptr++) << 8;
629
583k
    temp |= UCH(*bufferptr++);
630
583k
    if (temp > maxval)
631
1.89k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
583k
    ptr[bindex] = rescale[temp];
633
583k
    if (aindex >= 0)
634
110k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
583k
    ptr += ps;
636
583k
  }
637
150k
  return 1;
638
150k
}
rdppm-8.c:get_word_rgb_row
Line
Count
Source
599
58.6k
{
600
58.6k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
58.6k
  register _JSAMPROW ptr;
602
58.6k
  register U_CHAR *bufferptr;
603
58.6k
  register _JSAMPLE *rescale = source->rescale;
604
58.6k
  JDIMENSION col;
605
58.6k
  unsigned int maxval = source->maxval;
606
58.6k
  register int rindex = rgb_red[cinfo->in_color_space];
607
58.6k
  register int gindex = rgb_green[cinfo->in_color_space];
608
58.6k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
58.6k
  register int aindex = alpha_index[cinfo->in_color_space];
610
58.6k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
58.6k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
2.20k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
58.6k
  ptr = source->pub._buffer[0];
615
58.6k
  bufferptr = source->iobuffer;
616
323k
  for (col = cinfo->image_width; col > 0; col--) {
617
264k
    register unsigned int temp;
618
264k
    temp  = UCH(*bufferptr++) << 8;
619
264k
    temp |= UCH(*bufferptr++);
620
264k
    if (temp > maxval)
621
742
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
264k
    ptr[rindex] = rescale[temp];
623
264k
    temp  = UCH(*bufferptr++) << 8;
624
264k
    temp |= UCH(*bufferptr++);
625
264k
    if (temp > maxval)
626
789
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
264k
    ptr[gindex] = rescale[temp];
628
264k
    temp  = UCH(*bufferptr++) << 8;
629
264k
    temp |= UCH(*bufferptr++);
630
264k
    if (temp > maxval)
631
772
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
264k
    ptr[bindex] = rescale[temp];
633
264k
    if (aindex >= 0)
634
47.7k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
264k
    ptr += ps;
636
264k
  }
637
58.6k
  return 1;
638
58.6k
}
rdppm-12.c:get_word_rgb_row
Line
Count
Source
599
60.4k
{
600
60.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
60.4k
  register _JSAMPROW ptr;
602
60.4k
  register U_CHAR *bufferptr;
603
60.4k
  register _JSAMPLE *rescale = source->rescale;
604
60.4k
  JDIMENSION col;
605
60.4k
  unsigned int maxval = source->maxval;
606
60.4k
  register int rindex = rgb_red[cinfo->in_color_space];
607
60.4k
  register int gindex = rgb_green[cinfo->in_color_space];
608
60.4k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
60.4k
  register int aindex = alpha_index[cinfo->in_color_space];
610
60.4k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
60.4k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
2.33k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
60.4k
  ptr = source->pub._buffer[0];
615
60.4k
  bufferptr = source->iobuffer;
616
160k
  for (col = cinfo->image_width; col > 0; col--) {
617
100k
    register unsigned int temp;
618
100k
    temp  = UCH(*bufferptr++) << 8;
619
100k
    temp |= UCH(*bufferptr++);
620
100k
    if (temp > maxval)
621
1.21k
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
100k
    ptr[rindex] = rescale[temp];
623
100k
    temp  = UCH(*bufferptr++) << 8;
624
100k
    temp |= UCH(*bufferptr++);
625
100k
    if (temp > maxval)
626
935
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
100k
    ptr[gindex] = rescale[temp];
628
100k
    temp  = UCH(*bufferptr++) << 8;
629
100k
    temp |= UCH(*bufferptr++);
630
100k
    if (temp > maxval)
631
890
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
100k
    ptr[bindex] = rescale[temp];
633
100k
    if (aindex >= 0)
634
19.3k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
100k
    ptr += ps;
636
100k
  }
637
60.4k
  return 1;
638
60.4k
}
rdppm-16.c:get_word_rgb_row
Line
Count
Source
599
31.5k
{
600
31.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
601
31.5k
  register _JSAMPROW ptr;
602
31.5k
  register U_CHAR *bufferptr;
603
31.5k
  register _JSAMPLE *rescale = source->rescale;
604
31.5k
  JDIMENSION col;
605
31.5k
  unsigned int maxval = source->maxval;
606
31.5k
  register int rindex = rgb_red[cinfo->in_color_space];
607
31.5k
  register int gindex = rgb_green[cinfo->in_color_space];
608
31.5k
  register int bindex = rgb_blue[cinfo->in_color_space];
609
31.5k
  register int aindex = alpha_index[cinfo->in_color_space];
610
31.5k
  register int ps = rgb_pixelsize[cinfo->in_color_space];
611
612
31.5k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
613
1.34k
    ERREXIT(cinfo, JERR_INPUT_EOF);
614
31.5k
  ptr = source->pub._buffer[0];
615
31.5k
  bufferptr = source->iobuffer;
616
250k
  for (col = cinfo->image_width; col > 0; col--) {
617
218k
    register unsigned int temp;
618
218k
    temp  = UCH(*bufferptr++) << 8;
619
218k
    temp |= UCH(*bufferptr++);
620
218k
    if (temp > maxval)
621
335
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
622
218k
    ptr[rindex] = rescale[temp];
623
218k
    temp  = UCH(*bufferptr++) << 8;
624
218k
    temp |= UCH(*bufferptr++);
625
218k
    if (temp > maxval)
626
265
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
627
218k
    ptr[gindex] = rescale[temp];
628
218k
    temp  = UCH(*bufferptr++) << 8;
629
218k
    temp |= UCH(*bufferptr++);
630
218k
    if (temp > maxval)
631
230
      ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
632
218k
    ptr[bindex] = rescale[temp];
633
218k
    if (aindex >= 0)
634
43.6k
      ptr[aindex] = (1 << cinfo->data_precision) - 1;
635
218k
    ptr += ps;
636
218k
  }
637
31.5k
  return 1;
638
31.5k
}
639
640
641
METHODDEF(JDIMENSION)
642
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
643
/* This version is for reading raw-word-format PPM files with any maxval */
644
26.8k
{
645
26.8k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
26.8k
  register _JSAMPROW ptr;
647
26.8k
  register U_CHAR *bufferptr;
648
26.8k
  register _JSAMPLE *rescale = source->rescale;
649
26.8k
  JDIMENSION col;
650
26.8k
  unsigned int maxval = source->maxval;
651
652
26.8k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
1.04k
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
26.8k
  ptr = source->pub._buffer[0];
655
26.8k
  bufferptr = source->iobuffer;
656
26.8k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
53.7k
    for (col = cinfo->image_width; col > 0; col--) {
658
46.8k
      register unsigned int r, g, b;
659
46.8k
      r  = UCH(*bufferptr++) << 8;
660
46.8k
      r |= UCH(*bufferptr++);
661
46.8k
      if (r > maxval)
662
79
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
46.8k
      g  = UCH(*bufferptr++) << 8;
664
46.8k
      g |= UCH(*bufferptr++);
665
46.8k
      if (g > maxval)
666
87
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
46.8k
      b  = UCH(*bufferptr++) << 8;
668
46.8k
      b |= UCH(*bufferptr++);
669
46.8k
      if (b > maxval)
670
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
46.8k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
46.8k
                  ptr + 2, ptr + 3);
673
46.8k
      ptr += 4;
674
46.8k
    }
675
19.9k
  } else {
676
84.9k
    for (col = cinfo->image_width; col > 0; col--) {
677
65.0k
      register unsigned int r, g, b;
678
65.0k
      r  = UCH(*bufferptr++) << 8;
679
65.0k
      r |= UCH(*bufferptr++);
680
65.0k
      if (r > maxval)
681
354
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
65.0k
      g  = UCH(*bufferptr++) << 8;
683
65.0k
      g |= UCH(*bufferptr++);
684
65.0k
      if (g > maxval)
685
256
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
65.0k
      b  = UCH(*bufferptr++) << 8;
687
65.0k
      b |= UCH(*bufferptr++);
688
65.0k
      if (b > maxval)
689
234
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
65.0k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
65.0k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
65.0k
      ptr += 4;
693
65.0k
    }
694
19.9k
  }
695
26.8k
  return 1;
696
26.8k
}
rdppm-8.c:get_word_rgb_cmyk_row
Line
Count
Source
644
8.42k
{
645
8.42k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
8.42k
  register _JSAMPROW ptr;
647
8.42k
  register U_CHAR *bufferptr;
648
8.42k
  register _JSAMPLE *rescale = source->rescale;
649
8.42k
  JDIMENSION col;
650
8.42k
  unsigned int maxval = source->maxval;
651
652
8.42k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
309
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
8.42k
  ptr = source->pub._buffer[0];
655
8.42k
  bufferptr = source->iobuffer;
656
8.42k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
0
    for (col = cinfo->image_width; col > 0; col--) {
658
0
      register unsigned int r, g, b;
659
0
      r  = UCH(*bufferptr++) << 8;
660
0
      r |= UCH(*bufferptr++);
661
0
      if (r > maxval)
662
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
0
      g  = UCH(*bufferptr++) << 8;
664
0
      g |= UCH(*bufferptr++);
665
0
      if (g > maxval)
666
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
0
      b  = UCH(*bufferptr++) << 8;
668
0
      b |= UCH(*bufferptr++);
669
0
      if (b > maxval)
670
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
0
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
0
                  ptr + 2, ptr + 3);
673
0
      ptr += 4;
674
0
    }
675
8.42k
  } else {
676
56.4k
    for (col = cinfo->image_width; col > 0; col--) {
677
48.0k
      register unsigned int r, g, b;
678
48.0k
      r  = UCH(*bufferptr++) << 8;
679
48.0k
      r |= UCH(*bufferptr++);
680
48.0k
      if (r > maxval)
681
123
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
48.0k
      g  = UCH(*bufferptr++) << 8;
683
48.0k
      g |= UCH(*bufferptr++);
684
48.0k
      if (g > maxval)
685
103
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
48.0k
      b  = UCH(*bufferptr++) << 8;
687
48.0k
      b |= UCH(*bufferptr++);
688
48.0k
      if (b > maxval)
689
96
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
48.0k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
48.0k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
48.0k
      ptr += 4;
693
48.0k
    }
694
8.42k
  }
695
8.42k
  return 1;
696
8.42k
}
rdppm-12.c:get_word_rgb_cmyk_row
Line
Count
Source
644
12.0k
{
645
12.0k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
12.0k
  register _JSAMPROW ptr;
647
12.0k
  register U_CHAR *bufferptr;
648
12.0k
  register _JSAMPLE *rescale = source->rescale;
649
12.0k
  JDIMENSION col;
650
12.0k
  unsigned int maxval = source->maxval;
651
652
12.0k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
466
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
12.0k
  ptr = source->pub._buffer[0];
655
12.0k
  bufferptr = source->iobuffer;
656
12.0k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
11.8k
    for (col = cinfo->image_width; col > 0; col--) {
658
8.03k
      register unsigned int r, g, b;
659
8.03k
      r  = UCH(*bufferptr++) << 8;
660
8.03k
      r |= UCH(*bufferptr++);
661
8.03k
      if (r > maxval)
662
79
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
8.03k
      g  = UCH(*bufferptr++) << 8;
664
8.03k
      g |= UCH(*bufferptr++);
665
8.03k
      if (g > maxval)
666
87
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
8.03k
      b  = UCH(*bufferptr++) << 8;
668
8.03k
      b |= UCH(*bufferptr++);
669
8.03k
      if (b > maxval)
670
86
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
8.03k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
8.03k
                  ptr + 2, ptr + 3);
673
8.03k
      ptr += 4;
674
8.03k
    }
675
8.25k
  } else {
676
20.2k
    for (col = cinfo->image_width; col > 0; col--) {
677
11.9k
      register unsigned int r, g, b;
678
11.9k
      r  = UCH(*bufferptr++) << 8;
679
11.9k
      r |= UCH(*bufferptr++);
680
11.9k
      if (r > maxval)
681
164
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
11.9k
      g  = UCH(*bufferptr++) << 8;
683
11.9k
      g |= UCH(*bufferptr++);
684
11.9k
      if (g > maxval)
685
100
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
11.9k
      b  = UCH(*bufferptr++) << 8;
687
11.9k
      b |= UCH(*bufferptr++);
688
11.9k
      if (b > maxval)
689
92
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
11.9k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
11.9k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
11.9k
      ptr += 4;
693
11.9k
    }
694
8.25k
  }
695
12.0k
  return 1;
696
12.0k
}
rdppm-16.c:get_word_rgb_cmyk_row
Line
Count
Source
644
6.30k
{
645
6.30k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
646
6.30k
  register _JSAMPROW ptr;
647
6.30k
  register U_CHAR *bufferptr;
648
6.30k
  register _JSAMPLE *rescale = source->rescale;
649
6.30k
  JDIMENSION col;
650
6.30k
  unsigned int maxval = source->maxval;
651
652
6.30k
  if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
653
269
    ERREXIT(cinfo, JERR_INPUT_EOF);
654
6.30k
  ptr = source->pub._buffer[0];
655
6.30k
  bufferptr = source->iobuffer;
656
6.30k
  if (maxval == (1U << cinfo->data_precision) - 1U) {
657
41.8k
    for (col = cinfo->image_width; col > 0; col--) {
658
38.7k
      register unsigned int r, g, b;
659
38.7k
      r  = UCH(*bufferptr++) << 8;
660
38.7k
      r |= UCH(*bufferptr++);
661
38.7k
      if (r > maxval)
662
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
663
38.7k
      g  = UCH(*bufferptr++) << 8;
664
38.7k
      g |= UCH(*bufferptr++);
665
38.7k
      if (g > maxval)
666
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
667
38.7k
      b  = UCH(*bufferptr++) << 8;
668
38.7k
      b |= UCH(*bufferptr++);
669
38.7k
      if (b > maxval)
670
0
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
671
38.7k
      rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1,
672
38.7k
                  ptr + 2, ptr + 3);
673
38.7k
      ptr += 4;
674
38.7k
    }
675
3.24k
  } else {
676
8.25k
    for (col = cinfo->image_width; col > 0; col--) {
677
5.01k
      register unsigned int r, g, b;
678
5.01k
      r  = UCH(*bufferptr++) << 8;
679
5.01k
      r |= UCH(*bufferptr++);
680
5.01k
      if (r > maxval)
681
67
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
682
5.01k
      g  = UCH(*bufferptr++) << 8;
683
5.01k
      g |= UCH(*bufferptr++);
684
5.01k
      if (g > maxval)
685
53
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
686
5.01k
      b  = UCH(*bufferptr++) << 8;
687
5.01k
      b |= UCH(*bufferptr++);
688
5.01k
      if (b > maxval)
689
46
        ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
690
5.01k
      rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g],
691
5.01k
                  rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3);
692
5.01k
      ptr += 4;
693
5.01k
    }
694
3.24k
  }
695
6.30k
  return 1;
696
6.30k
}
697
698
699
/*
700
 * Read the file header; return image size and component count.
701
 */
702
703
METHODDEF(void)
704
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
705
182k
{
706
182k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
182k
  int c;
708
182k
  unsigned int w, h, maxval;
709
182k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
182k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
182k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
182k
  switch (c) {
718
17.9k
  case '2':                     /* it's a text-format PGM file */
719
38.6k
  case '3':                     /* it's a text-format PPM file */
720
139k
  case '5':                     /* it's a raw-format PGM file */
721
181k
  case '6':                     /* it's a raw-format PPM file */
722
181k
    break;
723
671
  default:
724
671
    ERREXIT(cinfo, JERR_PPM_NOT);
725
671
    break;
726
182k
  }
727
728
  /* fetch the remaining header info */
729
181k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
181k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
181k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
181k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
385
    ERREXIT(cinfo, JERR_PPM_NOT);
735
181k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
2.90k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
181k
  cinfo->image_width = (JDIMENSION)w;
739
181k
  cinfo->image_height = (JDIMENSION)h;
740
181k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
181k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
181k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
181k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
181k
  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
200
      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.12k
      source->pub.get_pixel_rows = get_text_gray_row;
755
11.3k
    else if (IsExtRGB(cinfo->in_color_space))
756
9.63k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
1.67k
    else if (cinfo->in_color_space == JCS_CMYK)
758
1.67k
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
13.4k
    need_iobuffer = FALSE;
762
13.4k
    break;
763
764
16.1k
  case '3':                     /* it's a text-format PPM file */
765
16.1k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
16.1k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
16.1k
    if (IsExtRGB(cinfo->in_color_space))
769
11.8k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
4.33k
    else if (cinfo->in_color_space == JCS_CMYK)
771
2.03k
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
2.29k
    else
773
2.29k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
16.1k
    need_iobuffer = FALSE;
775
16.1k
    break;
776
777
95.9k
  case '5':                     /* it's a raw-format PGM file */
778
95.9k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
95.9k
        cinfo->in_color_space == JCS_RGB)
780
770
      cinfo->in_color_space = JCS_GRAYSCALE;
781
95.9k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
95.9k
    if (maxval > 255) {
783
12.4k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
2.04k
        source->pub.get_pixel_rows = get_word_gray_row;
785
10.3k
      else if (IsExtRGB(cinfo->in_color_space))
786
8.82k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
1.57k
      else if (cinfo->in_color_space == JCS_CMYK)
788
1.57k
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
83.5k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
46.0k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
4.40k
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
743
      source->pub.get_pixel_rows = get_raw_row;
795
743
      use_raw_buffer = TRUE;
796
743
      need_rescale = FALSE;
797
82.7k
    } else {
798
82.7k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
12.0k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
70.7k
      else if (IsExtRGB(cinfo->in_color_space))
801
61.4k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
9.27k
      else if (cinfo->in_color_space == JCS_CMYK)
803
9.27k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
82.7k
    }
807
95.9k
    break;
808
809
38.5k
  case '6':                     /* it's a raw-format PPM file */
810
38.5k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
38.5k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
38.5k
    if (maxval > 255) {
814
17.4k
      if (IsExtRGB(cinfo->in_color_space))
815
12.7k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
4.74k
      else if (cinfo->in_color_space == JCS_CMYK)
817
2.27k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
2.47k
      else
819
2.47k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
21.0k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
11.9k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
2.29k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
2.29k
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
1.99k
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
373
      source->pub.get_pixel_rows = get_raw_row;
829
373
      use_raw_buffer = TRUE;
830
373
      need_rescale = FALSE;
831
20.7k
    } else {
832
20.7k
      if (IsExtRGB(cinfo->in_color_space))
833
15.1k
        source->pub.get_pixel_rows = get_rgb_row;
834
5.56k
      else if (cinfo->in_color_space == JCS_CMYK)
835
2.55k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
3.01k
      else
837
3.01k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
20.7k
    }
839
38.5k
    break;
840
181k
  }
841
842
156k
  if (IsExtRGB(cinfo->in_color_space))
843
120k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
36.3k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
16.9k
    cinfo->input_components = 1;
846
19.3k
  else if (cinfo->in_color_space == JCS_CMYK)
847
19.3k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
156k
  if (need_iobuffer) {
851
129k
    if (c == '6')
852
33.1k
      source->buffer_width = (size_t)w * 3 *
853
33.1k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
95.9k
    else
855
95.9k
      source->buffer_width = (size_t)w *
856
95.9k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
129k
    source->iobuffer = (U_CHAR *)
858
129k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
129k
                                  source->buffer_width);
860
129k
  }
861
862
  /* Create compressor input buffer. */
863
156k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
1.11k
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
1.11k
    source->pub._buffer = &source->pixrow;
868
1.11k
    source->pub.buffer_height = 1;
869
155k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
155k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
155k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
155k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
155k
    source->pub.buffer_height = 1;
875
155k
  }
876
877
  /* Compute the rescaling array if required. */
878
156k
  if (need_rescale) {
879
155k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
155k
    source->rescale = (_JSAMPLE *)
883
155k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
155k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
155k
                                           sizeof(_JSAMPLE)));
886
155k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
155k
                                        sizeof(_JSAMPLE)));
888
155k
    half_maxval = maxval / 2;
889
596M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
596M
      source->rescale[val] =
892
596M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
596M
                   maxval);
894
596M
    }
895
155k
  }
896
156k
}
rdppm-8.c:start_input_ppm
Line
Count
Source
705
91.5k
{
706
91.5k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
91.5k
  int c;
708
91.5k
  unsigned int w, h, maxval;
709
91.5k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
91.5k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
91.5k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
91.5k
  switch (c) {
718
8.51k
  case '2':                     /* it's a text-format PGM file */
719
17.9k
  case '3':                     /* it's a text-format PPM file */
720
71.2k
  case '5':                     /* it's a raw-format PGM file */
721
91.3k
  case '6':                     /* it's a raw-format PPM file */
722
91.3k
    break;
723
244
  default:
724
244
    ERREXIT(cinfo, JERR_PPM_NOT);
725
244
    break;
726
91.5k
  }
727
728
  /* fetch the remaining header info */
729
91.3k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
91.3k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
91.3k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
91.3k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
182
    ERREXIT(cinfo, JERR_PPM_NOT);
735
91.3k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
1.47k
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
91.3k
  cinfo->image_width = (JDIMENSION)w;
739
91.3k
  cinfo->image_height = (JDIMENSION)h;
740
91.3k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
91.3k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
91.3k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
91.3k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
91.3k
  switch (c) {
748
6.21k
  case '2':                     /* it's a text-format PGM file */
749
6.21k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
6.21k
        cinfo->in_color_space == JCS_RGB)
751
200
      cinfo->in_color_space = JCS_GRAYSCALE;
752
6.21k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
6.21k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
1.09k
      source->pub.get_pixel_rows = get_text_gray_row;
755
5.12k
    else if (IsExtRGB(cinfo->in_color_space))
756
4.48k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
640
    else if (cinfo->in_color_space == JCS_CMYK)
758
640
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
6.21k
    need_iobuffer = FALSE;
762
6.21k
    break;
763
764
7.50k
  case '3':                     /* it's a text-format PPM file */
765
7.50k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
7.50k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
7.50k
    if (IsExtRGB(cinfo->in_color_space))
769
5.65k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.85k
    else if (cinfo->in_color_space == JCS_CMYK)
771
796
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
1.05k
    else
773
1.05k
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
7.50k
    need_iobuffer = FALSE;
775
7.50k
    break;
776
777
50.6k
  case '5':                     /* it's a raw-format PGM file */
778
50.6k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
50.6k
        cinfo->in_color_space == JCS_RGB)
780
770
      cinfo->in_color_space = JCS_GRAYSCALE;
781
50.6k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
50.6k
    if (maxval > 255) {
783
4.58k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
923
        source->pub.get_pixel_rows = get_word_gray_row;
785
3.65k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.20k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
453
      else if (cinfo->in_color_space == JCS_CMYK)
788
453
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
46.0k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
46.0k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
4.40k
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
743
      source->pub.get_pixel_rows = get_raw_row;
795
743
      use_raw_buffer = TRUE;
796
743
      need_rescale = FALSE;
797
45.3k
    } else {
798
45.3k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
6.68k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
38.6k
      else if (IsExtRGB(cinfo->in_color_space))
801
34.7k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
3.91k
      else if (cinfo->in_color_space == JCS_CMYK)
803
3.91k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
45.3k
    }
807
50.6k
    break;
808
809
18.1k
  case '6':                     /* it's a raw-format PPM file */
810
18.1k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
18.1k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
18.1k
    if (maxval > 255) {
814
6.23k
      if (IsExtRGB(cinfo->in_color_space))
815
4.70k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
1.52k
      else if (cinfo->in_color_space == JCS_CMYK)
817
662
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
866
      else
819
866
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
11.9k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
11.9k
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
2.29k
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
2.29k
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
1.99k
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
373
      source->pub.get_pixel_rows = get_raw_row;
829
373
      use_raw_buffer = TRUE;
830
373
      need_rescale = FALSE;
831
11.5k
    } else {
832
11.5k
      if (IsExtRGB(cinfo->in_color_space))
833
8.61k
        source->pub.get_pixel_rows = get_rgb_row;
834
2.95k
      else if (cinfo->in_color_space == JCS_CMYK)
835
1.24k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
1.70k
      else
837
1.70k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
11.5k
    }
839
18.1k
    break;
840
91.3k
  }
841
842
78.9k
  if (IsExtRGB(cinfo->in_color_space))
843
61.7k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
17.1k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
9.44k
    cinfo->input_components = 1;
846
7.71k
  else if (cinfo->in_color_space == JCS_CMYK)
847
7.71k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
78.9k
  if (need_iobuffer) {
851
66.2k
    if (c == '6')
852
15.5k
      source->buffer_width = (size_t)w * 3 *
853
15.5k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
50.6k
    else
855
50.6k
      source->buffer_width = (size_t)w *
856
50.6k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
66.2k
    source->iobuffer = (U_CHAR *)
858
66.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
66.2k
                                  source->buffer_width);
860
66.2k
  }
861
862
  /* Create compressor input buffer. */
863
78.9k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
1.11k
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
1.11k
    source->pub._buffer = &source->pixrow;
868
1.11k
    source->pub.buffer_height = 1;
869
77.7k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
77.7k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
77.7k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
77.7k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
77.7k
    source->pub.buffer_height = 1;
875
77.7k
  }
876
877
  /* Compute the rescaling array if required. */
878
78.9k
  if (need_rescale) {
879
77.7k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
77.7k
    source->rescale = (_JSAMPLE *)
883
77.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
77.7k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
77.7k
                                           sizeof(_JSAMPLE)));
886
77.7k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
77.7k
                                        sizeof(_JSAMPLE)));
888
77.7k
    half_maxval = maxval / 2;
889
146M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
146M
      source->rescale[val] =
892
146M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
146M
                   maxval);
894
146M
    }
895
77.7k
  }
896
78.9k
}
rdppm-12.c:start_input_ppm
Line
Count
Source
705
65.4k
{
706
65.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
65.4k
  int c;
708
65.4k
  unsigned int w, h, maxval;
709
65.4k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
65.4k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
65.4k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
65.4k
  switch (c) {
718
6.25k
  case '2':                     /* it's a text-format PGM file */
719
13.4k
  case '3':                     /* it's a text-format PPM file */
720
49.0k
  case '5':                     /* it's a raw-format PGM file */
721
65.1k
  case '6':                     /* it's a raw-format PPM file */
722
65.1k
    break;
723
322
  default:
724
322
    ERREXIT(cinfo, JERR_PPM_NOT);
725
322
    break;
726
65.4k
  }
727
728
  /* fetch the remaining header info */
729
65.1k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
65.1k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
65.1k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
65.1k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
126
    ERREXIT(cinfo, JERR_PPM_NOT);
735
65.1k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
910
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
65.1k
  cinfo->image_width = (JDIMENSION)w;
739
65.1k
  cinfo->image_height = (JDIMENSION)h;
740
65.1k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
65.1k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
65.1k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
65.1k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
65.1k
  switch (c) {
748
4.68k
  case '2':                     /* it's a text-format PGM file */
749
4.68k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
4.68k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
4.68k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
4.68k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
669
      source->pub.get_pixel_rows = get_text_gray_row;
755
4.01k
    else if (IsExtRGB(cinfo->in_color_space))
756
3.34k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
669
    else if (cinfo->in_color_space == JCS_CMYK)
758
669
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
4.68k
    need_iobuffer = FALSE;
762
4.68k
    break;
763
764
5.62k
  case '3':                     /* it's a text-format PPM file */
765
5.62k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
5.62k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
5.62k
    if (IsExtRGB(cinfo->in_color_space))
769
4.01k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
1.60k
    else if (cinfo->in_color_space == JCS_CMYK)
771
803
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
803
    else
773
803
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
5.62k
    need_iobuffer = FALSE;
775
5.62k
    break;
776
777
33.9k
  case '5':                     /* it's a raw-format PGM file */
778
33.9k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
33.9k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
33.9k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
33.9k
    if (maxval > 255) {
783
5.11k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
730
        source->pub.get_pixel_rows = get_word_gray_row;
785
4.38k
      else if (IsExtRGB(cinfo->in_color_space))
786
3.65k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
730
      else if (cinfo->in_color_space == JCS_CMYK)
788
730
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
28.8k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
0
      source->pub.get_pixel_rows = get_raw_row;
795
0
      use_raw_buffer = TRUE;
796
0
      need_rescale = FALSE;
797
28.8k
    } else {
798
28.8k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
4.12k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
24.7k
      else if (IsExtRGB(cinfo->in_color_space))
801
20.6k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
4.12k
      else if (cinfo->in_color_space == JCS_CMYK)
803
4.12k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
28.8k
    }
807
33.9k
    break;
808
809
14.9k
  case '6':                     /* it's a raw-format PPM file */
810
14.9k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
14.9k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
14.9k
    if (maxval > 255) {
814
7.92k
      if (IsExtRGB(cinfo->in_color_space))
815
5.66k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
2.26k
      else if (cinfo->in_color_space == JCS_CMYK)
817
1.13k
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
1.13k
      else
819
1.13k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
7.92k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
0
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
0
      source->pub.get_pixel_rows = get_raw_row;
829
0
      use_raw_buffer = TRUE;
830
0
      need_rescale = FALSE;
831
7.02k
    } else {
832
7.02k
      if (IsExtRGB(cinfo->in_color_space))
833
5.01k
        source->pub.get_pixel_rows = get_rgb_row;
834
2.00k
      else if (cinfo->in_color_space == JCS_CMYK)
835
1.00k
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
1.00k
      else
837
1.00k
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
7.02k
    }
839
14.9k
    break;
840
65.1k
  }
841
842
56.3k
  if (IsExtRGB(cinfo->in_color_space))
843
42.3k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
13.9k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
5.52k
    cinfo->input_components = 1;
846
8.46k
  else if (cinfo->in_color_space == JCS_CMYK)
847
8.46k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
56.3k
  if (need_iobuffer) {
851
46.8k
    if (c == '6')
852
12.8k
      source->buffer_width = (size_t)w * 3 *
853
12.8k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
33.9k
    else
855
33.9k
      source->buffer_width = (size_t)w *
856
33.9k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
46.8k
    source->iobuffer = (U_CHAR *)
858
46.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
46.8k
                                  source->buffer_width);
860
46.8k
  }
861
862
  /* Create compressor input buffer. */
863
56.3k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
0
    source->pub._buffer = &source->pixrow;
868
0
    source->pub.buffer_height = 1;
869
56.3k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
56.3k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
56.3k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
56.3k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
56.3k
    source->pub.buffer_height = 1;
875
56.3k
  }
876
877
  /* Compute the rescaling array if required. */
878
56.3k
  if (need_rescale) {
879
56.3k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
56.3k
    source->rescale = (_JSAMPLE *)
883
56.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
56.3k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
56.3k
                                           sizeof(_JSAMPLE)));
886
56.3k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
56.3k
                                        sizeof(_JSAMPLE)));
888
56.3k
    half_maxval = maxval / 2;
889
155M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
155M
      source->rescale[val] =
892
155M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
155M
                   maxval);
894
155M
    }
895
56.3k
  }
896
56.3k
}
rdppm-16.c:start_input_ppm
Line
Count
Source
705
25.4k
{
706
25.4k
  ppm_source_ptr source = (ppm_source_ptr)sinfo;
707
25.4k
  int c;
708
25.4k
  unsigned int w, h, maxval;
709
25.4k
  boolean need_iobuffer, use_raw_buffer, need_rescale;
710
711
25.4k
  if (getc(source->pub.input_file) != 'P')
712
0
    ERREXIT(cinfo, JERR_PPM_NOT);
713
714
25.4k
  c = getc(source->pub.input_file); /* subformat discriminator character */
715
716
  /* detect unsupported variants (ie, PBM) before trying to read header */
717
25.4k
  switch (c) {
718
3.15k
  case '2':                     /* it's a text-format PGM file */
719
7.25k
  case '3':                     /* it's a text-format PPM file */
720
19.2k
  case '5':                     /* it's a raw-format PGM file */
721
25.3k
  case '6':                     /* it's a raw-format PPM file */
722
25.3k
    break;
723
105
  default:
724
105
    ERREXIT(cinfo, JERR_PPM_NOT);
725
105
    break;
726
25.4k
  }
727
728
  /* fetch the remaining header info */
729
25.3k
  w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
730
25.3k
  h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
731
25.3k
  maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
732
733
25.3k
  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
734
77
    ERREXIT(cinfo, JERR_PPM_NOT);
735
25.3k
  if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
736
525
    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
737
738
25.3k
  cinfo->image_width = (JDIMENSION)w;
739
25.3k
  cinfo->image_height = (JDIMENSION)h;
740
25.3k
  source->maxval = maxval;
741
742
  /* initialize flags to most common settings */
743
25.3k
  need_iobuffer = TRUE;         /* do we need an I/O buffer? */
744
25.3k
  use_raw_buffer = FALSE;       /* do we map input buffer onto I/O buffer? */
745
25.3k
  need_rescale = TRUE;          /* do we need a rescale array? */
746
747
25.3k
  switch (c) {
748
2.53k
  case '2':                     /* it's a text-format PGM file */
749
2.53k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
750
2.53k
        cinfo->in_color_space == JCS_RGB)
751
0
      cinfo->in_color_space = JCS_GRAYSCALE;
752
2.53k
    TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval);
753
2.53k
    if (cinfo->in_color_space == JCS_GRAYSCALE)
754
362
      source->pub.get_pixel_rows = get_text_gray_row;
755
2.17k
    else if (IsExtRGB(cinfo->in_color_space))
756
1.81k
      source->pub.get_pixel_rows = get_text_gray_rgb_row;
757
362
    else if (cinfo->in_color_space == JCS_CMYK)
758
362
      source->pub.get_pixel_rows = get_text_gray_cmyk_row;
759
0
    else
760
0
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
761
2.53k
    need_iobuffer = FALSE;
762
2.53k
    break;
763
764
3.06k
  case '3':                     /* it's a text-format PPM file */
765
3.06k
    if (cinfo->in_color_space == JCS_UNKNOWN)
766
0
      cinfo->in_color_space = JCS_EXT_RGB;
767
3.06k
    TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval);
768
3.06k
    if (IsExtRGB(cinfo->in_color_space))
769
2.19k
      source->pub.get_pixel_rows = get_text_rgb_row;
770
876
    else if (cinfo->in_color_space == JCS_CMYK)
771
438
      source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
772
438
    else
773
438
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
774
3.06k
    need_iobuffer = FALSE;
775
3.06k
    break;
776
777
11.3k
  case '5':                     /* it's a raw-format PGM file */
778
11.3k
    if (cinfo->in_color_space == JCS_UNKNOWN ||
779
11.3k
        cinfo->in_color_space == JCS_RGB)
780
0
      cinfo->in_color_space = JCS_GRAYSCALE;
781
11.3k
    TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval);
782
11.3k
    if (maxval > 255) {
783
2.75k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
784
393
        source->pub.get_pixel_rows = get_word_gray_row;
785
2.35k
      else if (IsExtRGB(cinfo->in_color_space))
786
1.96k
        source->pub.get_pixel_rows = get_word_gray_rgb_row;
787
393
      else if (cinfo->in_color_space == JCS_CMYK)
788
393
        source->pub.get_pixel_rows = get_word_gray_cmyk_row;
789
0
      else
790
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
791
8.59k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
792
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
793
0
               cinfo->in_color_space == JCS_GRAYSCALE) {
794
0
      source->pub.get_pixel_rows = get_raw_row;
795
0
      use_raw_buffer = TRUE;
796
0
      need_rescale = FALSE;
797
8.59k
    } else {
798
8.59k
      if (cinfo->in_color_space == JCS_GRAYSCALE)
799
1.22k
        source->pub.get_pixel_rows = get_scaled_gray_row;
800
7.36k
      else if (IsExtRGB(cinfo->in_color_space))
801
6.14k
        source->pub.get_pixel_rows = get_gray_rgb_row;
802
1.22k
      else if (cinfo->in_color_space == JCS_CMYK)
803
1.22k
        source->pub.get_pixel_rows = get_gray_cmyk_row;
804
0
      else
805
0
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
806
8.59k
    }
807
11.3k
    break;
808
809
5.48k
  case '6':                     /* it's a raw-format PPM file */
810
5.48k
    if (cinfo->in_color_space == JCS_UNKNOWN)
811
0
      cinfo->in_color_space = JCS_EXT_RGB;
812
5.48k
    TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval);
813
5.48k
    if (maxval > 255) {
814
3.33k
      if (IsExtRGB(cinfo->in_color_space))
815
2.38k
        source->pub.get_pixel_rows = get_word_rgb_row;
816
954
      else if (cinfo->in_color_space == JCS_CMYK)
817
477
        source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
818
477
      else
819
477
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
820
3.33k
    } else if (maxval <= _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
821
0
               maxval == ((1U << cinfo->data_precision) - 1U) &&
822
0
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
823
0
               (cinfo->in_color_space == JCS_EXT_RGB ||
824
0
                cinfo->in_color_space == JCS_RGB)) {
825
#else
826
               cinfo->in_color_space == JCS_EXT_RGB) {
827
#endif
828
0
      source->pub.get_pixel_rows = get_raw_row;
829
0
      use_raw_buffer = TRUE;
830
0
      need_rescale = FALSE;
831
2.14k
    } else {
832
2.14k
      if (IsExtRGB(cinfo->in_color_space))
833
1.53k
        source->pub.get_pixel_rows = get_rgb_row;
834
612
      else if (cinfo->in_color_space == JCS_CMYK)
835
306
        source->pub.get_pixel_rows = get_rgb_cmyk_row;
836
306
      else
837
306
        ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
838
2.14k
    }
839
5.48k
    break;
840
25.3k
  }
841
842
21.2k
  if (IsExtRGB(cinfo->in_color_space))
843
16.0k
    cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
844
5.18k
  else if (cinfo->in_color_space == JCS_GRAYSCALE)
845
1.98k
    cinfo->input_components = 1;
846
3.20k
  else if (cinfo->in_color_space == JCS_CMYK)
847
3.20k
    cinfo->input_components = 4;
848
849
  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
850
21.2k
  if (need_iobuffer) {
851
16.0k
    if (c == '6')
852
4.69k
      source->buffer_width = (size_t)w * 3 *
853
4.69k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
854
11.3k
    else
855
11.3k
      source->buffer_width = (size_t)w *
856
11.3k
        ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
857
16.0k
    source->iobuffer = (U_CHAR *)
858
16.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
859
16.0k
                                  source->buffer_width);
860
16.0k
  }
861
862
  /* Create compressor input buffer. */
863
21.2k
  if (use_raw_buffer) {
864
    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
865
    /* Synthesize a _JSAMPARRAY pointer structure */
866
0
    source->pixrow = (_JSAMPROW)source->iobuffer;
867
0
    source->pub._buffer = &source->pixrow;
868
0
    source->pub.buffer_height = 1;
869
21.2k
  } else {
870
    /* Need to translate anyway, so make a separate sample buffer. */
871
21.2k
    source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
872
21.2k
      ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
21.2k
       (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
874
21.2k
    source->pub.buffer_height = 1;
875
21.2k
  }
876
877
  /* Compute the rescaling array if required. */
878
21.2k
  if (need_rescale) {
879
21.2k
    long val, half_maxval;
880
881
    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
882
21.2k
    source->rescale = (_JSAMPLE *)
883
21.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
884
21.2k
                                  (size_t)(((long)MAX(maxval, 255) + 1L) *
885
21.2k
                                           sizeof(_JSAMPLE)));
886
21.2k
    memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
887
21.2k
                                        sizeof(_JSAMPLE)));
888
21.2k
    half_maxval = maxval / 2;
889
294M
    for (val = 0; val <= (long)maxval; val++) {
890
      /* The multiplication here must be done in 32 bits to avoid overflow */
891
294M
      source->rescale[val] =
892
294M
        (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
893
294M
                   maxval);
894
294M
    }
895
21.2k
  }
896
21.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
89.5k
{
906
  /* no work */
907
89.5k
}
rdppm-8.c:finish_input_ppm
Line
Count
Source
905
47.8k
{
906
  /* no work */
907
47.8k
}
rdppm-12.c:finish_input_ppm
Line
Count
Source
905
32.2k
{
906
  /* no work */
907
32.2k
}
rdppm-16.c:finish_input_ppm
Line
Count
Source
905
9.38k
{
906
  /* no work */
907
9.38k
}
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
182k
{
917
182k
  ppm_source_ptr source;
918
919
#if BITS_IN_JSAMPLE == 8
920
91.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
90.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
90.9k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
0
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
182k
  source = (ppm_source_ptr)
929
182k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
182k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
182k
  source->pub.start_input = start_input_ppm;
933
182k
  source->pub.finish_input = finish_input_ppm;
934
182k
  source->pub.max_pixels = 0;
935
936
182k
  return (cjpeg_source_ptr)source;
937
182k
}
jinit_read_ppm
Line
Count
Source
916
91.5k
{
917
91.5k
  ppm_source_ptr source;
918
919
91.5k
#if BITS_IN_JSAMPLE == 8
920
91.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
921
#else
922
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
924
#endif
925
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
926
927
  /* Create module interface object */
928
91.5k
  source = (ppm_source_ptr)
929
91.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
91.5k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
91.5k
  source->pub.start_input = start_input_ppm;
933
91.5k
  source->pub.finish_input = finish_input_ppm;
934
91.5k
  source->pub.max_pixels = 0;
935
936
91.5k
  return (cjpeg_source_ptr)source;
937
91.5k
}
j12init_read_ppm
Line
Count
Source
916
65.4k
{
917
65.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
65.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
65.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
65.4k
  source = (ppm_source_ptr)
929
65.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
65.4k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
65.4k
  source->pub.start_input = start_input_ppm;
933
65.4k
  source->pub.finish_input = finish_input_ppm;
934
65.4k
  source->pub.max_pixels = 0;
935
936
65.4k
  return (cjpeg_source_ptr)source;
937
65.4k
}
j16init_read_ppm
Line
Count
Source
916
25.4k
{
917
25.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
25.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
923
25.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
25.4k
  source = (ppm_source_ptr)
929
25.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
930
25.4k
                                sizeof(ppm_source_struct));
931
  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
932
25.4k
  source->pub.start_input = start_input_ppm;
933
25.4k
  source->pub.finish_input = finish_input_ppm;
934
25.4k
  source->pub.max_pixels = 0;
935
936
25.4k
  return (cjpeg_source_ptr)source;
937
25.4k
}
938
939
#endif /* defined(PPM_SUPPORTED) &&
940
          (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */