/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 | 242M | (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 | 4.13M | { |
74 | 4.13M | register int ch; |
75 | | |
76 | 4.13M | ch = getc(infile); |
77 | 4.13M | if (ch == '#') { |
78 | 705k | do { |
79 | 705k | ch = getc(infile); |
80 | 705k | } while (ch != '\n' && ch != EOF); |
81 | 60.4k | } |
82 | 4.13M | return ch; |
83 | 4.13M | } Line | Count | Source | 73 | 2.03M | { | 74 | 2.03M | register int ch; | 75 | | | 76 | 2.03M | ch = getc(infile); | 77 | 2.03M | if (ch == '#') { | 78 | 369k | do { | 79 | 369k | ch = getc(infile); | 80 | 369k | } while (ch != '\n' && ch != EOF); | 81 | 32.7k | } | 82 | 2.03M | return ch; | 83 | 2.03M | } |
Line | Count | Source | 73 | 1.37M | { | 74 | 1.37M | register int ch; | 75 | | | 76 | 1.37M | ch = getc(infile); | 77 | 1.37M | if (ch == '#') { | 78 | 235k | do { | 79 | 235k | ch = getc(infile); | 80 | 235k | } while (ch != '\n' && ch != EOF); | 81 | 18.3k | } | 82 | 1.37M | return ch; | 83 | 1.37M | } |
Line | Count | Source | 73 | 726k | { | 74 | 726k | register int ch; | 75 | | | 76 | 726k | ch = getc(infile); | 77 | 726k | if (ch == '#') { | 78 | 100k | do { | 79 | 100k | ch = getc(infile); | 80 | 100k | } while (ch != '\n' && ch != EOF); | 81 | 9.42k | } | 82 | 726k | return ch; | 83 | 726k | } |
|
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.66M | { |
93 | 1.66M | register int ch; |
94 | 1.66M | register unsigned int val; |
95 | | |
96 | | /* Skip any leading whitespace */ |
97 | 1.86M | do { |
98 | 1.86M | ch = pbm_getc(infile); |
99 | 1.86M | if (ch == EOF) |
100 | 35.5k | ERREXIT(cinfo, JERR_INPUT_EOF); |
101 | 1.86M | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); |
102 | | |
103 | 1.66M | if (ch < '0' || ch > '9') |
104 | 4.54k | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); |
105 | | |
106 | 1.66M | val = ch - '0'; |
107 | 2.31M | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { |
108 | 646k | val *= 10; |
109 | 646k | val += ch - '0'; |
110 | 646k | if (val > maxval) |
111 | 1.77k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
112 | 646k | } |
113 | | |
114 | 1.66M | return val; |
115 | 1.66M | } rdppm-8.c:read_pbm_integer Line | Count | Source | 92 | 816k | { | 93 | 816k | register int ch; | 94 | 816k | register unsigned int val; | 95 | | | 96 | | /* Skip any leading whitespace */ | 97 | 914k | do { | 98 | 914k | ch = pbm_getc(infile); | 99 | 914k | if (ch == EOF) | 100 | 17.0k | ERREXIT(cinfo, JERR_INPUT_EOF); | 101 | 914k | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); | 102 | | | 103 | 816k | if (ch < '0' || ch > '9') | 104 | 2.08k | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); | 105 | | | 106 | 816k | val = ch - '0'; | 107 | 1.13M | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { | 108 | 321k | val *= 10; | 109 | 321k | val += ch - '0'; | 110 | 321k | if (val > maxval) | 111 | 936 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 112 | 321k | } | 113 | | | 114 | 816k | return val; | 115 | 816k | } |
rdppm-12.c:read_pbm_integer Line | Count | Source | 92 | 550k | { | 93 | 550k | register int ch; | 94 | 550k | register unsigned int val; | 95 | | | 96 | | /* Skip any leading whitespace */ | 97 | 613k | do { | 98 | 613k | ch = pbm_getc(infile); | 99 | 613k | if (ch == EOF) | 100 | 12.0k | ERREXIT(cinfo, JERR_INPUT_EOF); | 101 | 613k | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); | 102 | | | 103 | 550k | if (ch < '0' || ch > '9') | 104 | 1.74k | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); | 105 | | | 106 | 550k | val = ch - '0'; | 107 | 774k | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { | 108 | 223k | val *= 10; | 109 | 223k | val += ch - '0'; | 110 | 223k | if (val > maxval) | 111 | 556 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 112 | 223k | } | 113 | | | 114 | 550k | return val; | 115 | 550k | } |
rdppm-16.c:read_pbm_integer Line | Count | Source | 92 | 298k | { | 93 | 298k | register int ch; | 94 | 298k | register unsigned int val; | 95 | | | 96 | | /* Skip any leading whitespace */ | 97 | 334k | do { | 98 | 334k | ch = pbm_getc(infile); | 99 | 334k | if (ch == EOF) | 100 | 6.53k | ERREXIT(cinfo, JERR_INPUT_EOF); | 101 | 334k | } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); | 102 | | | 103 | 298k | if (ch < '0' || ch > '9') | 104 | 716 | ERREXIT(cinfo, JERR_PPM_NONNUMERIC); | 105 | | | 106 | 298k | val = ch - '0'; | 107 | 399k | while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { | 108 | 100k | val *= 10; | 109 | 100k | val += ch - '0'; | 110 | 100k | if (val > maxval) | 111 | 278 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 112 | 100k | } | 113 | | | 114 | 298k | return val; | 115 | 298k | } |
|
116 | | |
117 | | |
118 | | /* |
119 | | * Read one row of pixels. |
120 | | * |
121 | | * We provide several different versions depending on input file format. |
122 | | * In all cases, input is scaled to cinfo->data_precision. |
123 | | * |
124 | | * A really fast path is provided for reading byte/sample raw files with |
125 | | * maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U, |
126 | | * which is the normal case for 8-bit data. |
127 | | */ |
128 | | |
129 | | |
130 | | METHODDEF(JDIMENSION) |
131 | | get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
132 | | /* This version is for reading text-format PGM files with any maxval */ |
133 | 21.7k | { |
134 | 21.7k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
135 | 21.7k | FILE *infile = source->pub.input_file; |
136 | 21.7k | register _JSAMPROW ptr; |
137 | 21.7k | register _JSAMPLE *rescale = source->rescale; |
138 | 21.7k | JDIMENSION col; |
139 | 21.7k | unsigned int maxval = source->maxval; |
140 | | |
141 | 21.7k | ptr = source->pub._buffer[0]; |
142 | 62.5k | for (col = cinfo->image_width; col > 0; col--) { |
143 | 40.7k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
144 | 40.7k | } |
145 | 21.7k | return 1; |
146 | 21.7k | } rdppm-8.c:get_text_gray_row Line | Count | Source | 133 | 11.0k | { | 134 | 11.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 135 | 11.0k | FILE *infile = source->pub.input_file; | 136 | 11.0k | register _JSAMPROW ptr; | 137 | 11.0k | register _JSAMPLE *rescale = source->rescale; | 138 | 11.0k | JDIMENSION col; | 139 | 11.0k | unsigned int maxval = source->maxval; | 140 | | | 141 | 11.0k | ptr = source->pub._buffer[0]; | 142 | 33.3k | for (col = cinfo->image_width; col > 0; col--) { | 143 | 22.2k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 144 | 22.2k | } | 145 | 11.0k | return 1; | 146 | 11.0k | } |
rdppm-12.c:get_text_gray_row Line | Count | Source | 133 | 7.27k | { | 134 | 7.27k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 135 | 7.27k | FILE *infile = source->pub.input_file; | 136 | 7.27k | register _JSAMPROW ptr; | 137 | 7.27k | register _JSAMPLE *rescale = source->rescale; | 138 | 7.27k | JDIMENSION col; | 139 | 7.27k | unsigned int maxval = source->maxval; | 140 | | | 141 | 7.27k | ptr = source->pub._buffer[0]; | 142 | 18.8k | for (col = cinfo->image_width; col > 0; col--) { | 143 | 11.5k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 144 | 11.5k | } | 145 | 7.27k | return 1; | 146 | 7.27k | } |
rdppm-16.c:get_text_gray_row Line | Count | Source | 133 | 3.50k | { | 134 | 3.50k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 135 | 3.50k | FILE *infile = source->pub.input_file; | 136 | 3.50k | register _JSAMPROW ptr; | 137 | 3.50k | register _JSAMPLE *rescale = source->rescale; | 138 | 3.50k | JDIMENSION col; | 139 | 3.50k | unsigned int maxval = source->maxval; | 140 | | | 141 | 3.50k | ptr = source->pub._buffer[0]; | 142 | 10.3k | for (col = cinfo->image_width; col > 0; col--) { | 143 | 6.88k | *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 144 | 6.88k | } | 145 | 3.50k | return 1; | 146 | 3.50k | } |
|
147 | | |
148 | | |
149 | 172M | #define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \ |
150 | 952M | for (col = cinfo->image_width; col > 0; col--) { \ |
151 | 780M | ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \ |
152 | 780M | alpha_set_op \ |
153 | 780M | ptr += ps; \ |
154 | 780M | } \ |
155 | 172M | } |
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 | 104k | { |
162 | 104k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
163 | 104k | FILE *infile = source->pub.input_file; |
164 | 104k | register _JSAMPROW ptr; |
165 | 104k | register _JSAMPLE *rescale = source->rescale; |
166 | 104k | JDIMENSION col; |
167 | 104k | unsigned int maxval = source->maxval; |
168 | 104k | register int rindex = rgb_red[cinfo->in_color_space]; |
169 | 104k | register int gindex = rgb_green[cinfo->in_color_space]; |
170 | 104k | register int bindex = rgb_blue[cinfo->in_color_space]; |
171 | 104k | register int aindex = alpha_index[cinfo->in_color_space]; |
172 | 104k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
173 | | |
174 | 104k | ptr = source->pub._buffer[0]; |
175 | 104k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
176 | 19.6k | if (aindex >= 0) |
177 | 3.28k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), |
178 | 19.6k | ptr[aindex] = (_JSAMPLE)maxval;) |
179 | 16.3k | else |
180 | 16.3k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) |
181 | 85.3k | } else { |
182 | 85.3k | if (aindex >= 0) |
183 | 14.1k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], |
184 | 85.3k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
185 | 71.1k | else |
186 | 71.1k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) |
187 | 85.3k | } |
188 | 104k | return 1; |
189 | 104k | } rdppm-8.c:get_text_gray_rgb_row Line | Count | Source | 161 | 51.0k | { | 162 | 51.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 163 | 51.0k | FILE *infile = source->pub.input_file; | 164 | 51.0k | register _JSAMPROW ptr; | 165 | 51.0k | register _JSAMPLE *rescale = source->rescale; | 166 | 51.0k | JDIMENSION col; | 167 | 51.0k | unsigned int maxval = source->maxval; | 168 | 51.0k | register int rindex = rgb_red[cinfo->in_color_space]; | 169 | 51.0k | register int gindex = rgb_green[cinfo->in_color_space]; | 170 | 51.0k | register int bindex = rgb_blue[cinfo->in_color_space]; | 171 | 51.0k | register int aindex = alpha_index[cinfo->in_color_space]; | 172 | 51.0k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 173 | | | 174 | 51.0k | ptr = source->pub._buffer[0]; | 175 | 51.0k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 176 | 10.3k | if (aindex >= 0) | 177 | 1.61k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 178 | 10.3k | ptr[aindex] = (_JSAMPLE)maxval;) | 179 | 8.76k | else | 180 | 8.76k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 181 | 40.6k | } else { | 182 | 40.6k | if (aindex >= 0) | 183 | 5.05k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 184 | 40.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 185 | 35.6k | else | 186 | 35.6k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 187 | 40.6k | } | 188 | 51.0k | return 1; | 189 | 51.0k | } |
rdppm-12.c:get_text_gray_rgb_row Line | Count | Source | 161 | 36.3k | { | 162 | 36.3k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 163 | 36.3k | FILE *infile = source->pub.input_file; | 164 | 36.3k | register _JSAMPROW ptr; | 165 | 36.3k | register _JSAMPLE *rescale = source->rescale; | 166 | 36.3k | JDIMENSION col; | 167 | 36.3k | unsigned int maxval = source->maxval; | 168 | 36.3k | register int rindex = rgb_red[cinfo->in_color_space]; | 169 | 36.3k | register int gindex = rgb_green[cinfo->in_color_space]; | 170 | 36.3k | register int bindex = rgb_blue[cinfo->in_color_space]; | 171 | 36.3k | register int aindex = alpha_index[cinfo->in_color_space]; | 172 | 36.3k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 173 | | | 174 | 36.3k | ptr = source->pub._buffer[0]; | 175 | 36.3k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 176 | 6.65k | if (aindex >= 0) | 177 | 1.23k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 178 | 6.65k | ptr[aindex] = (_JSAMPLE)maxval;) | 179 | 5.41k | else | 180 | 5.41k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 181 | 29.6k | } else { | 182 | 29.6k | if (aindex >= 0) | 183 | 6.03k | 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 | 36.3k | return 1; | 189 | 36.3k | } |
rdppm-16.c:get_text_gray_rgb_row Line | Count | Source | 161 | 17.5k | { | 162 | 17.5k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 163 | 17.5k | FILE *infile = source->pub.input_file; | 164 | 17.5k | register _JSAMPROW ptr; | 165 | 17.5k | register _JSAMPLE *rescale = source->rescale; | 166 | 17.5k | JDIMENSION col; | 167 | 17.5k | unsigned int maxval = source->maxval; | 168 | 17.5k | register int rindex = rgb_red[cinfo->in_color_space]; | 169 | 17.5k | register int gindex = rgb_green[cinfo->in_color_space]; | 170 | 17.5k | register int bindex = rgb_blue[cinfo->in_color_space]; | 171 | 17.5k | register int aindex = alpha_index[cinfo->in_color_space]; | 172 | 17.5k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 173 | | | 174 | 17.5k | ptr = source->pub._buffer[0]; | 175 | 17.5k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 176 | 2.58k | if (aindex >= 0) | 177 | 432 | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 178 | 2.58k | ptr[aindex] = (_JSAMPLE)maxval;) | 179 | 2.14k | else | 180 | 2.14k | GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 181 | 14.9k | } else { | 182 | 14.9k | if (aindex >= 0) | 183 | 3.07k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 184 | 14.9k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 185 | 11.8k | else | 186 | 11.8k | GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 187 | 14.9k | } | 188 | 17.5k | return 1; | 189 | 17.5k | } |
|
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.4k | { |
197 | 17.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
198 | 17.4k | FILE *infile = source->pub.input_file; |
199 | 17.4k | register _JSAMPROW ptr; |
200 | 17.4k | register _JSAMPLE *rescale = source->rescale; |
201 | 17.4k | JDIMENSION col; |
202 | 17.4k | unsigned int maxval = source->maxval; |
203 | | |
204 | 17.4k | ptr = source->pub._buffer[0]; |
205 | 17.4k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
206 | 14.4k | for (col = cinfo->image_width; col > 0; col--) { |
207 | 9.40k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
208 | 9.40k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); |
209 | 9.40k | ptr += 4; |
210 | 9.40k | } |
211 | 12.3k | } else { |
212 | 34.7k | for (col = cinfo->image_width; col > 0; col--) { |
213 | 22.4k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
214 | 22.4k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
215 | 22.4k | ptr + 1, ptr + 2, ptr + 3); |
216 | 22.4k | ptr += 4; |
217 | 22.4k | } |
218 | 12.3k | } |
219 | 17.4k | return 1; |
220 | 17.4k | } rdppm-8.c:get_text_gray_cmyk_row Line | Count | Source | 196 | 6.66k | { | 197 | 6.66k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 198 | 6.66k | FILE *infile = source->pub.input_file; | 199 | 6.66k | register _JSAMPROW ptr; | 200 | 6.66k | register _JSAMPLE *rescale = source->rescale; | 201 | 6.66k | JDIMENSION col; | 202 | 6.66k | unsigned int maxval = source->maxval; | 203 | | | 204 | 6.66k | ptr = source->pub._buffer[0]; | 205 | 6.66k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 206 | 7.02k | for (col = cinfo->image_width; col > 0; col--) { | 207 | 4.50k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 208 | 4.50k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 209 | 4.50k | ptr += 4; | 210 | 4.50k | } | 211 | 4.15k | } else { | 212 | 13.0k | for (col = cinfo->image_width; col > 0; col--) { | 213 | 8.87k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 214 | 8.87k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 215 | 8.87k | ptr + 1, ptr + 2, ptr + 3); | 216 | 8.87k | ptr += 4; | 217 | 8.87k | } | 218 | 4.15k | } | 219 | 6.66k | return 1; | 220 | 6.66k | } |
rdppm-12.c:get_text_gray_cmyk_row Line | Count | Source | 196 | 7.27k | { | 197 | 7.27k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 198 | 7.27k | FILE *infile = source->pub.input_file; | 199 | 7.27k | register _JSAMPROW ptr; | 200 | 7.27k | register _JSAMPLE *rescale = source->rescale; | 201 | 7.27k | JDIMENSION col; | 202 | 7.27k | unsigned int maxval = source->maxval; | 203 | | | 204 | 7.27k | ptr = source->pub._buffer[0]; | 205 | 7.27k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 206 | 4.95k | for (col = cinfo->image_width; col > 0; col--) { | 207 | 3.20k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 208 | 3.20k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 209 | 3.20k | ptr += 4; | 210 | 3.20k | } | 211 | 5.52k | } else { | 212 | 13.8k | for (col = cinfo->image_width; col > 0; col--) { | 213 | 8.34k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 214 | 8.34k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 215 | 8.34k | ptr + 1, ptr + 2, ptr + 3); | 216 | 8.34k | ptr += 4; | 217 | 8.34k | } | 218 | 5.52k | } | 219 | 7.27k | return 1; | 220 | 7.27k | } |
rdppm-16.c:get_text_gray_cmyk_row Line | Count | Source | 196 | 3.50k | { | 197 | 3.50k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 198 | 3.50k | FILE *infile = source->pub.input_file; | 199 | 3.50k | register _JSAMPROW ptr; | 200 | 3.50k | register _JSAMPLE *rescale = source->rescale; | 201 | 3.50k | JDIMENSION col; | 202 | 3.50k | unsigned int maxval = source->maxval; | 203 | | | 204 | 3.50k | ptr = source->pub._buffer[0]; | 205 | 3.50k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 206 | 2.51k | for (col = cinfo->image_width; col > 0; col--) { | 207 | 1.69k | _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 208 | 1.69k | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 209 | 1.69k | ptr += 4; | 210 | 1.69k | } | 211 | 2.69k | } else { | 212 | 7.88k | for (col = cinfo->image_width; col > 0; col--) { | 213 | 5.19k | _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 214 | 5.19k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 215 | 5.19k | ptr + 1, ptr + 2, ptr + 3); | 216 | 5.19k | ptr += 4; | 217 | 5.19k | } | 218 | 2.69k | } | 219 | 3.50k | return 1; | 220 | 3.50k | } |
|
221 | | |
222 | | |
223 | 8.94M | #define RGB_READ_LOOP(read_op, alpha_set_op) { \ |
224 | 77.8M | for (col = cinfo->image_width; col > 0; col--) { \ |
225 | 68.8M | ptr[rindex] = read_op; \ |
226 | 68.8M | ptr[gindex] = read_op; \ |
227 | 68.8M | ptr[bindex] = read_op; \ |
228 | 68.8M | alpha_set_op \ |
229 | 68.8M | ptr += ps; \ |
230 | 68.8M | } \ |
231 | 8.94M | } |
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 | 119k | { |
237 | 119k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
238 | 119k | FILE *infile = source->pub.input_file; |
239 | 119k | register _JSAMPROW ptr; |
240 | 119k | register _JSAMPLE *rescale = source->rescale; |
241 | 119k | JDIMENSION col; |
242 | 119k | unsigned int maxval = source->maxval; |
243 | 119k | register int rindex = rgb_red[cinfo->in_color_space]; |
244 | 119k | register int gindex = rgb_green[cinfo->in_color_space]; |
245 | 119k | register int bindex = rgb_blue[cinfo->in_color_space]; |
246 | 119k | register int aindex = alpha_index[cinfo->in_color_space]; |
247 | 119k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
248 | | |
249 | 119k | ptr = source->pub._buffer[0]; |
250 | 119k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
251 | 26.8k | if (aindex >= 0) |
252 | 4.86k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), |
253 | 26.8k | ptr[aindex] = (_JSAMPLE)maxval;) |
254 | 22.0k | else |
255 | 22.0k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) |
256 | 92.5k | } else { |
257 | 92.5k | if (aindex >= 0) |
258 | 15.1k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], |
259 | 92.5k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
260 | 77.4k | else |
261 | 77.4k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) |
262 | 92.5k | } |
263 | 119k | return 1; |
264 | 119k | } rdppm-8.c:get_text_rgb_row Line | Count | Source | 236 | 57.8k | { | 237 | 57.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 238 | 57.8k | FILE *infile = source->pub.input_file; | 239 | 57.8k | register _JSAMPROW ptr; | 240 | 57.8k | register _JSAMPLE *rescale = source->rescale; | 241 | 57.8k | JDIMENSION col; | 242 | 57.8k | unsigned int maxval = source->maxval; | 243 | 57.8k | register int rindex = rgb_red[cinfo->in_color_space]; | 244 | 57.8k | register int gindex = rgb_green[cinfo->in_color_space]; | 245 | 57.8k | register int bindex = rgb_blue[cinfo->in_color_space]; | 246 | 57.8k | register int aindex = alpha_index[cinfo->in_color_space]; | 247 | 57.8k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 248 | | | 249 | 57.8k | ptr = source->pub._buffer[0]; | 250 | 57.8k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 251 | 13.0k | if (aindex >= 0) | 252 | 1.91k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 253 | 13.0k | ptr[aindex] = (_JSAMPLE)maxval;) | 254 | 11.1k | else | 255 | 11.1k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 256 | 44.7k | } else { | 257 | 44.7k | if (aindex >= 0) | 258 | 5.77k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 259 | 44.7k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 260 | 38.9k | else | 261 | 38.9k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 262 | 44.7k | } | 263 | 57.8k | return 1; | 264 | 57.8k | } |
rdppm-12.c:get_text_rgb_row Line | Count | Source | 236 | 35.8k | { | 237 | 35.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 238 | 35.8k | FILE *infile = source->pub.input_file; | 239 | 35.8k | register _JSAMPROW ptr; | 240 | 35.8k | register _JSAMPLE *rescale = source->rescale; | 241 | 35.8k | JDIMENSION col; | 242 | 35.8k | unsigned int maxval = source->maxval; | 243 | 35.8k | register int rindex = rgb_red[cinfo->in_color_space]; | 244 | 35.8k | register int gindex = rgb_green[cinfo->in_color_space]; | 245 | 35.8k | register int bindex = rgb_blue[cinfo->in_color_space]; | 246 | 35.8k | register int aindex = alpha_index[cinfo->in_color_space]; | 247 | 35.8k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 248 | | | 249 | 35.8k | ptr = source->pub._buffer[0]; | 250 | 35.8k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 251 | 9.36k | if (aindex >= 0) | 252 | 1.95k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 253 | 9.36k | ptr[aindex] = (_JSAMPLE)maxval;) | 254 | 7.41k | else | 255 | 7.41k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 256 | 26.5k | } else { | 257 | 26.5k | if (aindex >= 0) | 258 | 5.21k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 259 | 26.5k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 260 | 21.2k | else | 261 | 21.2k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 262 | 26.5k | } | 263 | 35.8k | return 1; | 264 | 35.8k | } |
rdppm-16.c:get_text_rgb_row Line | Count | Source | 236 | 25.7k | { | 237 | 25.7k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 238 | 25.7k | FILE *infile = source->pub.input_file; | 239 | 25.7k | register _JSAMPROW ptr; | 240 | 25.7k | register _JSAMPLE *rescale = source->rescale; | 241 | 25.7k | JDIMENSION col; | 242 | 25.7k | unsigned int maxval = source->maxval; | 243 | 25.7k | register int rindex = rgb_red[cinfo->in_color_space]; | 244 | 25.7k | register int gindex = rgb_green[cinfo->in_color_space]; | 245 | 25.7k | register int bindex = rgb_blue[cinfo->in_color_space]; | 246 | 25.7k | register int aindex = alpha_index[cinfo->in_color_space]; | 247 | 25.7k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 248 | | | 249 | 25.7k | ptr = source->pub._buffer[0]; | 250 | 25.7k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 251 | 4.40k | if (aindex >= 0) | 252 | 1.00k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), | 253 | 4.40k | ptr[aindex] = (_JSAMPLE)maxval;) | 254 | 3.40k | else | 255 | 3.40k | RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) | 256 | 21.3k | } else { | 257 | 21.3k | if (aindex >= 0) | 258 | 4.14k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], | 259 | 21.3k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 260 | 17.1k | else | 261 | 17.1k | RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) | 262 | 21.3k | } | 263 | 25.7k | return 1; | 264 | 25.7k | } |
|
265 | | |
266 | | |
267 | | METHODDEF(JDIMENSION) |
268 | | get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
269 | | /* This version is for reading text-format PPM files with any maxval and |
270 | | converting to CMYK */ |
271 | 20.0k | { |
272 | 20.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
273 | 20.0k | FILE *infile = source->pub.input_file; |
274 | 20.0k | register _JSAMPROW ptr; |
275 | 20.0k | register _JSAMPLE *rescale = source->rescale; |
276 | 20.0k | JDIMENSION col; |
277 | 20.0k | unsigned int maxval = source->maxval; |
278 | | |
279 | 20.0k | ptr = source->pub._buffer[0]; |
280 | 20.0k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
281 | 23.4k | for (col = cinfo->image_width; col > 0; col--) { |
282 | 17.0k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
283 | 17.0k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
284 | 17.0k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); |
285 | 17.0k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
286 | 17.0k | ptr += 4; |
287 | 17.0k | } |
288 | 13.5k | } else { |
289 | 40.2k | for (col = cinfo->image_width; col > 0; col--) { |
290 | 26.6k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
291 | 26.6k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
292 | 26.6k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; |
293 | 26.6k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
294 | 26.6k | ptr + 2, ptr + 3); |
295 | 26.6k | ptr += 4; |
296 | 26.6k | } |
297 | 13.5k | } |
298 | 20.0k | return 1; |
299 | 20.0k | } rdppm-8.c:get_text_rgb_cmyk_row Line | Count | Source | 271 | 7.68k | { | 272 | 7.68k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 273 | 7.68k | FILE *infile = source->pub.input_file; | 274 | 7.68k | register _JSAMPROW ptr; | 275 | 7.68k | register _JSAMPLE *rescale = source->rescale; | 276 | 7.68k | JDIMENSION col; | 277 | 7.68k | unsigned int maxval = source->maxval; | 278 | | | 279 | 7.68k | ptr = source->pub._buffer[0]; | 280 | 7.68k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 281 | 9.84k | for (col = cinfo->image_width; col > 0; col--) { | 282 | 7.05k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 283 | 7.05k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 284 | 7.05k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 285 | 7.05k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 286 | 7.05k | ptr += 4; | 287 | 7.05k | } | 288 | 4.89k | } else { | 289 | 14.8k | for (col = cinfo->image_width; col > 0; col--) { | 290 | 10.0k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 291 | 10.0k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 292 | 10.0k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 293 | 10.0k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 294 | 10.0k | ptr + 2, ptr + 3); | 295 | 10.0k | ptr += 4; | 296 | 10.0k | } | 297 | 4.89k | } | 298 | 7.68k | return 1; | 299 | 7.68k | } |
rdppm-12.c:get_text_rgb_cmyk_row Line | Count | Source | 271 | 7.17k | { | 272 | 7.17k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 273 | 7.17k | FILE *infile = source->pub.input_file; | 274 | 7.17k | register _JSAMPROW ptr; | 275 | 7.17k | register _JSAMPLE *rescale = source->rescale; | 276 | 7.17k | JDIMENSION col; | 277 | 7.17k | unsigned int maxval = source->maxval; | 278 | | | 279 | 7.17k | ptr = source->pub._buffer[0]; | 280 | 7.17k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 281 | 8.73k | for (col = cinfo->image_width; col > 0; col--) { | 282 | 6.45k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 283 | 6.45k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 284 | 6.45k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 285 | 6.45k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 286 | 6.45k | ptr += 4; | 287 | 6.45k | } | 288 | 4.90k | } else { | 289 | 14.9k | for (col = cinfo->image_width; col > 0; col--) { | 290 | 10.0k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 291 | 10.0k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 292 | 10.0k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 293 | 10.0k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 294 | 10.0k | ptr + 2, ptr + 3); | 295 | 10.0k | ptr += 4; | 296 | 10.0k | } | 297 | 4.90k | } | 298 | 7.17k | return 1; | 299 | 7.17k | } |
rdppm-16.c:get_text_rgb_cmyk_row Line | Count | Source | 271 | 5.14k | { | 272 | 5.14k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 273 | 5.14k | FILE *infile = source->pub.input_file; | 274 | 5.14k | register _JSAMPROW ptr; | 275 | 5.14k | register _JSAMPLE *rescale = source->rescale; | 276 | 5.14k | JDIMENSION col; | 277 | 5.14k | unsigned int maxval = source->maxval; | 278 | | | 279 | 5.14k | ptr = source->pub._buffer[0]; | 280 | 5.14k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 281 | 4.87k | for (col = cinfo->image_width; col > 0; col--) { | 282 | 3.53k | _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 283 | 3.53k | _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 284 | 3.53k | _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); | 285 | 3.53k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 286 | 3.53k | ptr += 4; | 287 | 3.53k | } | 288 | 3.80k | } else { | 289 | 10.3k | for (col = cinfo->image_width; col > 0; col--) { | 290 | 6.55k | _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 291 | 6.55k | _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 292 | 6.55k | _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; | 293 | 6.55k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 294 | 6.55k | ptr + 2, ptr + 3); | 295 | 6.55k | ptr += 4; | 296 | 6.55k | } | 297 | 3.80k | } | 298 | 5.14k | return 1; | 299 | 5.14k | } |
|
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 | 32.1M | { |
306 | 32.1M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
307 | 32.1M | register _JSAMPROW ptr; |
308 | 32.1M | register unsigned char *bufferptr; |
309 | 32.1M | register _JSAMPLE *rescale = source->rescale; |
310 | 32.1M | JDIMENSION col; |
311 | | |
312 | 32.1M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
313 | 1.47k | ERREXIT(cinfo, JERR_INPUT_EOF); |
314 | 32.1M | ptr = source->pub._buffer[0]; |
315 | 32.1M | bufferptr = source->iobuffer; |
316 | 178M | for (col = cinfo->image_width; col > 0; col--) { |
317 | 146M | *ptr++ = rescale[*bufferptr++]; |
318 | 146M | } |
319 | 32.1M | return 1; |
320 | 32.1M | } rdppm-8.c:get_scaled_gray_row Line | Count | Source | 305 | 16.8M | { | 306 | 16.8M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 307 | 16.8M | register _JSAMPROW ptr; | 308 | 16.8M | register unsigned char *bufferptr; | 309 | 16.8M | register _JSAMPLE *rescale = source->rescale; | 310 | 16.8M | JDIMENSION col; | 311 | | | 312 | 16.8M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 313 | 1.00k | ERREXIT(cinfo, JERR_INPUT_EOF); | 314 | 16.8M | ptr = source->pub._buffer[0]; | 315 | 16.8M | bufferptr = source->iobuffer; | 316 | 84.9M | for (col = cinfo->image_width; col > 0; col--) { | 317 | 68.1M | *ptr++ = rescale[*bufferptr++]; | 318 | 68.1M | } | 319 | 16.8M | return 1; | 320 | 16.8M | } |
rdppm-12.c:get_scaled_gray_row Line | Count | Source | 305 | 11.7M | { | 306 | 11.7M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 307 | 11.7M | register _JSAMPROW ptr; | 308 | 11.7M | register unsigned char *bufferptr; | 309 | 11.7M | register _JSAMPLE *rescale = source->rescale; | 310 | 11.7M | JDIMENSION col; | 311 | | | 312 | 11.7M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 313 | 318 | ERREXIT(cinfo, JERR_INPUT_EOF); | 314 | 11.7M | ptr = source->pub._buffer[0]; | 315 | 11.7M | bufferptr = source->iobuffer; | 316 | 70.7M | for (col = cinfo->image_width; col > 0; col--) { | 317 | 58.9M | *ptr++ = rescale[*bufferptr++]; | 318 | 58.9M | } | 319 | 11.7M | return 1; | 320 | 11.7M | } |
rdppm-16.c:get_scaled_gray_row Line | Count | Source | 305 | 3.48M | { | 306 | 3.48M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 307 | 3.48M | register _JSAMPROW ptr; | 308 | 3.48M | register unsigned char *bufferptr; | 309 | 3.48M | register _JSAMPLE *rescale = source->rescale; | 310 | 3.48M | JDIMENSION col; | 311 | | | 312 | 3.48M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 313 | 158 | ERREXIT(cinfo, JERR_INPUT_EOF); | 314 | 3.48M | ptr = source->pub._buffer[0]; | 315 | 3.48M | bufferptr = source->iobuffer; | 316 | 22.8M | for (col = cinfo->image_width; col > 0; col--) { | 317 | 19.3M | *ptr++ = rescale[*bufferptr++]; | 318 | 19.3M | } | 319 | 3.48M | return 1; | 320 | 3.48M | } |
|
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 | 172M | { |
328 | 172M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
329 | 172M | register _JSAMPROW ptr; |
330 | 172M | register unsigned char *bufferptr; |
331 | 172M | register _JSAMPLE *rescale = source->rescale; |
332 | 172M | JDIMENSION col; |
333 | 172M | unsigned int maxval = source->maxval; |
334 | 172M | register int rindex = rgb_red[cinfo->in_color_space]; |
335 | 172M | register int gindex = rgb_green[cinfo->in_color_space]; |
336 | 172M | register int bindex = rgb_blue[cinfo->in_color_space]; |
337 | 172M | register int aindex = alpha_index[cinfo->in_color_space]; |
338 | 172M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
339 | | |
340 | 172M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
341 | 6.24k | ERREXIT(cinfo, JERR_INPUT_EOF); |
342 | 172M | ptr = source->pub._buffer[0]; |
343 | 172M | bufferptr = source->iobuffer; |
344 | 172M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
345 | 12.0M | if (aindex >= 0) |
346 | 1.36M | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) |
347 | 10.6M | else |
348 | 10.6M | GRAY_RGB_READ_LOOP(*bufferptr++, {}) |
349 | 160M | } else { |
350 | 160M | if (aindex >= 0) |
351 | 22.3M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
352 | 160M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
353 | 138M | else |
354 | 138M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) |
355 | 160M | } |
356 | 172M | return 1; |
357 | 172M | } rdppm-8.c:get_gray_rgb_row Line | Count | Source | 327 | 96.2M | { | 328 | 96.2M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 329 | 96.2M | register _JSAMPROW ptr; | 330 | 96.2M | register unsigned char *bufferptr; | 331 | 96.2M | register _JSAMPLE *rescale = source->rescale; | 332 | 96.2M | JDIMENSION col; | 333 | 96.2M | unsigned int maxval = source->maxval; | 334 | 96.2M | register int rindex = rgb_red[cinfo->in_color_space]; | 335 | 96.2M | register int gindex = rgb_green[cinfo->in_color_space]; | 336 | 96.2M | register int bindex = rgb_blue[cinfo->in_color_space]; | 337 | 96.2M | register int aindex = alpha_index[cinfo->in_color_space]; | 338 | 96.2M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 339 | | | 340 | 96.2M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 341 | 3.86k | ERREXIT(cinfo, JERR_INPUT_EOF); | 342 | 96.2M | ptr = source->pub._buffer[0]; | 343 | 96.2M | bufferptr = source->iobuffer; | 344 | 96.2M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 345 | 12.0M | if (aindex >= 0) | 346 | 1.36M | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 347 | 10.6M | else | 348 | 10.6M | GRAY_RGB_READ_LOOP(*bufferptr++, {}) | 349 | 84.2M | } else { | 350 | 84.2M | if (aindex >= 0) | 351 | 7.06M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 352 | 84.2M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 353 | 77.1M | else | 354 | 77.1M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) | 355 | 84.2M | } | 356 | 96.2M | return 1; | 357 | 96.2M | } |
rdppm-12.c:get_gray_rgb_row Line | Count | Source | 327 | 58.9M | { | 328 | 58.9M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 329 | 58.9M | register _JSAMPROW ptr; | 330 | 58.9M | register unsigned char *bufferptr; | 331 | 58.9M | register _JSAMPLE *rescale = source->rescale; | 332 | 58.9M | JDIMENSION col; | 333 | 58.9M | unsigned int maxval = source->maxval; | 334 | 58.9M | register int rindex = rgb_red[cinfo->in_color_space]; | 335 | 58.9M | register int gindex = rgb_green[cinfo->in_color_space]; | 336 | 58.9M | register int bindex = rgb_blue[cinfo->in_color_space]; | 337 | 58.9M | register int aindex = alpha_index[cinfo->in_color_space]; | 338 | 58.9M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 339 | | | 340 | 58.9M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 341 | 1.59k | ERREXIT(cinfo, JERR_INPUT_EOF); | 342 | 58.9M | ptr = source->pub._buffer[0]; | 343 | 58.9M | bufferptr = source->iobuffer; | 344 | 58.9M | 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 | 58.9M | } else { | 350 | 58.9M | if (aindex >= 0) | 351 | 11.7M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 352 | 58.9M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 353 | 47.1M | else | 354 | 47.1M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) | 355 | 58.9M | } | 356 | 58.9M | return 1; | 357 | 58.9M | } |
rdppm-16.c:get_gray_rgb_row Line | Count | Source | 327 | 17.4M | { | 328 | 17.4M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 329 | 17.4M | register _JSAMPROW ptr; | 330 | 17.4M | register unsigned char *bufferptr; | 331 | 17.4M | register _JSAMPLE *rescale = source->rescale; | 332 | 17.4M | JDIMENSION col; | 333 | 17.4M | unsigned int maxval = source->maxval; | 334 | 17.4M | register int rindex = rgb_red[cinfo->in_color_space]; | 335 | 17.4M | register int gindex = rgb_green[cinfo->in_color_space]; | 336 | 17.4M | register int bindex = rgb_blue[cinfo->in_color_space]; | 337 | 17.4M | register int aindex = alpha_index[cinfo->in_color_space]; | 338 | 17.4M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 339 | | | 340 | 17.4M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 341 | 790 | ERREXIT(cinfo, JERR_INPUT_EOF); | 342 | 17.4M | ptr = source->pub._buffer[0]; | 343 | 17.4M | bufferptr = source->iobuffer; | 344 | 17.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 | 17.4M | } else { | 350 | 17.4M | if (aindex >= 0) | 351 | 3.48M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 352 | 17.4M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 353 | 13.9M | else | 354 | 13.9M | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}) | 355 | 17.4M | } | 356 | 17.4M | return 1; | 357 | 17.4M | } |
|
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 | 23.7M | { |
365 | 23.7M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
366 | 23.7M | register _JSAMPROW ptr; |
367 | 23.7M | register unsigned char *bufferptr; |
368 | 23.7M | register _JSAMPLE *rescale = source->rescale; |
369 | 23.7M | JDIMENSION col; |
370 | 23.7M | unsigned int maxval = source->maxval; |
371 | | |
372 | 23.7M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
373 | 1.01k | ERREXIT(cinfo, JERR_INPUT_EOF); |
374 | 23.7M | ptr = source->pub._buffer[0]; |
375 | 23.7M | bufferptr = source->iobuffer; |
376 | 23.7M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
377 | 10.1M | for (col = cinfo->image_width; col > 0; col--) { |
378 | 8.32M | _JSAMPLE gray = *bufferptr++; |
379 | 8.32M | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); |
380 | 8.32M | ptr += 4; |
381 | 8.32M | } |
382 | 21.9M | } else { |
383 | 143M | for (col = cinfo->image_width; col > 0; col--) { |
384 | 121M | _JSAMPLE gray = rescale[*bufferptr++]; |
385 | 121M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
386 | 121M | ptr + 1, ptr + 2, ptr + 3); |
387 | 121M | ptr += 4; |
388 | 121M | } |
389 | 21.9M | } |
390 | 23.7M | return 1; |
391 | 23.7M | } rdppm-8.c:get_gray_cmyk_row Line | Count | Source | 364 | 8.42M | { | 365 | 8.42M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 366 | 8.42M | register _JSAMPROW ptr; | 367 | 8.42M | register unsigned char *bufferptr; | 368 | 8.42M | register _JSAMPLE *rescale = source->rescale; | 369 | 8.42M | JDIMENSION col; | 370 | 8.42M | unsigned int maxval = source->maxval; | 371 | | | 372 | 8.42M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 373 | 542 | ERREXIT(cinfo, JERR_INPUT_EOF); | 374 | 8.42M | ptr = source->pub._buffer[0]; | 375 | 8.42M | bufferptr = source->iobuffer; | 376 | 8.42M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 377 | 10.1M | for (col = cinfo->image_width; col > 0; col--) { | 378 | 8.32M | _JSAMPLE gray = *bufferptr++; | 379 | 8.32M | rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); | 380 | 8.32M | ptr += 4; | 381 | 8.32M | } | 382 | 6.64M | } else { | 383 | 49.7M | for (col = cinfo->image_width; col > 0; col--) { | 384 | 43.1M | _JSAMPLE gray = rescale[*bufferptr++]; | 385 | 43.1M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 386 | 43.1M | ptr + 1, ptr + 2, ptr + 3); | 387 | 43.1M | ptr += 4; | 388 | 43.1M | } | 389 | 6.64M | } | 390 | 8.42M | return 1; | 391 | 8.42M | } |
rdppm-12.c:get_gray_cmyk_row Line | Count | Source | 364 | 11.7M | { | 365 | 11.7M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 366 | 11.7M | register _JSAMPROW ptr; | 367 | 11.7M | register unsigned char *bufferptr; | 368 | 11.7M | register _JSAMPLE *rescale = source->rescale; | 369 | 11.7M | JDIMENSION col; | 370 | 11.7M | unsigned int maxval = source->maxval; | 371 | | | 372 | 11.7M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 373 | 318 | ERREXIT(cinfo, JERR_INPUT_EOF); | 374 | 11.7M | ptr = source->pub._buffer[0]; | 375 | 11.7M | bufferptr = source->iobuffer; | 376 | 11.7M | 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 | 11.7M | } else { | 383 | 70.7M | for (col = cinfo->image_width; col > 0; col--) { | 384 | 58.9M | _JSAMPLE gray = rescale[*bufferptr++]; | 385 | 58.9M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 386 | 58.9M | ptr + 1, ptr + 2, ptr + 3); | 387 | 58.9M | ptr += 4; | 388 | 58.9M | } | 389 | 11.7M | } | 390 | 11.7M | return 1; | 391 | 11.7M | } |
rdppm-16.c:get_gray_cmyk_row Line | Count | Source | 364 | 3.48M | { | 365 | 3.48M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 366 | 3.48M | register _JSAMPROW ptr; | 367 | 3.48M | register unsigned char *bufferptr; | 368 | 3.48M | register _JSAMPLE *rescale = source->rescale; | 369 | 3.48M | JDIMENSION col; | 370 | 3.48M | unsigned int maxval = source->maxval; | 371 | | | 372 | 3.48M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 373 | 158 | ERREXIT(cinfo, JERR_INPUT_EOF); | 374 | 3.48M | ptr = source->pub._buffer[0]; | 375 | 3.48M | bufferptr = source->iobuffer; | 376 | 3.48M | 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 | 3.48M | } else { | 383 | 22.8M | for (col = cinfo->image_width; col > 0; col--) { | 384 | 19.3M | _JSAMPLE gray = rescale[*bufferptr++]; | 385 | 19.3M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 386 | 19.3M | ptr + 1, ptr + 2, ptr + 3); | 387 | 19.3M | ptr += 4; | 388 | 19.3M | } | 389 | 3.48M | } | 390 | 3.48M | return 1; | 391 | 3.48M | } |
|
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 | 8.82M | { |
398 | 8.82M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
399 | 8.82M | register _JSAMPROW ptr; |
400 | 8.82M | register unsigned char *bufferptr; |
401 | 8.82M | register _JSAMPLE *rescale = source->rescale; |
402 | 8.82M | JDIMENSION col; |
403 | 8.82M | unsigned int maxval = source->maxval; |
404 | 8.82M | register int rindex = rgb_red[cinfo->in_color_space]; |
405 | 8.82M | register int gindex = rgb_green[cinfo->in_color_space]; |
406 | 8.82M | register int bindex = rgb_blue[cinfo->in_color_space]; |
407 | 8.82M | register int aindex = alpha_index[cinfo->in_color_space]; |
408 | 8.82M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
409 | | |
410 | 8.82M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
411 | 7.38k | ERREXIT(cinfo, JERR_INPUT_EOF); |
412 | 8.82M | ptr = source->pub._buffer[0]; |
413 | 8.82M | bufferptr = source->iobuffer; |
414 | 8.82M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
415 | 417k | if (aindex >= 0) |
416 | 96.1k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) |
417 | 321k | else |
418 | 321k | RGB_READ_LOOP(*bufferptr++, {}) |
419 | 8.41M | } else { |
420 | 8.41M | if (aindex >= 0) |
421 | 1.64M | RGB_READ_LOOP(rescale[*bufferptr++], |
422 | 8.41M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) |
423 | 6.76M | else |
424 | 6.76M | RGB_READ_LOOP(rescale[*bufferptr++], {}) |
425 | 8.41M | } |
426 | 8.82M | return 1; |
427 | 8.82M | } Line | Count | Source | 397 | 2.67M | { | 398 | 2.67M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 399 | 2.67M | register _JSAMPROW ptr; | 400 | 2.67M | register unsigned char *bufferptr; | 401 | 2.67M | register _JSAMPLE *rescale = source->rescale; | 402 | 2.67M | JDIMENSION col; | 403 | 2.67M | unsigned int maxval = source->maxval; | 404 | 2.67M | register int rindex = rgb_red[cinfo->in_color_space]; | 405 | 2.67M | register int gindex = rgb_green[cinfo->in_color_space]; | 406 | 2.67M | register int bindex = rgb_blue[cinfo->in_color_space]; | 407 | 2.67M | register int aindex = alpha_index[cinfo->in_color_space]; | 408 | 2.67M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 409 | | | 410 | 2.67M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 411 | 4.26k | ERREXIT(cinfo, JERR_INPUT_EOF); | 412 | 2.67M | ptr = source->pub._buffer[0]; | 413 | 2.67M | bufferptr = source->iobuffer; | 414 | 2.67M | if (maxval == (1U << cinfo->data_precision) - 1U) { | 415 | 417k | if (aindex >= 0) | 416 | 96.1k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;) | 417 | 321k | else | 418 | 321k | RGB_READ_LOOP(*bufferptr++, {}) | 419 | 2.26M | } else { | 420 | 2.26M | if (aindex >= 0) | 421 | 420k | RGB_READ_LOOP(rescale[*bufferptr++], | 422 | 2.26M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 423 | 1.84M | else | 424 | 1.84M | RGB_READ_LOOP(rescale[*bufferptr++], {}) | 425 | 2.26M | } | 426 | 2.67M | return 1; | 427 | 2.67M | } |
Line | Count | Source | 397 | 5.19M | { | 398 | 5.19M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 399 | 5.19M | register _JSAMPROW ptr; | 400 | 5.19M | register unsigned char *bufferptr; | 401 | 5.19M | register _JSAMPLE *rescale = source->rescale; | 402 | 5.19M | JDIMENSION col; | 403 | 5.19M | unsigned int maxval = source->maxval; | 404 | 5.19M | register int rindex = rgb_red[cinfo->in_color_space]; | 405 | 5.19M | register int gindex = rgb_green[cinfo->in_color_space]; | 406 | 5.19M | register int bindex = rgb_blue[cinfo->in_color_space]; | 407 | 5.19M | register int aindex = alpha_index[cinfo->in_color_space]; | 408 | 5.19M | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 409 | | | 410 | 5.19M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 411 | 1.99k | ERREXIT(cinfo, JERR_INPUT_EOF); | 412 | 5.19M | ptr = source->pub._buffer[0]; | 413 | 5.19M | bufferptr = source->iobuffer; | 414 | 5.19M | 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 | 5.19M | } else { | 420 | 5.19M | if (aindex >= 0) | 421 | 1.03M | RGB_READ_LOOP(rescale[*bufferptr++], | 422 | 5.19M | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 423 | 4.15M | else | 424 | 4.15M | RGB_READ_LOOP(rescale[*bufferptr++], {}) | 425 | 5.19M | } | 426 | 5.19M | return 1; | 427 | 5.19M | } |
Line | Count | Source | 397 | 953k | { | 398 | 953k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 399 | 953k | register _JSAMPROW ptr; | 400 | 953k | register unsigned char *bufferptr; | 401 | 953k | register _JSAMPLE *rescale = source->rescale; | 402 | 953k | JDIMENSION col; | 403 | 953k | unsigned int maxval = source->maxval; | 404 | 953k | register int rindex = rgb_red[cinfo->in_color_space]; | 405 | 953k | register int gindex = rgb_green[cinfo->in_color_space]; | 406 | 953k | register int bindex = rgb_blue[cinfo->in_color_space]; | 407 | 953k | register int aindex = alpha_index[cinfo->in_color_space]; | 408 | 953k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 409 | | | 410 | 953k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 411 | 1.12k | ERREXIT(cinfo, JERR_INPUT_EOF); | 412 | 953k | ptr = source->pub._buffer[0]; | 413 | 953k | bufferptr = source->iobuffer; | 414 | 953k | 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 | 953k | } else { | 420 | 953k | if (aindex >= 0) | 421 | 190k | RGB_READ_LOOP(rescale[*bufferptr++], | 422 | 953k | ptr[aindex] = (1 << cinfo->data_precision) - 1;) | 423 | 762k | else | 424 | 762k | RGB_READ_LOOP(rescale[*bufferptr++], {}) | 425 | 953k | } | 426 | 953k | return 1; | 427 | 953k | } |
|
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.74M | { |
435 | 1.74M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
436 | 1.74M | register _JSAMPROW ptr; |
437 | 1.74M | register unsigned char *bufferptr; |
438 | 1.74M | register _JSAMPLE *rescale = source->rescale; |
439 | 1.74M | JDIMENSION col; |
440 | 1.74M | unsigned int maxval = source->maxval; |
441 | | |
442 | 1.74M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
443 | 1.27k | ERREXIT(cinfo, JERR_INPUT_EOF); |
444 | 1.74M | ptr = source->pub._buffer[0]; |
445 | 1.74M | bufferptr = source->iobuffer; |
446 | 1.74M | if (maxval == (1U << cinfo->data_precision) - 1U) { |
447 | 798k | for (col = cinfo->image_width; col > 0; col--) { |
448 | 698k | _JSAMPLE r = *bufferptr++; |
449 | 698k | _JSAMPLE g = *bufferptr++; |
450 | 698k | _JSAMPLE b = *bufferptr++; |
451 | 698k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
452 | 698k | ptr += 4; |
453 | 698k | } |
454 | 1.64M | } else { |
455 | 14.5M | for (col = cinfo->image_width; col > 0; col--) { |
456 | 12.9M | _JSAMPLE r = rescale[*bufferptr++]; |
457 | 12.9M | _JSAMPLE g = rescale[*bufferptr++]; |
458 | 12.9M | _JSAMPLE b = rescale[*bufferptr++]; |
459 | 12.9M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
460 | 12.9M | ptr + 2, ptr + 3); |
461 | 12.9M | ptr += 4; |
462 | 12.9M | } |
463 | 1.64M | } |
464 | 1.74M | return 1; |
465 | 1.74M | } rdppm-8.c:get_rgb_cmyk_row Line | Count | Source | 434 | 517k | { | 435 | 517k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 436 | 517k | register _JSAMPROW ptr; | 437 | 517k | register unsigned char *bufferptr; | 438 | 517k | register _JSAMPLE *rescale = source->rescale; | 439 | 517k | JDIMENSION col; | 440 | 517k | unsigned int maxval = source->maxval; | 441 | | | 442 | 517k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 443 | 653 | ERREXIT(cinfo, JERR_INPUT_EOF); | 444 | 517k | ptr = source->pub._buffer[0]; | 445 | 517k | bufferptr = source->iobuffer; | 446 | 517k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 447 | 798k | for (col = cinfo->image_width; col > 0; col--) { | 448 | 698k | _JSAMPLE r = *bufferptr++; | 449 | 698k | _JSAMPLE g = *bufferptr++; | 450 | 698k | _JSAMPLE b = *bufferptr++; | 451 | 698k | rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 452 | 698k | ptr += 4; | 453 | 698k | } | 454 | 417k | } else { | 455 | 3.42M | for (col = cinfo->image_width; col > 0; col--) { | 456 | 3.00M | _JSAMPLE r = rescale[*bufferptr++]; | 457 | 3.00M | _JSAMPLE g = rescale[*bufferptr++]; | 458 | 3.00M | _JSAMPLE b = rescale[*bufferptr++]; | 459 | 3.00M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 460 | 3.00M | ptr + 2, ptr + 3); | 461 | 3.00M | ptr += 4; | 462 | 3.00M | } | 463 | 417k | } | 464 | 517k | return 1; | 465 | 517k | } |
rdppm-12.c:get_rgb_cmyk_row Line | Count | Source | 434 | 1.03M | { | 435 | 1.03M | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 436 | 1.03M | register _JSAMPROW ptr; | 437 | 1.03M | register unsigned char *bufferptr; | 438 | 1.03M | register _JSAMPLE *rescale = source->rescale; | 439 | 1.03M | JDIMENSION col; | 440 | 1.03M | unsigned int maxval = source->maxval; | 441 | | | 442 | 1.03M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 443 | 399 | ERREXIT(cinfo, JERR_INPUT_EOF); | 444 | 1.03M | ptr = source->pub._buffer[0]; | 445 | 1.03M | bufferptr = source->iobuffer; | 446 | 1.03M | 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.03M | } else { | 455 | 8.91M | for (col = cinfo->image_width; col > 0; col--) { | 456 | 7.87M | _JSAMPLE r = rescale[*bufferptr++]; | 457 | 7.87M | _JSAMPLE g = rescale[*bufferptr++]; | 458 | 7.87M | _JSAMPLE b = rescale[*bufferptr++]; | 459 | 7.87M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 460 | 7.87M | ptr + 2, ptr + 3); | 461 | 7.87M | ptr += 4; | 462 | 7.87M | } | 463 | 1.03M | } | 464 | 1.03M | return 1; | 465 | 1.03M | } |
rdppm-16.c:get_rgb_cmyk_row Line | Count | Source | 434 | 190k | { | 435 | 190k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 436 | 190k | register _JSAMPROW ptr; | 437 | 190k | register unsigned char *bufferptr; | 438 | 190k | register _JSAMPLE *rescale = source->rescale; | 439 | 190k | JDIMENSION col; | 440 | 190k | unsigned int maxval = source->maxval; | 441 | | | 442 | 190k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 443 | 225 | ERREXIT(cinfo, JERR_INPUT_EOF); | 444 | 190k | ptr = source->pub._buffer[0]; | 445 | 190k | bufferptr = source->iobuffer; | 446 | 190k | 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 | 190k | } else { | 455 | 2.20M | for (col = cinfo->image_width; col > 0; col--) { | 456 | 2.01M | _JSAMPLE r = rescale[*bufferptr++]; | 457 | 2.01M | _JSAMPLE g = rescale[*bufferptr++]; | 458 | 2.01M | _JSAMPLE b = rescale[*bufferptr++]; | 459 | 2.01M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 460 | 2.01M | ptr + 2, ptr + 3); | 461 | 2.01M | ptr += 4; | 462 | 2.01M | } | 463 | 190k | } | 464 | 190k | return 1; | 465 | 190k | } |
|
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 | 2.53M | { |
478 | 2.53M | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
479 | | |
480 | 2.53M | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
481 | 423 | ERREXIT(cinfo, JERR_INPUT_EOF); |
482 | 2.53M | return 1; |
483 | 2.53M | } |
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 | 139k | { |
492 | 139k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
493 | 139k | register _JSAMPROW ptr; |
494 | 139k | register unsigned char *bufferptr; |
495 | 139k | register _JSAMPLE *rescale = source->rescale; |
496 | 139k | JDIMENSION col; |
497 | 139k | unsigned int maxval = source->maxval; |
498 | | |
499 | 139k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
500 | 1.12k | ERREXIT(cinfo, JERR_INPUT_EOF); |
501 | 139k | ptr = source->pub._buffer[0]; |
502 | 139k | bufferptr = source->iobuffer; |
503 | 439k | for (col = cinfo->image_width; col > 0; col--) { |
504 | 300k | register unsigned int temp; |
505 | 300k | temp = (*bufferptr++) << 8; |
506 | 300k | temp |= (*bufferptr++); |
507 | 300k | if (temp > maxval) |
508 | 690 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
509 | 300k | *ptr++ = rescale[temp]; |
510 | 300k | } |
511 | 139k | return 1; |
512 | 139k | } rdppm-8.c:get_word_gray_row Line | Count | Source | 491 | 15.6k | { | 492 | 15.6k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 493 | 15.6k | register _JSAMPROW ptr; | 494 | 15.6k | register unsigned char *bufferptr; | 495 | 15.6k | register _JSAMPLE *rescale = source->rescale; | 496 | 15.6k | JDIMENSION col; | 497 | 15.6k | unsigned int maxval = source->maxval; | 498 | | | 499 | 15.6k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 500 | 536 | ERREXIT(cinfo, JERR_INPUT_EOF); | 501 | 15.6k | ptr = source->pub._buffer[0]; | 502 | 15.6k | bufferptr = source->iobuffer; | 503 | 73.6k | for (col = cinfo->image_width; col > 0; col--) { | 504 | 57.9k | register unsigned int temp; | 505 | 57.9k | temp = (*bufferptr++) << 8; | 506 | 57.9k | temp |= (*bufferptr++); | 507 | 57.9k | if (temp > maxval) | 508 | 342 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 509 | 57.9k | *ptr++ = rescale[temp]; | 510 | 57.9k | } | 511 | 15.6k | return 1; | 512 | 15.6k | } |
rdppm-12.c:get_word_gray_row Line | Count | Source | 491 | 94.8k | { | 492 | 94.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 493 | 94.8k | register _JSAMPROW ptr; | 494 | 94.8k | register unsigned char *bufferptr; | 495 | 94.8k | register _JSAMPLE *rescale = source->rescale; | 496 | 94.8k | JDIMENSION col; | 497 | 94.8k | unsigned int maxval = source->maxval; | 498 | | | 499 | 94.8k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 500 | 369 | ERREXIT(cinfo, JERR_INPUT_EOF); | 501 | 94.8k | ptr = source->pub._buffer[0]; | 502 | 94.8k | bufferptr = source->iobuffer; | 503 | 200k | for (col = cinfo->image_width; col > 0; col--) { | 504 | 105k | register unsigned int temp; | 505 | 105k | temp = (*bufferptr++) << 8; | 506 | 105k | temp |= (*bufferptr++); | 507 | 105k | if (temp > maxval) | 508 | 273 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 509 | 105k | *ptr++ = rescale[temp]; | 510 | 105k | } | 511 | 94.8k | return 1; | 512 | 94.8k | } |
rdppm-16.c:get_word_gray_row Line | Count | Source | 491 | 29.1k | { | 492 | 29.1k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 493 | 29.1k | register _JSAMPROW ptr; | 494 | 29.1k | register unsigned char *bufferptr; | 495 | 29.1k | register _JSAMPLE *rescale = source->rescale; | 496 | 29.1k | JDIMENSION col; | 497 | 29.1k | unsigned int maxval = source->maxval; | 498 | | | 499 | 29.1k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 500 | 224 | ERREXIT(cinfo, JERR_INPUT_EOF); | 501 | 29.1k | ptr = source->pub._buffer[0]; | 502 | 29.1k | bufferptr = source->iobuffer; | 503 | 165k | for (col = cinfo->image_width; col > 0; col--) { | 504 | 136k | register unsigned int temp; | 505 | 136k | temp = (*bufferptr++) << 8; | 506 | 136k | temp |= (*bufferptr++); | 507 | 136k | if (temp > maxval) | 508 | 75 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 509 | 136k | *ptr++ = rescale[temp]; | 510 | 136k | } | 511 | 29.1k | return 1; | 512 | 29.1k | } |
|
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 | 693k | { |
519 | 693k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
520 | 693k | register _JSAMPROW ptr; |
521 | 693k | register unsigned char *bufferptr; |
522 | 693k | register _JSAMPLE *rescale = source->rescale; |
523 | 693k | JDIMENSION col; |
524 | 693k | unsigned int maxval = source->maxval; |
525 | 693k | register int rindex = rgb_red[cinfo->in_color_space]; |
526 | 693k | register int gindex = rgb_green[cinfo->in_color_space]; |
527 | 693k | register int bindex = rgb_blue[cinfo->in_color_space]; |
528 | 693k | register int aindex = alpha_index[cinfo->in_color_space]; |
529 | 693k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
530 | | |
531 | 693k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
532 | 4.84k | ERREXIT(cinfo, JERR_INPUT_EOF); |
533 | 693k | ptr = source->pub._buffer[0]; |
534 | 693k | bufferptr = source->iobuffer; |
535 | 2.18M | for (col = cinfo->image_width; col > 0; col--) { |
536 | 1.49M | register unsigned int temp; |
537 | 1.49M | temp = (*bufferptr++) << 8; |
538 | 1.49M | temp |= (*bufferptr++); |
539 | 1.49M | if (temp > maxval) |
540 | 2.90k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
541 | 1.49M | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; |
542 | 1.49M | if (aindex >= 0) |
543 | 261k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
544 | 1.49M | ptr += ps; |
545 | 1.49M | } |
546 | 693k | return 1; |
547 | 693k | } rdppm-8.c:get_word_gray_rgb_row Line | Count | Source | 518 | 73.5k | { | 519 | 73.5k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 520 | 73.5k | register _JSAMPROW ptr; | 521 | 73.5k | register unsigned char *bufferptr; | 522 | 73.5k | register _JSAMPLE *rescale = source->rescale; | 523 | 73.5k | JDIMENSION col; | 524 | 73.5k | unsigned int maxval = source->maxval; | 525 | 73.5k | register int rindex = rgb_red[cinfo->in_color_space]; | 526 | 73.5k | register int gindex = rgb_green[cinfo->in_color_space]; | 527 | 73.5k | register int bindex = rgb_blue[cinfo->in_color_space]; | 528 | 73.5k | register int aindex = alpha_index[cinfo->in_color_space]; | 529 | 73.5k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 530 | | | 531 | 73.5k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 532 | 1.88k | ERREXIT(cinfo, JERR_INPUT_EOF); | 533 | 73.5k | ptr = source->pub._buffer[0]; | 534 | 73.5k | bufferptr = source->iobuffer; | 535 | 357k | for (col = cinfo->image_width; col > 0; col--) { | 536 | 284k | register unsigned int temp; | 537 | 284k | temp = (*bufferptr++) << 8; | 538 | 284k | temp |= (*bufferptr++); | 539 | 284k | if (temp > maxval) | 540 | 1.16k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 541 | 284k | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; | 542 | 284k | if (aindex >= 0) | 543 | 19.8k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 544 | 284k | ptr += ps; | 545 | 284k | } | 546 | 73.5k | return 1; | 547 | 73.5k | } |
rdppm-12.c:get_word_gray_rgb_row Line | Count | Source | 518 | 474k | { | 519 | 474k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 520 | 474k | register _JSAMPROW ptr; | 521 | 474k | register unsigned char *bufferptr; | 522 | 474k | register _JSAMPLE *rescale = source->rescale; | 523 | 474k | JDIMENSION col; | 524 | 474k | unsigned int maxval = source->maxval; | 525 | 474k | register int rindex = rgb_red[cinfo->in_color_space]; | 526 | 474k | register int gindex = rgb_green[cinfo->in_color_space]; | 527 | 474k | register int bindex = rgb_blue[cinfo->in_color_space]; | 528 | 474k | register int aindex = alpha_index[cinfo->in_color_space]; | 529 | 474k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 530 | | | 531 | 474k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 532 | 1.84k | ERREXIT(cinfo, JERR_INPUT_EOF); | 533 | 474k | ptr = source->pub._buffer[0]; | 534 | 474k | bufferptr = source->iobuffer; | 535 | 1.00M | for (col = cinfo->image_width; col > 0; col--) { | 536 | 529k | register unsigned int temp; | 537 | 529k | temp = (*bufferptr++) << 8; | 538 | 529k | temp |= (*bufferptr++); | 539 | 529k | if (temp > maxval) | 540 | 1.36k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 541 | 529k | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; | 542 | 529k | if (aindex >= 0) | 543 | 105k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 544 | 529k | ptr += ps; | 545 | 529k | } | 546 | 474k | return 1; | 547 | 474k | } |
rdppm-16.c:get_word_gray_rgb_row Line | Count | Source | 518 | 145k | { | 519 | 145k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 520 | 145k | register _JSAMPROW ptr; | 521 | 145k | register unsigned char *bufferptr; | 522 | 145k | register _JSAMPLE *rescale = source->rescale; | 523 | 145k | JDIMENSION col; | 524 | 145k | unsigned int maxval = source->maxval; | 525 | 145k | register int rindex = rgb_red[cinfo->in_color_space]; | 526 | 145k | register int gindex = rgb_green[cinfo->in_color_space]; | 527 | 145k | register int bindex = rgb_blue[cinfo->in_color_space]; | 528 | 145k | register int aindex = alpha_index[cinfo->in_color_space]; | 529 | 145k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 530 | | | 531 | 145k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 532 | 1.12k | ERREXIT(cinfo, JERR_INPUT_EOF); | 533 | 145k | ptr = source->pub._buffer[0]; | 534 | 145k | bufferptr = source->iobuffer; | 535 | 827k | for (col = cinfo->image_width; col > 0; col--) { | 536 | 682k | register unsigned int temp; | 537 | 682k | temp = (*bufferptr++) << 8; | 538 | 682k | temp |= (*bufferptr++); | 539 | 682k | if (temp > maxval) | 540 | 375 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 541 | 682k | ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; | 542 | 682k | if (aindex >= 0) | 543 | 136k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 544 | 682k | ptr += ps; | 545 | 682k | } | 546 | 145k | return 1; | 547 | 145k | } |
|
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 | 134k | { |
554 | 134k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
555 | 134k | register _JSAMPROW ptr; |
556 | 134k | register unsigned char *bufferptr; |
557 | 134k | register _JSAMPLE *rescale = source->rescale; |
558 | 134k | JDIMENSION col; |
559 | 134k | unsigned int maxval = source->maxval; |
560 | | |
561 | 134k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
562 | 852 | ERREXIT(cinfo, JERR_INPUT_EOF); |
563 | 134k | ptr = source->pub._buffer[0]; |
564 | 134k | bufferptr = source->iobuffer; |
565 | 134k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
566 | 144k | for (col = cinfo->image_width; col > 0; col--) { |
567 | 124k | register unsigned int gray; |
568 | 124k | gray = (*bufferptr++) << 8; |
569 | 124k | gray |= (*bufferptr++); |
570 | 124k | if (gray > maxval) |
571 | 97 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
572 | 124k | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, |
573 | 124k | ptr + 1, ptr + 2, ptr + 3); |
574 | 124k | ptr += 4; |
575 | 124k | } |
576 | 114k | } else { |
577 | 252k | for (col = cinfo->image_width; col > 0; col--) { |
578 | 137k | register unsigned int temp; |
579 | 137k | _JSAMPLE gray; |
580 | 137k | temp = (*bufferptr++) << 8; |
581 | 137k | temp |= (*bufferptr++); |
582 | 137k | if (temp > maxval) |
583 | 417 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
584 | 137k | gray = rescale[temp]; |
585 | 137k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
586 | 137k | ptr + 1, ptr + 2, ptr + 3); |
587 | 137k | ptr += 4; |
588 | 137k | } |
589 | 114k | } |
590 | 134k | return 1; |
591 | 134k | } rdppm-8.c:get_word_gray_cmyk_row Line | Count | Source | 553 | 10.6k | { | 554 | 10.6k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 555 | 10.6k | register _JSAMPROW ptr; | 556 | 10.6k | register unsigned char *bufferptr; | 557 | 10.6k | register _JSAMPLE *rescale = source->rescale; | 558 | 10.6k | JDIMENSION col; | 559 | 10.6k | unsigned int maxval = source->maxval; | 560 | | | 561 | 10.6k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 562 | 259 | ERREXIT(cinfo, JERR_INPUT_EOF); | 563 | 10.6k | ptr = source->pub._buffer[0]; | 564 | 10.6k | bufferptr = source->iobuffer; | 565 | 10.6k | 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.6k | } else { | 577 | 30.6k | for (col = cinfo->image_width; col > 0; col--) { | 578 | 19.9k | register unsigned int temp; | 579 | 19.9k | _JSAMPLE gray; | 580 | 19.9k | temp = (*bufferptr++) << 8; | 581 | 19.9k | temp |= (*bufferptr++); | 582 | 19.9k | if (temp > maxval) | 583 | 166 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 584 | 19.9k | gray = rescale[temp]; | 585 | 19.9k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 586 | 19.9k | ptr + 1, ptr + 2, ptr + 3); | 587 | 19.9k | ptr += 4; | 588 | 19.9k | } | 589 | 10.6k | } | 590 | 10.6k | return 1; | 591 | 10.6k | } |
rdppm-12.c:get_word_gray_cmyk_row Line | Count | Source | 553 | 94.8k | { | 554 | 94.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 555 | 94.8k | register _JSAMPROW ptr; | 556 | 94.8k | register unsigned char *bufferptr; | 557 | 94.8k | register _JSAMPLE *rescale = source->rescale; | 558 | 94.8k | JDIMENSION col; | 559 | 94.8k | unsigned int maxval = source->maxval; | 560 | | | 561 | 94.8k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 562 | 369 | ERREXIT(cinfo, JERR_INPUT_EOF); | 563 | 94.8k | ptr = source->pub._buffer[0]; | 564 | 94.8k | bufferptr = source->iobuffer; | 565 | 94.8k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 566 | 8.49k | for (col = cinfo->image_width; col > 0; col--) { | 567 | 5.33k | register unsigned int gray; | 568 | 5.33k | gray = (*bufferptr++) << 8; | 569 | 5.33k | gray |= (*bufferptr++); | 570 | 5.33k | if (gray > maxval) | 571 | 97 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 572 | 5.33k | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, | 573 | 5.33k | ptr + 1, ptr + 2, ptr + 3); | 574 | 5.33k | ptr += 4; | 575 | 5.33k | } | 576 | 91.7k | } else { | 577 | 192k | for (col = cinfo->image_width; col > 0; col--) { | 578 | 100k | register unsigned int temp; | 579 | 100k | _JSAMPLE gray; | 580 | 100k | temp = (*bufferptr++) << 8; | 581 | 100k | temp |= (*bufferptr++); | 582 | 100k | if (temp > maxval) | 583 | 176 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 584 | 100k | gray = rescale[temp]; | 585 | 100k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 586 | 100k | ptr + 1, ptr + 2, ptr + 3); | 587 | 100k | ptr += 4; | 588 | 100k | } | 589 | 91.7k | } | 590 | 94.8k | return 1; | 591 | 94.8k | } |
rdppm-16.c:get_word_gray_cmyk_row Line | Count | Source | 553 | 29.1k | { | 554 | 29.1k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 555 | 29.1k | register _JSAMPROW ptr; | 556 | 29.1k | register unsigned char *bufferptr; | 557 | 29.1k | register _JSAMPLE *rescale = source->rescale; | 558 | 29.1k | JDIMENSION col; | 559 | 29.1k | unsigned int maxval = source->maxval; | 560 | | | 561 | 29.1k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 562 | 224 | ERREXIT(cinfo, JERR_INPUT_EOF); | 563 | 29.1k | ptr = source->pub._buffer[0]; | 564 | 29.1k | bufferptr = source->iobuffer; | 565 | 29.1k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 566 | 136k | for (col = cinfo->image_width; col > 0; col--) { | 567 | 119k | register unsigned int gray; | 568 | 119k | gray = (*bufferptr++) << 8; | 569 | 119k | gray |= (*bufferptr++); | 570 | 119k | if (gray > maxval) | 571 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 572 | 119k | rgb_to_cmyk(maxval, (_JSAMPLE)gray, (_JSAMPLE)gray, (_JSAMPLE)gray, ptr, | 573 | 119k | ptr + 1, ptr + 2, ptr + 3); | 574 | 119k | ptr += 4; | 575 | 119k | } | 576 | 16.5k | } else { | 577 | 29.3k | for (col = cinfo->image_width; col > 0; col--) { | 578 | 16.8k | register unsigned int temp; | 579 | 16.8k | _JSAMPLE gray; | 580 | 16.8k | temp = (*bufferptr++) << 8; | 581 | 16.8k | temp |= (*bufferptr++); | 582 | 16.8k | if (temp > maxval) | 583 | 75 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 584 | 16.8k | gray = rescale[temp]; | 585 | 16.8k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 586 | 16.8k | ptr + 1, ptr + 2, ptr + 3); | 587 | 16.8k | ptr += 4; | 588 | 16.8k | } | 589 | 12.5k | } | 590 | 29.1k | return 1; | 591 | 29.1k | } |
|
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 | 164k | { |
598 | 164k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
599 | 164k | register _JSAMPROW ptr; |
600 | 164k | register unsigned char *bufferptr; |
601 | 164k | register _JSAMPLE *rescale = source->rescale; |
602 | 164k | JDIMENSION col; |
603 | 164k | unsigned int maxval = source->maxval; |
604 | 164k | register int rindex = rgb_red[cinfo->in_color_space]; |
605 | 164k | register int gindex = rgb_green[cinfo->in_color_space]; |
606 | 164k | register int bindex = rgb_blue[cinfo->in_color_space]; |
607 | 164k | register int aindex = alpha_index[cinfo->in_color_space]; |
608 | 164k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
609 | | |
610 | 164k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
611 | 6.18k | ERREXIT(cinfo, JERR_INPUT_EOF); |
612 | 164k | ptr = source->pub._buffer[0]; |
613 | 164k | bufferptr = source->iobuffer; |
614 | 732k | for (col = cinfo->image_width; col > 0; col--) { |
615 | 567k | register unsigned int temp; |
616 | 567k | temp = (*bufferptr++) << 8; |
617 | 567k | temp |= (*bufferptr++); |
618 | 567k | if (temp > maxval) |
619 | 2.15k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
620 | 567k | ptr[rindex] = rescale[temp]; |
621 | 567k | temp = (*bufferptr++) << 8; |
622 | 567k | temp |= (*bufferptr++); |
623 | 567k | if (temp > maxval) |
624 | 1.95k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
625 | 567k | ptr[gindex] = rescale[temp]; |
626 | 567k | temp = (*bufferptr++) << 8; |
627 | 567k | temp |= (*bufferptr++); |
628 | 567k | if (temp > maxval) |
629 | 1.82k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
630 | 567k | ptr[bindex] = rescale[temp]; |
631 | 567k | if (aindex >= 0) |
632 | 107k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
633 | 567k | ptr += ps; |
634 | 567k | } |
635 | 164k | return 1; |
636 | 164k | } rdppm-8.c:get_word_rgb_row Line | Count | Source | 597 | 60.1k | { | 598 | 60.1k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 599 | 60.1k | register _JSAMPROW ptr; | 600 | 60.1k | register unsigned char *bufferptr; | 601 | 60.1k | register _JSAMPLE *rescale = source->rescale; | 602 | 60.1k | JDIMENSION col; | 603 | 60.1k | unsigned int maxval = source->maxval; | 604 | 60.1k | register int rindex = rgb_red[cinfo->in_color_space]; | 605 | 60.1k | register int gindex = rgb_green[cinfo->in_color_space]; | 606 | 60.1k | register int bindex = rgb_blue[cinfo->in_color_space]; | 607 | 60.1k | register int aindex = alpha_index[cinfo->in_color_space]; | 608 | 60.1k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 609 | | | 610 | 60.1k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 611 | 2.37k | ERREXIT(cinfo, JERR_INPUT_EOF); | 612 | 60.1k | ptr = source->pub._buffer[0]; | 613 | 60.1k | bufferptr = source->iobuffer; | 614 | 156k | for (col = cinfo->image_width; col > 0; col--) { | 615 | 96.0k | register unsigned int temp; | 616 | 96.0k | temp = (*bufferptr++) << 8; | 617 | 96.0k | temp |= (*bufferptr++); | 618 | 96.0k | if (temp > maxval) | 619 | 695 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 620 | 96.0k | ptr[rindex] = rescale[temp]; | 621 | 96.0k | temp = (*bufferptr++) << 8; | 622 | 96.0k | temp |= (*bufferptr++); | 623 | 96.0k | if (temp > maxval) | 624 | 811 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 625 | 96.0k | ptr[gindex] = rescale[temp]; | 626 | 96.0k | temp = (*bufferptr++) << 8; | 627 | 96.0k | temp |= (*bufferptr++); | 628 | 96.0k | if (temp > maxval) | 629 | 713 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 630 | 96.0k | ptr[bindex] = rescale[temp]; | 631 | 96.0k | if (aindex >= 0) | 632 | 14.0k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 633 | 96.0k | ptr += ps; | 634 | 96.0k | } | 635 | 60.1k | return 1; | 636 | 60.1k | } |
rdppm-12.c:get_word_rgb_row Line | Count | Source | 597 | 62.3k | { | 598 | 62.3k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 599 | 62.3k | register _JSAMPROW ptr; | 600 | 62.3k | register unsigned char *bufferptr; | 601 | 62.3k | register _JSAMPLE *rescale = source->rescale; | 602 | 62.3k | JDIMENSION col; | 603 | 62.3k | unsigned int maxval = source->maxval; | 604 | 62.3k | register int rindex = rgb_red[cinfo->in_color_space]; | 605 | 62.3k | register int gindex = rgb_green[cinfo->in_color_space]; | 606 | 62.3k | register int bindex = rgb_blue[cinfo->in_color_space]; | 607 | 62.3k | register int aindex = alpha_index[cinfo->in_color_space]; | 608 | 62.3k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 609 | | | 610 | 62.3k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 611 | 2.36k | ERREXIT(cinfo, JERR_INPUT_EOF); | 612 | 62.3k | ptr = source->pub._buffer[0]; | 613 | 62.3k | bufferptr = source->iobuffer; | 614 | 259k | for (col = cinfo->image_width; col > 0; col--) { | 615 | 196k | register unsigned int temp; | 616 | 196k | temp = (*bufferptr++) << 8; | 617 | 196k | temp |= (*bufferptr++); | 618 | 196k | if (temp > maxval) | 619 | 1.14k | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 620 | 196k | ptr[rindex] = rescale[temp]; | 621 | 196k | temp = (*bufferptr++) << 8; | 622 | 196k | temp |= (*bufferptr++); | 623 | 196k | if (temp > maxval) | 624 | 865 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 625 | 196k | ptr[gindex] = rescale[temp]; | 626 | 196k | temp = (*bufferptr++) << 8; | 627 | 196k | temp |= (*bufferptr++); | 628 | 196k | if (temp > maxval) | 629 | 855 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 630 | 196k | ptr[bindex] = rescale[temp]; | 631 | 196k | if (aindex >= 0) | 632 | 38.7k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 633 | 196k | ptr += ps; | 634 | 196k | } | 635 | 62.3k | return 1; | 636 | 62.3k | } |
rdppm-16.c:get_word_rgb_row Line | Count | Source | 597 | 42.4k | { | 598 | 42.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 599 | 42.4k | register _JSAMPROW ptr; | 600 | 42.4k | register unsigned char *bufferptr; | 601 | 42.4k | register _JSAMPLE *rescale = source->rescale; | 602 | 42.4k | JDIMENSION col; | 603 | 42.4k | unsigned int maxval = source->maxval; | 604 | 42.4k | register int rindex = rgb_red[cinfo->in_color_space]; | 605 | 42.4k | register int gindex = rgb_green[cinfo->in_color_space]; | 606 | 42.4k | register int bindex = rgb_blue[cinfo->in_color_space]; | 607 | 42.4k | register int aindex = alpha_index[cinfo->in_color_space]; | 608 | 42.4k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 609 | | | 610 | 42.4k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 611 | 1.45k | ERREXIT(cinfo, JERR_INPUT_EOF); | 612 | 42.4k | ptr = source->pub._buffer[0]; | 613 | 42.4k | bufferptr = source->iobuffer; | 614 | 317k | for (col = cinfo->image_width; col > 0; col--) { | 615 | 274k | register unsigned int temp; | 616 | 274k | temp = (*bufferptr++) << 8; | 617 | 274k | temp |= (*bufferptr++); | 618 | 274k | if (temp > maxval) | 619 | 315 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 620 | 274k | ptr[rindex] = rescale[temp]; | 621 | 274k | temp = (*bufferptr++) << 8; | 622 | 274k | temp |= (*bufferptr++); | 623 | 274k | if (temp > maxval) | 624 | 275 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 625 | 274k | ptr[gindex] = rescale[temp]; | 626 | 274k | temp = (*bufferptr++) << 8; | 627 | 274k | temp |= (*bufferptr++); | 628 | 274k | if (temp > maxval) | 629 | 260 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 630 | 274k | ptr[bindex] = rescale[temp]; | 631 | 274k | if (aindex >= 0) | 632 | 54.8k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 633 | 274k | ptr += ps; | 634 | 274k | } | 635 | 42.4k | return 1; | 636 | 42.4k | } |
|
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 | 29.4k | { |
643 | 29.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
644 | 29.4k | register _JSAMPROW ptr; |
645 | 29.4k | register unsigned char *bufferptr; |
646 | 29.4k | register _JSAMPLE *rescale = source->rescale; |
647 | 29.4k | JDIMENSION col; |
648 | 29.4k | unsigned int maxval = source->maxval; |
649 | | |
650 | 29.4k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) |
651 | 1.10k | ERREXIT(cinfo, JERR_INPUT_EOF); |
652 | 29.4k | ptr = source->pub._buffer[0]; |
653 | 29.4k | bufferptr = source->iobuffer; |
654 | 29.4k | if (maxval == (1U << cinfo->data_precision) - 1U) { |
655 | 67.3k | for (col = cinfo->image_width; col > 0; col--) { |
656 | 58.3k | register unsigned int r, g, b; |
657 | 58.3k | r = (*bufferptr++) << 8; |
658 | 58.3k | r |= (*bufferptr++); |
659 | 58.3k | if (r > maxval) |
660 | 90 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
661 | 58.3k | g = (*bufferptr++) << 8; |
662 | 58.3k | g |= (*bufferptr++); |
663 | 58.3k | if (g > maxval) |
664 | 73 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
665 | 58.3k | b = (*bufferptr++) << 8; |
666 | 58.3k | b |= (*bufferptr++); |
667 | 58.3k | if (b > maxval) |
668 | 84 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
669 | 58.3k | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, |
670 | 58.3k | ptr + 2, ptr + 3); |
671 | 58.3k | ptr += 4; |
672 | 58.3k | } |
673 | 20.4k | } else { |
674 | 70.8k | for (col = cinfo->image_width; col > 0; col--) { |
675 | 50.3k | register unsigned int r, g, b; |
676 | 50.3k | r = (*bufferptr++) << 8; |
677 | 50.3k | r |= (*bufferptr++); |
678 | 50.3k | if (r > maxval) |
679 | 316 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
680 | 50.3k | g = (*bufferptr++) << 8; |
681 | 50.3k | g |= (*bufferptr++); |
682 | 50.3k | if (g > maxval) |
683 | 259 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
684 | 50.3k | b = (*bufferptr++) << 8; |
685 | 50.3k | b |= (*bufferptr++); |
686 | 50.3k | if (b > maxval) |
687 | 222 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); |
688 | 50.3k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], |
689 | 50.3k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); |
690 | 50.3k | ptr += 4; |
691 | 50.3k | } |
692 | 20.4k | } |
693 | 29.4k | return 1; |
694 | 29.4k | } rdppm-8.c:get_word_rgb_cmyk_row Line | Count | Source | 642 | 8.48k | { | 643 | 8.48k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 644 | 8.48k | register _JSAMPROW ptr; | 645 | 8.48k | register unsigned char *bufferptr; | 646 | 8.48k | register _JSAMPLE *rescale = source->rescale; | 647 | 8.48k | JDIMENSION col; | 648 | 8.48k | unsigned int maxval = source->maxval; | 649 | | | 650 | 8.48k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 651 | 338 | ERREXIT(cinfo, JERR_INPUT_EOF); | 652 | 8.48k | ptr = source->pub._buffer[0]; | 653 | 8.48k | bufferptr = source->iobuffer; | 654 | 8.48k | 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.48k | } else { | 674 | 22.8k | for (col = cinfo->image_width; col > 0; col--) { | 675 | 14.3k | register unsigned int r, g, b; | 676 | 14.3k | r = (*bufferptr++) << 8; | 677 | 14.3k | r |= (*bufferptr++); | 678 | 14.3k | if (r > maxval) | 679 | 115 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 680 | 14.3k | g = (*bufferptr++) << 8; | 681 | 14.3k | g |= (*bufferptr++); | 682 | 14.3k | if (g > maxval) | 683 | 104 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 684 | 14.3k | b = (*bufferptr++) << 8; | 685 | 14.3k | b |= (*bufferptr++); | 686 | 14.3k | if (b > maxval) | 687 | 83 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 688 | 14.3k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], | 689 | 14.3k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); | 690 | 14.3k | ptr += 4; | 691 | 14.3k | } | 692 | 8.48k | } | 693 | 8.48k | return 1; | 694 | 8.48k | } |
rdppm-12.c:get_word_rgb_cmyk_row Line | Count | Source | 642 | 12.4k | { | 643 | 12.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 644 | 12.4k | register _JSAMPROW ptr; | 645 | 12.4k | register unsigned char *bufferptr; | 646 | 12.4k | register _JSAMPLE *rescale = source->rescale; | 647 | 12.4k | JDIMENSION col; | 648 | 12.4k | unsigned int maxval = source->maxval; | 649 | | | 650 | 12.4k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 651 | 472 | ERREXIT(cinfo, JERR_INPUT_EOF); | 652 | 12.4k | ptr = source->pub._buffer[0]; | 653 | 12.4k | bufferptr = source->iobuffer; | 654 | 12.4k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 655 | 12.7k | for (col = cinfo->image_width; col > 0; col--) { | 656 | 8.72k | register unsigned int r, g, b; | 657 | 8.72k | r = (*bufferptr++) << 8; | 658 | 8.72k | r |= (*bufferptr++); | 659 | 8.72k | if (r > maxval) | 660 | 90 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 661 | 8.72k | g = (*bufferptr++) << 8; | 662 | 8.72k | g |= (*bufferptr++); | 663 | 8.72k | if (g > maxval) | 664 | 73 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 665 | 8.72k | b = (*bufferptr++) << 8; | 666 | 8.72k | b |= (*bufferptr++); | 667 | 8.72k | if (b > maxval) | 668 | 84 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 669 | 8.72k | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, | 670 | 8.72k | ptr + 2, ptr + 3); | 671 | 8.72k | ptr += 4; | 672 | 8.72k | } | 673 | 8.44k | } else { | 674 | 39.0k | for (col = cinfo->image_width; col > 0; col--) { | 675 | 30.6k | register unsigned int r, g, b; | 676 | 30.6k | r = (*bufferptr++) << 8; | 677 | 30.6k | r |= (*bufferptr++); | 678 | 30.6k | if (r > maxval) | 679 | 138 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 680 | 30.6k | g = (*bufferptr++) << 8; | 681 | 30.6k | g |= (*bufferptr++); | 682 | 30.6k | if (g > maxval) | 683 | 100 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 684 | 30.6k | b = (*bufferptr++) << 8; | 685 | 30.6k | b |= (*bufferptr++); | 686 | 30.6k | if (b > maxval) | 687 | 87 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 688 | 30.6k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], | 689 | 30.6k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); | 690 | 30.6k | ptr += 4; | 691 | 30.6k | } | 692 | 8.44k | } | 693 | 12.4k | return 1; | 694 | 12.4k | } |
rdppm-16.c:get_word_rgb_cmyk_row Line | Count | Source | 642 | 8.49k | { | 643 | 8.49k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 644 | 8.49k | register _JSAMPROW ptr; | 645 | 8.49k | register unsigned char *bufferptr; | 646 | 8.49k | register _JSAMPLE *rescale = source->rescale; | 647 | 8.49k | JDIMENSION col; | 648 | 8.49k | unsigned int maxval = source->maxval; | 649 | | | 650 | 8.49k | if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) | 651 | 290 | ERREXIT(cinfo, JERR_INPUT_EOF); | 652 | 8.49k | ptr = source->pub._buffer[0]; | 653 | 8.49k | bufferptr = source->iobuffer; | 654 | 8.49k | if (maxval == (1U << cinfo->data_precision) - 1U) { | 655 | 54.6k | for (col = cinfo->image_width; col > 0; col--) { | 656 | 49.6k | register unsigned int r, g, b; | 657 | 49.6k | r = (*bufferptr++) << 8; | 658 | 49.6k | r |= (*bufferptr++); | 659 | 49.6k | if (r > maxval) | 660 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 661 | 49.6k | g = (*bufferptr++) << 8; | 662 | 49.6k | g |= (*bufferptr++); | 663 | 49.6k | if (g > maxval) | 664 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 665 | 49.6k | b = (*bufferptr++) << 8; | 666 | 49.6k | b |= (*bufferptr++); | 667 | 49.6k | if (b > maxval) | 668 | 0 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 669 | 49.6k | rgb_to_cmyk(maxval, (_JSAMPLE)r, (_JSAMPLE)g, (_JSAMPLE)b, ptr, ptr + 1, | 670 | 49.6k | ptr + 2, ptr + 3); | 671 | 49.6k | ptr += 4; | 672 | 49.6k | } | 673 | 4.97k | } else { | 674 | 8.83k | for (col = cinfo->image_width; col > 0; col--) { | 675 | 5.31k | register unsigned int r, g, b; | 676 | 5.31k | r = (*bufferptr++) << 8; | 677 | 5.31k | r |= (*bufferptr++); | 678 | 5.31k | if (r > maxval) | 679 | 63 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 680 | 5.31k | g = (*bufferptr++) << 8; | 681 | 5.31k | g |= (*bufferptr++); | 682 | 5.31k | if (g > maxval) | 683 | 55 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 684 | 5.31k | b = (*bufferptr++) << 8; | 685 | 5.31k | b |= (*bufferptr++); | 686 | 5.31k | if (b > maxval) | 687 | 52 | ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); | 688 | 5.31k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, rescale[r], rescale[g], | 689 | 5.31k | rescale[b], ptr, ptr + 1, ptr + 2, ptr + 3); | 690 | 5.31k | ptr += 4; | 691 | 5.31k | } | 692 | 3.51k | } | 693 | 8.49k | return 1; | 694 | 8.49k | } |
|
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 | 184k | { |
704 | 184k | ppm_source_ptr source = (ppm_source_ptr)sinfo; |
705 | 184k | int c; |
706 | 184k | unsigned int w, h, maxval; |
707 | 184k | boolean need_iobuffer, use_raw_buffer, need_rescale; |
708 | | |
709 | 184k | if (getc(source->pub.input_file) != 'P') |
710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); |
711 | | |
712 | 184k | c = getc(source->pub.input_file); /* subformat discriminator character */ |
713 | | |
714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ |
715 | 184k | switch (c) { |
716 | 18.7k | case '2': /* it's a text-format PGM file */ |
717 | 40.0k | case '3': /* it's a text-format PPM file */ |
718 | 139k | case '5': /* it's a raw-format PGM file */ |
719 | 183k | case '6': /* it's a raw-format PPM file */ |
720 | 183k | break; |
721 | 686 | default: |
722 | 686 | ERREXIT(cinfo, JERR_PPM_NOT); |
723 | 686 | break; |
724 | 184k | } |
725 | | |
726 | | /* fetch the remaining header info */ |
727 | 183k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); |
728 | 183k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); |
729 | 183k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); |
730 | | |
731 | 183k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ |
732 | 392 | ERREXIT(cinfo, JERR_PPM_NOT); |
733 | 183k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) |
734 | 285 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); |
735 | 183k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) |
736 | 2.67k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); |
737 | | |
738 | 183k | cinfo->image_width = (JDIMENSION)w; |
739 | 183k | cinfo->image_height = (JDIMENSION)h; |
740 | 183k | source->maxval = maxval; |
741 | | |
742 | | /* initialize flags to most common settings */ |
743 | 183k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ |
744 | 183k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ |
745 | 183k | need_rescale = TRUE; /* do we need a rescale array? */ |
746 | | |
747 | 183k | switch (c) { |
748 | 14.3k | case '2': /* it's a text-format PGM file */ |
749 | 14.3k | if (cinfo->in_color_space == JCS_UNKNOWN || |
750 | 14.3k | cinfo->in_color_space == JCS_RGB) |
751 | 218 | cinfo->in_color_space = JCS_GRAYSCALE; |
752 | 14.3k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); |
753 | 14.3k | if (cinfo->in_color_space == JCS_GRAYSCALE) |
754 | 2.26k | source->pub.get_pixel_rows = get_text_gray_row; |
755 | 12.0k | else if (IsExtRGB(cinfo->in_color_space)) |
756 | 10.2k | source->pub.get_pixel_rows = get_text_gray_rgb_row; |
757 | 1.79k | else if (cinfo->in_color_space == JCS_CMYK) |
758 | 1.79k | source->pub.get_pixel_rows = get_text_gray_cmyk_row; |
759 | 0 | else |
760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
761 | 14.3k | need_iobuffer = FALSE; |
762 | 14.3k | break; |
763 | | |
764 | 16.8k | case '3': /* it's a text-format PPM file */ |
765 | 16.8k | if (cinfo->in_color_space == JCS_UNKNOWN) |
766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
767 | 16.8k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); |
768 | 16.8k | if (IsExtRGB(cinfo->in_color_space)) |
769 | 12.2k | source->pub.get_pixel_rows = get_text_rgb_row; |
770 | 4.51k | else if (cinfo->in_color_space == JCS_CMYK) |
771 | 2.13k | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; |
772 | 2.37k | else |
773 | 2.37k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
774 | 16.8k | need_iobuffer = FALSE; |
775 | 16.8k | break; |
776 | | |
777 | 93.6k | case '5': /* it's a raw-format PGM file */ |
778 | 93.6k | if (cinfo->in_color_space == JCS_UNKNOWN || |
779 | 93.6k | cinfo->in_color_space == JCS_RGB) |
780 | 850 | cinfo->in_color_space = JCS_GRAYSCALE; |
781 | 93.6k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); |
782 | 93.6k | if (maxval > 255) { |
783 | 12.6k | if (cinfo->in_color_space == JCS_GRAYSCALE) |
784 | 2.07k | source->pub.get_pixel_rows = get_word_gray_row; |
785 | 10.5k | else if (IsExtRGB(cinfo->in_color_space)) |
786 | 8.99k | source->pub.get_pixel_rows = get_word_gray_rgb_row; |
787 | 1.59k | else if (cinfo->in_color_space == JCS_CMYK) |
788 | 1.59k | 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 | 46.6k | } else if (maxval <= _MAXJSAMPLE && |
793 | 46.6k | maxval == ((1U << cinfo->data_precision) - 1U) && |
794 | 6.56k | cinfo->in_color_space == JCS_GRAYSCALE) { |
795 | 1.08k | source->pub.get_pixel_rows = get_raw_row; |
796 | 1.08k | use_raw_buffer = TRUE; |
797 | 1.08k | need_rescale = FALSE; |
798 | | #endif |
799 | 79.8k | } else { |
800 | 79.8k | if (cinfo->in_color_space == JCS_GRAYSCALE) |
801 | 11.4k | source->pub.get_pixel_rows = get_scaled_gray_row; |
802 | 68.4k | else if (IsExtRGB(cinfo->in_color_space)) |
803 | 59.5k | source->pub.get_pixel_rows = get_gray_rgb_row; |
804 | 8.88k | else if (cinfo->in_color_space == JCS_CMYK) |
805 | 8.88k | source->pub.get_pixel_rows = get_gray_cmyk_row; |
806 | 0 | else |
807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
808 | 79.8k | } |
809 | 93.6k | break; |
810 | | |
811 | 40.5k | case '6': /* it's a raw-format PPM file */ |
812 | 40.5k | if (cinfo->in_color_space == JCS_UNKNOWN) |
813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
814 | 40.5k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); |
815 | 40.5k | if (maxval > 255) { |
816 | 17.7k | if (IsExtRGB(cinfo->in_color_space)) |
817 | 12.9k | source->pub.get_pixel_rows = get_word_rgb_row; |
818 | 4.81k | else if (cinfo->in_color_space == JCS_CMYK) |
819 | 2.30k | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; |
820 | 2.51k | else |
821 | 2.51k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
822 | | #if BITS_IN_JSAMPLE == 8 |
823 | 13.2k | } else if (maxval <= _MAXJSAMPLE && |
824 | 13.2k | maxval == ((1U << cinfo->data_precision) - 1U) && |
825 | 2.55k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 |
826 | 2.55k | (cinfo->in_color_space == JCS_EXT_RGB || |
827 | 2.21k | cinfo->in_color_space == JCS_RGB)) { |
828 | | #else |
829 | | cinfo->in_color_space == JCS_EXT_RGB) { |
830 | | #endif |
831 | 387 | source->pub.get_pixel_rows = get_raw_row; |
832 | 387 | use_raw_buffer = TRUE; |
833 | 387 | need_rescale = FALSE; |
834 | | #endif |
835 | 22.3k | } else { |
836 | 22.3k | if (IsExtRGB(cinfo->in_color_space)) |
837 | 16.3k | source->pub.get_pixel_rows = get_rgb_row; |
838 | 6.04k | else if (cinfo->in_color_space == JCS_CMYK) |
839 | 2.78k | source->pub.get_pixel_rows = get_rgb_cmyk_row; |
840 | 3.25k | else |
841 | 3.25k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
842 | 22.3k | } |
843 | 40.5k | break; |
844 | 183k | } |
845 | | |
846 | 157k | if (IsExtRGB(cinfo->in_color_space)) |
847 | 120k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; |
848 | 36.3k | else if (cinfo->in_color_space == JCS_GRAYSCALE) |
849 | 16.8k | cinfo->input_components = 1; |
850 | 19.4k | else if (cinfo->in_color_space == JCS_CMYK) |
851 | 19.4k | cinfo->input_components = 4; |
852 | | |
853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ |
854 | 157k | if (need_iobuffer) { |
855 | 128k | if (c == '6') |
856 | 34.7k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); |
857 | 93.6k | else |
858 | 93.6k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); |
859 | 128k | source->iobuffer = (unsigned char *) |
860 | 128k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
861 | 128k | source->buffer_width); |
862 | 128k | } |
863 | | |
864 | | /* Create compressor input buffer. */ |
865 | 157k | 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.46k | source->pixrow = (_JSAMPROW)source->iobuffer; |
869 | 1.46k | source->pub._buffer = &source->pixrow; |
870 | 1.46k | source->pub.buffer_height = 1; |
871 | 155k | } else { |
872 | | /* Need to translate anyway, so make a separate sample buffer. */ |
873 | 155k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
874 | 155k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
875 | 155k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); |
876 | 155k | source->pub.buffer_height = 1; |
877 | 155k | } |
878 | | |
879 | | /* Compute the rescaling array if required. */ |
880 | 157k | if (need_rescale) { |
881 | 155k | size_t val, half_maxval; |
882 | | |
883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ |
884 | 155k | source->rescale = (_JSAMPLE *) |
885 | 155k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
886 | 155k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); |
887 | 155k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); |
888 | 155k | half_maxval = (size_t)maxval / 2; |
889 | 686M | for (val = 0; val <= (size_t)maxval; val++) { |
890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ |
891 | 686M | source->rescale[val] = |
892 | 686M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / |
893 | 686M | maxval); |
894 | 686M | } |
895 | 155k | } |
896 | 157k | } rdppm-8.c:start_input_ppm Line | Count | Source | 703 | 94.8k | { | 704 | 94.8k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 705 | 94.8k | int c; | 706 | 94.8k | unsigned int w, h, maxval; | 707 | 94.8k | boolean need_iobuffer, use_raw_buffer, need_rescale; | 708 | | | 709 | 94.8k | if (getc(source->pub.input_file) != 'P') | 710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); | 711 | | | 712 | 94.8k | c = getc(source->pub.input_file); /* subformat discriminator character */ | 713 | | | 714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ | 715 | 94.8k | switch (c) { | 716 | 8.95k | case '2': /* it's a text-format PGM file */ | 717 | 18.5k | case '3': /* it's a text-format PPM file */ | 718 | 72.9k | case '5': /* it's a raw-format PGM file */ | 719 | 94.5k | case '6': /* it's a raw-format PPM file */ | 720 | 94.5k | break; | 721 | 259 | default: | 722 | 259 | ERREXIT(cinfo, JERR_PPM_NOT); | 723 | 259 | break; | 724 | 94.8k | } | 725 | | | 726 | | /* fetch the remaining header info */ | 727 | 94.5k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 728 | 94.5k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 729 | 94.5k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 730 | | | 731 | 94.5k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ | 732 | 182 | ERREXIT(cinfo, JERR_PPM_NOT); | 733 | 94.5k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) | 734 | 152 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 735 | 94.5k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) | 736 | 1.19k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 737 | | | 738 | 94.5k | cinfo->image_width = (JDIMENSION)w; | 739 | 94.5k | cinfo->image_height = (JDIMENSION)h; | 740 | 94.5k | source->maxval = maxval; | 741 | | | 742 | | /* initialize flags to most common settings */ | 743 | 94.5k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ | 744 | 94.5k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 745 | 94.5k | need_rescale = TRUE; /* do we need a rescale array? */ | 746 | | | 747 | 94.5k | switch (c) { | 748 | 6.62k | case '2': /* it's a text-format PGM file */ | 749 | 6.62k | if (cinfo->in_color_space == JCS_UNKNOWN || | 750 | 6.62k | cinfo->in_color_space == JCS_RGB) | 751 | 218 | cinfo->in_color_space = JCS_GRAYSCALE; | 752 | 6.62k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); | 753 | 6.62k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 754 | 1.17k | source->pub.get_pixel_rows = get_text_gray_row; | 755 | 5.45k | else if (IsExtRGB(cinfo->in_color_space)) | 756 | 4.76k | source->pub.get_pixel_rows = get_text_gray_rgb_row; | 757 | 695 | else if (cinfo->in_color_space == JCS_CMYK) | 758 | 695 | source->pub.get_pixel_rows = get_text_gray_cmyk_row; | 759 | 0 | else | 760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 761 | 6.62k | need_iobuffer = FALSE; | 762 | 6.62k | break; | 763 | | | 764 | 7.73k | case '3': /* it's a text-format PPM file */ | 765 | 7.73k | if (cinfo->in_color_space == JCS_UNKNOWN) | 766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 767 | 7.73k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); | 768 | 7.73k | if (IsExtRGB(cinfo->in_color_space)) | 769 | 5.81k | source->pub.get_pixel_rows = get_text_rgb_row; | 770 | 1.92k | else if (cinfo->in_color_space == JCS_CMYK) | 771 | 839 | 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.73k | need_iobuffer = FALSE; | 775 | 7.73k | break; | 776 | | | 777 | 51.4k | case '5': /* it's a raw-format PGM file */ | 778 | 51.4k | if (cinfo->in_color_space == JCS_UNKNOWN || | 779 | 51.4k | cinfo->in_color_space == JCS_RGB) | 780 | 850 | cinfo->in_color_space = JCS_GRAYSCALE; | 781 | 51.4k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); | 782 | 51.4k | if (maxval > 255) { | 783 | 4.79k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 784 | 952 | source->pub.get_pixel_rows = get_word_gray_row; | 785 | 3.84k | else if (IsExtRGB(cinfo->in_color_space)) | 786 | 3.37k | source->pub.get_pixel_rows = get_word_gray_rgb_row; | 787 | 475 | else if (cinfo->in_color_space == JCS_CMYK) | 788 | 475 | source->pub.get_pixel_rows = get_word_gray_cmyk_row; | 789 | 0 | else | 790 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 791 | 4.79k | #if BITS_IN_JSAMPLE == 8 | 792 | 46.6k | } else if (maxval <= _MAXJSAMPLE && | 793 | 46.6k | maxval == ((1U << cinfo->data_precision) - 1U) && | 794 | 6.56k | cinfo->in_color_space == JCS_GRAYSCALE) { | 795 | 1.08k | source->pub.get_pixel_rows = get_raw_row; | 796 | 1.08k | use_raw_buffer = TRUE; | 797 | 1.08k | need_rescale = FALSE; | 798 | 1.08k | #endif | 799 | 45.6k | } else { | 800 | 45.6k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 801 | 6.51k | source->pub.get_pixel_rows = get_scaled_gray_row; | 802 | 39.0k | else if (IsExtRGB(cinfo->in_color_space)) | 803 | 35.1k | source->pub.get_pixel_rows = get_gray_rgb_row; | 804 | 3.98k | else if (cinfo->in_color_space == JCS_CMYK) | 805 | 3.98k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 806 | 0 | else | 807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 808 | 45.6k | } | 809 | 51.4k | break; | 810 | | | 811 | 19.6k | case '6': /* it's a raw-format PPM file */ | 812 | 19.6k | if (cinfo->in_color_space == JCS_UNKNOWN) | 813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 814 | 19.6k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); | 815 | 19.6k | if (maxval > 255) { | 816 | 6.41k | if (IsExtRGB(cinfo->in_color_space)) | 817 | 4.84k | source->pub.get_pixel_rows = get_word_rgb_row; | 818 | 1.57k | else if (cinfo->in_color_space == JCS_CMYK) | 819 | 679 | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; | 820 | 895 | else | 821 | 895 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 822 | 6.41k | #if BITS_IN_JSAMPLE == 8 | 823 | 13.2k | } else if (maxval <= _MAXJSAMPLE && | 824 | 13.2k | maxval == ((1U << cinfo->data_precision) - 1U) && | 825 | 2.55k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 826 | 2.55k | (cinfo->in_color_space == JCS_EXT_RGB || | 827 | 2.21k | cinfo->in_color_space == JCS_RGB)) { | 828 | | #else | 829 | | cinfo->in_color_space == JCS_EXT_RGB) { | 830 | | #endif | 831 | 387 | source->pub.get_pixel_rows = get_raw_row; | 832 | 387 | use_raw_buffer = TRUE; | 833 | 387 | need_rescale = FALSE; | 834 | 387 | #endif | 835 | 12.8k | } else { | 836 | 12.8k | if (IsExtRGB(cinfo->in_color_space)) | 837 | 9.52k | source->pub.get_pixel_rows = get_rgb_row; | 838 | 3.32k | else if (cinfo->in_color_space == JCS_CMYK) | 839 | 1.42k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 840 | 1.89k | else | 841 | 1.89k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 842 | 12.8k | } | 843 | 19.6k | break; | 844 | 94.5k | } | 845 | | | 846 | 81.6k | if (IsExtRGB(cinfo->in_color_space)) | 847 | 63.8k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 848 | 17.8k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 849 | 9.71k | cinfo->input_components = 1; | 850 | 8.10k | else if (cinfo->in_color_space == JCS_CMYK) | 851 | 8.10k | cinfo->input_components = 4; | 852 | | | 853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 854 | 81.6k | if (need_iobuffer) { | 855 | 68.3k | if (c == '6') | 856 | 16.8k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); | 857 | 51.4k | else | 858 | 51.4k | 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.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 | 1.46k | source->pixrow = (_JSAMPROW)source->iobuffer; | 869 | 1.46k | source->pub._buffer = &source->pixrow; | 870 | 1.46k | source->pub.buffer_height = 1; | 871 | 80.1k | } else { | 872 | | /* Need to translate anyway, so make a separate sample buffer. */ | 873 | 80.1k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 874 | 80.1k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 875 | 80.1k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); | 876 | 80.1k | source->pub.buffer_height = 1; | 877 | 80.1k | } | 878 | | | 879 | | /* Compute the rescaling array if required. */ | 880 | 81.6k | if (need_rescale) { | 881 | 80.1k | size_t val, half_maxval; | 882 | | | 883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ | 884 | 80.1k | source->rescale = (_JSAMPLE *) | 885 | 80.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 886 | 80.1k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 887 | 80.1k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 888 | 80.1k | half_maxval = (size_t)maxval / 2; | 889 | 203M | for (val = 0; val <= (size_t)maxval; val++) { | 890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 891 | 203M | source->rescale[val] = | 892 | 203M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 893 | 203M | maxval); | 894 | 203M | } | 895 | 80.1k | } | 896 | 81.6k | } |
rdppm-12.c:start_input_ppm Line | Count | Source | 703 | 63.4k | { | 704 | 63.4k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 705 | 63.4k | int c; | 706 | 63.4k | unsigned int w, h, maxval; | 707 | 63.4k | boolean need_iobuffer, use_raw_buffer, need_rescale; | 708 | | | 709 | 63.4k | if (getc(source->pub.input_file) != 'P') | 710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); | 711 | | | 712 | 63.4k | c = getc(source->pub.input_file); /* subformat discriminator character */ | 713 | | | 714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ | 715 | 63.4k | switch (c) { | 716 | 6.58k | case '2': /* it's a text-format PGM file */ | 717 | 14.0k | case '3': /* it's a text-format PPM file */ | 718 | 47.2k | case '5': /* it's a raw-format PGM file */ | 719 | 63.1k | case '6': /* it's a raw-format PPM file */ | 720 | 63.1k | break; | 721 | 322 | default: | 722 | 322 | ERREXIT(cinfo, JERR_PPM_NOT); | 723 | 322 | break; | 724 | 63.4k | } | 725 | | | 726 | | /* fetch the remaining header info */ | 727 | 63.1k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 728 | 63.1k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 729 | 63.1k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 730 | | | 731 | 63.1k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ | 732 | 126 | ERREXIT(cinfo, JERR_PPM_NOT); | 733 | 63.1k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) | 734 | 91 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 735 | 63.1k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) | 736 | 952 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 737 | | | 738 | 63.1k | cinfo->image_width = (JDIMENSION)w; | 739 | 63.1k | cinfo->image_height = (JDIMENSION)h; | 740 | 63.1k | source->maxval = maxval; | 741 | | | 742 | | /* initialize flags to most common settings */ | 743 | 63.1k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ | 744 | 63.1k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 745 | 63.1k | need_rescale = TRUE; /* do we need a rescale array? */ | 746 | | | 747 | 63.1k | switch (c) { | 748 | 5.04k | case '2': /* it's a text-format PGM file */ | 749 | 5.04k | if (cinfo->in_color_space == JCS_UNKNOWN || | 750 | 5.04k | cinfo->in_color_space == JCS_RGB) | 751 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 752 | 5.04k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); | 753 | 5.04k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 754 | 721 | source->pub.get_pixel_rows = get_text_gray_row; | 755 | 4.32k | else if (IsExtRGB(cinfo->in_color_space)) | 756 | 3.60k | source->pub.get_pixel_rows = get_text_gray_rgb_row; | 757 | 721 | else if (cinfo->in_color_space == JCS_CMYK) | 758 | 721 | source->pub.get_pixel_rows = get_text_gray_cmyk_row; | 759 | 0 | else | 760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 761 | 5.04k | need_iobuffer = FALSE; | 762 | 5.04k | break; | 763 | | | 764 | 5.83k | case '3': /* it's a text-format PPM file */ | 765 | 5.83k | if (cinfo->in_color_space == JCS_UNKNOWN) | 766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 767 | 5.83k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); | 768 | 5.83k | if (IsExtRGB(cinfo->in_color_space)) | 769 | 4.16k | source->pub.get_pixel_rows = get_text_rgb_row; | 770 | 1.66k | else if (cinfo->in_color_space == JCS_CMYK) | 771 | 833 | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; | 772 | 833 | else | 773 | 833 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 774 | 5.83k | need_iobuffer = FALSE; | 775 | 5.83k | break; | 776 | | | 777 | 31.4k | case '5': /* it's a raw-format PGM file */ | 778 | 31.4k | if (cinfo->in_color_space == JCS_UNKNOWN || | 779 | 31.4k | cinfo->in_color_space == JCS_RGB) | 780 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 781 | 31.4k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); | 782 | 31.4k | if (maxval > 255) { | 783 | 5.18k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 784 | 740 | source->pub.get_pixel_rows = get_word_gray_row; | 785 | 4.44k | else if (IsExtRGB(cinfo->in_color_space)) | 786 | 3.70k | source->pub.get_pixel_rows = get_word_gray_rgb_row; | 787 | 740 | else if (cinfo->in_color_space == JCS_CMYK) | 788 | 740 | 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 | 26.2k | } else { | 800 | 26.2k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 801 | 3.75k | source->pub.get_pixel_rows = get_scaled_gray_row; | 802 | 22.5k | else if (IsExtRGB(cinfo->in_color_space)) | 803 | 18.7k | source->pub.get_pixel_rows = get_gray_rgb_row; | 804 | 3.75k | else if (cinfo->in_color_space == JCS_CMYK) | 805 | 3.75k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 806 | 0 | else | 807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 808 | 26.2k | } | 809 | 31.4k | break; | 810 | | | 811 | 14.5k | case '6': /* it's a raw-format PPM file */ | 812 | 14.5k | if (cinfo->in_color_space == JCS_UNKNOWN) | 813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 814 | 14.5k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); | 815 | 14.5k | if (maxval > 255) { | 816 | 7.69k | if (IsExtRGB(cinfo->in_color_space)) | 817 | 5.49k | source->pub.get_pixel_rows = get_word_rgb_row; | 818 | 2.19k | else if (cinfo->in_color_space == JCS_CMYK) | 819 | 1.09k | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; | 820 | 1.09k | else | 821 | 1.09k | 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.69k | } else { | 836 | 6.84k | if (IsExtRGB(cinfo->in_color_space)) | 837 | 4.89k | source->pub.get_pixel_rows = get_rgb_row; | 838 | 1.95k | else if (cinfo->in_color_space == JCS_CMYK) | 839 | 978 | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 840 | 978 | else | 841 | 978 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 842 | 6.84k | } | 843 | 14.5k | break; | 844 | 63.1k | } | 845 | | | 846 | 53.9k | if (IsExtRGB(cinfo->in_color_space)) | 847 | 40.6k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 848 | 13.3k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 849 | 5.21k | cinfo->input_components = 1; | 850 | 8.12k | else if (cinfo->in_color_space == JCS_CMYK) | 851 | 8.12k | cinfo->input_components = 4; | 852 | | | 853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 854 | 53.9k | if (need_iobuffer) { | 855 | 43.9k | if (c == '6') | 856 | 12.4k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); | 857 | 31.4k | else | 858 | 31.4k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); | 859 | 43.9k | source->iobuffer = (unsigned char *) | 860 | 43.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 861 | 43.9k | source->buffer_width); | 862 | 43.9k | } | 863 | | | 864 | | /* Create compressor input buffer. */ | 865 | 53.9k | 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 | 53.9k | } else { | 872 | | /* Need to translate anyway, so make a separate sample buffer. */ | 873 | 53.9k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 874 | 53.9k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 875 | 53.9k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); | 876 | 53.9k | source->pub.buffer_height = 1; | 877 | 53.9k | } | 878 | | | 879 | | /* Compute the rescaling array if required. */ | 880 | 53.9k | if (need_rescale) { | 881 | 53.9k | size_t val, half_maxval; | 882 | | | 883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ | 884 | 53.9k | source->rescale = (_JSAMPLE *) | 885 | 53.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 886 | 53.9k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 887 | 53.9k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 888 | 53.9k | half_maxval = (size_t)maxval / 2; | 889 | 163M | for (val = 0; val <= (size_t)maxval; val++) { | 890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 891 | 163M | source->rescale[val] = | 892 | 163M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 893 | 163M | maxval); | 894 | 163M | } | 895 | 53.9k | } | 896 | 53.9k | } |
rdppm-16.c:start_input_ppm Line | Count | Source | 703 | 26.0k | { | 704 | 26.0k | ppm_source_ptr source = (ppm_source_ptr)sinfo; | 705 | 26.0k | int c; | 706 | 26.0k | unsigned int w, h, maxval; | 707 | 26.0k | boolean need_iobuffer, use_raw_buffer, need_rescale; | 708 | | | 709 | 26.0k | if (getc(source->pub.input_file) != 'P') | 710 | 0 | ERREXIT(cinfo, JERR_PPM_NOT); | 711 | | | 712 | 26.0k | c = getc(source->pub.input_file); /* subformat discriminator character */ | 713 | | | 714 | | /* detect unsupported variants (ie, PBM) before trying to read header */ | 715 | 26.0k | switch (c) { | 716 | 3.22k | case '2': /* it's a text-format PGM file */ | 717 | 7.49k | case '3': /* it's a text-format PPM file */ | 718 | 18.8k | case '5': /* it's a raw-format PGM file */ | 719 | 25.9k | case '6': /* it's a raw-format PPM file */ | 720 | 25.9k | break; | 721 | 105 | default: | 722 | 105 | ERREXIT(cinfo, JERR_PPM_NOT); | 723 | 105 | break; | 724 | 26.0k | } | 725 | | | 726 | | /* fetch the remaining header info */ | 727 | 25.9k | w = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 728 | 25.9k | h = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 729 | 25.9k | maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); | 730 | | | 731 | 25.9k | if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ | 732 | 84 | ERREXIT(cinfo, JERR_PPM_NOT); | 733 | 25.9k | if (w > JPEG_MAX_DIMENSION || h > JPEG_MAX_DIMENSION) | 734 | 42 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 735 | 25.9k | if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) | 736 | 525 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 737 | | | 738 | 25.9k | cinfo->image_width = (JDIMENSION)w; | 739 | 25.9k | cinfo->image_height = (JDIMENSION)h; | 740 | 25.9k | source->maxval = maxval; | 741 | | | 742 | | /* initialize flags to most common settings */ | 743 | 25.9k | need_iobuffer = TRUE; /* do we need an I/O buffer? */ | 744 | 25.9k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 745 | 25.9k | need_rescale = TRUE; /* do we need a rescale array? */ | 746 | | | 747 | 25.9k | switch (c) { | 748 | 2.63k | case '2': /* it's a text-format PGM file */ | 749 | 2.63k | if (cinfo->in_color_space == JCS_UNKNOWN || | 750 | 2.63k | cinfo->in_color_space == JCS_RGB) | 751 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 752 | 2.63k | TRACEMS3(cinfo, 1, JTRC_PGM_TEXT, w, h, maxval); | 753 | 2.63k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 754 | 377 | source->pub.get_pixel_rows = get_text_gray_row; | 755 | 2.26k | else if (IsExtRGB(cinfo->in_color_space)) | 756 | 1.88k | source->pub.get_pixel_rows = get_text_gray_rgb_row; | 757 | 377 | else if (cinfo->in_color_space == JCS_CMYK) | 758 | 377 | source->pub.get_pixel_rows = get_text_gray_cmyk_row; | 759 | 0 | else | 760 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 761 | 2.63k | need_iobuffer = FALSE; | 762 | 2.63k | break; | 763 | | | 764 | 3.23k | case '3': /* it's a text-format PPM file */ | 765 | 3.23k | if (cinfo->in_color_space == JCS_UNKNOWN) | 766 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 767 | 3.23k | TRACEMS3(cinfo, 1, JTRC_PPM_TEXT, w, h, maxval); | 768 | 3.23k | if (IsExtRGB(cinfo->in_color_space)) | 769 | 2.31k | source->pub.get_pixel_rows = get_text_rgb_row; | 770 | 924 | else if (cinfo->in_color_space == JCS_CMYK) | 771 | 462 | source->pub.get_pixel_rows = get_text_rgb_cmyk_row; | 772 | 462 | else | 773 | 462 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 774 | 3.23k | need_iobuffer = FALSE; | 775 | 3.23k | break; | 776 | | | 777 | 10.6k | case '5': /* it's a raw-format PGM file */ | 778 | 10.6k | if (cinfo->in_color_space == JCS_UNKNOWN || | 779 | 10.6k | cinfo->in_color_space == JCS_RGB) | 780 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 781 | 10.6k | TRACEMS3(cinfo, 1, JTRC_PGM, w, h, maxval); | 782 | 10.6k | if (maxval > 255) { | 783 | 2.68k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 784 | 384 | source->pub.get_pixel_rows = get_word_gray_row; | 785 | 2.30k | else if (IsExtRGB(cinfo->in_color_space)) | 786 | 1.92k | source->pub.get_pixel_rows = get_word_gray_rgb_row; | 787 | 384 | else if (cinfo->in_color_space == JCS_CMYK) | 788 | 384 | 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.96k | } else { | 800 | 7.96k | if (cinfo->in_color_space == JCS_GRAYSCALE) | 801 | 1.13k | source->pub.get_pixel_rows = get_scaled_gray_row; | 802 | 6.82k | else if (IsExtRGB(cinfo->in_color_space)) | 803 | 5.69k | source->pub.get_pixel_rows = get_gray_rgb_row; | 804 | 1.13k | else if (cinfo->in_color_space == JCS_CMYK) | 805 | 1.13k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 806 | 0 | else | 807 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 808 | 7.96k | } | 809 | 10.6k | break; | 810 | | | 811 | 6.34k | case '6': /* it's a raw-format PPM file */ | 812 | 6.34k | if (cinfo->in_color_space == JCS_UNKNOWN) | 813 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 814 | 6.34k | TRACEMS3(cinfo, 1, JTRC_PPM, w, h, maxval); | 815 | 6.34k | if (maxval > 255) { | 816 | 3.65k | if (IsExtRGB(cinfo->in_color_space)) | 817 | 2.61k | source->pub.get_pixel_rows = get_word_rgb_row; | 818 | 1.04k | else if (cinfo->in_color_space == JCS_CMYK) | 819 | 522 | source->pub.get_pixel_rows = get_word_rgb_cmyk_row; | 820 | 522 | else | 821 | 522 | 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.65k | } else { | 836 | 2.68k | if (IsExtRGB(cinfo->in_color_space)) | 837 | 1.92k | source->pub.get_pixel_rows = get_rgb_row; | 838 | 768 | else if (cinfo->in_color_space == JCS_CMYK) | 839 | 384 | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 840 | 384 | else | 841 | 384 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 842 | 2.68k | } | 843 | 6.34k | break; | 844 | 25.9k | } | 845 | | | 846 | 21.5k | if (IsExtRGB(cinfo->in_color_space)) | 847 | 16.3k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 848 | 5.16k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 849 | 1.89k | cinfo->input_components = 1; | 850 | 3.26k | else if (cinfo->in_color_space == JCS_CMYK) | 851 | 3.26k | cinfo->input_components = 4; | 852 | | | 853 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 854 | 21.5k | if (need_iobuffer) { | 855 | 16.0k | if (c == '6') | 856 | 5.43k | source->buffer_width = (size_t)w * 3 * (maxval <= 255 ? 1 : 2); | 857 | 10.6k | else | 858 | 10.6k | source->buffer_width = (size_t)w * (maxval <= 255 ? 1 : 2); | 859 | 16.0k | source->iobuffer = (unsigned char *) | 860 | 16.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 861 | 16.0k | source->buffer_width); | 862 | 16.0k | } | 863 | | | 864 | | /* Create compressor input buffer. */ | 865 | 21.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 | 21.5k | } else { | 872 | | /* Need to translate anyway, so make a separate sample buffer. */ | 873 | 21.5k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 874 | 21.5k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 875 | 21.5k | (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); | 876 | 21.5k | source->pub.buffer_height = 1; | 877 | 21.5k | } | 878 | | | 879 | | /* Compute the rescaling array if required. */ | 880 | 21.5k | if (need_rescale) { | 881 | 21.5k | size_t val, half_maxval; | 882 | | | 883 | | /* On 16-bit-int machines we have to be careful of maxval = 65535 */ | 884 | 21.5k | source->rescale = (_JSAMPLE *) | 885 | 21.5k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 886 | 21.5k | (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 887 | 21.5k | memset(source->rescale, 0, (MAX(maxval, 255) + 1L) * sizeof(_JSAMPLE)); | 888 | 21.5k | half_maxval = (size_t)maxval / 2; | 889 | 320M | for (val = 0; val <= (size_t)maxval; val++) { | 890 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 891 | 320M | source->rescale[val] = | 892 | 320M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 893 | 320M | maxval); | 894 | 320M | } | 895 | 21.5k | } | 896 | 21.5k | } |
|
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.15k | { |
903 | 1.15k | return FALSE; |
904 | 1.15k | } rdppm-8.c:read_icc_profile_ppm Line | Count | Source | 902 | 1.15k | { | 903 | 1.15k | return FALSE; | 904 | 1.15k | } |
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 | 134k | { |
914 | | /* no work */ |
915 | 134k | } rdppm-8.c:finish_input_ppm Line | Count | Source | 913 | 71.4k | { | 914 | | /* no work */ | 915 | 71.4k | } |
rdppm-12.c:finish_input_ppm Line | Count | Source | 913 | 46.0k | { | 914 | | /* no work */ | 915 | 46.0k | } |
rdppm-16.c:finish_input_ppm Line | Count | Source | 913 | 17.3k | { | 914 | | /* no work */ | 915 | 17.3k | } |
|
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 | 184k | { |
925 | 184k | ppm_source_ptr source; |
926 | | |
927 | | #if BITS_IN_JSAMPLE == 8 |
928 | 94.8k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
929 | | #else |
930 | 89.4k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
931 | 89.4k | 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 | 184k | source = (ppm_source_ptr) |
937 | 184k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
938 | 184k | sizeof(ppm_source_struct)); |
939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
940 | 184k | source->pub.start_input = start_input_ppm; |
941 | 184k | source->pub.read_icc_profile = read_icc_profile_ppm; |
942 | 184k | source->pub.finish_input = finish_input_ppm; |
943 | 184k | source->pub.max_pixels = 0; |
944 | | |
945 | 184k | return (cjpeg_source_ptr)source; |
946 | 184k | } Line | Count | Source | 924 | 94.8k | { | 925 | 94.8k | ppm_source_ptr source; | 926 | | | 927 | 94.8k | #if BITS_IN_JSAMPLE == 8 | 928 | 94.8k | 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.8k | source = (ppm_source_ptr) | 937 | 94.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 938 | 94.8k | sizeof(ppm_source_struct)); | 939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 940 | 94.8k | source->pub.start_input = start_input_ppm; | 941 | 94.8k | source->pub.read_icc_profile = read_icc_profile_ppm; | 942 | 94.8k | source->pub.finish_input = finish_input_ppm; | 943 | 94.8k | source->pub.max_pixels = 0; | 944 | | | 945 | 94.8k | return (cjpeg_source_ptr)source; | 946 | 94.8k | } |
Line | Count | Source | 924 | 63.4k | { | 925 | 63.4k | 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 | 63.4k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 931 | 63.4k | 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 | 63.4k | source = (ppm_source_ptr) | 937 | 63.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 938 | 63.4k | sizeof(ppm_source_struct)); | 939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 940 | 63.4k | source->pub.start_input = start_input_ppm; | 941 | 63.4k | source->pub.read_icc_profile = read_icc_profile_ppm; | 942 | 63.4k | source->pub.finish_input = finish_input_ppm; | 943 | 63.4k | source->pub.max_pixels = 0; | 944 | | | 945 | 63.4k | return (cjpeg_source_ptr)source; | 946 | 63.4k | } |
Line | Count | Source | 924 | 26.0k | { | 925 | 26.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 | 26.0k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 931 | 26.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 | 26.0k | source = (ppm_source_ptr) | 937 | 26.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 938 | 26.0k | sizeof(ppm_source_struct)); | 939 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 940 | 26.0k | source->pub.start_input = start_input_ppm; | 941 | 26.0k | source->pub.read_icc_profile = read_icc_profile_ppm; | 942 | 26.0k | source->pub.finish_input = finish_input_ppm; | 943 | 26.0k | source->pub.max_pixels = 0; | 944 | | | 945 | 26.0k | return (cjpeg_source_ptr)source; | 946 | 26.0k | } |
|
947 | | |
948 | | #endif /* defined(PPM_SUPPORTED) && |
949 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ |