/src/libjpeg-turbo.main/src/rdppm.c
Line | Count | Source |
1 | | /* |
2 | | * rdppm.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1991-1997, Thomas G. Lane. |
6 | | * Modified 2009 by Bill Allombert, Guido Vollbeding. |
7 | | * libjpeg-turbo Modifications: |
8 | | * Copyright (C) 2015-2017, 2020-2026, D. R. Commander. |
9 | | * For conditions of distribution and use, see the accompanying README.ijg |
10 | | * file. |
11 | | * |
12 | | * This file contains routines to read input images in PPM/PGM format. |
13 | | * The extended 2-byte-per-sample raw PPM/PGM formats are supported. |
14 | | * The PBMPLUS library is NOT required to compile this software |
15 | | * (but it is highly useful as a set of PPM image manipulation programs). |
16 | | * |
17 | | * These routines may need modification for non-Unix environments or |
18 | | * specialized applications. As they stand, they assume input from |
19 | | * an ordinary stdio stream. They further assume that reading begins |
20 | | * at the start of the file; start_input may need work if the |
21 | | * user interface has already read some data (e.g., to determine that |
22 | | * the file is indeed PPM format). |
23 | | */ |
24 | | |
25 | | #include "cmyk.h" |
26 | | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
27 | | |
28 | | #if defined(PPM_SUPPORTED) && \ |
29 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) |
30 | | |
31 | | |
32 | | /* Portions of this code are based on the PBMPLUS library, which is: |
33 | | ** |
34 | | ** Copyright (C) 1988 by Jef Poskanzer. |
35 | | ** |
36 | | ** Permission to use, copy, modify, and distribute this software and its |
37 | | ** documentation for any purpose and without fee is hereby granted, provided |
38 | | ** that the above copyright notice appear in all copies and that both that |
39 | | ** copyright notice and this permission notice appear in supporting |
40 | | ** documentation. This software is provided "as is" without express or |
41 | | ** implied warranty. |
42 | | */ |
43 | | |
44 | | |
45 | | #define ReadOK(file, buffer, len) \ |
46 | 258M | (fread(buffer, 1, len, file) == ((size_t)(len))) |
47 | | |
48 | | static int alpha_index[JPEG_NUMCS] = { |
49 | | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 |
50 | | }; |
51 | | |
52 | | |
53 | | /* Private version of data source object */ |
54 | | |
55 | | typedef struct { |
56 | | struct cjpeg_source_struct pub; /* public fields */ |
57 | | |
58 | | /* Usually these two pointers point to the same place: */ |
59 | | unsigned char *iobuffer; /* fread's I/O buffer */ |
60 | | _JSAMPROW pixrow; /* compressor input buffer */ |
61 | | size_t buffer_width; /* width of I/O buffer */ |
62 | | _JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ |
63 | | unsigned int maxval; |
64 | | } ppm_source_struct; |
65 | | |
66 | | typedef ppm_source_struct *ppm_source_ptr; |
67 | | |
68 | | |
69 | | LOCAL(int) |
70 | | pbm_getc(FILE *infile) |
71 | | /* Read next char, skipping over any comments */ |
72 | | /* A comment/newline sequence is returned as a newline */ |
73 | 3.82M | { |
74 | 3.82M | register int ch; |
75 | | |
76 | 3.82M | ch = getc(infile); |
77 | 3.82M | if (ch == '#') { |
78 | 817k | do { |
79 | 817k | ch = getc(infile); |
80 | 817k | } while (ch != '\n' && ch != EOF); |
81 | 49.7k | } |
82 | 3.82M | return ch; |
83 | 3.82M | } Line | Count | Source | 73 | 1.76M | { | 74 | 1.76M | register int ch; | 75 | | | 76 | 1.76M | ch = getc(infile); | 77 | 1.76M | if (ch == '#') { | 78 | 338k | do { | 79 | 338k | ch = getc(infile); | 80 | 338k | } while (ch != '\n' && ch != EOF); | 81 | 23.2k | } | 82 | 1.76M | return ch; | 83 | 1.76M | } |
Line | Count | Source | 73 | 1.42M | { | 74 | 1.42M | register int ch; | 75 | | | 76 | 1.42M | ch = getc(infile); | 77 | 1.42M | if (ch == '#') { | 78 | 298k | do { | 79 | 298k | ch = getc(infile); | 80 | 298k | } while (ch != '\n' && ch != EOF); | 81 | 16.1k | } | 82 | 1.42M | return ch; | 83 | 1.42M | } |
Line | Count | Source | 73 | 631k | { | 74 | 631k | register int ch; | 75 | | | 76 | 631k | ch = getc(infile); | 77 | 631k | if (ch == '#') { | 78 | 181k | do { | 79 | 181k | ch = getc(infile); | 80 | 181k | } while (ch != '\n' && ch != EOF); | 81 | 10.3k | } | 82 | 631k | return ch; | 83 | 631k | } |
|
84 | | |
85 | | |
86 | | LOCAL(unsigned int) |
87 | | read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval) |
88 | | /* Read an unsigned decimal integer from the PPM file */ |
89 | | /* Swallows one trailing character after the integer */ |
90 | | /* Note that on a 16-bit-int machine, only values up to 64k can be read. */ |
91 | | /* This should not be a problem in practice. */ |
92 | 1.63M | { |
93 | 1.63M | register int ch; |
94 | 1.63M | register unsigned int val; |
95 | | |
96 | | /* Skip any leading whitespace */ |
97 | 1.75M | do { |
98 | 1.75M | ch = pbm_getc(infile); |
99 | 1.75M | if (ch == EOF) |
100 | 35.8k | ERREXIT(cinfo, JERR_INPUT_EOF); |
101 | 1.75M | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); |
102 | | |
103 | 1.63M | if (ch < '0' || ch > '9') |
104 | 3.23k | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); |
105 | | |
106 | 1.63M | val = ch - '0'; |
107 | 2.10M | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { |
108 | 470k | val *= 10; |
109 | 470k | val += ch - '0'; |
110 | 470k | if (val > maxval) |
111 | 1.63k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
112 | 470k | } |
113 | | |
114 | 1.63M | return val; |
115 | 1.63M | } rdppm-8.c:read_pbm_integer Line | Count | Source | 92 | 751k | { | 93 | 751k | register int ch; | 94 | 751k | register unsigned int val; | 95 | | | 96 | | /* Skip any leading whitespace */ | 97 | 805k | do { | 98 | 805k | ch = pbm_getc(infile); | 99 | 805k | if (ch == EOF) | 100 | 17.4k | ERREXIT(cinfo, JERR_INPUT_EOF); | 101 | 805k | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); | 102 | | | 103 | 751k | if (ch < '0' || ch > '9') | 104 | 1.53k | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); | 105 | | | 106 | 751k | val = ch - '0'; | 107 | 977k | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { | 108 | 226k | val *= 10; | 109 | 226k | val += ch - '0'; | 110 | 226k | if (val > maxval) | 111 | 834 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 112 | 226k | } | 113 | | | 114 | 751k | return val; | 115 | 751k | } |
rdppm-12.c:read_pbm_integer Line | Count | Source | 92 | 608k | { | 93 | 608k | register int ch; | 94 | 608k | register unsigned int val; | 95 | | | 96 | | /* Skip any leading whitespace */ | 97 | 661k | do { | 98 | 661k | ch = pbm_getc(infile); | 99 | 661k | if (ch == EOF) | 100 | 11.6k | ERREXIT(cinfo, JERR_INPUT_EOF); | 101 | 661k | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); | 102 | | | 103 | 608k | if (ch < '0' || ch > '9') | 104 | 1.18k | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); | 105 | | | 106 | 608k | val = ch - '0'; | 107 | 778k | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { | 108 | 170k | val *= 10; | 109 | 170k | val += ch - '0'; | 110 | 170k | if (val > maxval) | 111 | 535 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 112 | 170k | } | 113 | | | 114 | 608k | return val; | 115 | 608k | } |
rdppm-16.c:read_pbm_integer Line | Count | Source | 92 | 274k | { | 93 | 274k | register int ch; | 94 | 274k | register unsigned int val; | 95 | | | 96 | | /* Skip any leading whitespace */ | 97 | 291k | do { | 98 | 291k | ch = pbm_getc(infile); | 99 | 291k | if (ch == EOF) | 100 | 6.77k | ERREXIT(cinfo, JERR_INPUT_EOF); | 101 | 291k | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); | 102 | | | 103 | 274k | if (ch < '0' || ch > '9') | 104 | 514 | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); | 105 | | | 106 | 274k | val = ch - '0'; | 107 | 348k | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { | 108 | 73.9k | val *= 10; | 109 | 73.9k | val += ch - '0'; | 110 | 73.9k | if (val > maxval) | 111 | 264 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 112 | 73.9k | } | 113 | | | 114 | 274k | return val; | 115 | 274k | } |
|
116 | | |
117 | | |
118 | | /* |
119 | | * Read one row of pixels. |
120 | | * |
121 | | * We provide several different versions depending on input file format. |
122 | | * In all cases, input is scaled to cinfo->data_precision. |
123 | | * |
124 | | * A really fast path is provided for reading byte/sample raw files with |
125 | | * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U, |
126 | | * which is the normal case for 8-bit data. |
127 | | */ |
128 | | |
129 | | |
130 | | METHODDEF(JDIMENSION) |
131 | | get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
132 | | /* This version is for reading text-format PGM files with any maxval */ |
133 | 22.7k | { |
134 | 22.7k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
135 | 22.7k | FILE *infile = source->pub.input_file; |
136 | 22.7k | register _JSAMPROW ptr; |
137 | 22.7k | register _JSAMPLE *rescale = source->rescale; |
138 | 22.7k | JDIMENSION col; |
139 | 22.7k | unsigned int maxval = source->maxval; |
140 | | |
141 | 22.7k | ptr = source->pub._buffer[0]; |
142 | 62.3k | for (col = cinfo->image_width; col > 0; col--) { |
143 | 39.6k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
144 | 39.6k | } |
145 | 22.7k | return 1; |
146 | 22.7k | } rdppm-8.c:get_text_gray_row Line | Count | Source | 133 | 11.9k | { | 134 | 11.9k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 135 | 11.9k | FILE *infile = source->pub.input_file; | 136 | 11.9k | register _JSAMPROW ptr; | 137 | 11.9k | register _JSAMPLE *rescale = source->rescale; | 138 | 11.9k | JDIMENSION col; | 139 | 11.9k | unsigned int maxval = source->maxval; | 140 | | | 141 | 11.9k | ptr = source->pub._buffer[0]; | 142 | 32.8k | for (col = cinfo->image_width; col > 0; col--) { | 143 | 20.8k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 144 | 20.8k | } | 145 | 11.9k | return 1; | 146 | 11.9k | } |
rdppm-12.c:get_text_gray_row Line | Count | Source | 133 | 7.01k | { | 134 | 7.01k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 135 | 7.01k | FILE *infile = source->pub.input_file; | 136 | 7.01k | register _JSAMPROW ptr; | 137 | 7.01k | register _JSAMPLE *rescale = source->rescale; | 138 | 7.01k | JDIMENSION col; | 139 | 7.01k | unsigned int maxval = source->maxval; | 140 | | | 141 | 7.01k | ptr = source->pub._buffer[0]; | 142 | 18.5k | for (col = cinfo->image_width; col > 0; col--) { | 143 | 11.5k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 144 | 11.5k | } | 145 | 7.01k | return 1; | 146 | 7.01k | } |
rdppm-16.c:get_text_gray_row Line | Count | Source | 133 | 3.76k | { | 134 | 3.76k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 135 | 3.76k | FILE *infile = source->pub.input_file; | 136 | 3.76k | register _JSAMPROW ptr; | 137 | 3.76k | register _JSAMPLE *rescale = source->rescale; | 138 | 3.76k | JDIMENSION col; | 139 | 3.76k | unsigned int maxval = source->maxval; | 140 | | | 141 | 3.76k | ptr = source->pub._buffer[0]; | 142 | 10.9k | for (col = cinfo->image_width; col > 0; col--) { | 143 | 7.22k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 144 | 7.22k | } | 145 | 3.76k | return 1; | 146 | 3.76k | } |
|
147 | | |
148 | | |
149 | 182M | #define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \ |
150 | 926M | for (col = cinfo->image_width; col > 0; col--) { \ |
151 | 744M | ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \ |
152 | 744M | alpha_set_op \ |
153 | 744M | ptr += ps; \ |
154 | 744M | } \ |
155 | 182M | } |
156 | | |
157 | | METHODDEF(JDIMENSION) |
158 | | get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
159 | | /* This version is for reading text-format PGM files with any maxval and |
160 | | converting to extended RGB */ |
161 | 109k | { |
162 | 109k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
163 | 109k | FILE *infile = source->pub.input_file; |
164 | 109k | register _JSAMPROW ptr; |
165 | 109k | register _JSAMPLE *rescale = source->rescale; |
166 | 109k | JDIMENSION col; |
167 | 109k | unsigned int maxval = source->maxval; |
168 | 109k | register int rindex = rgb_red[cinfo->in_color_space]; |
169 | 109k | register int gindex = rgb_green[cinfo->in_color_space]; |
170 | 109k | register int bindex = rgb_blue[cinfo->in_color_space]; |
171 | 109k | register int aindex = alpha_index[cinfo->in_color_space]; |
172 | 109k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
173 | | |
174 | 109k | ptr = source->pub._buffer[0]; |
175 | 109k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
176 | 18.0k | if (aindex >= 0) |
177 | 2.67k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), |
178 | 18.0k | ptr[aindex] = (_JSAMPLE)maxval;) |
179 | 15.3k | else |
180 | 15.3k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) |
181 | 91.4k | } else { |
182 | 91.4k | if (aindex >= 0) |
183 | 15.2k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], |
184 | 91.4k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
185 | 76.1k | else |
186 | 76.1k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) |
187 | 91.4k | } |
188 | 109k | return 1; |
189 | 109k | } rdppm-8.c:get_text_gray_rgb_row Line | Count | Source | 161 | 55.5k | { | 162 | 55.5k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 163 | 55.5k | FILE *infile = source->pub.input_file; | 164 | 55.5k | register _JSAMPROW ptr; | 165 | 55.5k | register _JSAMPLE *rescale = source->rescale; | 166 | 55.5k | JDIMENSION col; | 167 | 55.5k | unsigned int maxval = source->maxval; | 168 | 55.5k | register int rindex = rgb_red[cinfo->in_color_space]; | 169 | 55.5k | register int gindex = rgb_green[cinfo->in_color_space]; | 170 | 55.5k | register int bindex = rgb_blue[cinfo->in_color_space]; | 171 | 55.5k | register int aindex = alpha_index[cinfo->in_color_space]; | 172 | 55.5k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 173 | | | 174 | 55.5k | ptr = source->pub._buffer[0]; | 175 | 55.5k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 176 | 10.4k | if (aindex >= 0) | 177 | 1.18k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 178 | 10.4k | ptr[aindex] = (_JSAMPLE)maxval;) | 179 | 9.26k | else | 180 | 9.26k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 181 | 45.1k | } else { | 182 | 45.1k | if (aindex >= 0) | 183 | 6.00k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 184 | 45.1k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 185 | 39.1k | else | 186 | 39.1k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 187 | 45.1k | } | 188 | 55.5k | return 1; | 189 | 55.5k | } |
rdppm-12.c:get_text_gray_rgb_row Line | Count | Source | 161 | 35.0k | { | 162 | 35.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 163 | 35.0k | FILE *infile = source->pub.input_file; | 164 | 35.0k | register _JSAMPROW ptr; | 165 | 35.0k | register _JSAMPLE *rescale = source->rescale; | 166 | 35.0k | JDIMENSION col; | 167 | 35.0k | unsigned int maxval = source->maxval; | 168 | 35.0k | register int rindex = rgb_red[cinfo->in_color_space]; | 169 | 35.0k | register int gindex = rgb_green[cinfo->in_color_space]; | 170 | 35.0k | register int bindex = rgb_blue[cinfo->in_color_space]; | 171 | 35.0k | register int aindex = alpha_index[cinfo->in_color_space]; | 172 | 35.0k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 173 | | | 174 | 35.0k | ptr = source->pub._buffer[0]; | 175 | 35.0k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 176 | 5.45k | if (aindex >= 0) | 177 | 1.06k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 178 | 5.45k | ptr[aindex] = (_JSAMPLE)maxval;) | 179 | 4.38k | else | 180 | 4.38k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 181 | 29.6k | } else { | 182 | 29.6k | if (aindex >= 0) | 183 | 5.94k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 184 | 29.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 185 | 23.6k | else | 186 | 23.6k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 187 | 29.6k | } | 188 | 35.0k | return 1; | 189 | 35.0k | } |
rdppm-16.c:get_text_gray_rgb_row Line | Count | Source | 161 | 18.8k | { | 162 | 18.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 163 | 18.8k | FILE *infile = source->pub.input_file; | 164 | 18.8k | register _JSAMPROW ptr; | 165 | 18.8k | register _JSAMPLE *rescale = source->rescale; | 166 | 18.8k | JDIMENSION col; | 167 | 18.8k | unsigned int maxval = source->maxval; | 168 | 18.8k | register int rindex = rgb_red[cinfo->in_color_space]; | 169 | 18.8k | register int gindex = rgb_green[cinfo->in_color_space]; | 170 | 18.8k | register int bindex = rgb_blue[cinfo->in_color_space]; | 171 | 18.8k | register int aindex = alpha_index[cinfo->in_color_space]; | 172 | 18.8k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 173 | | | 174 | 18.8k | ptr = source->pub._buffer[0]; | 175 | 18.8k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 176 | 2.10k | if (aindex >= 0) | 177 | 434 | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 178 | 2.10k | ptr[aindex] = (_JSAMPLE)maxval;) | 179 | 1.67k | else | 180 | 1.67k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 181 | 16.6k | } else { | 182 | 16.6k | if (aindex >= 0) | 183 | 3.32k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 184 | 16.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 185 | 13.3k | else | 186 | 13.3k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 187 | 16.6k | } | 188 | 18.8k | return 1; | 189 | 18.8k | } |
|
190 | | |
191 | | |
192 | | METHODDEF(JDIMENSION) |
193 | | get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
194 | | /* This version is for reading text-format PGM files with any maxval and |
195 | | converting to CMYK */ |
196 | 17.9k | { |
197 | 17.9k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
198 | 17.9k | FILE *infile = source->pub.input_file; |
199 | 17.9k | register _JSAMPROW ptr; |
200 | 17.9k | register _JSAMPLE *rescale = source->rescale; |
201 | 17.9k | JDIMENSION col; |
202 | 17.9k | unsigned int maxval = source->maxval; |
203 | | |
204 | 17.9k | ptr = source->pub._buffer[0]; |
205 | 17.9k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
206 | 12.3k | for (col = cinfo->image_width; col > 0; col--) { |
207 | 8.47k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
208 | 8.47k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); |
209 | 8.47k | ptr += 4; |
210 | 8.47k | } |
211 | 14.0k | } else { |
212 | 36.8k | for (col = cinfo->image_width; col > 0; col--) { |
213 | 22.7k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
214 | 22.7k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
215 | 22.7k | ptr + 1, ptr + 2, ptr + 3); |
216 | 22.7k | ptr += 4; |
217 | 22.7k | } |
218 | 14.0k | } |
219 | 17.9k | return 1; |
220 | 17.9k | } rdppm-8.c:get_text_gray_cmyk_row Line | Count | Source | 196 | 7.18k | { | 197 | 7.18k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 198 | 7.18k | FILE *infile = source->pub.input_file; | 199 | 7.18k | register _JSAMPROW ptr; | 200 | 7.18k | register _JSAMPLE *rescale = source->rescale; | 201 | 7.18k | JDIMENSION col; | 202 | 7.18k | unsigned int maxval = source->maxval; | 203 | | | 204 | 7.18k | ptr = source->pub._buffer[0]; | 205 | 7.18k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 206 | 5.52k | for (col = cinfo->image_width; col > 0; col--) { | 207 | 3.65k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 208 | 3.65k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 209 | 3.65k | ptr += 4; | 210 | 3.65k | } | 211 | 5.31k | } else { | 212 | 14.1k | for (col = cinfo->image_width; col > 0; col--) { | 213 | 8.83k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 214 | 8.83k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 215 | 8.83k | ptr + 1, ptr + 2, ptr + 3); | 216 | 8.83k | ptr += 4; | 217 | 8.83k | } | 218 | 5.31k | } | 219 | 7.18k | return 1; | 220 | 7.18k | } |
rdppm-12.c:get_text_gray_cmyk_row Line | Count | Source | 196 | 7.01k | { | 197 | 7.01k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 198 | 7.01k | FILE *infile = source->pub.input_file; | 199 | 7.01k | register _JSAMPROW ptr; | 200 | 7.01k | register _JSAMPLE *rescale = source->rescale; | 201 | 7.01k | JDIMENSION col; | 202 | 7.01k | unsigned int maxval = source->maxval; | 203 | | | 204 | 7.01k | ptr = source->pub._buffer[0]; | 205 | 7.01k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 206 | 4.32k | for (col = cinfo->image_width; col > 0; col--) { | 207 | 2.94k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 208 | 2.94k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 209 | 2.94k | ptr += 4; | 210 | 2.94k | } | 211 | 5.62k | } else { | 212 | 14.2k | for (col = cinfo->image_width; col > 0; col--) { | 213 | 8.62k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 214 | 8.62k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 215 | 8.62k | ptr + 1, ptr + 2, ptr + 3); | 216 | 8.62k | ptr += 4; | 217 | 8.62k | } | 218 | 5.62k | } | 219 | 7.01k | return 1; | 220 | 7.01k | } |
rdppm-16.c:get_text_gray_cmyk_row Line | Count | Source | 196 | 3.76k | { | 197 | 3.76k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 198 | 3.76k | FILE *infile = source->pub.input_file; | 199 | 3.76k | register _JSAMPROW ptr; | 200 | 3.76k | register _JSAMPLE *rescale = source->rescale; | 201 | 3.76k | JDIMENSION col; | 202 | 3.76k | unsigned int maxval = source->maxval; | 203 | | | 204 | 3.76k | ptr = source->pub._buffer[0]; | 205 | 3.76k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 206 | 2.53k | for (col = cinfo->image_width; col > 0; col--) { | 207 | 1.88k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 208 | 1.88k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 209 | 1.88k | ptr += 4; | 210 | 1.88k | } | 211 | 3.10k | } else { | 212 | 8.44k | for (col = cinfo->image_width; col > 0; col--) { | 213 | 5.34k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 214 | 5.34k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 215 | 5.34k | ptr + 1, ptr + 2, ptr + 3); | 216 | 5.34k | ptr += 4; | 217 | 5.34k | } | 218 | 3.10k | } | 219 | 3.76k | return 1; | 220 | 3.76k | } |
|
221 | | |
222 | | |
223 | 9.91M | #define RGB_READ_LOOP(read_op, alpha_set_op) { \ |
224 | 85.9M | for (col = cinfo->image_width; col > 0; col--) { \ |
225 | 76.0M | ptr[rindex] = read_op; \ |
226 | 76.0M | ptr[gindex] = read_op; \ |
227 | 76.0M | ptr[bindex] = read_op; \ |
228 | 76.0M | alpha_set_op \ |
229 | 76.0M | ptr += ps; \ |
230 | 76.0M | } \ |
231 | 9.91M | } |
232 | | |
233 | | METHODDEF(JDIMENSION) |
234 | | get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
235 | | /* This version is for reading text-format PPM files with any maxval */ |
236 | 133k | { |
237 | 133k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
238 | 133k | FILE *infile = source->pub.input_file; |
239 | 133k | register _JSAMPROW ptr; |
240 | 133k | register _JSAMPLE *rescale = source->rescale; |
241 | 133k | JDIMENSION col; |
242 | 133k | unsigned int maxval = source->maxval; |
243 | 133k | register int rindex = rgb_red[cinfo->in_color_space]; |
244 | 133k | register int gindex = rgb_green[cinfo->in_color_space]; |
245 | 133k | register int bindex = rgb_blue[cinfo->in_color_space]; |
246 | 133k | register int aindex = alpha_index[cinfo->in_color_space]; |
247 | 133k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
248 | | |
249 | 133k | ptr = source->pub._buffer[0]; |
250 | 133k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
251 | 40.0k | if (aindex >= 0) |
252 | 6.31k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), |
253 | 40.0k | ptr[aindex] = (_JSAMPLE)maxval;) |
254 | 33.7k | else |
255 | 33.7k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) |
256 | 93.2k | } else { |
257 | 93.2k | if (aindex >= 0) |
258 | 16.5k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], |
259 | 93.2k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
260 | 76.7k | else |
261 | 76.7k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) |
262 | 93.2k | } |
263 | 133k | return 1; |
264 | 133k | } rdppm-8.c:get_text_rgb_row Line | Count | Source | 236 | 57.1k | { | 237 | 57.1k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 238 | 57.1k | FILE *infile = source->pub.input_file; | 239 | 57.1k | register _JSAMPROW ptr; | 240 | 57.1k | register _JSAMPLE *rescale = source->rescale; | 241 | 57.1k | JDIMENSION col; | 242 | 57.1k | unsigned int maxval = source->maxval; | 243 | 57.1k | register int rindex = rgb_red[cinfo->in_color_space]; | 244 | 57.1k | register int gindex = rgb_green[cinfo->in_color_space]; | 245 | 57.1k | register int bindex = rgb_blue[cinfo->in_color_space]; | 246 | 57.1k | register int aindex = alpha_index[cinfo->in_color_space]; | 247 | 57.1k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 248 | | | 249 | 57.1k | ptr = source->pub._buffer[0]; | 250 | 57.1k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 251 | 13.4k | if (aindex >= 0) | 252 | 1.29k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 253 | 13.4k | ptr[aindex] = (_JSAMPLE)maxval;) | 254 | 12.1k | else | 255 | 12.1k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 256 | 43.6k | } else { | 257 | 43.6k | if (aindex >= 0) | 258 | 6.28k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 259 | 43.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 260 | 37.4k | else | 261 | 37.4k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 262 | 43.6k | } | 263 | 57.1k | return 1; | 264 | 57.1k | } |
rdppm-12.c:get_text_rgb_row Line | Count | Source | 236 | 50.2k | { | 237 | 50.2k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 238 | 50.2k | FILE *infile = source->pub.input_file; | 239 | 50.2k | register _JSAMPROW ptr; | 240 | 50.2k | register _JSAMPLE *rescale = source->rescale; | 241 | 50.2k | JDIMENSION col; | 242 | 50.2k | unsigned int maxval = source->maxval; | 243 | 50.2k | register int rindex = rgb_red[cinfo->in_color_space]; | 244 | 50.2k | register int gindex = rgb_green[cinfo->in_color_space]; | 245 | 50.2k | register int bindex = rgb_blue[cinfo->in_color_space]; | 246 | 50.2k | register int aindex = alpha_index[cinfo->in_color_space]; | 247 | 50.2k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 248 | | | 249 | 50.2k | ptr = source->pub._buffer[0]; | 250 | 50.2k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 251 | 22.3k | if (aindex >= 0) | 252 | 4.57k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 253 | 22.3k | ptr[aindex] = (_JSAMPLE)maxval;) | 254 | 17.7k | else | 255 | 17.7k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 256 | 27.8k | } else { | 257 | 27.8k | if (aindex >= 0) | 258 | 5.47k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 259 | 27.8k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 260 | 22.4k | else | 261 | 22.4k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 262 | 27.8k | } | 263 | 50.2k | return 1; | 264 | 50.2k | } |
rdppm-16.c:get_text_rgb_row Line | Count | Source | 236 | 26.0k | { | 237 | 26.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 238 | 26.0k | FILE *infile = source->pub.input_file; | 239 | 26.0k | register _JSAMPROW ptr; | 240 | 26.0k | register _JSAMPLE *rescale = source->rescale; | 241 | 26.0k | JDIMENSION col; | 242 | 26.0k | unsigned int maxval = source->maxval; | 243 | 26.0k | register int rindex = rgb_red[cinfo->in_color_space]; | 244 | 26.0k | register int gindex = rgb_green[cinfo->in_color_space]; | 245 | 26.0k | register int bindex = rgb_blue[cinfo->in_color_space]; | 246 | 26.0k | register int aindex = alpha_index[cinfo->in_color_space]; | 247 | 26.0k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 248 | | | 249 | 26.0k | ptr = source->pub._buffer[0]; | 250 | 26.0k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 251 | 4.31k | if (aindex >= 0) | 252 | 451 | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 253 | 4.31k | ptr[aindex] = (_JSAMPLE)maxval;) | 254 | 3.86k | else | 255 | 3.86k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 256 | 21.6k | } else { | 257 | 21.6k | if (aindex >= 0) | 258 | 4.75k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 259 | 21.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 260 | 16.9k | else | 261 | 16.9k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 262 | 21.6k | } | 263 | 26.0k | return 1; | 264 | 26.0k | } |
|
265 | | |
266 | | |
267 | | METHODDEF(JDIMENSION) |
268 | | get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
269 | | /* This version is for reading text-format PPM files with any maxval and |
270 | | converting to CMYK */ |
271 | 22.8k | { |
272 | 22.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
273 | 22.8k | FILE *infile = source->pub.input_file; |
274 | 22.8k | register _JSAMPROW ptr; |
275 | 22.8k | register _JSAMPLE *rescale = source->rescale; |
276 | 22.8k | JDIMENSION col; |
277 | 22.8k | unsigned int maxval = source->maxval; |
278 | | |
279 | 22.8k | ptr = source->pub._buffer[0]; |
280 | 22.8k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
281 | 27.7k | for (col = cinfo->image_width; col > 0; col--) { |
282 | 19.0k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
283 | 19.0k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
284 | 19.0k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
285 | 19.0k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
286 | 19.0k | ptr += 4; |
287 | 19.0k | } |
288 | 14.0k | } else { |
289 | 38.8k | for (col = cinfo->image_width; col > 0; col--) { |
290 | 24.7k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
291 | 24.7k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
292 | 24.7k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
293 | 24.7k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
294 | 24.7k | ptr + 2, ptr + 3); |
295 | 24.7k | ptr += 4; |
296 | 24.7k | } |
297 | 14.0k | } |
298 | 22.8k | return 1; |
299 | 22.8k | } rdppm-8.c:get_text_rgb_cmyk_row Line | Count | Source | 271 | 7.57k | { | 272 | 7.57k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 273 | 7.57k | FILE *infile = source->pub.input_file; | 274 | 7.57k | register _JSAMPROW ptr; | 275 | 7.57k | register _JSAMPLE *rescale = source->rescale; | 276 | 7.57k | JDIMENSION col; | 277 | 7.57k | unsigned int maxval = source->maxval; | 278 | | | 279 | 7.57k | ptr = source->pub._buffer[0]; | 280 | 7.57k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 281 | 7.40k | for (col = cinfo->image_width; col > 0; col--) { | 282 | 5.07k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 283 | 5.07k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 284 | 5.07k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 285 | 5.07k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 286 | 5.07k | ptr += 4; | 287 | 5.07k | } | 288 | 5.24k | } else { | 289 | 15.0k | for (col = cinfo->image_width; col > 0; col--) { | 290 | 9.81k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 291 | 9.81k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 292 | 9.81k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 293 | 9.81k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 294 | 9.81k | ptr + 2, ptr + 3); | 295 | 9.81k | ptr += 4; | 296 | 9.81k | } | 297 | 5.24k | } | 298 | 7.57k | return 1; | 299 | 7.57k | } |
rdppm-12.c:get_text_rgb_cmyk_row Line | Count | Source | 271 | 10.0k | { | 272 | 10.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 273 | 10.0k | FILE *infile = source->pub.input_file; | 274 | 10.0k | register _JSAMPROW ptr; | 275 | 10.0k | register _JSAMPLE *rescale = source->rescale; | 276 | 10.0k | JDIMENSION col; | 277 | 10.0k | unsigned int maxval = source->maxval; | 278 | | | 279 | 10.0k | ptr = source->pub._buffer[0]; | 280 | 10.0k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 281 | 15.8k | for (col = cinfo->image_width; col > 0; col--) { | 282 | 11.0k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 283 | 11.0k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 284 | 11.0k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 285 | 11.0k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 286 | 11.0k | ptr += 4; | 287 | 11.0k | } | 288 | 5.24k | } else { | 289 | 14.3k | for (col = cinfo->image_width; col > 0; col--) { | 290 | 9.11k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 291 | 9.11k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 292 | 9.11k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 293 | 9.11k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 294 | 9.11k | ptr + 2, ptr + 3); | 295 | 9.11k | ptr += 4; | 296 | 9.11k | } | 297 | 5.24k | } | 298 | 10.0k | return 1; | 299 | 10.0k | } |
rdppm-16.c:get_text_rgb_cmyk_row Line | Count | Source | 271 | 5.20k | { | 272 | 5.20k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 273 | 5.20k | FILE *infile = source->pub.input_file; | 274 | 5.20k | register _JSAMPROW ptr; | 275 | 5.20k | register _JSAMPLE *rescale = source->rescale; | 276 | 5.20k | JDIMENSION col; | 277 | 5.20k | unsigned int maxval = source->maxval; | 278 | | | 279 | 5.20k | ptr = source->pub._buffer[0]; | 280 | 5.20k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 281 | 4.55k | for (col = cinfo->image_width; col > 0; col--) { | 282 | 2.94k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 283 | 2.94k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 284 | 2.94k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 285 | 2.94k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 286 | 2.94k | ptr += 4; | 287 | 2.94k | } | 288 | 3.59k | } else { | 289 | 9.41k | for (col = cinfo->image_width; col > 0; col--) { | 290 | 5.81k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 291 | 5.81k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 292 | 5.81k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 293 | 5.81k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 294 | 5.81k | ptr + 2, ptr + 3); | 295 | 5.81k | ptr += 4; | 296 | 5.81k | } | 297 | 3.59k | } | 298 | 5.20k | return 1; | 299 | 5.20k | } |
|
300 | | |
301 | | |
302 | | METHODDEF(JDIMENSION) |
303 | | get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
304 | | /* This version is for reading raw-byte-format PGM files with any maxval */ |
305 | 34.7M | { |
306 | 34.7M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
307 | 34.7M | register _JSAMPROW ptr; |
308 | 34.7M | register unsigned char *bufferptr; |
309 | 34.7M | register _JSAMPLE *rescale = source->rescale; |
310 | 34.7M | JDIMENSION col; |
311 | | |
312 | 34.7M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
313 | 1.39k | ERREXIT(cinfo, JERR_INPUT_EOF); |
314 | 34.7M | ptr = source->pub._buffer[0]; |
315 | 34.7M | bufferptr = source->iobuffer; |
316 | 179M | for (col = cinfo->image_width; col > 0; col--) { |
317 | 144M | *ptr++ = rescale[*bufferptr++]; |
318 | 144M | } |
319 | 34.7M | return 1; |
320 | 34.7M | } rdppm-8.c:get_scaled_gray_row Line | Count | Source | 305 | 17.1M | { | 306 | 17.1M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 307 | 17.1M | register _JSAMPROW ptr; | 308 | 17.1M | register unsigned char *bufferptr; | 309 | 17.1M | register _JSAMPLE *rescale = source->rescale; | 310 | 17.1M | JDIMENSION col; | 311 | | | 312 | 17.1M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 313 | 965 | ERREXIT(cinfo, JERR_INPUT_EOF); | 314 | 17.1M | ptr = source->pub._buffer[0]; | 315 | 17.1M | bufferptr = source->iobuffer; | 316 | 80.7M | for (col = cinfo->image_width; col > 0; col--) { | 317 | 63.5M | *ptr++ = rescale[*bufferptr++]; | 318 | 63.5M | } | 319 | 17.1M | return 1; | 320 | 17.1M | } |
rdppm-12.c:get_scaled_gray_row Line | Count | Source | 305 | 12.6M | { | 306 | 12.6M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 307 | 12.6M | register _JSAMPROW ptr; | 308 | 12.6M | register unsigned char *bufferptr; | 309 | 12.6M | register _JSAMPLE *rescale = source->rescale; | 310 | 12.6M | JDIMENSION col; | 311 | | | 312 | 12.6M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 313 | 295 | ERREXIT(cinfo, JERR_INPUT_EOF); | 314 | 12.6M | ptr = source->pub._buffer[0]; | 315 | 12.6M | bufferptr = source->iobuffer; | 316 | 70.6M | for (col = cinfo->image_width; col > 0; col--) { | 317 | 57.9M | *ptr++ = rescale[*bufferptr++]; | 318 | 57.9M | } | 319 | 12.6M | return 1; | 320 | 12.6M | } |
rdppm-16.c:get_scaled_gray_row Line | Count | Source | 305 | 4.91M | { | 306 | 4.91M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 307 | 4.91M | register _JSAMPROW ptr; | 308 | 4.91M | register unsigned char *bufferptr; | 309 | 4.91M | register _JSAMPLE *rescale = source->rescale; | 310 | 4.91M | JDIMENSION col; | 311 | | | 312 | 4.91M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 313 | 139 | ERREXIT(cinfo, JERR_INPUT_EOF); | 314 | 4.91M | ptr = source->pub._buffer[0]; | 315 | 4.91M | bufferptr = source->iobuffer; | 316 | 27.9M | for (col = cinfo->image_width; col > 0; col--) { | 317 | 23.0M | *ptr++ = rescale[*bufferptr++]; | 318 | 23.0M | } | 319 | 4.91M | return 1; | 320 | 4.91M | } |
|
321 | | |
322 | | |
323 | | METHODDEF(JDIMENSION) |
324 | | get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
325 | | /* This version is for reading raw-byte-format PGM files with any maxval |
326 | | and converting to extended RGB */ |
327 | 182M | { |
328 | 182M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
329 | 182M | register _JSAMPROW ptr; |
330 | 182M | register unsigned char *bufferptr; |
331 | 182M | register _JSAMPLE *rescale = source->rescale; |
332 | 182M | JDIMENSION col; |
333 | 182M | unsigned int maxval = source->maxval; |
334 | 182M | register int rindex = rgb_red[cinfo->in_color_space]; |
335 | 182M | register int gindex = rgb_green[cinfo->in_color_space]; |
336 | 182M | register int bindex = rgb_blue[cinfo->in_color_space]; |
337 | 182M | register int aindex = alpha_index[cinfo->in_color_space]; |
338 | 182M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
339 | | |
340 | 182M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
341 | 5.71k | ERREXIT(cinfo, JERR_INPUT_EOF); |
342 | 182M | ptr = source->pub._buffer[0]; |
343 | 182M | bufferptr = source->iobuffer; |
344 | 182M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
345 | 8.03M | if (aindex >= 0) |
346 | 651k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) |
347 | 7.38M | else |
348 | 7.38M | GRAY_RGB_READ_LOOP(*bufferptr++, {}) |
349 | 174M | } else { |
350 | 174M | if (aindex >= 0) |
351 | 25.6M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
352 | 174M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
353 | 148M | else |
354 | 148M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) |
355 | 174M | } |
356 | 182M | return 1; |
357 | 182M | } rdppm-8.c:get_gray_rgb_row Line | Count | Source | 327 | 94.0M | { | 328 | 94.0M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 329 | 94.0M | register _JSAMPROW ptr; | 330 | 94.0M | register unsigned char *bufferptr; | 331 | 94.0M | register _JSAMPLE *rescale = source->rescale; | 332 | 94.0M | JDIMENSION col; | 333 | 94.0M | unsigned int maxval = source->maxval; | 334 | 94.0M | register int rindex = rgb_red[cinfo->in_color_space]; | 335 | 94.0M | register int gindex = rgb_green[cinfo->in_color_space]; | 336 | 94.0M | register int bindex = rgb_blue[cinfo->in_color_space]; | 337 | 94.0M | register int aindex = alpha_index[cinfo->in_color_space]; | 338 | 94.0M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 339 | | | 340 | 94.0M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 341 | 3.54k | ERREXIT(cinfo, JERR_INPUT_EOF); | 342 | 94.0M | ptr = source->pub._buffer[0]; | 343 | 94.0M | bufferptr = source->iobuffer; | 344 | 94.0M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 345 | 8.03M | if (aindex >= 0) | 346 | 651k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 347 | 7.38M | else | 348 | 7.38M | GRAY_RGB_READ_LOOP(*bufferptr++, {}) | 349 | 86.0M | } else { | 350 | 86.0M | if (aindex >= 0) | 351 | 8.04M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 352 | 86.0M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 353 | 77.9M | else | 354 | 77.9M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) | 355 | 86.0M | } | 356 | 94.0M | return 1; | 357 | 94.0M | } |
rdppm-12.c:get_gray_rgb_row Line | Count | Source | 327 | 63.4M | { | 328 | 63.4M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 329 | 63.4M | register _JSAMPROW ptr; | 330 | 63.4M | register unsigned char *bufferptr; | 331 | 63.4M | register _JSAMPLE *rescale = source->rescale; | 332 | 63.4M | JDIMENSION col; | 333 | 63.4M | unsigned int maxval = source->maxval; | 334 | 63.4M | register int rindex = rgb_red[cinfo->in_color_space]; | 335 | 63.4M | register int gindex = rgb_green[cinfo->in_color_space]; | 336 | 63.4M | register int bindex = rgb_blue[cinfo->in_color_space]; | 337 | 63.4M | register int aindex = alpha_index[cinfo->in_color_space]; | 338 | 63.4M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 339 | | | 340 | 63.4M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 341 | 1.47k | ERREXIT(cinfo, JERR_INPUT_EOF); | 342 | 63.4M | ptr = source->pub._buffer[0]; | 343 | 63.4M | bufferptr = source->iobuffer; | 344 | 63.4M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 345 | 0 | if (aindex >= 0) | 346 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 347 | 0 | else | 348 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, {}) | 349 | 63.4M | } else { | 350 | 63.4M | if (aindex >= 0) | 351 | 12.6M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 352 | 63.4M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 353 | 50.7M | else | 354 | 50.7M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) | 355 | 63.4M | } | 356 | 63.4M | return 1; | 357 | 63.4M | } |
rdppm-16.c:get_gray_rgb_row Line | Count | Source | 327 | 24.5M | { | 328 | 24.5M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 329 | 24.5M | register _JSAMPROW ptr; | 330 | 24.5M | register unsigned char *bufferptr; | 331 | 24.5M | register _JSAMPLE *rescale = source->rescale; | 332 | 24.5M | JDIMENSION col; | 333 | 24.5M | unsigned int maxval = source->maxval; | 334 | 24.5M | register int rindex = rgb_red[cinfo->in_color_space]; | 335 | 24.5M | register int gindex = rgb_green[cinfo->in_color_space]; | 336 | 24.5M | register int bindex = rgb_blue[cinfo->in_color_space]; | 337 | 24.5M | register int aindex = alpha_index[cinfo->in_color_space]; | 338 | 24.5M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 339 | | | 340 | 24.5M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 341 | 695 | ERREXIT(cinfo, JERR_INPUT_EOF); | 342 | 24.5M | ptr = source->pub._buffer[0]; | 343 | 24.5M | bufferptr = source->iobuffer; | 344 | 24.5M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 345 | 0 | if (aindex >= 0) | 346 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 347 | 0 | else | 348 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, {}) | 349 | 24.5M | } else { | 350 | 24.5M | if (aindex >= 0) | 351 | 4.91M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 352 | 24.5M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 353 | 19.6M | else | 354 | 19.6M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) | 355 | 24.5M | } | 356 | 24.5M | return 1; | 357 | 24.5M | } |
|
358 | | |
359 | | |
360 | | METHODDEF(JDIMENSION) |
361 | | get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
362 | | /* This version is for reading raw-byte-format PGM files with any maxval |
363 | | and converting to CMYK */ |
364 | 26.3M | { |
365 | 26.3M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
366 | 26.3M | register _JSAMPROW ptr; |
367 | 26.3M | register unsigned char *bufferptr; |
368 | 26.3M | register _JSAMPLE *rescale = source->rescale; |
369 | 26.3M | JDIMENSION col; |
370 | 26.3M | unsigned int maxval = source->maxval; |
371 | | |
372 | 26.3M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
373 | 947 | ERREXIT(cinfo, JERR_INPUT_EOF); |
374 | 26.3M | ptr = source->pub._buffer[0]; |
375 | 26.3M | bufferptr = source->iobuffer; |
376 | 26.3M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
377 | 4.44M | for (col = cinfo->image_width; col > 0; col--) { |
378 | 3.42M | _JSAMPLE gray = *bufferptr++; |
379 | 3.42M | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); |
380 | 3.42M | ptr += 4; |
381 | 3.42M | } |
382 | 25.2M | } else { |
383 | 149M | for (col = cinfo->image_width; col > 0; col--) { |
384 | 124M | _JSAMPLE gray = rescale[*bufferptr++]; |
385 | 124M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
386 | 124M | ptr + 1, ptr + 2, ptr + 3); |
387 | 124M | ptr += 4; |
388 | 124M | } |
389 | 25.2M | } |
390 | 26.3M | return 1; |
391 | 26.3M | } rdppm-8.c:get_gray_cmyk_row Line | Count | Source | 364 | 8.69M | { | 365 | 8.69M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 366 | 8.69M | register _JSAMPROW ptr; | 367 | 8.69M | register unsigned char *bufferptr; | 368 | 8.69M | register _JSAMPLE *rescale = source->rescale; | 369 | 8.69M | JDIMENSION col; | 370 | 8.69M | unsigned int maxval = source->maxval; | 371 | | | 372 | 8.69M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 373 | 513 | ERREXIT(cinfo, JERR_INPUT_EOF); | 374 | 8.69M | ptr = source->pub._buffer[0]; | 375 | 8.69M | bufferptr = source->iobuffer; | 376 | 8.69M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 377 | 4.44M | for (col = cinfo->image_width; col > 0; col--) { | 378 | 3.42M | _JSAMPLE gray = *bufferptr++; | 379 | 3.42M | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 380 | 3.42M | ptr += 4; | 381 | 3.42M | } | 382 | 7.67M | } else { | 383 | 50.9M | for (col = cinfo->image_width; col > 0; col--) { | 384 | 43.2M | _JSAMPLE gray = rescale[*bufferptr++]; | 385 | 43.2M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 386 | 43.2M | ptr + 1, ptr + 2, ptr + 3); | 387 | 43.2M | ptr += 4; | 388 | 43.2M | } | 389 | 7.67M | } | 390 | 8.69M | return 1; | 391 | 8.69M | } |
rdppm-12.c:get_gray_cmyk_row Line | Count | Source | 364 | 12.6M | { | 365 | 12.6M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 366 | 12.6M | register _JSAMPROW ptr; | 367 | 12.6M | register unsigned char *bufferptr; | 368 | 12.6M | register _JSAMPLE *rescale = source->rescale; | 369 | 12.6M | JDIMENSION col; | 370 | 12.6M | unsigned int maxval = source->maxval; | 371 | | | 372 | 12.6M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 373 | 295 | ERREXIT(cinfo, JERR_INPUT_EOF); | 374 | 12.6M | ptr = source->pub._buffer[0]; | 375 | 12.6M | bufferptr = source->iobuffer; | 376 | 12.6M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 377 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 378 | 0 | _JSAMPLE gray = *bufferptr++; | 379 | 0 | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 380 | 0 | ptr += 4; | 381 | 0 | } | 382 | 12.6M | } else { | 383 | 70.6M | for (col = cinfo->image_width; col > 0; col--) { | 384 | 57.9M | _JSAMPLE gray = rescale[*bufferptr++]; | 385 | 57.9M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 386 | 57.9M | ptr + 1, ptr + 2, ptr + 3); | 387 | 57.9M | ptr += 4; | 388 | 57.9M | } | 389 | 12.6M | } | 390 | 12.6M | return 1; | 391 | 12.6M | } |
rdppm-16.c:get_gray_cmyk_row Line | Count | Source | 364 | 4.91M | { | 365 | 4.91M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 366 | 4.91M | register _JSAMPROW ptr; | 367 | 4.91M | register unsigned char *bufferptr; | 368 | 4.91M | register _JSAMPLE *rescale = source->rescale; | 369 | 4.91M | JDIMENSION col; | 370 | 4.91M | unsigned int maxval = source->maxval; | 371 | | | 372 | 4.91M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 373 | 139 | ERREXIT(cinfo, JERR_INPUT_EOF); | 374 | 4.91M | ptr = source->pub._buffer[0]; | 375 | 4.91M | bufferptr = source->iobuffer; | 376 | 4.91M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 377 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 378 | 0 | _JSAMPLE gray = *bufferptr++; | 379 | 0 | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 380 | 0 | ptr += 4; | 381 | 0 | } | 382 | 4.91M | } else { | 383 | 27.9M | for (col = cinfo->image_width; col > 0; col--) { | 384 | 23.0M | _JSAMPLE gray = rescale[*bufferptr++]; | 385 | 23.0M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 386 | 23.0M | ptr + 1, ptr + 2, ptr + 3); | 387 | 23.0M | ptr += 4; | 388 | 23.0M | } | 389 | 4.91M | } | 390 | 4.91M | return 1; | 391 | 4.91M | } |
|
392 | | |
393 | | |
394 | | METHODDEF(JDIMENSION) |
395 | | get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
396 | | /* This version is for reading raw-byte-format PPM files with any maxval */ |
397 | 9.78M | { |
398 | 9.78M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
399 | 9.78M | register _JSAMPROW ptr; |
400 | 9.78M | register unsigned char *bufferptr; |
401 | 9.78M | register _JSAMPLE *rescale = source->rescale; |
402 | 9.78M | JDIMENSION col; |
403 | 9.78M | unsigned int maxval = source->maxval; |
404 | 9.78M | register int rindex = rgb_red[cinfo->in_color_space]; |
405 | 9.78M | register int gindex = rgb_green[cinfo->in_color_space]; |
406 | 9.78M | register int bindex = rgb_blue[cinfo->in_color_space]; |
407 | 9.78M | register int aindex = alpha_index[cinfo->in_color_space]; |
408 | 9.78M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
409 | | |
410 | 9.78M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
411 | 7.41k | ERREXIT(cinfo, JERR_INPUT_EOF); |
412 | 9.78M | ptr = source->pub._buffer[0]; |
413 | 9.78M | bufferptr = source->iobuffer; |
414 | 9.78M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
415 | 193k | if (aindex >= 0) |
416 | 47.5k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) |
417 | 146k | else |
418 | 146k | RGB_READ_LOOP(*bufferptr++, {}) |
419 | 9.58M | } else { |
420 | 9.58M | if (aindex >= 0) |
421 | 1.88M | RGB_READ_LOOP(rescale[*bufferptr++], |
422 | 9.58M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
423 | 7.70M | else |
424 | 7.70M | RGB_READ_LOOP(rescale[*bufferptr++], {}) |
425 | 9.58M | } |
426 | 9.78M | return 1; |
427 | 9.78M | } Line | Count | Source | 397 | 1.50M | { | 398 | 1.50M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 399 | 1.50M | register _JSAMPROW ptr; | 400 | 1.50M | register unsigned char *bufferptr; | 401 | 1.50M | register _JSAMPLE *rescale = source->rescale; | 402 | 1.50M | JDIMENSION col; | 403 | 1.50M | unsigned int maxval = source->maxval; | 404 | 1.50M | register int rindex = rgb_red[cinfo->in_color_space]; | 405 | 1.50M | register int gindex = rgb_green[cinfo->in_color_space]; | 406 | 1.50M | register int bindex = rgb_blue[cinfo->in_color_space]; | 407 | 1.50M | register int aindex = alpha_index[cinfo->in_color_space]; | 408 | 1.50M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 409 | | | 410 | 1.50M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 411 | 4.33k | ERREXIT(cinfo, JERR_INPUT_EOF); | 412 | 1.50M | ptr = source->pub._buffer[0]; | 413 | 1.50M | bufferptr = source->iobuffer; | 414 | 1.50M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 415 | 193k | if (aindex >= 0) | 416 | 47.5k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 417 | 146k | else | 418 | 146k | RGB_READ_LOOP(*bufferptr++, {}) | 419 | 1.31M | } else { | 420 | 1.31M | if (aindex >= 0) | 421 | 233k | RGB_READ_LOOP(rescale[*bufferptr++], | 422 | 1.31M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 423 | 1.07M | else | 424 | 1.07M | RGB_READ_LOOP(rescale[*bufferptr++], {}) | 425 | 1.31M | } | 426 | 1.50M | return 1; | 427 | 1.50M | } |
Line | Count | Source | 397 | 8.12M | { | 398 | 8.12M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 399 | 8.12M | register _JSAMPROW ptr; | 400 | 8.12M | register unsigned char *bufferptr; | 401 | 8.12M | register _JSAMPLE *rescale = source->rescale; | 402 | 8.12M | JDIMENSION col; | 403 | 8.12M | unsigned int maxval = source->maxval; | 404 | 8.12M | register int rindex = rgb_red[cinfo->in_color_space]; | 405 | 8.12M | register int gindex = rgb_green[cinfo->in_color_space]; | 406 | 8.12M | register int bindex = rgb_blue[cinfo->in_color_space]; | 407 | 8.12M | register int aindex = alpha_index[cinfo->in_color_space]; | 408 | 8.12M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 409 | | | 410 | 8.12M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 411 | 2.00k | ERREXIT(cinfo, JERR_INPUT_EOF); | 412 | 8.12M | ptr = source->pub._buffer[0]; | 413 | 8.12M | bufferptr = source->iobuffer; | 414 | 8.12M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 415 | 0 | if (aindex >= 0) | 416 | 0 | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 417 | 0 | else | 418 | 0 | RGB_READ_LOOP(*bufferptr++, {}) | 419 | 8.12M | } else { | 420 | 8.12M | if (aindex >= 0) | 421 | 1.62M | RGB_READ_LOOP(rescale[*bufferptr++], | 422 | 8.12M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 423 | 6.50M | else | 424 | 6.50M | RGB_READ_LOOP(rescale[*bufferptr++], {}) | 425 | 8.12M | } | 426 | 8.12M | return 1; | 427 | 8.12M | } |
Line | Count | Source | 397 | 148k | { | 398 | 148k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 399 | 148k | register _JSAMPROW ptr; | 400 | 148k | register unsigned char *bufferptr; | 401 | 148k | register _JSAMPLE *rescale = source->rescale; | 402 | 148k | JDIMENSION col; | 403 | 148k | unsigned int maxval = source->maxval; | 404 | 148k | register int rindex = rgb_red[cinfo->in_color_space]; | 405 | 148k | register int gindex = rgb_green[cinfo->in_color_space]; | 406 | 148k | register int bindex = rgb_blue[cinfo->in_color_space]; | 407 | 148k | register int aindex = alpha_index[cinfo->in_color_space]; | 408 | 148k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 409 | | | 410 | 148k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 411 | 1.07k | ERREXIT(cinfo, JERR_INPUT_EOF); | 412 | 148k | ptr = source->pub._buffer[0]; | 413 | 148k | bufferptr = source->iobuffer; | 414 | 148k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 415 | 0 | if (aindex >= 0) | 416 | 0 | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 417 | 0 | else | 418 | 0 | RGB_READ_LOOP(*bufferptr++, {}) | 419 | 148k | } else { | 420 | 148k | if (aindex >= 0) | 421 | 29.4k | RGB_READ_LOOP(rescale[*bufferptr++], | 422 | 148k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 423 | 118k | else | 424 | 118k | RGB_READ_LOOP(rescale[*bufferptr++], {}) | 425 | 148k | } | 426 | 148k | return 1; | 427 | 148k | } |
|
428 | | |
429 | | |
430 | | METHODDEF(JDIMENSION) |
431 | | get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
432 | | /* This version is for reading raw-byte-format PPM files with any maxval and |
433 | | converting to CMYK */ |
434 | 1.93M | { |
435 | 1.93M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
436 | 1.93M | register _JSAMPROW ptr; |
437 | 1.93M | register unsigned char *bufferptr; |
438 | 1.93M | register _JSAMPLE *rescale = source->rescale; |
439 | 1.93M | JDIMENSION col; |
440 | 1.93M | unsigned int maxval = source->maxval; |
441 | | |
442 | 1.93M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
443 | 1.26k | ERREXIT(cinfo, JERR_INPUT_EOF); |
444 | 1.93M | ptr = source->pub._buffer[0]; |
445 | 1.93M | bufferptr = source->iobuffer; |
446 | 1.93M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
447 | 416k | for (col = cinfo->image_width; col > 0; col--) { |
448 | 310k | _JSAMPLE r = *bufferptr++; |
449 | 310k | _JSAMPLE g = *bufferptr++; |
450 | 310k | _JSAMPLE b = *bufferptr++; |
451 | 310k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
452 | 310k | ptr += 4; |
453 | 310k | } |
454 | 1.83M | } else { |
455 | 16.3M | for (col = cinfo->image_width; col > 0; col--) { |
456 | 14.5M | _JSAMPLE r = rescale[*bufferptr++]; |
457 | 14.5M | _JSAMPLE g = rescale[*bufferptr++]; |
458 | 14.5M | _JSAMPLE b = rescale[*bufferptr++]; |
459 | 14.5M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
460 | 14.5M | ptr + 2, ptr + 3); |
461 | 14.5M | ptr += 4; |
462 | 14.5M | } |
463 | 1.83M | } |
464 | 1.93M | return 1; |
465 | 1.93M | } rdppm-8.c:get_rgb_cmyk_row Line | Count | Source | 434 | 281k | { | 435 | 281k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 436 | 281k | register _JSAMPROW ptr; | 437 | 281k | register unsigned char *bufferptr; | 438 | 281k | register _JSAMPLE *rescale = source->rescale; | 439 | 281k | JDIMENSION col; | 440 | 281k | unsigned int maxval = source->maxval; | 441 | | | 442 | 281k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 443 | 651 | ERREXIT(cinfo, JERR_INPUT_EOF); | 444 | 281k | ptr = source->pub._buffer[0]; | 445 | 281k | bufferptr = source->iobuffer; | 446 | 281k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 447 | 416k | for (col = cinfo->image_width; col > 0; col--) { | 448 | 310k | _JSAMPLE r = *bufferptr++; | 449 | 310k | _JSAMPLE g = *bufferptr++; | 450 | 310k | _JSAMPLE b = *bufferptr++; | 451 | 310k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 452 | 310k | ptr += 4; | 453 | 310k | } | 454 | 174k | } else { | 455 | 1.38M | for (col = cinfo->image_width; col > 0; col--) { | 456 | 1.21M | _JSAMPLE r = rescale[*bufferptr++]; | 457 | 1.21M | _JSAMPLE g = rescale[*bufferptr++]; | 458 | 1.21M | _JSAMPLE b = rescale[*bufferptr++]; | 459 | 1.21M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 460 | 1.21M | ptr + 2, ptr + 3); | 461 | 1.21M | ptr += 4; | 462 | 1.21M | } | 463 | 174k | } | 464 | 281k | return 1; | 465 | 281k | } |
rdppm-12.c:get_rgb_cmyk_row Line | Count | Source | 434 | 1.62M | { | 435 | 1.62M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 436 | 1.62M | register _JSAMPROW ptr; | 437 | 1.62M | register unsigned char *bufferptr; | 438 | 1.62M | register _JSAMPLE *rescale = source->rescale; | 439 | 1.62M | JDIMENSION col; | 440 | 1.62M | unsigned int maxval = source->maxval; | 441 | | | 442 | 1.62M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 443 | 400 | ERREXIT(cinfo, JERR_INPUT_EOF); | 444 | 1.62M | ptr = source->pub._buffer[0]; | 445 | 1.62M | bufferptr = source->iobuffer; | 446 | 1.62M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 447 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 448 | 0 | _JSAMPLE r = *bufferptr++; | 449 | 0 | _JSAMPLE g = *bufferptr++; | 450 | 0 | _JSAMPLE b = *bufferptr++; | 451 | 0 | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 452 | 0 | ptr += 4; | 453 | 0 | } | 454 | 1.62M | } else { | 455 | 12.3M | for (col = cinfo->image_width; col > 0; col--) { | 456 | 10.7M | _JSAMPLE r = rescale[*bufferptr++]; | 457 | 10.7M | _JSAMPLE g = rescale[*bufferptr++]; | 458 | 10.7M | _JSAMPLE b = rescale[*bufferptr++]; | 459 | 10.7M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 460 | 10.7M | ptr + 2, ptr + 3); | 461 | 10.7M | ptr += 4; | 462 | 10.7M | } | 463 | 1.62M | } | 464 | 1.62M | return 1; | 465 | 1.62M | } |
rdppm-16.c:get_rgb_cmyk_row Line | Count | Source | 434 | 29.6k | { | 435 | 29.6k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 436 | 29.6k | register _JSAMPROW ptr; | 437 | 29.6k | register unsigned char *bufferptr; | 438 | 29.6k | register _JSAMPLE *rescale = source->rescale; | 439 | 29.6k | JDIMENSION col; | 440 | 29.6k | unsigned int maxval = source->maxval; | 441 | | | 442 | 29.6k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 443 | 215 | ERREXIT(cinfo, JERR_INPUT_EOF); | 444 | 29.6k | ptr = source->pub._buffer[0]; | 445 | 29.6k | bufferptr = source->iobuffer; | 446 | 29.6k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 447 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 448 | 0 | _JSAMPLE r = *bufferptr++; | 449 | 0 | _JSAMPLE g = *bufferptr++; | 450 | 0 | _JSAMPLE b = *bufferptr++; | 451 | 0 | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 452 | 0 | ptr += 4; | 453 | 0 | } | 454 | 29.6k | } else { | 455 | 2.58M | for (col = cinfo->image_width; col > 0; col--) { | 456 | 2.56M | _JSAMPLE r = rescale[*bufferptr++]; | 457 | 2.56M | _JSAMPLE g = rescale[*bufferptr++]; | 458 | 2.56M | _JSAMPLE b = rescale[*bufferptr++]; | 459 | 2.56M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 460 | 2.56M | ptr + 2, ptr + 3); | 461 | 2.56M | ptr += 4; | 462 | 2.56M | } | 463 | 29.6k | } | 464 | 29.6k | return 1; | 465 | 29.6k | } |
|
466 | | |
467 | | |
468 | | #if BITS_IN_JSAMPLE == 8 |
469 | | |
470 | | METHODDEF(JDIMENSION) |
471 | | get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
472 | | /* This version is for reading raw-byte-format files with |
473 | | * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U. |
474 | | * In this case we just read right into the _JSAMPLE buffer! |
475 | | * Note that same code works for PPM and PGM files. |
476 | | */ |
477 | 1.70M | { |
478 | 1.70M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
479 | | |
480 | 1.70M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
481 | 411 | ERREXIT(cinfo, JERR_INPUT_EOF); |
482 | 1.70M | return 1; |
483 | 1.70M | } |
484 | | |
485 | | #endif |
486 | | |
487 | | |
488 | | METHODDEF(JDIMENSION) |
489 | | get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
490 | | /* This version is for reading raw-word-format PGM files with any maxval */ |
491 | 224k | { |
492 | 224k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
493 | 224k | register _JSAMPROW ptr; |
494 | 224k | register unsigned char *bufferptr; |
495 | 224k | register _JSAMPLE *rescale = source->rescale; |
496 | 224k | JDIMENSION col; |
497 | 224k | unsigned int maxval = source->maxval; |
498 | | |
499 | 224k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
500 | 1.04k | ERREXIT(cinfo, JERR_INPUT_EOF); |
501 | 224k | ptr = source->pub._buffer[0]; |
502 | 224k | bufferptr = source->iobuffer; |
503 | 539k | for (col = cinfo->image_width; col > 0; col--) { |
504 | 314k | register unsigned int temp; |
505 | 314k | temp = (*bufferptr++) << 8; |
506 | 314k | temp |= (*bufferptr++); |
507 | 314k | if (temp > maxval) |
508 | 678 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
509 | 314k | *ptr++ = rescale[temp]; |
510 | 314k | } |
511 | 224k | return 1; |
512 | 224k | } rdppm-8.c:get_word_gray_row Line | Count | Source | 491 | 14.8k | { | 492 | 14.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 493 | 14.8k | register _JSAMPROW ptr; | 494 | 14.8k | register unsigned char *bufferptr; | 495 | 14.8k | register _JSAMPLE *rescale = source->rescale; | 496 | 14.8k | JDIMENSION col; | 497 | 14.8k | unsigned int maxval = source->maxval; | 498 | | | 499 | 14.8k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 500 | 519 | ERREXIT(cinfo, JERR_INPUT_EOF); | 501 | 14.8k | ptr = source->pub._buffer[0]; | 502 | 14.8k | bufferptr = source->iobuffer; | 503 | 53.7k | for (col = cinfo->image_width; col > 0; col--) { | 504 | 38.8k | register unsigned int temp; | 505 | 38.8k | temp = (*bufferptr++) << 8; | 506 | 38.8k | temp |= (*bufferptr++); | 507 | 38.8k | if (temp > maxval) | 508 | 335 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 509 | 38.8k | *ptr++ = rescale[temp]; | 510 | 38.8k | } | 511 | 14.8k | return 1; | 512 | 14.8k | } |
rdppm-12.c:get_word_gray_row Line | Count | Source | 491 | 186k | { | 492 | 186k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 493 | 186k | register _JSAMPROW ptr; | 494 | 186k | register unsigned char *bufferptr; | 495 | 186k | register _JSAMPLE *rescale = source->rescale; | 496 | 186k | JDIMENSION col; | 497 | 186k | unsigned int maxval = source->maxval; | 498 | | | 499 | 186k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 500 | 324 | ERREXIT(cinfo, JERR_INPUT_EOF); | 501 | 186k | ptr = source->pub._buffer[0]; | 502 | 186k | bufferptr = source->iobuffer; | 503 | 378k | for (col = cinfo->image_width; col > 0; col--) { | 504 | 191k | register unsigned int temp; | 505 | 191k | temp = (*bufferptr++) << 8; | 506 | 191k | temp |= (*bufferptr++); | 507 | 191k | if (temp > maxval) | 508 | 267 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 509 | 191k | *ptr++ = rescale[temp]; | 510 | 191k | } | 511 | 186k | return 1; | 512 | 186k | } |
rdppm-16.c:get_word_gray_row Line | Count | Source | 491 | 23.7k | { | 492 | 23.7k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 493 | 23.7k | register _JSAMPROW ptr; | 494 | 23.7k | register unsigned char *bufferptr; | 495 | 23.7k | register _JSAMPLE *rescale = source->rescale; | 496 | 23.7k | JDIMENSION col; | 497 | 23.7k | unsigned int maxval = source->maxval; | 498 | | | 499 | 23.7k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 500 | 202 | ERREXIT(cinfo, JERR_INPUT_EOF); | 501 | 23.7k | ptr = source->pub._buffer[0]; | 502 | 23.7k | bufferptr = source->iobuffer; | 503 | 107k | for (col = cinfo->image_width; col > 0; col--) { | 504 | 84.0k | register unsigned int temp; | 505 | 84.0k | temp = (*bufferptr++) << 8; | 506 | 84.0k | temp |= (*bufferptr++); | 507 | 84.0k | if (temp > maxval) | 508 | 76 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 509 | 84.0k | *ptr++ = rescale[temp]; | 510 | 84.0k | } | 511 | 23.7k | return 1; | 512 | 23.7k | } |
|
513 | | |
514 | | |
515 | | METHODDEF(JDIMENSION) |
516 | | get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
517 | | /* This version is for reading raw-word-format PGM files with any maxval */ |
518 | 1.11M | { |
519 | 1.11M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
520 | 1.11M | register _JSAMPROW ptr; |
521 | 1.11M | register unsigned char *bufferptr; |
522 | 1.11M | register _JSAMPLE *rescale = source->rescale; |
523 | 1.11M | JDIMENSION col; |
524 | 1.11M | unsigned int maxval = source->maxval; |
525 | 1.11M | register int rindex = rgb_red[cinfo->in_color_space]; |
526 | 1.11M | register int gindex = rgb_green[cinfo->in_color_space]; |
527 | 1.11M | register int bindex = rgb_blue[cinfo->in_color_space]; |
528 | 1.11M | register int aindex = alpha_index[cinfo->in_color_space]; |
529 | 1.11M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
530 | | |
531 | 1.11M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
532 | 4.47k | ERREXIT(cinfo, JERR_INPUT_EOF); |
533 | 1.11M | ptr = source->pub._buffer[0]; |
534 | 1.11M | bufferptr = source->iobuffer; |
535 | 2.68M | for (col = cinfo->image_width; col > 0; col--) { |
536 | 1.56M | register unsigned int temp; |
537 | 1.56M | temp = (*bufferptr++) << 8; |
538 | 1.56M | temp |= (*bufferptr++); |
539 | 1.56M | if (temp > maxval) |
540 | 2.84k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
541 | 1.56M | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; |
542 | 1.56M | if (aindex >= 0) |
543 | 289k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
544 | 1.56M | ptr += ps; |
545 | 1.56M | } |
546 | 1.11M | return 1; |
547 | 1.11M | } rdppm-8.c:get_word_gray_rgb_row Line | Count | Source | 518 | 69.1k | { | 519 | 69.1k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 520 | 69.1k | register _JSAMPROW ptr; | 521 | 69.1k | register unsigned char *bufferptr; | 522 | 69.1k | register _JSAMPLE *rescale = source->rescale; | 523 | 69.1k | JDIMENSION col; | 524 | 69.1k | unsigned int maxval = source->maxval; | 525 | 69.1k | register int rindex = rgb_red[cinfo->in_color_space]; | 526 | 69.1k | register int gindex = rgb_green[cinfo->in_color_space]; | 527 | 69.1k | register int bindex = rgb_blue[cinfo->in_color_space]; | 528 | 69.1k | register int aindex = alpha_index[cinfo->in_color_space]; | 529 | 69.1k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 530 | | | 531 | 69.1k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 532 | 1.84k | ERREXIT(cinfo, JERR_INPUT_EOF); | 533 | 69.1k | ptr = source->pub._buffer[0]; | 534 | 69.1k | bufferptr = source->iobuffer; | 535 | 256k | for (col = cinfo->image_width; col > 0; col--) { | 536 | 187k | register unsigned int temp; | 537 | 187k | temp = (*bufferptr++) << 8; | 538 | 187k | temp |= (*bufferptr++); | 539 | 187k | if (temp > maxval) | 540 | 1.12k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 541 | 187k | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; | 542 | 187k | if (aindex >= 0) | 543 | 14.3k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 544 | 187k | ptr += ps; | 545 | 187k | } | 546 | 69.1k | return 1; | 547 | 69.1k | } |
rdppm-12.c:get_word_gray_rgb_row Line | Count | Source | 518 | 931k | { | 519 | 931k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 520 | 931k | register _JSAMPROW ptr; | 521 | 931k | register unsigned char *bufferptr; | 522 | 931k | register _JSAMPLE *rescale = source->rescale; | 523 | 931k | JDIMENSION col; | 524 | 931k | unsigned int maxval = source->maxval; | 525 | 931k | register int rindex = rgb_red[cinfo->in_color_space]; | 526 | 931k | register int gindex = rgb_green[cinfo->in_color_space]; | 527 | 931k | register int bindex = rgb_blue[cinfo->in_color_space]; | 528 | 931k | register int aindex = alpha_index[cinfo->in_color_space]; | 529 | 931k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 530 | | | 531 | 931k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 532 | 1.62k | ERREXIT(cinfo, JERR_INPUT_EOF); | 533 | 931k | ptr = source->pub._buffer[0]; | 534 | 931k | bufferptr = source->iobuffer; | 535 | 1.89M | for (col = cinfo->image_width; col > 0; col--) { | 536 | 958k | register unsigned int temp; | 537 | 958k | temp = (*bufferptr++) << 8; | 538 | 958k | temp |= (*bufferptr++); | 539 | 958k | if (temp > maxval) | 540 | 1.33k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 541 | 958k | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; | 542 | 958k | if (aindex >= 0) | 543 | 191k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 544 | 958k | ptr += ps; | 545 | 958k | } | 546 | 931k | return 1; | 547 | 931k | } |
rdppm-16.c:get_word_gray_rgb_row Line | Count | Source | 518 | 118k | { | 519 | 118k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 520 | 118k | register _JSAMPROW ptr; | 521 | 118k | register unsigned char *bufferptr; | 522 | 118k | register _JSAMPLE *rescale = source->rescale; | 523 | 118k | JDIMENSION col; | 524 | 118k | unsigned int maxval = source->maxval; | 525 | 118k | register int rindex = rgb_red[cinfo->in_color_space]; | 526 | 118k | register int gindex = rgb_green[cinfo->in_color_space]; | 527 | 118k | register int bindex = rgb_blue[cinfo->in_color_space]; | 528 | 118k | register int aindex = alpha_index[cinfo->in_color_space]; | 529 | 118k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 530 | | | 531 | 118k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 532 | 1.01k | ERREXIT(cinfo, JERR_INPUT_EOF); | 533 | 118k | ptr = source->pub._buffer[0]; | 534 | 118k | bufferptr = source->iobuffer; | 535 | 539k | for (col = cinfo->image_width; col > 0; col--) { | 536 | 420k | register unsigned int temp; | 537 | 420k | temp = (*bufferptr++) << 8; | 538 | 420k | temp |= (*bufferptr++); | 539 | 420k | if (temp > maxval) | 540 | 380 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 541 | 420k | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; | 542 | 420k | if (aindex >= 0) | 543 | 83.9k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 544 | 420k | ptr += ps; | 545 | 420k | } | 546 | 118k | return 1; | 547 | 118k | } |
|
548 | | |
549 | | |
550 | | METHODDEF(JDIMENSION) |
551 | | get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
552 | | /* This version is for reading raw-word-format PGM files with any maxval */ |
553 | 220k | { |
554 | 220k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
555 | 220k | register _JSAMPROW ptr; |
556 | 220k | register unsigned char *bufferptr; |
557 | 220k | register _JSAMPLE *rescale = source->rescale; |
558 | 220k | JDIMENSION col; |
559 | 220k | unsigned int maxval = source->maxval; |
560 | | |
561 | 220k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
562 | 787 | ERREXIT(cinfo, JERR_INPUT_EOF); |
563 | 220k | ptr = source->pub._buffer[0]; |
564 | 220k | bufferptr = source->iobuffer; |
565 | 220k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
566 | 97.2k | for (col = cinfo->image_width; col > 0; col--) { |
567 | 76.7k | register unsigned int gray; |
568 | 76.7k | gray = (*bufferptr++) << 8; |
569 | 76.7k | gray |= (*bufferptr++); |
570 | 76.7k | if (gray > maxval) |
571 | 76 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
572 | 76.7k | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, |
573 | 76.7k | ptr + 1, ptr + 2, ptr + 3); |
574 | 76.7k | ptr += 4; |
575 | 76.7k | } |
576 | 200k | } else { |
577 | 413k | for (col = cinfo->image_width; col > 0; col--) { |
578 | 213k | register unsigned int temp; |
579 | 213k | _JSAMPLE gray; |
580 | 213k | temp = (*bufferptr++) << 8; |
581 | 213k | temp |= (*bufferptr++); |
582 | 213k | if (temp > maxval) |
583 | 430 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
584 | 213k | gray = rescale[temp]; |
585 | 213k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
586 | 213k | ptr + 1, ptr + 2, ptr + 3); |
587 | 213k | ptr += 4; |
588 | 213k | } |
589 | 200k | } |
590 | 220k | return 1; |
591 | 220k | } rdppm-8.c:get_word_gray_cmyk_row Line | Count | Source | 553 | 10.4k | { | 554 | 10.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 555 | 10.4k | register _JSAMPROW ptr; | 556 | 10.4k | register unsigned char *bufferptr; | 557 | 10.4k | register _JSAMPLE *rescale = source->rescale; | 558 | 10.4k | JDIMENSION col; | 559 | 10.4k | unsigned int maxval = source->maxval; | 560 | | | 561 | 10.4k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 562 | 261 | ERREXIT(cinfo, JERR_INPUT_EOF); | 563 | 10.4k | ptr = source->pub._buffer[0]; | 564 | 10.4k | bufferptr = source->iobuffer; | 565 | 10.4k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 566 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 567 | 0 | register unsigned int gray; | 568 | 0 | gray = (*bufferptr++) << 8; | 569 | 0 | gray |= (*bufferptr++); | 570 | 0 | if (gray > maxval) | 571 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 572 | 0 | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, | 573 | 0 | ptr + 1, ptr + 2, ptr + 3); | 574 | 0 | ptr += 4; | 575 | 0 | } | 576 | 10.4k | } else { | 577 | 24.9k | for (col = cinfo->image_width; col > 0; col--) { | 578 | 14.4k | register unsigned int temp; | 579 | 14.4k | _JSAMPLE gray; | 580 | 14.4k | temp = (*bufferptr++) << 8; | 581 | 14.4k | temp |= (*bufferptr++); | 582 | 14.4k | if (temp > maxval) | 583 | 163 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 584 | 14.4k | gray = rescale[temp]; | 585 | 14.4k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 586 | 14.4k | ptr + 1, ptr + 2, ptr + 3); | 587 | 14.4k | ptr += 4; | 588 | 14.4k | } | 589 | 10.4k | } | 590 | 10.4k | return 1; | 591 | 10.4k | } |
rdppm-12.c:get_word_gray_cmyk_row Line | Count | Source | 553 | 186k | { | 554 | 186k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 555 | 186k | register _JSAMPROW ptr; | 556 | 186k | register unsigned char *bufferptr; | 557 | 186k | register _JSAMPLE *rescale = source->rescale; | 558 | 186k | JDIMENSION col; | 559 | 186k | unsigned int maxval = source->maxval; | 560 | | | 561 | 186k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 562 | 324 | ERREXIT(cinfo, JERR_INPUT_EOF); | 563 | 186k | ptr = source->pub._buffer[0]; | 564 | 186k | bufferptr = source->iobuffer; | 565 | 186k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 566 | 5.82k | for (col = cinfo->image_width; col > 0; col--) { | 567 | 3.93k | register unsigned int gray; | 568 | 3.93k | gray = (*bufferptr++) << 8; | 569 | 3.93k | gray |= (*bufferptr++); | 570 | 3.93k | if (gray > maxval) | 571 | 76 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 572 | 3.93k | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, | 573 | 3.93k | ptr + 1, ptr + 2, ptr + 3); | 574 | 3.93k | ptr += 4; | 575 | 3.93k | } | 576 | 184k | } else { | 577 | 372k | for (col = cinfo->image_width; col > 0; col--) { | 578 | 187k | register unsigned int temp; | 579 | 187k | _JSAMPLE gray; | 580 | 187k | temp = (*bufferptr++) << 8; | 581 | 187k | temp |= (*bufferptr++); | 582 | 187k | if (temp > maxval) | 583 | 191 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 584 | 187k | gray = rescale[temp]; | 585 | 187k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 586 | 187k | ptr + 1, ptr + 2, ptr + 3); | 587 | 187k | ptr += 4; | 588 | 187k | } | 589 | 184k | } | 590 | 186k | return 1; | 591 | 186k | } |
rdppm-16.c:get_word_gray_cmyk_row Line | Count | Source | 553 | 23.7k | { | 554 | 23.7k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 555 | 23.7k | register _JSAMPROW ptr; | 556 | 23.7k | register unsigned char *bufferptr; | 557 | 23.7k | register _JSAMPLE *rescale = source->rescale; | 558 | 23.7k | JDIMENSION col; | 559 | 23.7k | unsigned int maxval = source->maxval; | 560 | | | 561 | 23.7k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 562 | 202 | ERREXIT(cinfo, JERR_INPUT_EOF); | 563 | 23.7k | ptr = source->pub._buffer[0]; | 564 | 23.7k | bufferptr = source->iobuffer; | 565 | 23.7k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 566 | 91.3k | for (col = cinfo->image_width; col > 0; col--) { | 567 | 72.8k | register unsigned int gray; | 568 | 72.8k | gray = (*bufferptr++) << 8; | 569 | 72.8k | gray |= (*bufferptr++); | 570 | 72.8k | if (gray > maxval) | 571 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 572 | 72.8k | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, | 573 | 72.8k | ptr + 1, ptr + 2, ptr + 3); | 574 | 72.8k | ptr += 4; | 575 | 72.8k | } | 576 | 18.5k | } else { | 577 | 16.4k | for (col = cinfo->image_width; col > 0; col--) { | 578 | 11.1k | register unsigned int temp; | 579 | 11.1k | _JSAMPLE gray; | 580 | 11.1k | temp = (*bufferptr++) << 8; | 581 | 11.1k | temp |= (*bufferptr++); | 582 | 11.1k | if (temp > maxval) | 583 | 76 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 584 | 11.1k | gray = rescale[temp]; | 585 | 11.1k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 586 | 11.1k | ptr + 1, ptr + 2, ptr + 3); | 587 | 11.1k | ptr += 4; | 588 | 11.1k | } | 589 | 5.22k | } | 590 | 23.7k | return 1; | 591 | 23.7k | } |
|
592 | | |
593 | | |
594 | | METHODDEF(JDIMENSION) |
595 | | get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
596 | | /* This version is for reading raw-word-format PPM files with any maxval */ |
597 | 183k | { |
598 | 183k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
599 | 183k | register _JSAMPROW ptr; |
600 | 183k | register unsigned char *bufferptr; |
601 | 183k | register _JSAMPLE *rescale = source->rescale; |
602 | 183k | JDIMENSION col; |
603 | 183k | unsigned int maxval = source->maxval; |
604 | 183k | register int rindex = rgb_red[cinfo->in_color_space]; |
605 | 183k | register int gindex = rgb_green[cinfo->in_color_space]; |
606 | 183k | register int bindex = rgb_blue[cinfo->in_color_space]; |
607 | 183k | register int aindex = alpha_index[cinfo->in_color_space]; |
608 | 183k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
609 | | |
610 | 183k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
611 | 5.72k | ERREXIT(cinfo, JERR_INPUT_EOF); |
612 | 183k | ptr = source->pub._buffer[0]; |
613 | 183k | bufferptr = source->iobuffer; |
614 | 583k | for (col = cinfo->image_width; col > 0; col--) { |
615 | 399k | register unsigned int temp; |
616 | 399k | temp = (*bufferptr++) << 8; |
617 | 399k | temp |= (*bufferptr++); |
618 | 399k | if (temp > maxval) |
619 | 2.15k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
620 | 399k | ptr[rindex] = rescale[temp]; |
621 | 399k | temp = (*bufferptr++) << 8; |
622 | 399k | temp |= (*bufferptr++); |
623 | 399k | if (temp > maxval) |
624 | 1.88k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
625 | 399k | ptr[gindex] = rescale[temp]; |
626 | 399k | temp = (*bufferptr++) << 8; |
627 | 399k | temp |= (*bufferptr++); |
628 | 399k | if (temp > maxval) |
629 | 1.90k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
630 | 399k | ptr[bindex] = rescale[temp]; |
631 | 399k | if (aindex >= 0) |
632 | 74.7k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
633 | 399k | ptr += ps; |
634 | 399k | } |
635 | 183k | return 1; |
636 | 183k | } rdppm-8.c:get_word_rgb_row Line | Count | Source | 597 | 53.4k | { | 598 | 53.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 599 | 53.4k | register _JSAMPROW ptr; | 600 | 53.4k | register unsigned char *bufferptr; | 601 | 53.4k | register _JSAMPLE *rescale = source->rescale; | 602 | 53.4k | JDIMENSION col; | 603 | 53.4k | unsigned int maxval = source->maxval; | 604 | 53.4k | register int rindex = rgb_red[cinfo->in_color_space]; | 605 | 53.4k | register int gindex = rgb_green[cinfo->in_color_space]; | 606 | 53.4k | register int bindex = rgb_blue[cinfo->in_color_space]; | 607 | 53.4k | register int aindex = alpha_index[cinfo->in_color_space]; | 608 | 53.4k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 609 | | | 610 | 53.4k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 611 | 2.14k | ERREXIT(cinfo, JERR_INPUT_EOF); | 612 | 53.4k | ptr = source->pub._buffer[0]; | 613 | 53.4k | bufferptr = source->iobuffer; | 614 | 135k | for (col = cinfo->image_width; col > 0; col--) { | 615 | 81.9k | register unsigned int temp; | 616 | 81.9k | temp = (*bufferptr++) << 8; | 617 | 81.9k | temp |= (*bufferptr++); | 618 | 81.9k | if (temp > maxval) | 619 | 787 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 620 | 81.9k | ptr[rindex] = rescale[temp]; | 621 | 81.9k | temp = (*bufferptr++) << 8; | 622 | 81.9k | temp |= (*bufferptr++); | 623 | 81.9k | if (temp > maxval) | 624 | 779 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 625 | 81.9k | ptr[gindex] = rescale[temp]; | 626 | 81.9k | temp = (*bufferptr++) << 8; | 627 | 81.9k | temp |= (*bufferptr++); | 628 | 81.9k | if (temp > maxval) | 629 | 756 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 630 | 81.9k | ptr[bindex] = rescale[temp]; | 631 | 81.9k | if (aindex >= 0) | 632 | 12.0k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 633 | 81.9k | ptr += ps; | 634 | 81.9k | } | 635 | 53.4k | return 1; | 636 | 53.4k | } |
rdppm-12.c:get_word_rgb_row Line | Count | Source | 597 | 63.5k | { | 598 | 63.5k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 599 | 63.5k | register _JSAMPROW ptr; | 600 | 63.5k | register unsigned char *bufferptr; | 601 | 63.5k | register _JSAMPLE *rescale = source->rescale; | 602 | 63.5k | JDIMENSION col; | 603 | 63.5k | unsigned int maxval = source->maxval; | 604 | 63.5k | register int rindex = rgb_red[cinfo->in_color_space]; | 605 | 63.5k | register int gindex = rgb_green[cinfo->in_color_space]; | 606 | 63.5k | register int bindex = rgb_blue[cinfo->in_color_space]; | 607 | 63.5k | register int aindex = alpha_index[cinfo->in_color_space]; | 608 | 63.5k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 609 | | | 610 | 63.5k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 611 | 2.27k | ERREXIT(cinfo, JERR_INPUT_EOF); | 612 | 63.5k | ptr = source->pub._buffer[0]; | 613 | 63.5k | bufferptr = source->iobuffer; | 614 | 164k | for (col = cinfo->image_width; col > 0; col--) { | 615 | 101k | register unsigned int temp; | 616 | 101k | temp = (*bufferptr++) << 8; | 617 | 101k | temp |= (*bufferptr++); | 618 | 101k | if (temp > maxval) | 619 | 1.03k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 620 | 101k | ptr[rindex] = rescale[temp]; | 621 | 101k | temp = (*bufferptr++) << 8; | 622 | 101k | temp |= (*bufferptr++); | 623 | 101k | if (temp > maxval) | 624 | 865 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 625 | 101k | ptr[gindex] = rescale[temp]; | 626 | 101k | temp = (*bufferptr++) << 8; | 627 | 101k | temp |= (*bufferptr++); | 628 | 101k | if (temp > maxval) | 629 | 900 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 630 | 101k | ptr[bindex] = rescale[temp]; | 631 | 101k | if (aindex >= 0) | 632 | 19.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 633 | 101k | ptr += ps; | 634 | 101k | } | 635 | 63.5k | return 1; | 636 | 63.5k | } |
rdppm-16.c:get_word_rgb_row Line | Count | Source | 597 | 66.8k | { | 598 | 66.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 599 | 66.8k | register _JSAMPROW ptr; | 600 | 66.8k | register unsigned char *bufferptr; | 601 | 66.8k | register _JSAMPLE *rescale = source->rescale; | 602 | 66.8k | JDIMENSION col; | 603 | 66.8k | unsigned int maxval = source->maxval; | 604 | 66.8k | register int rindex = rgb_red[cinfo->in_color_space]; | 605 | 66.8k | register int gindex = rgb_green[cinfo->in_color_space]; | 606 | 66.8k | register int bindex = rgb_blue[cinfo->in_color_space]; | 607 | 66.8k | register int aindex = alpha_index[cinfo->in_color_space]; | 608 | 66.8k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 609 | | | 610 | 66.8k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 611 | 1.30k | ERREXIT(cinfo, JERR_INPUT_EOF); | 612 | 66.8k | ptr = source->pub._buffer[0]; | 613 | 66.8k | bufferptr = source->iobuffer; | 614 | 282k | for (col = cinfo->image_width; col > 0; col--) { | 615 | 216k | register unsigned int temp; | 616 | 216k | temp = (*bufferptr++) << 8; | 617 | 216k | temp |= (*bufferptr++); | 618 | 216k | if (temp > maxval) | 619 | 335 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 620 | 216k | ptr[rindex] = rescale[temp]; | 621 | 216k | temp = (*bufferptr++) << 8; | 622 | 216k | temp |= (*bufferptr++); | 623 | 216k | if (temp > maxval) | 624 | 240 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 625 | 216k | ptr[gindex] = rescale[temp]; | 626 | 216k | temp = (*bufferptr++) << 8; | 627 | 216k | temp |= (*bufferptr++); | 628 | 216k | if (temp > maxval) | 629 | 250 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 630 | 216k | ptr[bindex] = rescale[temp]; | 631 | 216k | if (aindex >= 0) | 632 | 43.0k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 633 | 216k | ptr += ps; | 634 | 216k | } | 635 | 66.8k | return 1; | 636 | 66.8k | } |
|
637 | | |
638 | | |
639 | | METHODDEF(JDIMENSION) |
640 | | get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
641 | | /* This version is for reading raw-word-format PPM files with any maxval */ |
642 | 34.2k | { |
643 | 34.2k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
644 | 34.2k | register _JSAMPROW ptr; |
645 | 34.2k | register unsigned char *bufferptr; |
646 | 34.2k | register _JSAMPLE *rescale = source->rescale; |
647 | 34.2k | JDIMENSION col; |
648 | 34.2k | unsigned int maxval = source->maxval; |
649 | | |
650 | 34.2k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
651 | 1.03k | ERREXIT(cinfo, JERR_INPUT_EOF); |
652 | 34.2k | ptr = source->pub._buffer[0]; |
653 | 34.2k | bufferptr = source->iobuffer; |
654 | 34.2k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
655 | 59.9k | for (col = cinfo->image_width; col > 0; col--) { |
656 | 46.1k | register unsigned int r, g, b; |
657 | 46.1k | r = (*bufferptr++) << 8; |
658 | 46.1k | r |= (*bufferptr++); |
659 | 46.1k | if (r > maxval) |
660 | 76 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
661 | 46.1k | g = (*bufferptr++) << 8; |
662 | 46.1k | g |= (*bufferptr++); |
663 | 46.1k | if (g > maxval) |
664 | 74 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
665 | 46.1k | b = (*bufferptr++) << 8; |
666 | 46.1k | b |= (*bufferptr++); |
667 | 46.1k | if (b > maxval) |
668 | 84 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
669 | 46.1k | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, |
670 | 46.1k | ptr + 2, ptr + 3); |
671 | 46.1k | ptr += 4; |
672 | 46.1k | } |
673 | 20.3k | } else { |
674 | 50.0k | for (col = cinfo->image_width; col > 0; col--) { |
675 | 29.6k | register unsigned int r, g, b; |
676 | 29.6k | r = (*bufferptr++) << 8; |
677 | 29.6k | r |= (*bufferptr++); |
678 | 29.6k | if (r > maxval) |
679 | 324 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
680 | 29.6k | g = (*bufferptr++) << 8; |
681 | 29.6k | g |= (*bufferptr++); |
682 | 29.6k | if (g > maxval) |
683 | 252 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
684 | 29.6k | b = (*bufferptr++) << 8; |
685 | 29.6k | b |= (*bufferptr++); |
686 | 29.6k | if (b > maxval) |
687 | 239 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
688 | 29.6k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], |
689 | 29.6k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); |
690 | 29.6k | ptr += 4; |
691 | 29.6k | } |
692 | 20.3k | } |
693 | 34.2k | return 1; |
694 | 34.2k | } rdppm-8.c:get_word_rgb_cmyk_row Line | Count | Source | 642 | 8.12k | { | 643 | 8.12k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 644 | 8.12k | register _JSAMPROW ptr; | 645 | 8.12k | register unsigned char *bufferptr; | 646 | 8.12k | register _JSAMPLE *rescale = source->rescale; | 647 | 8.12k | JDIMENSION col; | 648 | 8.12k | unsigned int maxval = source->maxval; | 649 | | | 650 | 8.12k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 651 | 317 | ERREXIT(cinfo, JERR_INPUT_EOF); | 652 | 8.12k | ptr = source->pub._buffer[0]; | 653 | 8.12k | bufferptr = source->iobuffer; | 654 | 8.12k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 655 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 656 | 0 | register unsigned int r, g, b; | 657 | 0 | r = (*bufferptr++) << 8; | 658 | 0 | r |= (*bufferptr++); | 659 | 0 | if (r > maxval) | 660 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 661 | 0 | g = (*bufferptr++) << 8; | 662 | 0 | g |= (*bufferptr++); | 663 | 0 | if (g > maxval) | 664 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 665 | 0 | b = (*bufferptr++) << 8; | 666 | 0 | b |= (*bufferptr++); | 667 | 0 | if (b > maxval) | 668 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 669 | 0 | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, | 670 | 0 | ptr + 2, ptr + 3); | 671 | 0 | ptr += 4; | 672 | 0 | } | 673 | 8.12k | } else { | 674 | 20.4k | for (col = cinfo->image_width; col > 0; col--) { | 675 | 12.3k | register unsigned int r, g, b; | 676 | 12.3k | r = (*bufferptr++) << 8; | 677 | 12.3k | r |= (*bufferptr++); | 678 | 12.3k | if (r > maxval) | 679 | 127 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 680 | 12.3k | g = (*bufferptr++) << 8; | 681 | 12.3k | g |= (*bufferptr++); | 682 | 12.3k | if (g > maxval) | 683 | 105 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 684 | 12.3k | b = (*bufferptr++) << 8; | 685 | 12.3k | b |= (*bufferptr++); | 686 | 12.3k | if (b > maxval) | 687 | 93 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 688 | 12.3k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], | 689 | 12.3k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); | 690 | 12.3k | ptr += 4; | 691 | 12.3k | } | 692 | 8.12k | } | 693 | 8.12k | return 1; | 694 | 8.12k | } |
rdppm-12.c:get_word_rgb_cmyk_row Line | Count | Source | 642 | 12.7k | { | 643 | 12.7k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 644 | 12.7k | register _JSAMPROW ptr; | 645 | 12.7k | register unsigned char *bufferptr; | 646 | 12.7k | register _JSAMPLE *rescale = source->rescale; | 647 | 12.7k | JDIMENSION col; | 648 | 12.7k | unsigned int maxval = source->maxval; | 649 | | | 650 | 12.7k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 651 | 455 | ERREXIT(cinfo, JERR_INPUT_EOF); | 652 | 12.7k | ptr = source->pub._buffer[0]; | 653 | 12.7k | bufferptr = source->iobuffer; | 654 | 12.7k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 655 | 12.1k | for (col = cinfo->image_width; col > 0; col--) { | 656 | 8.16k | register unsigned int r, g, b; | 657 | 8.16k | r = (*bufferptr++) << 8; | 658 | 8.16k | r |= (*bufferptr++); | 659 | 8.16k | if (r > maxval) | 660 | 76 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 661 | 8.16k | g = (*bufferptr++) << 8; | 662 | 8.16k | g |= (*bufferptr++); | 663 | 8.16k | if (g > maxval) | 664 | 74 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 665 | 8.16k | b = (*bufferptr++) << 8; | 666 | 8.16k | b |= (*bufferptr++); | 667 | 8.16k | if (b > maxval) | 668 | 84 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 669 | 8.16k | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, | 670 | 8.16k | ptr + 2, ptr + 3); | 671 | 8.16k | ptr += 4; | 672 | 8.16k | } | 673 | 8.75k | } else { | 674 | 20.8k | for (col = cinfo->image_width; col > 0; col--) { | 675 | 12.0k | register unsigned int r, g, b; | 676 | 12.0k | r = (*bufferptr++) << 8; | 677 | 12.0k | r |= (*bufferptr++); | 678 | 12.0k | if (r > maxval) | 679 | 130 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 680 | 12.0k | g = (*bufferptr++) << 8; | 681 | 12.0k | g |= (*bufferptr++); | 682 | 12.0k | if (g > maxval) | 683 | 99 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 684 | 12.0k | b = (*bufferptr++) << 8; | 685 | 12.0k | b |= (*bufferptr++); | 686 | 12.0k | if (b > maxval) | 687 | 96 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 688 | 12.0k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], | 689 | 12.0k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); | 690 | 12.0k | ptr += 4; | 691 | 12.0k | } | 692 | 8.75k | } | 693 | 12.7k | return 1; | 694 | 12.7k | } |
rdppm-16.c:get_word_rgb_cmyk_row Line | Count | Source | 642 | 13.3k | { | 643 | 13.3k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 644 | 13.3k | register _JSAMPROW ptr; | 645 | 13.3k | register unsigned char *bufferptr; | 646 | 13.3k | register _JSAMPLE *rescale = source->rescale; | 647 | 13.3k | JDIMENSION col; | 648 | 13.3k | unsigned int maxval = source->maxval; | 649 | | | 650 | 13.3k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 651 | 260 | ERREXIT(cinfo, JERR_INPUT_EOF); | 652 | 13.3k | ptr = source->pub._buffer[0]; | 653 | 13.3k | bufferptr = source->iobuffer; | 654 | 13.3k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 655 | 47.8k | for (col = cinfo->image_width; col > 0; col--) { | 656 | 37.9k | register unsigned int r, g, b; | 657 | 37.9k | r = (*bufferptr++) << 8; | 658 | 37.9k | r |= (*bufferptr++); | 659 | 37.9k | if (r > maxval) | 660 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 661 | 37.9k | g = (*bufferptr++) << 8; | 662 | 37.9k | g |= (*bufferptr++); | 663 | 37.9k | if (g > maxval) | 664 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 665 | 37.9k | b = (*bufferptr++) << 8; | 666 | 37.9k | b |= (*bufferptr++); | 667 | 37.9k | if (b > maxval) | 668 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 669 | 37.9k | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, | 670 | 37.9k | ptr + 2, ptr + 3); | 671 | 37.9k | ptr += 4; | 672 | 37.9k | } | 673 | 9.89k | } else { | 674 | 8.70k | for (col = cinfo->image_width; col > 0; col--) { | 675 | 5.21k | register unsigned int r, g, b; | 676 | 5.21k | r = (*bufferptr++) << 8; | 677 | 5.21k | r |= (*bufferptr++); | 678 | 5.21k | if (r > maxval) | 679 | 67 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 680 | 5.21k | g = (*bufferptr++) << 8; | 681 | 5.21k | g |= (*bufferptr++); | 682 | 5.21k | if (g > maxval) | 683 | 48 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 684 | 5.21k | b = (*bufferptr++) << 8; | 685 | 5.21k | b |= (*bufferptr++); | 686 | 5.21k | if (b > maxval) | 687 | 50 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 688 | 5.21k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], | 689 | 5.21k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); | 690 | 5.21k | ptr += 4; | 691 | 5.21k | } | 692 | 3.48k | } | 693 | 13.3k | return 1; | 694 | 13.3k | } |
|
695 | | |
696 | | |
697 | | /* |
698 | | * Read the file header; return image size and component count. |
699 | | */ |
700 | | |
701 | | METHODDEF(void) |
702 | | start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
703 | 179k | { |
704 | 179k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
705 | 179k | int c; |
706 | 179k | unsigned int w, h, maxval; |
707 | 179k | boolean need_iobuffer, use_raw_buffer, need_rescale; |
708 | | |
709 | 179k | if (getc(source->pub.input_file) != 'P') |
710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); |
711 | | |
712 | 179k | c = getc(source->pub.input_file); /* subformat discriminator character */ |
713 | | |
714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ |
715 | 179k | switch (c) { |
716 | 18.6k | case '2': /* it's a text-format PGM file */ |
717 | 39.0k | case '3': /* it's a text-format PPM file */ |
718 | 136k | case '5': /* it's a raw-format PGM file */ |
719 | 179k | case '6': /* it's a raw-format PPM file */ |
720 | 179k | break; |
721 | 515 | default: |
722 | 515 | ERREXIT(cinfo, JERR_PPM_NOT); |
723 | 515 | break; |
724 | 179k | } |
725 | | |
726 | | /* fetch the remaining header info */ |
727 | 179k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); |
728 | 179k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); |
729 | 179k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); |
730 | | |
731 | 179k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ |
732 | 424 | ERREXIT(cinfo, JERR_PPM_NOT); |
733 | 179k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) |
734 | 240 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); |
735 | 179k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) |
736 | 2.62k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); |
737 | | |
738 | 179k | cinfo->image_width = (JDIMENSION)w; |
739 | 179k | cinfo->image_height = (JDIMENSION)h; |
740 | 179k | source->maxval = maxval; |
741 | | |
742 | | /* initialize flags to most common settings */ |
743 | 179k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ |
744 | 179k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ |
745 | 179k | need_rescale = TRUE; /* do we need a rescale array? */ |
746 | | |
747 | 179k | switch (c) { |
748 | 13.8k | case '2': /* it's a text-format PGM file */ |
749 | 13.8k | if (cinfo->in_color_space == JCS_UNKNOWN || |
750 | 13.8k | cinfo->in_color_space == JCS_RGB) |
751 | 224 | cinfo->in_color_space = JCS_GRAYSCALE; |
752 | 13.8k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); |
753 | 13.8k | if (cinfo->in_color_space == JCS_GRAYSCALE) |
754 | 2.21k | source->pub.get_pixel_rows = get_text_gray_row; |
755 | 11.6k | else if (IsExtRGB(cinfo->in_color_space)) |
756 | 9.94k | source->pub.get_pixel_rows = get_text_gray_rgb_row; |
757 | 1.73k | else if (cinfo->in_color_space == JCS_CMYK) |
758 | 1.73k | source->pub.get_pixel_rows = get_text_gray_cmyk_row; |
759 | 0 | else |
760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
761 | 13.8k | need_iobuffer = FALSE; |
762 | 13.8k | break; |
763 | | |
764 | 16.2k | case '3': /* it's a text-format PPM file */ |
765 | 16.2k | if (cinfo->in_color_space == JCS_UNKNOWN) |
766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
767 | 16.2k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); |
768 | 16.2k | if (IsExtRGB(cinfo->in_color_space)) |
769 | 11.9k | source->pub.get_pixel_rows = get_text_rgb_row; |
770 | 4.36k | else if (cinfo->in_color_space == JCS_CMYK) |
771 | 2.05k | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; |
772 | 2.30k | else |
773 | 2.30k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
774 | 16.2k | need_iobuffer = FALSE; |
775 | 16.2k | break; |
776 | | |
777 | 92.4k | case '5': /* it's a raw-format PGM file */ |
778 | 92.4k | if (cinfo->in_color_space == JCS_UNKNOWN || |
779 | 92.4k | cinfo->in_color_space == JCS_RGB) |
780 | 882 | cinfo->in_color_space = JCS_GRAYSCALE; |
781 | 92.4k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); |
782 | 92.4k | if (maxval > 255) { |
783 | 11.9k | if (cinfo->in_color_space == JCS_GRAYSCALE) |
784 | 1.96k | source->pub.get_pixel_rows = get_word_gray_row; |
785 | 9.98k | else if (IsExtRGB(cinfo->in_color_space)) |
786 | 8.47k | source->pub.get_pixel_rows = get_word_gray_rgb_row; |
787 | 1.51k | else if (cinfo->in_color_space == JCS_CMYK) |
788 | 1.51k | source->pub.get_pixel_rows = get_word_gray_cmyk_row; |
789 | 0 | else |
790 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
791 | | #if BITS_IN_JSAMPLE == 8 |
792 | 47.7k | } else if (maxval <= _MAXJSAMPLE && |
793 | 47.7k | maxval == ((1U << cinfo->data_precision) - 1U) && |
794 | 4.87k | cinfo->in_color_space == JCS_GRAYSCALE) { |
795 | 831 | source->pub.get_pixel_rows = get_raw_row; |
796 | 831 | use_raw_buffer = TRUE; |
797 | 831 | need_rescale = FALSE; |
798 | | #endif |
799 | 79.6k | } else { |
800 | 79.6k | if (cinfo->in_color_space == JCS_GRAYSCALE) |
801 | 11.5k | source->pub.get_pixel_rows = get_scaled_gray_row; |
802 | 68.1k | else if (IsExtRGB(cinfo->in_color_space)) |
803 | 59.0k | source->pub.get_pixel_rows = get_gray_rgb_row; |
804 | 9.07k | else if (cinfo->in_color_space == JCS_CMYK) |
805 | 9.07k | source->pub.get_pixel_rows = get_gray_cmyk_row; |
806 | 0 | else |
807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
808 | 79.6k | } |
809 | 92.4k | break; |
810 | | |
811 | 38.7k | case '6': /* it's a raw-format PPM file */ |
812 | 38.7k | if (cinfo->in_color_space == JCS_UNKNOWN) |
813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
814 | 38.7k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); |
815 | 38.7k | if (maxval > 255) { |
816 | 16.9k | if (IsExtRGB(cinfo->in_color_space)) |
817 | 12.3k | source->pub.get_pixel_rows = get_word_rgb_row; |
818 | 4.60k | else if (cinfo->in_color_space == JCS_CMYK) |
819 | 2.20k | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; |
820 | 2.39k | else |
821 | 2.39k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
822 | | #if BITS_IN_JSAMPLE == 8 |
823 | 12.4k | } else if (maxval <= _MAXJSAMPLE && |
824 | 12.4k | maxval == ((1U << cinfo->data_precision) - 1U) && |
825 | 2.14k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 |
826 | 2.14k | (cinfo->in_color_space == JCS_EXT_RGB || |
827 | 1.86k | cinfo->in_color_space == JCS_RGB)) { |
828 | | #else |
829 | | cinfo->in_color_space == JCS_EXT_RGB) { |
830 | | #endif |
831 | 322 | source->pub.get_pixel_rows = get_raw_row; |
832 | 322 | use_raw_buffer = TRUE; |
833 | 322 | need_rescale = FALSE; |
834 | | #endif |
835 | 21.4k | } else { |
836 | 21.4k | if (IsExtRGB(cinfo->in_color_space)) |
837 | 15.6k | source->pub.get_pixel_rows = get_rgb_row; |
838 | 5.79k | else if (cinfo->in_color_space == JCS_CMYK) |
839 | 2.67k | source->pub.get_pixel_rows = get_rgb_cmyk_row; |
840 | 3.11k | else |
841 | 3.11k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
842 | 21.4k | } |
843 | 38.7k | break; |
844 | 179k | } |
845 | | |
846 | 153k | if (IsExtRGB(cinfo->in_color_space)) |
847 | 117k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; |
848 | 35.8k | else if (cinfo->in_color_space == JCS_GRAYSCALE) |
849 | 16.5k | cinfo->input_components = 1; |
850 | 19.2k | else if (cinfo->in_color_space == JCS_CMYK) |
851 | 19.2k | cinfo->input_components = 4; |
852 | | |
853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ |
854 | 153k | if (need_iobuffer) { |
855 | 125k | if (c == '6') |
856 | 33.2k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); |
857 | 92.4k | else |
858 | 92.4k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); |
859 | 125k | source->iobuffer = (unsigned char *) |
860 | 125k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
861 | 125k | source->buffer_width); |
862 | 125k | } |
863 | | |
864 | | /* Create compressor input buffer. */ |
865 | 153k | if (use_raw_buffer) { |
866 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ |
867 | | /* Synthesize a _JSAMPARRAY pointer structure */ |
868 | 1.15k | source->pixrow = (_JSAMPROW)source->iobuffer; |
869 | 1.15k | source->pub._buffer = &source->pixrow; |
870 | 1.15k | source->pub.buffer_height = 1; |
871 | 152k | } else { |
872 | | /* Need to translate anyway, so make a separate sample buffer. */ |
873 | 152k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
874 | 152k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
875 | 152k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); |
876 | 152k | source->pub.buffer_height = 1; |
877 | 152k | } |
878 | | |
879 | | /* Compute the rescaling array if required. */ |
880 | 153k | if (need_rescale) { |
881 | 152k | size_t val, half_maxval; |
882 | | |
883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ |
884 | 152k | source->rescale = (_JSAMPLE *) |
885 | 152k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
886 | 152k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); |
887 | 152k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); |
888 | 152k | half_maxval = (size_t)maxval / 2; |
889 | 528M | for (val = 0; val <= (size_t)maxval; val++) { |
890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ |
891 | 527M | source->rescale[val] = |
892 | 527M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / |
893 | 527M | maxval); |
894 | 527M | } |
895 | 152k | } |
896 | 153k | } rdppm-8.c:start_input_ppm Line | Count | Source | 703 | 94.1k | { | 704 | 94.1k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 705 | 94.1k | int c; | 706 | 94.1k | unsigned int w, h, maxval; | 707 | 94.1k | boolean need_iobuffer, use_raw_buffer, need_rescale; | 708 | | | 709 | 94.1k | if (getc(source->pub.input_file) != 'P') | 710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); | 711 | | | 712 | 94.1k | c = getc(source->pub.input_file); /* subformat discriminator character */ | 713 | | | 714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ | 715 | 94.1k | switch (c) { | 716 | 8.85k | case '2': /* it's a text-format PGM file */ | 717 | 18.3k | case '3': /* it's a text-format PPM file */ | 718 | 73.3k | case '5': /* it's a raw-format PGM file */ | 719 | 93.9k | case '6': /* it's a raw-format PPM file */ | 720 | 93.9k | break; | 721 | 221 | default: | 722 | 221 | ERREXIT(cinfo, JERR_PPM_NOT); | 723 | 221 | break; | 724 | 94.1k | } | 725 | | | 726 | | /* fetch the remaining header info */ | 727 | 93.9k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 728 | 93.9k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 729 | 93.9k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 730 | | | 731 | 93.9k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ | 732 | 200 | ERREXIT(cinfo, JERR_PPM_NOT); | 733 | 93.9k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) | 734 | 114 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 735 | 93.9k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) | 736 | 1.10k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 737 | | | 738 | 93.9k | cinfo->image_width = (JDIMENSION)w; | 739 | 93.9k | cinfo->image_height = (JDIMENSION)h; | 740 | 93.9k | source->maxval = maxval; | 741 | | | 742 | | /* initialize flags to most common settings */ | 743 | 93.9k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ | 744 | 93.9k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 745 | 93.9k | need_rescale = TRUE; /* do we need a rescale array? */ | 746 | | | 747 | 93.9k | switch (c) { | 748 | 6.47k | case '2': /* it's a text-format PGM file */ | 749 | 6.47k | if (cinfo->in_color_space == JCS_UNKNOWN || | 750 | 6.47k | cinfo->in_color_space == JCS_RGB) | 751 | 224 | cinfo->in_color_space = JCS_GRAYSCALE; | 752 | 6.47k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); | 753 | 6.47k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 754 | 1.15k | source->pub.get_pixel_rows = get_text_gray_row; | 755 | 5.31k | else if (IsExtRGB(cinfo->in_color_space)) | 756 | 4.64k | source->pub.get_pixel_rows = get_text_gray_rgb_row; | 757 | 678 | else if (cinfo->in_color_space == JCS_CMYK) | 758 | 678 | source->pub.get_pixel_rows = get_text_gray_cmyk_row; | 759 | 0 | else | 760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 761 | 6.47k | need_iobuffer = FALSE; | 762 | 6.47k | break; | 763 | | | 764 | 7.67k | case '3': /* it's a text-format PPM file */ | 765 | 7.67k | if (cinfo->in_color_space == JCS_UNKNOWN) | 766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 767 | 7.67k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); | 768 | 7.67k | if (IsExtRGB(cinfo->in_color_space)) | 769 | 5.77k | source->pub.get_pixel_rows = get_text_rgb_row; | 770 | 1.90k | else if (cinfo->in_color_space == JCS_CMYK) | 771 | 829 | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; | 772 | 1.08k | else | 773 | 1.08k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 774 | 7.67k | need_iobuffer = FALSE; | 775 | 7.67k | break; | 776 | | | 777 | 52.3k | case '5': /* it's a raw-format PGM file */ | 778 | 52.3k | if (cinfo->in_color_space == JCS_UNKNOWN || | 779 | 52.3k | cinfo->in_color_space == JCS_RGB) | 780 | 882 | cinfo->in_color_space = JCS_GRAYSCALE; | 781 | 52.3k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); | 782 | 52.3k | if (maxval > 255) { | 783 | 4.57k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 784 | 913 | source->pub.get_pixel_rows = get_word_gray_row; | 785 | 3.66k | else if (IsExtRGB(cinfo->in_color_space)) | 786 | 3.20k | source->pub.get_pixel_rows = get_word_gray_rgb_row; | 787 | 460 | else if (cinfo->in_color_space == JCS_CMYK) | 788 | 460 | source->pub.get_pixel_rows = get_word_gray_cmyk_row; | 789 | 0 | else | 790 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 791 | 4.57k | #if BITS_IN_JSAMPLE == 8 | 792 | 47.7k | } else if (maxval <= _MAXJSAMPLE && | 793 | 47.7k | maxval == ((1U << cinfo->data_precision) - 1U) && | 794 | 4.87k | cinfo->in_color_space == JCS_GRAYSCALE) { | 795 | 831 | source->pub.get_pixel_rows = get_raw_row; | 796 | 831 | use_raw_buffer = TRUE; | 797 | 831 | need_rescale = FALSE; | 798 | 831 | #endif | 799 | 46.9k | } else { | 800 | 46.9k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 801 | 6.90k | source->pub.get_pixel_rows = get_scaled_gray_row; | 802 | 40.0k | else if (IsExtRGB(cinfo->in_color_space)) | 803 | 35.6k | source->pub.get_pixel_rows = get_gray_rgb_row; | 804 | 4.39k | else if (cinfo->in_color_space == JCS_CMYK) | 805 | 4.39k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 806 | 0 | else | 807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 808 | 46.9k | } | 809 | 52.3k | break; | 810 | | | 811 | 18.6k | case '6': /* it's a raw-format PPM file */ | 812 | 18.6k | if (cinfo->in_color_space == JCS_UNKNOWN) | 813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 814 | 18.6k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); | 815 | 18.6k | if (maxval > 255) { | 816 | 6.18k | if (IsExtRGB(cinfo->in_color_space)) | 817 | 4.65k | source->pub.get_pixel_rows = get_word_rgb_row; | 818 | 1.53k | else if (cinfo->in_color_space == JCS_CMYK) | 819 | 674 | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; | 820 | 863 | else | 821 | 863 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 822 | 6.18k | #if BITS_IN_JSAMPLE == 8 | 823 | 12.4k | } else if (maxval <= _MAXJSAMPLE && | 824 | 12.4k | maxval == ((1U << cinfo->data_precision) - 1U) && | 825 | 2.14k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 826 | 2.14k | (cinfo->in_color_space == JCS_EXT_RGB || | 827 | 1.86k | cinfo->in_color_space == JCS_RGB)) { | 828 | | #else | 829 | | cinfo->in_color_space == JCS_EXT_RGB) { | 830 | | #endif | 831 | 322 | source->pub.get_pixel_rows = get_raw_row; | 832 | 322 | use_raw_buffer = TRUE; | 833 | 322 | need_rescale = FALSE; | 834 | 322 | #endif | 835 | 12.1k | } else { | 836 | 12.1k | if (IsExtRGB(cinfo->in_color_space)) | 837 | 9.00k | source->pub.get_pixel_rows = get_rgb_row; | 838 | 3.11k | else if (cinfo->in_color_space == JCS_CMYK) | 839 | 1.33k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 840 | 1.77k | else | 841 | 1.77k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 842 | 12.1k | } | 843 | 18.6k | break; | 844 | 93.9k | } | 845 | | | 846 | 81.3k | if (IsExtRGB(cinfo->in_color_space)) | 847 | 63.2k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 848 | 18.1k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 849 | 9.79k | cinfo->input_components = 1; | 850 | 8.37k | else if (cinfo->in_color_space == JCS_CMYK) | 851 | 8.37k | cinfo->input_components = 4; | 852 | | | 853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 854 | 81.3k | if (need_iobuffer) { | 855 | 68.3k | if (c == '6') | 856 | 15.9k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); | 857 | 52.3k | else | 858 | 52.3k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); | 859 | 68.3k | source->iobuffer = (unsigned char *) | 860 | 68.3k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 861 | 68.3k | source->buffer_width); | 862 | 68.3k | } | 863 | | | 864 | | /* Create compressor input buffer. */ | 865 | 81.3k | if (use_raw_buffer) { | 866 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 867 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 868 | 1.15k | source->pixrow = (_JSAMPROW)source->iobuffer; | 869 | 1.15k | source->pub._buffer = &source->pixrow; | 870 | 1.15k | source->pub.buffer_height = 1; | 871 | 80.2k | } else { | 872 | | /* Need to translate anyway, so make a separate sample buffer. */ | 873 | 80.2k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 874 | 80.2k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 875 | 80.2k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); | 876 | 80.2k | source->pub.buffer_height = 1; | 877 | 80.2k | } | 878 | | | 879 | | /* Compute the rescaling array if required. */ | 880 | 81.3k | if (need_rescale) { | 881 | 80.2k | size_t val, half_maxval; | 882 | | | 883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ | 884 | 80.2k | source->rescale = (_JSAMPLE *) | 885 | 80.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 886 | 80.2k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 887 | 80.2k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 888 | 80.2k | half_maxval = (size_t)maxval / 2; | 889 | 132M | for (val = 0; val <= (size_t)maxval; val++) { | 890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 891 | 132M | source->rescale[val] = | 892 | 132M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 893 | 132M | maxval); | 894 | 132M | } | 895 | 80.2k | } | 896 | 81.3k | } |
rdppm-12.c:start_input_ppm Line | Count | Source | 703 | 60.5k | { | 704 | 60.5k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 705 | 60.5k | int c; | 706 | 60.5k | unsigned int w, h, maxval; | 707 | 60.5k | boolean need_iobuffer, use_raw_buffer, need_rescale; | 708 | | | 709 | 60.5k | if (getc(source->pub.input_file) != 'P') | 710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); | 711 | | | 712 | 60.5k | c = getc(source->pub.input_file); /* subformat discriminator character */ | 713 | | | 714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ | 715 | 60.5k | switch (c) { | 716 | 6.48k | case '2': /* it's a text-format PGM file */ | 717 | 13.2k | case '3': /* it's a text-format PPM file */ | 718 | 44.7k | case '5': /* it's a raw-format PGM file */ | 719 | 60.3k | case '6': /* it's a raw-format PPM file */ | 720 | 60.3k | break; | 721 | 245 | default: | 722 | 245 | ERREXIT(cinfo, JERR_PPM_NOT); | 723 | 245 | break; | 724 | 60.5k | } | 725 | | | 726 | | /* fetch the remaining header info */ | 727 | 60.3k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 728 | 60.3k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 729 | 60.3k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 730 | | | 731 | 60.3k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ | 732 | 147 | ERREXIT(cinfo, JERR_PPM_NOT); | 733 | 60.3k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) | 734 | 70 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 735 | 60.3k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) | 736 | 1.02k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 737 | | | 738 | 60.3k | cinfo->image_width = (JDIMENSION)w; | 739 | 60.3k | cinfo->image_height = (JDIMENSION)h; | 740 | 60.3k | source->maxval = maxval; | 741 | | | 742 | | /* initialize flags to most common settings */ | 743 | 60.3k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ | 744 | 60.3k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 745 | 60.3k | need_rescale = TRUE; /* do we need a rescale array? */ | 746 | | | 747 | 60.3k | switch (c) { | 748 | 4.75k | case '2': /* it's a text-format PGM file */ | 749 | 4.75k | if (cinfo->in_color_space == JCS_UNKNOWN || | 750 | 4.75k | cinfo->in_color_space == JCS_RGB) | 751 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 752 | 4.75k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); | 753 | 4.75k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 754 | 679 | source->pub.get_pixel_rows = get_text_gray_row; | 755 | 4.07k | else if (IsExtRGB(cinfo->in_color_space)) | 756 | 3.39k | source->pub.get_pixel_rows = get_text_gray_rgb_row; | 757 | 679 | else if (cinfo->in_color_space == JCS_CMYK) | 758 | 679 | source->pub.get_pixel_rows = get_text_gray_cmyk_row; | 759 | 0 | else | 760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 761 | 4.75k | need_iobuffer = FALSE; | 762 | 4.75k | break; | 763 | | | 764 | 5.39k | case '3': /* it's a text-format PPM file */ | 765 | 5.39k | if (cinfo->in_color_space == JCS_UNKNOWN) | 766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 767 | 5.39k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); | 768 | 5.39k | if (IsExtRGB(cinfo->in_color_space)) | 769 | 3.85k | source->pub.get_pixel_rows = get_text_rgb_row; | 770 | 1.54k | else if (cinfo->in_color_space == JCS_CMYK) | 771 | 771 | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; | 772 | 771 | else | 773 | 771 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 774 | 5.39k | need_iobuffer = FALSE; | 775 | 5.39k | break; | 776 | | | 777 | 29.8k | case '5': /* it's a raw-format PGM file */ | 778 | 29.8k | if (cinfo->in_color_space == JCS_UNKNOWN || | 779 | 29.8k | cinfo->in_color_space == JCS_RGB) | 780 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 781 | 29.8k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); | 782 | 29.8k | if (maxval > 255) { | 783 | 4.77k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 784 | 682 | source->pub.get_pixel_rows = get_word_gray_row; | 785 | 4.09k | else if (IsExtRGB(cinfo->in_color_space)) | 786 | 3.41k | source->pub.get_pixel_rows = get_word_gray_rgb_row; | 787 | 682 | else if (cinfo->in_color_space == JCS_CMYK) | 788 | 682 | source->pub.get_pixel_rows = get_word_gray_cmyk_row; | 789 | 0 | else | 790 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 791 | | #if BITS_IN_JSAMPLE == 8 | 792 | | } else if (maxval <= _MAXJSAMPLE && | 793 | | maxval == ((1U << cinfo->data_precision) - 1U) && | 794 | | cinfo->in_color_space == JCS_GRAYSCALE) { | 795 | | source->pub.get_pixel_rows = get_raw_row; | 796 | | use_raw_buffer = TRUE; | 797 | | need_rescale = FALSE; | 798 | | #endif | 799 | 25.1k | } else { | 800 | 25.1k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 801 | 3.58k | source->pub.get_pixel_rows = get_scaled_gray_row; | 802 | 21.5k | else if (IsExtRGB(cinfo->in_color_space)) | 803 | 17.9k | source->pub.get_pixel_rows = get_gray_rgb_row; | 804 | 3.58k | else if (cinfo->in_color_space == JCS_CMYK) | 805 | 3.58k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 806 | 0 | else | 807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 808 | 25.1k | } | 809 | 29.8k | break; | 810 | | | 811 | 14.2k | case '6': /* it's a raw-format PPM file */ | 812 | 14.2k | if (cinfo->in_color_space == JCS_UNKNOWN) | 813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 814 | 14.2k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); | 815 | 14.2k | if (maxval > 255) { | 816 | 7.44k | if (IsExtRGB(cinfo->in_color_space)) | 817 | 5.31k | source->pub.get_pixel_rows = get_word_rgb_row; | 818 | 2.12k | else if (cinfo->in_color_space == JCS_CMYK) | 819 | 1.06k | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; | 820 | 1.06k | else | 821 | 1.06k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 822 | | #if BITS_IN_JSAMPLE == 8 | 823 | | } else if (maxval <= _MAXJSAMPLE && | 824 | | maxval == ((1U << cinfo->data_precision) - 1U) && | 825 | | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 826 | | (cinfo->in_color_space == JCS_EXT_RGB || | 827 | | cinfo->in_color_space == JCS_RGB)) { | 828 | | #else | 829 | | cinfo->in_color_space == JCS_EXT_RGB) { | 830 | | #endif | 831 | | source->pub.get_pixel_rows = get_raw_row; | 832 | | use_raw_buffer = TRUE; | 833 | | need_rescale = FALSE; | 834 | | #endif | 835 | 7.44k | } else { | 836 | 6.83k | if (IsExtRGB(cinfo->in_color_space)) | 837 | 4.88k | source->pub.get_pixel_rows = get_rgb_row; | 838 | 1.95k | else if (cinfo->in_color_space == JCS_CMYK) | 839 | 976 | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 840 | 976 | else | 841 | 976 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 842 | 6.83k | } | 843 | 14.2k | break; | 844 | 60.3k | } | 845 | | | 846 | 51.5k | if (IsExtRGB(cinfo->in_color_space)) | 847 | 38.7k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 848 | 12.7k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 849 | 4.94k | cinfo->input_components = 1; | 850 | 7.75k | else if (cinfo->in_color_space == JCS_CMYK) | 851 | 7.75k | cinfo->input_components = 4; | 852 | | | 853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 854 | 51.5k | if (need_iobuffer) { | 855 | 42.1k | if (c == '6') | 856 | 12.2k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); | 857 | 29.8k | else | 858 | 29.8k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); | 859 | 42.1k | source->iobuffer = (unsigned char *) | 860 | 42.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 861 | 42.1k | source->buffer_width); | 862 | 42.1k | } | 863 | | | 864 | | /* Create compressor input buffer. */ | 865 | 51.5k | if (use_raw_buffer) { | 866 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 867 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 868 | 0 | source->pixrow = (_JSAMPROW)source->iobuffer; | 869 | 0 | source->pub._buffer = &source->pixrow; | 870 | 0 | source->pub.buffer_height = 1; | 871 | 51.5k | } else { | 872 | | /* Need to translate anyway, so make a separate sample buffer. */ | 873 | 51.5k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 874 | 51.5k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 875 | 51.5k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); | 876 | 51.5k | source->pub.buffer_height = 1; | 877 | 51.5k | } | 878 | | | 879 | | /* Compute the rescaling array if required. */ | 880 | 51.5k | if (need_rescale) { | 881 | 51.5k | size_t val, half_maxval; | 882 | | | 883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ | 884 | 51.5k | source->rescale = (_JSAMPLE *) | 885 | 51.5k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 886 | 51.5k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 887 | 51.5k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 888 | 51.5k | half_maxval = (size_t)maxval / 2; | 889 | 118M | for (val = 0; val <= (size_t)maxval; val++) { | 890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 891 | 118M | source->rescale[val] = | 892 | 118M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 893 | 118M | maxval); | 894 | 118M | } | 895 | 51.5k | } | 896 | 51.5k | } |
rdppm-16.c:start_input_ppm Line | Count | Source | 703 | 25.0k | { | 704 | 25.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 705 | 25.0k | int c; | 706 | 25.0k | unsigned int w, h, maxval; | 707 | 25.0k | boolean need_iobuffer, use_raw_buffer, need_rescale; | 708 | | | 709 | 25.0k | if (getc(source->pub.input_file) != 'P') | 710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); | 711 | | | 712 | 25.0k | c = getc(source->pub.input_file); /* subformat discriminator character */ | 713 | | | 714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ | 715 | 25.0k | switch (c) { | 716 | 3.32k | case '2': /* it's a text-format PGM file */ | 717 | 7.41k | case '3': /* it's a text-format PPM file */ | 718 | 18.5k | case '5': /* it's a raw-format PGM file */ | 719 | 24.9k | case '6': /* it's a raw-format PPM file */ | 720 | 24.9k | break; | 721 | 49 | default: | 722 | 49 | ERREXIT(cinfo, JERR_PPM_NOT); | 723 | 49 | break; | 724 | 25.0k | } | 725 | | | 726 | | /* fetch the remaining header info */ | 727 | 24.9k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 728 | 24.9k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 729 | 24.9k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 730 | | | 731 | 24.9k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ | 732 | 77 | ERREXIT(cinfo, JERR_PPM_NOT); | 733 | 24.9k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) | 734 | 56 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 735 | 24.9k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) | 736 | 497 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 737 | | | 738 | 24.9k | cinfo->image_width = (JDIMENSION)w; | 739 | 24.9k | cinfo->image_height = (JDIMENSION)h; | 740 | 24.9k | source->maxval = maxval; | 741 | | | 742 | | /* initialize flags to most common settings */ | 743 | 24.9k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ | 744 | 24.9k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 745 | 24.9k | need_rescale = TRUE; /* do we need a rescale array? */ | 746 | | | 747 | 24.9k | switch (c) { | 748 | 2.67k | case '2': /* it's a text-format PGM file */ | 749 | 2.67k | if (cinfo->in_color_space == JCS_UNKNOWN || | 750 | 2.67k | cinfo->in_color_space == JCS_RGB) | 751 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 752 | 2.67k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); | 753 | 2.67k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 754 | 382 | source->pub.get_pixel_rows = get_text_gray_row; | 755 | 2.29k | else if (IsExtRGB(cinfo->in_color_space)) | 756 | 1.91k | source->pub.get_pixel_rows = get_text_gray_rgb_row; | 757 | 382 | else if (cinfo->in_color_space == JCS_CMYK) | 758 | 382 | source->pub.get_pixel_rows = get_text_gray_cmyk_row; | 759 | 0 | else | 760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 761 | 2.67k | need_iobuffer = FALSE; | 762 | 2.67k | break; | 763 | | | 764 | 3.18k | case '3': /* it's a text-format PPM file */ | 765 | 3.18k | if (cinfo->in_color_space == JCS_UNKNOWN) | 766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 767 | 3.18k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); | 768 | 3.18k | if (IsExtRGB(cinfo->in_color_space)) | 769 | 2.27k | source->pub.get_pixel_rows = get_text_rgb_row; | 770 | 910 | else if (cinfo->in_color_space == JCS_CMYK) | 771 | 455 | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; | 772 | 455 | else | 773 | 455 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 774 | 3.18k | need_iobuffer = FALSE; | 775 | 3.18k | break; | 776 | | | 777 | 10.2k | case '5': /* it's a raw-format PGM file */ | 778 | 10.2k | if (cinfo->in_color_space == JCS_UNKNOWN || | 779 | 10.2k | cinfo->in_color_space == JCS_RGB) | 780 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 781 | 10.2k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); | 782 | 10.2k | if (maxval > 255) { | 783 | 2.59k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 784 | 371 | source->pub.get_pixel_rows = get_word_gray_row; | 785 | 2.22k | else if (IsExtRGB(cinfo->in_color_space)) | 786 | 1.85k | source->pub.get_pixel_rows = get_word_gray_rgb_row; | 787 | 371 | else if (cinfo->in_color_space == JCS_CMYK) | 788 | 371 | source->pub.get_pixel_rows = get_word_gray_cmyk_row; | 789 | 0 | else | 790 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 791 | | #if BITS_IN_JSAMPLE == 8 | 792 | | } else if (maxval <= _MAXJSAMPLE && | 793 | | maxval == ((1U << cinfo->data_precision) - 1U) && | 794 | | cinfo->in_color_space == JCS_GRAYSCALE) { | 795 | | source->pub.get_pixel_rows = get_raw_row; | 796 | | use_raw_buffer = TRUE; | 797 | | need_rescale = FALSE; | 798 | | #endif | 799 | 7.65k | } else { | 800 | 7.65k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 801 | 1.09k | source->pub.get_pixel_rows = get_scaled_gray_row; | 802 | 6.55k | else if (IsExtRGB(cinfo->in_color_space)) | 803 | 5.46k | source->pub.get_pixel_rows = get_gray_rgb_row; | 804 | 1.09k | else if (cinfo->in_color_space == JCS_CMYK) | 805 | 1.09k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 806 | 0 | else | 807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 808 | 7.65k | } | 809 | 10.2k | break; | 810 | | | 811 | 5.83k | case '6': /* it's a raw-format PPM file */ | 812 | 5.83k | if (cinfo->in_color_space == JCS_UNKNOWN) | 813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 814 | 5.83k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); | 815 | 5.83k | if (maxval > 255) { | 816 | 3.30k | if (IsExtRGB(cinfo->in_color_space)) | 817 | 2.36k | source->pub.get_pixel_rows = get_word_rgb_row; | 818 | 944 | else if (cinfo->in_color_space == JCS_CMYK) | 819 | 472 | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; | 820 | 472 | else | 821 | 472 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 822 | | #if BITS_IN_JSAMPLE == 8 | 823 | | } else if (maxval <= _MAXJSAMPLE && | 824 | | maxval == ((1U << cinfo->data_precision) - 1U) && | 825 | | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 826 | | (cinfo->in_color_space == JCS_EXT_RGB || | 827 | | cinfo->in_color_space == JCS_RGB)) { | 828 | | #else | 829 | | cinfo->in_color_space == JCS_EXT_RGB) { | 830 | | #endif | 831 | | source->pub.get_pixel_rows = get_raw_row; | 832 | | use_raw_buffer = TRUE; | 833 | | need_rescale = FALSE; | 834 | | #endif | 835 | 3.30k | } else { | 836 | 2.52k | if (IsExtRGB(cinfo->in_color_space)) | 837 | 1.80k | source->pub.get_pixel_rows = get_rgb_row; | 838 | 722 | else if (cinfo->in_color_space == JCS_CMYK) | 839 | 361 | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 840 | 361 | else | 841 | 361 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 842 | 2.52k | } | 843 | 5.83k | break; | 844 | 24.9k | } | 845 | | | 846 | 20.6k | if (IsExtRGB(cinfo->in_color_space)) | 847 | 15.6k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 848 | 4.98k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 849 | 1.84k | cinfo->input_components = 1; | 850 | 3.13k | else if (cinfo->in_color_space == JCS_CMYK) | 851 | 3.13k | cinfo->input_components = 4; | 852 | | | 853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 854 | 20.6k | if (need_iobuffer) { | 855 | 15.2k | if (c == '6') | 856 | 4.99k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); | 857 | 10.2k | else | 858 | 10.2k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); | 859 | 15.2k | source->iobuffer = (unsigned char *) | 860 | 15.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 861 | 15.2k | source->buffer_width); | 862 | 15.2k | } | 863 | | | 864 | | /* Create compressor input buffer. */ | 865 | 20.6k | if (use_raw_buffer) { | 866 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 867 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 868 | 0 | source->pixrow = (_JSAMPROW)source->iobuffer; | 869 | 0 | source->pub._buffer = &source->pixrow; | 870 | 0 | source->pub.buffer_height = 1; | 871 | 20.6k | } else { | 872 | | /* Need to translate anyway, so make a separate sample buffer. */ | 873 | 20.6k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 874 | 20.6k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 875 | 20.6k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); | 876 | 20.6k | source->pub.buffer_height = 1; | 877 | 20.6k | } | 878 | | | 879 | | /* Compute the rescaling array if required. */ | 880 | 20.6k | if (need_rescale) { | 881 | 20.6k | size_t val, half_maxval; | 882 | | | 883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ | 884 | 20.6k | source->rescale = (_JSAMPLE *) | 885 | 20.6k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 886 | 20.6k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 887 | 20.6k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 888 | 20.6k | half_maxval = (size_t)maxval / 2; | 889 | 276M | for (val = 0; val <= (size_t)maxval; val++) { | 890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 891 | 276M | source->rescale[val] = | 892 | 276M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 893 | 276M | maxval); | 894 | 276M | } | 895 | 20.6k | } | 896 | 20.6k | } |
|
897 | | |
898 | | |
899 | | METHODDEF(boolean) |
900 | | read_icc_profile_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo, |
901 | | JOCTET **icc_data_ptr, unsigned int *icc_data_len) |
902 | 1.11k | { |
903 | 1.11k | return FALSE; |
904 | 1.11k | } rdppm-8.c:read_icc_profile_ppm Line | Count | Source | 902 | 1.11k | { | 903 | 1.11k | return FALSE; | 904 | 1.11k | } |
Unexecuted instantiation: rdppm-12.c:read_icc_profile_ppm Unexecuted instantiation: rdppm-16.c:read_icc_profile_ppm |
905 | | |
906 | | |
907 | | /* |
908 | | * Finish up at the end of the file. |
909 | | */ |
910 | | |
911 | | METHODDEF(void) |
912 | | finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
913 | 132k | { |
914 | | /* no work */ |
915 | 132k | } rdppm-8.c:finish_input_ppm Line | Count | Source | 913 | 72.0k | { | 914 | | /* no work */ | 915 | 72.0k | } |
rdppm-12.c:finish_input_ppm Line | Count | Source | 913 | 43.9k | { | 914 | | /* no work */ | 915 | 43.9k | } |
rdppm-16.c:finish_input_ppm Line | Count | Source | 913 | 16.7k | { | 914 | | /* no work */ | 915 | 16.7k | } |
|
916 | | |
917 | | |
918 | | /* |
919 | | * The module selection routine for PPM format input. |
920 | | */ |
921 | | |
922 | | GLOBAL(cjpeg_source_ptr) |
923 | | _jinit_read_ppm(j_compress_ptr cinfo) |
924 | 179k | { |
925 | 179k | ppm_source_ptr source; |
926 | | |
927 | | #if BITS_IN_JSAMPLE == 8 |
928 | 94.1k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
929 | | #else |
930 | 85.5k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
931 | 85.5k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
932 | 0 | #endif |
933 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
934 | | |
935 | | /* Create module interface object */ |
936 | 179k | source = (ppm_source_ptr) |
937 | 179k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
938 | 179k | sizeof(ppm_source_struct)); |
939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
940 | 179k | source->pub.start_input = start_input_ppm; |
941 | 179k | source->pub.read_icc_profile = read_icc_profile_ppm; |
942 | 179k | source->pub.finish_input = finish_input_ppm; |
943 | 179k | source->pub.max_pixels = 0; |
944 | | |
945 | 179k | return (cjpeg_source_ptr)source; |
946 | 179k | } Line | Count | Source | 924 | 94.1k | { | 925 | 94.1k | ppm_source_ptr source; | 926 | | | 927 | 94.1k | #if BITS_IN_JSAMPLE == 8 | 928 | 94.1k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 929 | | #else | 930 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 931 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 932 | | #endif | 933 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 934 | | | 935 | | /* Create module interface object */ | 936 | 94.1k | source = (ppm_source_ptr) | 937 | 94.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 938 | 94.1k | sizeof(ppm_source_struct)); | 939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 940 | 94.1k | source->pub.start_input = start_input_ppm; | 941 | 94.1k | source->pub.read_icc_profile = read_icc_profile_ppm; | 942 | 94.1k | source->pub.finish_input = finish_input_ppm; | 943 | 94.1k | source->pub.max_pixels = 0; | 944 | | | 945 | 94.1k | return (cjpeg_source_ptr)source; | 946 | 94.1k | } |
Line | Count | Source | 924 | 60.5k | { | 925 | 60.5k | ppm_source_ptr source; | 926 | | | 927 | | #if BITS_IN_JSAMPLE == 8 | 928 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 929 | | #else | 930 | 60.5k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 931 | 60.5k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 932 | 0 | #endif | 933 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 934 | | | 935 | | /* Create module interface object */ | 936 | 60.5k | source = (ppm_source_ptr) | 937 | 60.5k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 938 | 60.5k | sizeof(ppm_source_struct)); | 939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 940 | 60.5k | source->pub.start_input = start_input_ppm; | 941 | 60.5k | source->pub.read_icc_profile = read_icc_profile_ppm; | 942 | 60.5k | source->pub.finish_input = finish_input_ppm; | 943 | 60.5k | source->pub.max_pixels = 0; | 944 | | | 945 | 60.5k | return (cjpeg_source_ptr)source; | 946 | 60.5k | } |
Line | Count | Source | 924 | 25.0k | { | 925 | 25.0k | ppm_source_ptr source; | 926 | | | 927 | | #if BITS_IN_JSAMPLE == 8 | 928 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 929 | | #else | 930 | 25.0k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 931 | 25.0k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 932 | 0 | #endif | 933 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 934 | | | 935 | | /* Create module interface object */ | 936 | 25.0k | source = (ppm_source_ptr) | 937 | 25.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 938 | 25.0k | sizeof(ppm_source_struct)); | 939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 940 | 25.0k | source->pub.start_input = start_input_ppm; | 941 | 25.0k | source->pub.read_icc_profile = read_icc_profile_ppm; | 942 | 25.0k | source->pub.finish_input = finish_input_ppm; | 943 | 25.0k | source->pub.max_pixels = 0; | 944 | | | 945 | 25.0k | return (cjpeg_source_ptr)source; | 946 | 25.0k | } |
|
947 | | |
948 | | #endif /* defined(PPM_SUPPORTED) && |
949 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ |