/src/libjpeg-turbo.main/src/rdpng.c
Line | Count | Source |
1 | | /* |
2 | | * rdpng.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1991-1997, Thomas G. Lane. |
6 | | * libjpeg-turbo Modifications: |
7 | | * Copyright (C) 2015-2017, 2020-2026, D. R. Commander. |
8 | | * For conditions of distribution and use, see the accompanying README.ijg |
9 | | * file. |
10 | | * |
11 | | * This file contains routines to read input images in 8-bit-per-channel or |
12 | | * 16-bit-per-channel PNG format. libspng is required to compile this |
13 | | * software. |
14 | | */ |
15 | | |
16 | | #ifdef _MSC_VER |
17 | | #define _CRT_SECURE_NO_DEPRECATE |
18 | | #endif |
19 | | |
20 | | #include "cmyk.h" |
21 | | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
22 | | #include "spng/spng.h" |
23 | | |
24 | | #if defined(PNG_SUPPORTED) && \ |
25 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) |
26 | | |
27 | | |
28 | | static int alpha_index[JPEG_NUMCS] = { |
29 | | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 |
30 | | }; |
31 | | |
32 | | |
33 | 502k | #define TRY_SPNG(f) { \ |
34 | 502k | int __spng_error = (f); \ |
35 | 502k | if (__spng_error) \ |
36 | 502k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(__spng_error)); \ |
37 | 502k | } |
38 | | |
39 | | |
40 | | /* Private version of data source object */ |
41 | | |
42 | | typedef struct { |
43 | | struct cjpeg_source_struct pub; /* public fields */ |
44 | | |
45 | | spng_ctx *ctx; |
46 | | uint8_t png_bit_depth, png_color_type; |
47 | | int png_alpha; |
48 | | struct spng_plte colormap; /* PNG colormap */ |
49 | | |
50 | | /* Usually these two pointers point to the same place: */ |
51 | | unsigned char *iobuffer; /* libspng's I/O buffer */ |
52 | | _JSAMPROW pixrow; /* compressor input buffer */ |
53 | | size_t buffer_width; /* width of I/O buffer */ |
54 | | _JSAMPLE *rescale; /* PNG bit depth => data precision remapping |
55 | | array, or NULL */ |
56 | | } png_source_struct; |
57 | | |
58 | | typedef png_source_struct *png_source_ptr; |
59 | | |
60 | | |
61 | | /* |
62 | | * Read one row of pixels. |
63 | | * |
64 | | * We provide several different versions depending on input file format. |
65 | | * In all cases, input is scaled to cinfo->data_precision. |
66 | | * |
67 | | * get_raw_row() is used when the pixel format is JCS_EXT_RGB/JCS_RGB or |
68 | | * JCS_GRAYSCALE, cinfo->data_precision is 8 or 16, and the PNG file doesn't |
69 | | * have an alpha channel. Thus, we can read the pixels directly from the PNG |
70 | | * file. |
71 | | */ |
72 | | |
73 | | METHODDEF(JDIMENSION) |
74 | | get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
75 | 2.82M | { |
76 | 2.82M | png_source_ptr source = (png_source_ptr)sinfo; |
77 | 2.82M | int spng_error; |
78 | | |
79 | 2.82M | spng_error = spng_decode_row(source->ctx, source->iobuffer, |
80 | 2.82M | source->buffer_width); |
81 | 2.82M | if (spng_error && spng_error != SPNG_EOI) |
82 | 23.6k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ |
83 | 2.82M | return 1; |
84 | 2.82M | } Line | Count | Source | 75 | 1.28M | { | 76 | 1.28M | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 1.28M | int spng_error; | 78 | | | 79 | 1.28M | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 1.28M | source->buffer_width); | 81 | 1.28M | if (spng_error && spng_error != SPNG_EOI) | 82 | 10.8k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 1.28M | return 1; | 84 | 1.28M | } |
Line | Count | Source | 75 | 893k | { | 76 | 893k | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 893k | int spng_error; | 78 | | | 79 | 893k | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 893k | source->buffer_width); | 81 | 893k | if (spng_error && spng_error != SPNG_EOI) | 82 | 7.93k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 893k | return 1; | 84 | 893k | } |
Line | Count | Source | 75 | 649k | { | 76 | 649k | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 649k | int spng_error; | 78 | | | 79 | 649k | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 649k | source->buffer_width); | 81 | 649k | if (spng_error && spng_error != SPNG_EOI) | 82 | 4.78k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 649k | return 1; | 84 | 649k | } |
|
85 | | |
86 | | |
87 | 1.12M | #define GRAY_RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \ |
88 | 130M | for (col = cinfo->image_width; col > 0; col--) { \ |
89 | 129M | ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \ |
90 | 129M | alpha_set_op \ |
91 | 129M | ptr += ps; \ |
92 | 129M | pointer_op \ |
93 | 129M | } \ |
94 | 1.12M | } |
95 | | |
96 | | |
97 | | METHODDEF(JDIMENSION) |
98 | | get_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
99 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
100 | | * grayscale or grayscale + alpha PNG files. |
101 | | */ |
102 | 160k | { |
103 | 160k | png_source_ptr source = (png_source_ptr)sinfo; |
104 | 160k | register _JSAMPROW ptr; |
105 | 160k | register _JSAMPLE *rescale = source->rescale; |
106 | 160k | JDIMENSION col; |
107 | | |
108 | 160k | get_raw_row(cinfo, sinfo); |
109 | 160k | ptr = source->pub._buffer[0]; |
110 | | #if BITS_IN_JSAMPLE != 12 |
111 | 127k | if (source->png_bit_depth == cinfo->data_precision) { |
112 | 4.53k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
113 | 45.8k | for (col = cinfo->image_width; col > 0; col--) { |
114 | 41.3k | *ptr++ = *bufferptr++; |
115 | 41.3k | bufferptr += source->png_alpha; |
116 | 41.3k | } |
117 | 4.53k | } else |
118 | 123k | #endif |
119 | 155k | if (source->png_bit_depth == 16) { |
120 | 92.6k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
121 | 4.78M | for (col = cinfo->image_width; col > 0; col--) { |
122 | 4.69M | *ptr++ = rescale[*bufferptr++]; |
123 | 4.69M | bufferptr += source->png_alpha; |
124 | 4.69M | } |
125 | 92.6k | } else { |
126 | 62.9k | register unsigned char *bufferptr = source->iobuffer; |
127 | 13.6M | for (col = cinfo->image_width; col > 0; col--) { |
128 | 13.6M | *ptr++ = rescale[*bufferptr++]; |
129 | 13.6M | bufferptr += source->png_alpha; |
130 | 13.6M | } |
131 | 62.9k | } |
132 | 160k | return 1; |
133 | 160k | } Line | Count | Source | 102 | 96.0k | { | 103 | 96.0k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 96.0k | register _JSAMPROW ptr; | 105 | 96.0k | register _JSAMPLE *rescale = source->rescale; | 106 | 96.0k | JDIMENSION col; | 107 | | | 108 | 96.0k | get_raw_row(cinfo, sinfo); | 109 | 96.0k | ptr = source->pub._buffer[0]; | 110 | 96.0k | #if BITS_IN_JSAMPLE != 12 | 111 | 96.0k | if (source->png_bit_depth == cinfo->data_precision) { | 112 | 351 | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | 24.9k | for (col = cinfo->image_width; col > 0; col--) { | 114 | 24.6k | *ptr++ = *bufferptr++; | 115 | 24.6k | bufferptr += source->png_alpha; | 116 | 24.6k | } | 117 | 351 | } else | 118 | 95.7k | #endif | 119 | 95.7k | if (source->png_bit_depth == 16) { | 120 | 90.5k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 4.65M | for (col = cinfo->image_width; col > 0; col--) { | 122 | 4.56M | *ptr++ = rescale[*bufferptr++]; | 123 | 4.56M | bufferptr += source->png_alpha; | 124 | 4.56M | } | 125 | 90.5k | } else { | 126 | 5.19k | register unsigned char *bufferptr = source->iobuffer; | 127 | 363k | for (col = cinfo->image_width; col > 0; col--) { | 128 | 358k | *ptr++ = rescale[*bufferptr++]; | 129 | 358k | bufferptr += source->png_alpha; | 130 | 358k | } | 131 | 5.19k | } | 132 | 96.0k | return 1; | 133 | 96.0k | } |
Line | Count | Source | 102 | 32.2k | { | 103 | 32.2k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 32.2k | register _JSAMPROW ptr; | 105 | 32.2k | register _JSAMPLE *rescale = source->rescale; | 106 | 32.2k | JDIMENSION col; | 107 | | | 108 | 32.2k | get_raw_row(cinfo, sinfo); | 109 | 32.2k | ptr = source->pub._buffer[0]; | 110 | | #if BITS_IN_JSAMPLE != 12 | 111 | | if (source->png_bit_depth == cinfo->data_precision) { | 112 | | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | | for (col = cinfo->image_width; col > 0; col--) { | 114 | | *ptr++ = *bufferptr++; | 115 | | bufferptr += source->png_alpha; | 116 | | } | 117 | | } else | 118 | | #endif | 119 | 32.2k | if (source->png_bit_depth == 16) { | 120 | 2.10k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 130k | for (col = cinfo->image_width; col > 0; col--) { | 122 | 128k | *ptr++ = rescale[*bufferptr++]; | 123 | 128k | bufferptr += source->png_alpha; | 124 | 128k | } | 125 | 30.1k | } else { | 126 | 30.1k | register unsigned char *bufferptr = source->iobuffer; | 127 | 5.20M | for (col = cinfo->image_width; col > 0; col--) { | 128 | 5.17M | *ptr++ = rescale[*bufferptr++]; | 129 | 5.17M | bufferptr += source->png_alpha; | 130 | 5.17M | } | 131 | 30.1k | } | 132 | 32.2k | return 1; | 133 | 32.2k | } |
Line | Count | Source | 102 | 31.7k | { | 103 | 31.7k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 31.7k | register _JSAMPROW ptr; | 105 | 31.7k | register _JSAMPLE *rescale = source->rescale; | 106 | 31.7k | JDIMENSION col; | 107 | | | 108 | 31.7k | get_raw_row(cinfo, sinfo); | 109 | 31.7k | ptr = source->pub._buffer[0]; | 110 | 31.7k | #if BITS_IN_JSAMPLE != 12 | 111 | 31.7k | if (source->png_bit_depth == cinfo->data_precision) { | 112 | 4.18k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | 20.8k | for (col = cinfo->image_width; col > 0; col--) { | 114 | 16.6k | *ptr++ = *bufferptr++; | 115 | 16.6k | bufferptr += source->png_alpha; | 116 | 16.6k | } | 117 | 4.18k | } else | 118 | 27.6k | #endif | 119 | 27.6k | if (source->png_bit_depth == 16) { | 120 | 0 | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 122 | 0 | *ptr++ = rescale[*bufferptr++]; | 123 | 0 | bufferptr += source->png_alpha; | 124 | 0 | } | 125 | 27.6k | } else { | 126 | 27.6k | register unsigned char *bufferptr = source->iobuffer; | 127 | 8.12M | for (col = cinfo->image_width; col > 0; col--) { | 128 | 8.09M | *ptr++ = rescale[*bufferptr++]; | 129 | 8.09M | bufferptr += source->png_alpha; | 130 | 8.09M | } | 131 | 27.6k | } | 132 | 31.7k | return 1; | 133 | 31.7k | } |
|
134 | | |
135 | | |
136 | | METHODDEF(JDIMENSION) |
137 | | get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
138 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
139 | | * grayscale or grayscale + alpha PNG files and converting to extended RGB. |
140 | | */ |
141 | 1.12M | { |
142 | 1.12M | png_source_ptr source = (png_source_ptr)sinfo; |
143 | 1.12M | register _JSAMPROW ptr; |
144 | 1.12M | register _JSAMPLE *rescale = source->rescale; |
145 | 1.12M | JDIMENSION col; |
146 | 1.12M | register int rindex = rgb_red[cinfo->in_color_space]; |
147 | 1.12M | register int gindex = rgb_green[cinfo->in_color_space]; |
148 | 1.12M | register int bindex = rgb_blue[cinfo->in_color_space]; |
149 | 1.12M | register int aindex = alpha_index[cinfo->in_color_space]; |
150 | 1.12M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
151 | | |
152 | 1.12M | get_raw_row(cinfo, sinfo); |
153 | 1.12M | ptr = source->pub._buffer[0]; |
154 | | #if BITS_IN_JSAMPLE != 12 |
155 | 968k | if (source->png_bit_depth == cinfo->data_precision) { |
156 | 239k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
157 | 239k | if (aindex >= 0) |
158 | 1.54k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, |
159 | 239k | bufferptr += source->png_alpha;) |
160 | 238k | else |
161 | 238k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) |
162 | 239k | } else |
163 | 728k | #endif |
164 | 889k | if (source->png_bit_depth == 16) { |
165 | 580k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
166 | 580k | if (aindex >= 0) |
167 | 47.1k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
168 | 580k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
169 | 580k | bufferptr += source->png_alpha;) |
170 | 532k | else |
171 | 532k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, |
172 | 580k | bufferptr += source->png_alpha;) |
173 | 580k | } else { |
174 | 309k | register unsigned char *bufferptr = source->iobuffer; |
175 | 309k | if (aindex >= 0) |
176 | 61.5k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
177 | 309k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
178 | 309k | bufferptr += source->png_alpha;) |
179 | 248k | else |
180 | 248k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, |
181 | 309k | bufferptr += source->png_alpha;) |
182 | 309k | } |
183 | 1.12M | return 1; |
184 | 1.12M | } rdpng-8.c:get_gray_rgb_row Line | Count | Source | 141 | 617k | { | 142 | 617k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 617k | register _JSAMPROW ptr; | 144 | 617k | register _JSAMPLE *rescale = source->rescale; | 145 | 617k | JDIMENSION col; | 146 | 617k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 617k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 617k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 617k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 617k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 617k | get_raw_row(cinfo, sinfo); | 153 | 617k | ptr = source->pub._buffer[0]; | 154 | 617k | #if BITS_IN_JSAMPLE != 12 | 155 | 617k | if (source->png_bit_depth == cinfo->data_precision) { | 156 | 154k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | 154k | if (aindex >= 0) | 158 | 1.54k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | 154k | bufferptr += source->png_alpha;) | 160 | 153k | else | 161 | 153k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | 154k | } else | 163 | 462k | #endif | 164 | 462k | if (source->png_bit_depth == 16) { | 165 | 441k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 441k | if (aindex >= 0) | 167 | 2.48k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 441k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 441k | bufferptr += source->png_alpha;) | 170 | 439k | else | 171 | 439k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 441k | bufferptr += source->png_alpha;) | 173 | 441k | } else { | 174 | 20.6k | register unsigned char *bufferptr = source->iobuffer; | 175 | 20.6k | if (aindex >= 0) | 176 | 4.52k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 20.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 20.6k | bufferptr += source->png_alpha;) | 179 | 16.1k | else | 180 | 16.1k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 20.6k | bufferptr += source->png_alpha;) | 182 | 20.6k | } | 183 | 617k | return 1; | 184 | 617k | } |
rdpng-12.c:get_gray_rgb_row Line | Count | Source | 141 | 161k | { | 142 | 161k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 161k | register _JSAMPROW ptr; | 144 | 161k | register _JSAMPLE *rescale = source->rescale; | 145 | 161k | JDIMENSION col; | 146 | 161k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 161k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 161k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 161k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 161k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 161k | get_raw_row(cinfo, sinfo); | 153 | 161k | ptr = source->pub._buffer[0]; | 154 | | #if BITS_IN_JSAMPLE != 12 | 155 | | if (source->png_bit_depth == cinfo->data_precision) { | 156 | | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | | if (aindex >= 0) | 158 | | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | | bufferptr += source->png_alpha;) | 160 | | else | 161 | | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | | } else | 163 | | #endif | 164 | 161k | if (source->png_bit_depth == 16) { | 165 | 10.5k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 10.5k | if (aindex >= 0) | 167 | 2.10k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 10.5k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 10.5k | bufferptr += source->png_alpha;) | 170 | 8.42k | else | 171 | 8.42k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 10.5k | bufferptr += source->png_alpha;) | 173 | 150k | } else { | 174 | 150k | register unsigned char *bufferptr = source->iobuffer; | 175 | 150k | if (aindex >= 0) | 176 | 29.6k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 150k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 150k | bufferptr += source->png_alpha;) | 179 | 120k | else | 180 | 120k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 150k | bufferptr += source->png_alpha;) | 182 | 150k | } | 183 | 161k | return 1; | 184 | 161k | } |
rdpng-16.c:get_gray_rgb_row Line | Count | Source | 141 | 351k | { | 142 | 351k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 351k | register _JSAMPROW ptr; | 144 | 351k | register _JSAMPLE *rescale = source->rescale; | 145 | 351k | JDIMENSION col; | 146 | 351k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 351k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 351k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 351k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 351k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 351k | get_raw_row(cinfo, sinfo); | 153 | 351k | ptr = source->pub._buffer[0]; | 154 | 351k | #if BITS_IN_JSAMPLE != 12 | 155 | 351k | if (source->png_bit_depth == cinfo->data_precision) { | 156 | 85.0k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | 85.0k | if (aindex >= 0) | 158 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | 85.0k | bufferptr += source->png_alpha;) | 160 | 85.0k | else | 161 | 85.0k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | 85.0k | } else | 163 | 266k | #endif | 164 | 266k | if (source->png_bit_depth == 16) { | 165 | 127k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 127k | if (aindex >= 0) | 167 | 42.5k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 127k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 127k | bufferptr += source->png_alpha;) | 170 | 85.0k | else | 171 | 85.0k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 127k | bufferptr += source->png_alpha;) | 173 | 138k | } else { | 174 | 138k | register unsigned char *bufferptr = source->iobuffer; | 175 | 138k | if (aindex >= 0) | 176 | 27.3k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 138k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 138k | bufferptr += source->png_alpha;) | 179 | 111k | else | 180 | 111k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 138k | bufferptr += source->png_alpha;) | 182 | 138k | } | 183 | 351k | return 1; | 184 | 351k | } |
|
185 | | |
186 | | |
187 | | METHODDEF(JDIMENSION) |
188 | | get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
189 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
190 | | * grayscale or grayscale + alpha PNG files and converting to CMYK. |
191 | | */ |
192 | 111k | { |
193 | 111k | png_source_ptr source = (png_source_ptr)sinfo; |
194 | 111k | register _JSAMPROW ptr; |
195 | 111k | register _JSAMPLE *rescale = source->rescale; |
196 | 111k | JDIMENSION col; |
197 | | |
198 | 111k | get_raw_row(cinfo, sinfo); |
199 | 111k | ptr = source->pub._buffer[0]; |
200 | | #if BITS_IN_JSAMPLE != 12 |
201 | 79.1k | if (source->png_bit_depth == cinfo->data_precision) { |
202 | 44.0k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
203 | 1.85M | for (col = cinfo->image_width; col > 0; col--) { |
204 | 1.80M | _JSAMPLE gray = *bufferptr++; |
205 | 1.80M | bufferptr += source->png_alpha; |
206 | 1.80M | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, |
207 | 1.80M | ptr + 3); |
208 | 1.80M | ptr += 4; |
209 | 1.80M | } |
210 | 44.0k | } else |
211 | 35.0k | #endif |
212 | 67.2k | if (source->png_bit_depth == 16) { |
213 | 4.59k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
214 | 358k | for (col = cinfo->image_width; col > 0; col--) { |
215 | 353k | _JSAMPLE gray = rescale[*bufferptr++]; |
216 | 353k | bufferptr += source->png_alpha; |
217 | 353k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
218 | 353k | ptr + 1, ptr + 2, ptr + 3); |
219 | 353k | ptr += 4; |
220 | 353k | } |
221 | 62.6k | } else { |
222 | 62.6k | register unsigned char *bufferptr = source->iobuffer; |
223 | 13.6M | for (col = cinfo->image_width; col > 0; col--) { |
224 | 13.6M | _JSAMPLE gray = rescale[*bufferptr++]; |
225 | 13.6M | bufferptr += source->png_alpha; |
226 | 13.6M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
227 | 13.6M | ptr + 1, ptr + 2, ptr + 3); |
228 | 13.6M | ptr += 4; |
229 | 13.6M | } |
230 | 62.6k | } |
231 | 111k | return 1; |
232 | 111k | } rdpng-8.c:get_gray_cmyk_row Line | Count | Source | 192 | 8.88k | { | 193 | 8.88k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 8.88k | register _JSAMPROW ptr; | 195 | 8.88k | register _JSAMPLE *rescale = source->rescale; | 196 | 8.88k | JDIMENSION col; | 197 | | | 198 | 8.88k | get_raw_row(cinfo, sinfo); | 199 | 8.88k | ptr = source->pub._buffer[0]; | 200 | 8.88k | #if BITS_IN_JSAMPLE != 12 | 201 | 8.88k | if (source->png_bit_depth == cinfo->data_precision) { | 202 | 1.54k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | 118k | for (col = cinfo->image_width; col > 0; col--) { | 204 | 117k | _JSAMPLE gray = *bufferptr++; | 205 | 117k | bufferptr += source->png_alpha; | 206 | 117k | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | 117k | ptr + 3); | 208 | 117k | ptr += 4; | 209 | 117k | } | 210 | 1.54k | } else | 211 | 7.33k | #endif | 212 | 7.33k | if (source->png_bit_depth == 16) { | 213 | 2.48k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 227k | for (col = cinfo->image_width; col > 0; col--) { | 215 | 225k | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 225k | bufferptr += source->png_alpha; | 217 | 225k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 225k | ptr + 1, ptr + 2, ptr + 3); | 219 | 225k | ptr += 4; | 220 | 225k | } | 221 | 4.85k | } else { | 222 | 4.85k | register unsigned char *bufferptr = source->iobuffer; | 223 | 363k | for (col = cinfo->image_width; col > 0; col--) { | 224 | 358k | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 358k | bufferptr += source->png_alpha; | 226 | 358k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 358k | ptr + 1, ptr + 2, ptr + 3); | 228 | 358k | ptr += 4; | 229 | 358k | } | 230 | 4.85k | } | 231 | 8.88k | return 1; | 232 | 8.88k | } |
rdpng-12.c:get_gray_cmyk_row Line | Count | Source | 192 | 32.2k | { | 193 | 32.2k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 32.2k | register _JSAMPROW ptr; | 195 | 32.2k | register _JSAMPLE *rescale = source->rescale; | 196 | 32.2k | JDIMENSION col; | 197 | | | 198 | 32.2k | get_raw_row(cinfo, sinfo); | 199 | 32.2k | ptr = source->pub._buffer[0]; | 200 | | #if BITS_IN_JSAMPLE != 12 | 201 | | if (source->png_bit_depth == cinfo->data_precision) { | 202 | | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | | for (col = cinfo->image_width; col > 0; col--) { | 204 | | _JSAMPLE gray = *bufferptr++; | 205 | | bufferptr += source->png_alpha; | 206 | | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | | ptr + 3); | 208 | | ptr += 4; | 209 | | } | 210 | | } else | 211 | | #endif | 212 | 32.2k | if (source->png_bit_depth == 16) { | 213 | 2.10k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 130k | for (col = cinfo->image_width; col > 0; col--) { | 215 | 128k | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 128k | bufferptr += source->png_alpha; | 217 | 128k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 128k | ptr + 1, ptr + 2, ptr + 3); | 219 | 128k | ptr += 4; | 220 | 128k | } | 221 | 30.1k | } else { | 222 | 30.1k | register unsigned char *bufferptr = source->iobuffer; | 223 | 5.20M | for (col = cinfo->image_width; col > 0; col--) { | 224 | 5.17M | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 5.17M | bufferptr += source->png_alpha; | 226 | 5.17M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 5.17M | ptr + 1, ptr + 2, ptr + 3); | 228 | 5.17M | ptr += 4; | 229 | 5.17M | } | 230 | 30.1k | } | 231 | 32.2k | return 1; | 232 | 32.2k | } |
rdpng-16.c:get_gray_cmyk_row Line | Count | Source | 192 | 70.2k | { | 193 | 70.2k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 70.2k | register _JSAMPROW ptr; | 195 | 70.2k | register _JSAMPLE *rescale = source->rescale; | 196 | 70.2k | JDIMENSION col; | 197 | | | 198 | 70.2k | get_raw_row(cinfo, sinfo); | 199 | 70.2k | ptr = source->pub._buffer[0]; | 200 | 70.2k | #if BITS_IN_JSAMPLE != 12 | 201 | 70.2k | if (source->png_bit_depth == cinfo->data_precision) { | 202 | 42.5k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | 1.73M | for (col = cinfo->image_width; col > 0; col--) { | 204 | 1.69M | _JSAMPLE gray = *bufferptr++; | 205 | 1.69M | bufferptr += source->png_alpha; | 206 | 1.69M | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | 1.69M | ptr + 3); | 208 | 1.69M | ptr += 4; | 209 | 1.69M | } | 210 | 42.5k | } else | 211 | 27.6k | #endif | 212 | 27.6k | if (source->png_bit_depth == 16) { | 213 | 0 | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 215 | 0 | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 0 | bufferptr += source->png_alpha; | 217 | 0 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 0 | ptr + 1, ptr + 2, ptr + 3); | 219 | 0 | ptr += 4; | 220 | 0 | } | 221 | 27.6k | } else { | 222 | 27.6k | register unsigned char *bufferptr = source->iobuffer; | 223 | 8.12M | for (col = cinfo->image_width; col > 0; col--) { | 224 | 8.09M | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 8.09M | bufferptr += source->png_alpha; | 226 | 8.09M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 8.09M | ptr + 1, ptr + 2, ptr + 3); | 228 | 8.09M | ptr += 4; | 229 | 8.09M | } | 230 | 27.6k | } | 231 | 70.2k | return 1; | 232 | 70.2k | } |
|
233 | | |
234 | | |
235 | 1.12M | #define RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \ |
236 | 498M | for (col = cinfo->image_width; col > 0; col--) { \ |
237 | 497M | ptr[rindex] = read_op; \ |
238 | 497M | ptr[gindex] = read_op; \ |
239 | 497M | ptr[bindex] = read_op; \ |
240 | 497M | alpha_set_op \ |
241 | 497M | pointer_op \ |
242 | 497M | ptr += ps; \ |
243 | 497M | } \ |
244 | 1.12M | } |
245 | | |
246 | | |
247 | | METHODDEF(JDIMENSION) |
248 | | get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
249 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
250 | | * truecolor or truecolor + alpha PNG files and converting to extended RGB. |
251 | | */ |
252 | 1.12M | { |
253 | 1.12M | png_source_ptr source = (png_source_ptr)sinfo; |
254 | 1.12M | register _JSAMPROW ptr; |
255 | 1.12M | register _JSAMPLE *rescale = source->rescale; |
256 | 1.12M | JDIMENSION col; |
257 | 1.12M | register int rindex = rgb_red[cinfo->in_color_space]; |
258 | 1.12M | register int gindex = rgb_green[cinfo->in_color_space]; |
259 | 1.12M | register int bindex = rgb_blue[cinfo->in_color_space]; |
260 | 1.12M | register int aindex = alpha_index[cinfo->in_color_space]; |
261 | 1.12M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
262 | | |
263 | 1.12M | get_raw_row(cinfo, sinfo); |
264 | 1.12M | ptr = source->pub._buffer[0]; |
265 | | #if BITS_IN_JSAMPLE != 12 |
266 | 566k | if (source->png_bit_depth == cinfo->data_precision) { |
267 | 312k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
268 | 312k | if (aindex >= 0) |
269 | 6.40k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, |
270 | 312k | bufferptr += source->png_alpha;) |
271 | 306k | else |
272 | 306k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) |
273 | 312k | } else |
274 | 253k | #endif |
275 | 808k | if (source->png_bit_depth == 16) { |
276 | 318k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
277 | 318k | if (aindex >= 0) |
278 | 59.3k | RGB_READ_LOOP(rescale[*bufferptr++], |
279 | 318k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
280 | 318k | bufferptr += source->png_alpha;) |
281 | 258k | else |
282 | 258k | RGB_READ_LOOP(rescale[*bufferptr++], {}, |
283 | 318k | bufferptr += source->png_alpha;) |
284 | 490k | } else { |
285 | 490k | register unsigned char *bufferptr = source->iobuffer; |
286 | 490k | if (aindex >= 0) |
287 | 99.1k | RGB_READ_LOOP(rescale[*bufferptr++], |
288 | 490k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
289 | 490k | bufferptr += source->png_alpha;) |
290 | 391k | else |
291 | 391k | RGB_READ_LOOP(rescale[*bufferptr++], {}, |
292 | 490k | bufferptr += source->png_alpha;) |
293 | 490k | } |
294 | 1.12M | return 1; |
295 | 1.12M | } Line | Count | Source | 252 | 440k | { | 253 | 440k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 440k | register _JSAMPROW ptr; | 255 | 440k | register _JSAMPLE *rescale = source->rescale; | 256 | 440k | JDIMENSION col; | 257 | 440k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 440k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 440k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 440k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 440k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 440k | get_raw_row(cinfo, sinfo); | 264 | 440k | ptr = source->pub._buffer[0]; | 265 | 440k | #if BITS_IN_JSAMPLE != 12 | 266 | 440k | if (source->png_bit_depth == cinfo->data_precision) { | 267 | 310k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | 310k | if (aindex >= 0) | 269 | 6.40k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | 310k | bufferptr += source->png_alpha;) | 271 | 303k | else | 272 | 303k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | 310k | } else | 274 | 129k | #endif | 275 | 129k | if (source->png_bit_depth == 16) { | 276 | 58.2k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 58.2k | if (aindex >= 0) | 278 | 6.40k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 58.2k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 58.2k | bufferptr += source->png_alpha;) | 281 | 51.8k | else | 282 | 51.8k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 58.2k | bufferptr += source->png_alpha;) | 284 | 71.4k | } else { | 285 | 71.4k | register unsigned char *bufferptr = source->iobuffer; | 286 | 71.4k | if (aindex >= 0) | 287 | 16.5k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 71.4k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 71.4k | bufferptr += source->png_alpha;) | 290 | 54.9k | else | 291 | 54.9k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 71.4k | bufferptr += source->png_alpha;) | 293 | 71.4k | } | 294 | 440k | return 1; | 295 | 440k | } |
Line | Count | Source | 252 | 555k | { | 253 | 555k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 555k | register _JSAMPROW ptr; | 255 | 555k | register _JSAMPLE *rescale = source->rescale; | 256 | 555k | JDIMENSION col; | 257 | 555k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 555k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 555k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 555k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 555k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 555k | get_raw_row(cinfo, sinfo); | 264 | 555k | ptr = source->pub._buffer[0]; | 265 | | #if BITS_IN_JSAMPLE != 12 | 266 | | if (source->png_bit_depth == cinfo->data_precision) { | 267 | | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | | if (aindex >= 0) | 269 | | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | | bufferptr += source->png_alpha;) | 271 | | else | 272 | | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | | } else | 274 | | #endif | 275 | 555k | if (source->png_bit_depth == 16) { | 276 | 252k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 252k | if (aindex >= 0) | 278 | 50.5k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 252k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 252k | bufferptr += source->png_alpha;) | 281 | 202k | else | 282 | 202k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 252k | bufferptr += source->png_alpha;) | 284 | 302k | } else { | 285 | 302k | register unsigned char *bufferptr = source->iobuffer; | 286 | 302k | if (aindex >= 0) | 287 | 59.6k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 302k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 302k | bufferptr += source->png_alpha;) | 290 | 242k | else | 291 | 242k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 302k | bufferptr += source->png_alpha;) | 293 | 302k | } | 294 | 555k | return 1; | 295 | 555k | } |
Line | Count | Source | 252 | 126k | { | 253 | 126k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 126k | register _JSAMPROW ptr; | 255 | 126k | register _JSAMPLE *rescale = source->rescale; | 256 | 126k | JDIMENSION col; | 257 | 126k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 126k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 126k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 126k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 126k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 126k | get_raw_row(cinfo, sinfo); | 264 | 126k | ptr = source->pub._buffer[0]; | 265 | 126k | #if BITS_IN_JSAMPLE != 12 | 266 | 126k | if (source->png_bit_depth == cinfo->data_precision) { | 267 | 2.66k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | 2.66k | if (aindex >= 0) | 269 | 0 | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | 2.66k | bufferptr += source->png_alpha;) | 271 | 2.66k | else | 272 | 2.66k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | 2.66k | } else | 274 | 124k | #endif | 275 | 124k | if (source->png_bit_depth == 16) { | 276 | 7.22k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 7.22k | if (aindex >= 0) | 278 | 2.40k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 7.22k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 7.22k | bufferptr += source->png_alpha;) | 281 | 4.81k | else | 282 | 4.81k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 7.22k | bufferptr += source->png_alpha;) | 284 | 117k | } else { | 285 | 117k | register unsigned char *bufferptr = source->iobuffer; | 286 | 117k | if (aindex >= 0) | 287 | 22.9k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 117k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 117k | bufferptr += source->png_alpha;) | 290 | 94.0k | else | 291 | 94.0k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 117k | bufferptr += source->png_alpha;) | 293 | 117k | } | 294 | 126k | return 1; | 295 | 126k | } |
|
296 | | |
297 | | |
298 | | METHODDEF(JDIMENSION) |
299 | | get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
300 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
301 | | * truecolor or truecolor + alpha PNG files and converting to CMYK. |
302 | | */ |
303 | 166k | { |
304 | 166k | png_source_ptr source = (png_source_ptr)sinfo; |
305 | 166k | register _JSAMPROW ptr; |
306 | 166k | register _JSAMPLE *rescale = source->rescale; |
307 | 166k | JDIMENSION col; |
308 | | |
309 | 166k | get_raw_row(cinfo, sinfo); |
310 | 166k | ptr = source->pub._buffer[0]; |
311 | | #if BITS_IN_JSAMPLE != 12 |
312 | 55.8k | if (source->png_bit_depth == cinfo->data_precision) { |
313 | 8.81k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
314 | 3.48M | for (col = cinfo->image_width; col > 0; col--) { |
315 | 3.47M | _JSAMPLE r = *bufferptr++; |
316 | 3.47M | _JSAMPLE g = *bufferptr++; |
317 | 3.47M | _JSAMPLE b = *bufferptr++; |
318 | 3.47M | bufferptr += source->png_alpha; |
319 | 3.47M | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
320 | 3.47M | ptr += 4; |
321 | 3.47M | } |
322 | 8.81k | } else |
323 | 46.9k | #endif |
324 | 157k | if (source->png_bit_depth == 16) { |
325 | 56.9k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
326 | 4.34M | for (col = cinfo->image_width; col > 0; col--) { |
327 | 4.28M | _JSAMPLE r = rescale[*bufferptr++]; |
328 | 4.28M | _JSAMPLE g = rescale[*bufferptr++]; |
329 | 4.28M | _JSAMPLE b = rescale[*bufferptr++]; |
330 | 4.28M | bufferptr += source->png_alpha; |
331 | 4.28M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
332 | 4.28M | ptr + 2, ptr + 3); |
333 | 4.28M | ptr += 4; |
334 | 4.28M | } |
335 | 101k | } else { |
336 | 101k | register unsigned char *bufferptr = source->iobuffer; |
337 | 35.2M | for (col = cinfo->image_width; col > 0; col--) { |
338 | 35.1M | _JSAMPLE r = rescale[*bufferptr++]; |
339 | 35.1M | _JSAMPLE g = rescale[*bufferptr++]; |
340 | 35.1M | _JSAMPLE b = rescale[*bufferptr++]; |
341 | 35.1M | bufferptr += source->png_alpha; |
342 | 35.1M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
343 | 35.1M | ptr + 2, ptr + 3); |
344 | 35.1M | ptr += 4; |
345 | 35.1M | } |
346 | 101k | } |
347 | 166k | return 1; |
348 | 166k | } rdpng-8.c:get_rgb_cmyk_row Line | Count | Source | 303 | 29.9k | { | 304 | 29.9k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 29.9k | register _JSAMPROW ptr; | 306 | 29.9k | register _JSAMPLE *rescale = source->rescale; | 307 | 29.9k | JDIMENSION col; | 308 | | | 309 | 29.9k | get_raw_row(cinfo, sinfo); | 310 | 29.9k | ptr = source->pub._buffer[0]; | 311 | 29.9k | #if BITS_IN_JSAMPLE != 12 | 312 | 29.9k | if (source->png_bit_depth == cinfo->data_precision) { | 313 | 6.40k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | 3.25M | for (col = cinfo->image_width; col > 0; col--) { | 315 | 3.24M | _JSAMPLE r = *bufferptr++; | 316 | 3.24M | _JSAMPLE g = *bufferptr++; | 317 | 3.24M | _JSAMPLE b = *bufferptr++; | 318 | 3.24M | bufferptr += source->png_alpha; | 319 | 3.24M | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | 3.24M | ptr += 4; | 321 | 3.24M | } | 322 | 6.40k | } else | 323 | 23.5k | #endif | 324 | 23.5k | if (source->png_bit_depth == 16) { | 325 | 6.40k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 534k | for (col = cinfo->image_width; col > 0; col--) { | 327 | 528k | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 528k | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 528k | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 528k | bufferptr += source->png_alpha; | 331 | 528k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 528k | ptr + 2, ptr + 3); | 333 | 528k | ptr += 4; | 334 | 528k | } | 335 | 17.1k | } else { | 336 | 17.1k | register unsigned char *bufferptr = source->iobuffer; | 337 | 16.0M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 16.0M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 16.0M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 16.0M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 16.0M | bufferptr += source->png_alpha; | 342 | 16.0M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 16.0M | ptr + 2, ptr + 3); | 344 | 16.0M | ptr += 4; | 345 | 16.0M | } | 346 | 17.1k | } | 347 | 29.9k | return 1; | 348 | 29.9k | } |
rdpng-12.c:get_rgb_cmyk_row Line | Count | Source | 303 | 111k | { | 304 | 111k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 111k | register _JSAMPROW ptr; | 306 | 111k | register _JSAMPLE *rescale = source->rescale; | 307 | 111k | JDIMENSION col; | 308 | | | 309 | 111k | get_raw_row(cinfo, sinfo); | 310 | 111k | ptr = source->pub._buffer[0]; | 311 | | #if BITS_IN_JSAMPLE != 12 | 312 | | if (source->png_bit_depth == cinfo->data_precision) { | 313 | | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | | for (col = cinfo->image_width; col > 0; col--) { | 315 | | _JSAMPLE r = *bufferptr++; | 316 | | _JSAMPLE g = *bufferptr++; | 317 | | _JSAMPLE b = *bufferptr++; | 318 | | bufferptr += source->png_alpha; | 319 | | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | | ptr += 4; | 321 | | } | 322 | | } else | 323 | | #endif | 324 | 111k | if (source->png_bit_depth == 16) { | 325 | 50.5k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 3.81M | for (col = cinfo->image_width; col > 0; col--) { | 327 | 3.75M | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 3.75M | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 3.75M | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 3.75M | bufferptr += source->png_alpha; | 331 | 3.75M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 3.75M | ptr + 2, ptr + 3); | 333 | 3.75M | ptr += 4; | 334 | 3.75M | } | 335 | 60.4k | } else { | 336 | 60.4k | register unsigned char *bufferptr = source->iobuffer; | 337 | 13.7M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 13.7M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 13.7M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 13.7M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 13.7M | bufferptr += source->png_alpha; | 342 | 13.7M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 13.7M | ptr + 2, ptr + 3); | 344 | 13.7M | ptr += 4; | 345 | 13.7M | } | 346 | 60.4k | } | 347 | 111k | return 1; | 348 | 111k | } |
rdpng-16.c:get_rgb_cmyk_row Line | Count | Source | 303 | 25.8k | { | 304 | 25.8k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 25.8k | register _JSAMPROW ptr; | 306 | 25.8k | register _JSAMPLE *rescale = source->rescale; | 307 | 25.8k | JDIMENSION col; | 308 | | | 309 | 25.8k | get_raw_row(cinfo, sinfo); | 310 | 25.8k | ptr = source->pub._buffer[0]; | 311 | 25.8k | #if BITS_IN_JSAMPLE != 12 | 312 | 25.8k | if (source->png_bit_depth == cinfo->data_precision) { | 313 | 2.40k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | 227k | for (col = cinfo->image_width; col > 0; col--) { | 315 | 224k | _JSAMPLE r = *bufferptr++; | 316 | 224k | _JSAMPLE g = *bufferptr++; | 317 | 224k | _JSAMPLE b = *bufferptr++; | 318 | 224k | bufferptr += source->png_alpha; | 319 | 224k | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | 224k | ptr += 4; | 321 | 224k | } | 322 | 2.40k | } else | 323 | 23.4k | #endif | 324 | 23.4k | if (source->png_bit_depth == 16) { | 325 | 0 | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 327 | 0 | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 0 | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 0 | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 0 | bufferptr += source->png_alpha; | 331 | 0 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 0 | ptr + 2, ptr + 3); | 333 | 0 | ptr += 4; | 334 | 0 | } | 335 | 23.4k | } else { | 336 | 23.4k | register unsigned char *bufferptr = source->iobuffer; | 337 | 5.41M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 5.39M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 5.39M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 5.39M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 5.39M | bufferptr += source->png_alpha; | 342 | 5.39M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 5.39M | ptr + 2, ptr + 3); | 344 | 5.39M | ptr += 4; | 345 | 5.39M | } | 346 | 23.4k | } | 347 | 25.8k | return 1; | 348 | 25.8k | } |
|
349 | | |
350 | | |
351 | | METHODDEF(JDIMENSION) |
352 | | get_indexed_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
353 | 7.18k | { |
354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and |
355 | | * converting to extended RGB or CMYK. |
356 | | */ |
357 | 7.18k | png_source_ptr source = (png_source_ptr)sinfo; |
358 | 7.18k | register _JSAMPROW ptr; |
359 | 7.18k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; |
360 | 7.18k | register _JSAMPLE *rescale = source->rescale; |
361 | 7.18k | JDIMENSION col; |
362 | | |
363 | 7.18k | get_raw_row(cinfo, sinfo); |
364 | 7.18k | ptr = source->pub._buffer[0]; |
365 | | #if BITS_IN_JSAMPLE == 8 |
366 | 2.76k | if (source->png_bit_depth == cinfo->data_precision) { |
367 | 1.92k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
368 | 1.19k | for (col = cinfo->image_width; col > 0; col--) { |
369 | 1.05k | JSAMPLE index = *bufferptr++; |
370 | | |
371 | 1.05k | if (index >= source->colormap.n_entries) |
372 | 22 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
373 | 1.05k | *ptr++ = source->colormap.entries[index].red; |
374 | 1.05k | } |
375 | 1.77k | } else if (cinfo->in_color_space == JCS_CMYK) { |
376 | 764 | for (col = cinfo->image_width; col > 0; col--) { |
377 | 676 | JSAMPLE index = *bufferptr++; |
378 | | |
379 | 676 | if (index >= source->colormap.n_entries) |
380 | 8 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
381 | 676 | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, |
382 | 676 | source->colormap.entries[index].green, |
383 | 676 | source->colormap.entries[index].blue, ptr, ptr + 1, |
384 | 676 | ptr + 2, ptr + 3); |
385 | 676 | ptr += 4; |
386 | 676 | } |
387 | 1.69k | } else { |
388 | 1.69k | register int rindex = rgb_red[cinfo->in_color_space]; |
389 | 1.69k | register int gindex = rgb_green[cinfo->in_color_space]; |
390 | 1.69k | register int bindex = rgb_blue[cinfo->in_color_space]; |
391 | 1.69k | register int aindex = alpha_index[cinfo->in_color_space]; |
392 | 1.69k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
393 | | |
394 | 29.3k | for (col = cinfo->image_width; col > 0; col--) { |
395 | 27.6k | JSAMPLE index = *bufferptr++; |
396 | | |
397 | 27.6k | if (index >= source->colormap.n_entries) |
398 | 161 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
399 | 27.6k | ptr[rindex] = source->colormap.entries[index].red; |
400 | 27.6k | ptr[gindex] = source->colormap.entries[index].green; |
401 | 27.6k | ptr[bindex] = source->colormap.entries[index].blue; |
402 | 27.6k | if (aindex >= 0) |
403 | 668 | ptr[aindex] = _MAXJSAMPLE; |
404 | 27.6k | ptr += ps; |
405 | 27.6k | } |
406 | 1.69k | } |
407 | 1.92k | } else |
408 | 846 | #endif |
409 | 846 | { |
410 | 5.26k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
411 | 1.24k | for (col = cinfo->image_width; col > 0; col--) { |
412 | 1.09k | JSAMPLE index = *bufferptr++; |
413 | | |
414 | 1.09k | if (index >= source->colormap.n_entries) |
415 | 24 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
416 | 1.09k | *ptr++ = rescale[source->colormap.entries[index].red]; |
417 | 1.09k | } |
418 | 5.11k | } else if (cinfo->in_color_space == JCS_CMYK) { |
419 | 15.6k | for (col = cinfo->image_width; col > 0; col--) { |
420 | 14.8k | JSAMPLE index = *bufferptr++; |
421 | | |
422 | 14.8k | if (index >= source->colormap.n_entries) |
423 | 100 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
424 | 14.8k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, |
425 | 14.8k | rescale[source->colormap.entries[index].red], |
426 | 14.8k | rescale[source->colormap.entries[index].green], |
427 | 14.8k | rescale[source->colormap.entries[index].blue], ptr, |
428 | 14.8k | ptr + 1, ptr + 2, ptr + 3); |
429 | 14.8k | ptr += 4; |
430 | 14.8k | } |
431 | 4.32k | } else { |
432 | 4.32k | register int rindex = rgb_red[cinfo->in_color_space]; |
433 | 4.32k | register int gindex = rgb_green[cinfo->in_color_space]; |
434 | 4.32k | register int bindex = rgb_blue[cinfo->in_color_space]; |
435 | 4.32k | register int aindex = alpha_index[cinfo->in_color_space]; |
436 | 4.32k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
437 | | |
438 | 80.5k | for (col = cinfo->image_width; col > 0; col--) { |
439 | 76.1k | JSAMPLE index = *bufferptr++; |
440 | | |
441 | 76.1k | if (index >= source->colormap.n_entries) |
442 | 480 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
443 | 76.1k | ptr[rindex] = rescale[source->colormap.entries[index].red]; |
444 | 76.1k | ptr[gindex] = rescale[source->colormap.entries[index].green]; |
445 | 76.1k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; |
446 | 76.1k | if (aindex >= 0) |
447 | 15.8k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
448 | 76.1k | ptr += ps; |
449 | 76.1k | } |
450 | 4.32k | } |
451 | 846 | } |
452 | 7.18k | return 1; |
453 | 7.18k | } rdpng-8.c:get_indexed_row Line | Count | Source | 353 | 2.76k | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 2.76k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 2.76k | register _JSAMPROW ptr; | 359 | 2.76k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 2.76k | register _JSAMPLE *rescale = source->rescale; | 361 | 2.76k | JDIMENSION col; | 362 | | | 363 | 2.76k | get_raw_row(cinfo, sinfo); | 364 | 2.76k | ptr = source->pub._buffer[0]; | 365 | 2.76k | #if BITS_IN_JSAMPLE == 8 | 366 | 2.76k | if (source->png_bit_depth == cinfo->data_precision) { | 367 | 1.92k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 368 | 1.19k | for (col = cinfo->image_width; col > 0; col--) { | 369 | 1.05k | JSAMPLE index = *bufferptr++; | 370 | | | 371 | 1.05k | if (index >= source->colormap.n_entries) | 372 | 22 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 373 | 1.05k | *ptr++ = source->colormap.entries[index].red; | 374 | 1.05k | } | 375 | 1.77k | } else if (cinfo->in_color_space == JCS_CMYK) { | 376 | 764 | for (col = cinfo->image_width; col > 0; col--) { | 377 | 676 | JSAMPLE index = *bufferptr++; | 378 | | | 379 | 676 | if (index >= source->colormap.n_entries) | 380 | 8 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 381 | 676 | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, | 382 | 676 | source->colormap.entries[index].green, | 383 | 676 | source->colormap.entries[index].blue, ptr, ptr + 1, | 384 | 676 | ptr + 2, ptr + 3); | 385 | 676 | ptr += 4; | 386 | 676 | } | 387 | 1.69k | } else { | 388 | 1.69k | register int rindex = rgb_red[cinfo->in_color_space]; | 389 | 1.69k | register int gindex = rgb_green[cinfo->in_color_space]; | 390 | 1.69k | register int bindex = rgb_blue[cinfo->in_color_space]; | 391 | 1.69k | register int aindex = alpha_index[cinfo->in_color_space]; | 392 | 1.69k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 393 | | | 394 | 29.3k | for (col = cinfo->image_width; col > 0; col--) { | 395 | 27.6k | JSAMPLE index = *bufferptr++; | 396 | | | 397 | 27.6k | if (index >= source->colormap.n_entries) | 398 | 161 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 399 | 27.6k | ptr[rindex] = source->colormap.entries[index].red; | 400 | 27.6k | ptr[gindex] = source->colormap.entries[index].green; | 401 | 27.6k | ptr[bindex] = source->colormap.entries[index].blue; | 402 | 27.6k | if (aindex >= 0) | 403 | 668 | ptr[aindex] = _MAXJSAMPLE; | 404 | 27.6k | ptr += ps; | 405 | 27.6k | } | 406 | 1.69k | } | 407 | 1.92k | } else | 408 | 846 | #endif | 409 | 846 | { | 410 | 846 | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 397 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 350 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 350 | if (index >= source->colormap.n_entries) | 415 | 7 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 350 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 350 | } | 418 | 799 | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 927 | for (col = cinfo->image_width; col > 0; col--) { | 420 | 817 | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 817 | if (index >= source->colormap.n_entries) | 423 | 20 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 817 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 817 | rescale[source->colormap.entries[index].red], | 426 | 817 | rescale[source->colormap.entries[index].green], | 427 | 817 | rescale[source->colormap.entries[index].blue], ptr, | 428 | 817 | ptr + 1, ptr + 2, ptr + 3); | 429 | 817 | ptr += 4; | 430 | 817 | } | 431 | 689 | } else { | 432 | 689 | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 689 | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 689 | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 689 | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 689 | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 3.95k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 3.26k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 3.26k | if (index >= source->colormap.n_entries) | 442 | 80 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 3.26k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 3.26k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 3.26k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 3.26k | if (aindex >= 0) | 447 | 797 | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 3.26k | ptr += ps; | 449 | 3.26k | } | 450 | 689 | } | 451 | 846 | } | 452 | 2.76k | return 1; | 453 | 2.76k | } |
rdpng-12.c:get_indexed_row Line | Count | Source | 353 | 1.42k | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 1.42k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 1.42k | register _JSAMPROW ptr; | 359 | 1.42k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 1.42k | register _JSAMPLE *rescale = source->rescale; | 361 | 1.42k | JDIMENSION col; | 362 | | | 363 | 1.42k | get_raw_row(cinfo, sinfo); | 364 | 1.42k | ptr = source->pub._buffer[0]; | 365 | | #if BITS_IN_JSAMPLE == 8 | 366 | | if (source->png_bit_depth == cinfo->data_precision) { | 367 | | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 368 | | for (col = cinfo->image_width; col > 0; col--) { | 369 | | JSAMPLE index = *bufferptr++; | 370 | | | 371 | | if (index >= source->colormap.n_entries) | 372 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 373 | | *ptr++ = source->colormap.entries[index].red; | 374 | | } | 375 | | } else if (cinfo->in_color_space == JCS_CMYK) { | 376 | | for (col = cinfo->image_width; col > 0; col--) { | 377 | | JSAMPLE index = *bufferptr++; | 378 | | | 379 | | if (index >= source->colormap.n_entries) | 380 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 381 | | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, | 382 | | source->colormap.entries[index].green, | 383 | | source->colormap.entries[index].blue, ptr, ptr + 1, | 384 | | ptr + 2, ptr + 3); | 385 | | ptr += 4; | 386 | | } | 387 | | } else { | 388 | | register int rindex = rgb_red[cinfo->in_color_space]; | 389 | | register int gindex = rgb_green[cinfo->in_color_space]; | 390 | | register int bindex = rgb_blue[cinfo->in_color_space]; | 391 | | register int aindex = alpha_index[cinfo->in_color_space]; | 392 | | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 393 | | | 394 | | for (col = cinfo->image_width; col > 0; col--) { | 395 | | JSAMPLE index = *bufferptr++; | 396 | | | 397 | | if (index >= source->colormap.n_entries) | 398 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 399 | | ptr[rindex] = source->colormap.entries[index].red; | 400 | | ptr[gindex] = source->colormap.entries[index].green; | 401 | | ptr[bindex] = source->colormap.entries[index].blue; | 402 | | if (aindex >= 0) | 403 | | ptr[aindex] = _MAXJSAMPLE; | 404 | | ptr += ps; | 405 | | } | 406 | | } | 407 | | } else | 408 | | #endif | 409 | 1.42k | { | 410 | 1.42k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 598 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 526 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 526 | if (index >= source->colormap.n_entries) | 415 | 13 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 526 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 526 | } | 418 | 1.35k | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 2.61k | for (col = cinfo->image_width; col > 0; col--) { | 420 | 2.40k | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 2.40k | if (index >= source->colormap.n_entries) | 423 | 52 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 2.40k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 2.40k | rescale[source->colormap.entries[index].red], | 426 | 2.40k | rescale[source->colormap.entries[index].green], | 427 | 2.40k | rescale[source->colormap.entries[index].blue], ptr, | 428 | 2.40k | ptr + 1, ptr + 2, ptr + 3); | 429 | 2.40k | ptr += 4; | 430 | 2.40k | } | 431 | 1.14k | } else { | 432 | 1.14k | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 1.14k | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 1.14k | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 1.14k | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 1.14k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 16.0k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 14.8k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 14.8k | if (index >= source->colormap.n_entries) | 442 | 260 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 14.8k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 14.8k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 14.8k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 14.8k | if (aindex >= 0) | 447 | 3.45k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 14.8k | ptr += ps; | 449 | 14.8k | } | 450 | 1.14k | } | 451 | 1.42k | } | 452 | 1.42k | return 1; | 453 | 1.42k | } |
rdpng-16.c:get_indexed_row Line | Count | Source | 353 | 2.99k | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 2.99k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 2.99k | register _JSAMPROW ptr; | 359 | 2.99k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 2.99k | register _JSAMPLE *rescale = source->rescale; | 361 | 2.99k | JDIMENSION col; | 362 | | | 363 | 2.99k | get_raw_row(cinfo, sinfo); | 364 | 2.99k | ptr = source->pub._buffer[0]; | 365 | | #if BITS_IN_JSAMPLE == 8 | 366 | | if (source->png_bit_depth == cinfo->data_precision) { | 367 | | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 368 | | for (col = cinfo->image_width; col > 0; col--) { | 369 | | JSAMPLE index = *bufferptr++; | 370 | | | 371 | | if (index >= source->colormap.n_entries) | 372 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 373 | | *ptr++ = source->colormap.entries[index].red; | 374 | | } | 375 | | } else if (cinfo->in_color_space == JCS_CMYK) { | 376 | | for (col = cinfo->image_width; col > 0; col--) { | 377 | | JSAMPLE index = *bufferptr++; | 378 | | | 379 | | if (index >= source->colormap.n_entries) | 380 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 381 | | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, | 382 | | source->colormap.entries[index].green, | 383 | | source->colormap.entries[index].blue, ptr, ptr + 1, | 384 | | ptr + 2, ptr + 3); | 385 | | ptr += 4; | 386 | | } | 387 | | } else { | 388 | | register int rindex = rgb_red[cinfo->in_color_space]; | 389 | | register int gindex = rgb_green[cinfo->in_color_space]; | 390 | | register int bindex = rgb_blue[cinfo->in_color_space]; | 391 | | register int aindex = alpha_index[cinfo->in_color_space]; | 392 | | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 393 | | | 394 | | for (col = cinfo->image_width; col > 0; col--) { | 395 | | JSAMPLE index = *bufferptr++; | 396 | | | 397 | | if (index >= source->colormap.n_entries) | 398 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 399 | | ptr[rindex] = source->colormap.entries[index].red; | 400 | | ptr[gindex] = source->colormap.entries[index].green; | 401 | | ptr[bindex] = source->colormap.entries[index].blue; | 402 | | if (aindex >= 0) | 403 | | ptr[aindex] = _MAXJSAMPLE; | 404 | | ptr += ps; | 405 | | } | 406 | | } | 407 | | } else | 408 | | #endif | 409 | 2.99k | { | 410 | 2.99k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 253 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 223 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 223 | if (index >= source->colormap.n_entries) | 415 | 4 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 223 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 223 | } | 418 | 2.96k | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 12.0k | for (col = cinfo->image_width; col > 0; col--) { | 420 | 11.6k | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 11.6k | if (index >= source->colormap.n_entries) | 423 | 28 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 11.6k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 11.6k | rescale[source->colormap.entries[index].red], | 426 | 11.6k | rescale[source->colormap.entries[index].green], | 427 | 11.6k | rescale[source->colormap.entries[index].blue], ptr, | 428 | 11.6k | ptr + 1, ptr + 2, ptr + 3); | 429 | 11.6k | ptr += 4; | 430 | 11.6k | } | 431 | 2.48k | } else { | 432 | 2.48k | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 2.48k | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 2.48k | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 2.48k | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 2.48k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 60.5k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 58.0k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 58.0k | if (index >= source->colormap.n_entries) | 442 | 140 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 58.0k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 58.0k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 58.0k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 58.0k | if (aindex >= 0) | 447 | 11.5k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 58.0k | ptr += ps; | 449 | 58.0k | } | 450 | 2.48k | } | 451 | 2.99k | } | 452 | 2.99k | return 1; | 453 | 2.99k | } |
|
454 | | |
455 | | |
456 | | #ifdef ZERO_BUFFERS |
457 | | |
458 | | static void *spng_malloc(size_t size) |
459 | | { |
460 | | return calloc(1, size); |
461 | | } |
462 | | |
463 | | #endif |
464 | | |
465 | | |
466 | | /* |
467 | | * Read the file header; return image size and component count. |
468 | | */ |
469 | | |
470 | | METHODDEF(void) |
471 | | start_input_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
472 | 191k | { |
473 | 191k | png_source_ptr source = (png_source_ptr)sinfo; |
474 | 191k | struct spng_ihdr ihdr; |
475 | 191k | int png_components = 3; |
476 | 191k | boolean use_raw_buffer; |
477 | | #ifdef ZERO_BUFFERS |
478 | | struct spng_alloc alloc; |
479 | | |
480 | | alloc.malloc_fn = spng_malloc; |
481 | | alloc.realloc_fn = realloc; |
482 | | alloc.calloc_fn = calloc; |
483 | | alloc.free_fn = free; |
484 | | source->ctx = spng_ctx_new2(&alloc, 0); |
485 | | #else |
486 | 191k | source->ctx = spng_ctx_new(0); |
487 | 191k | #endif |
488 | 191k | if (!source->ctx) |
489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); |
490 | | |
491 | 191k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); |
492 | | |
493 | 191k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); |
494 | | |
495 | 191k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) |
496 | 23.0k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); |
497 | 191k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) |
498 | 30.9k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); |
499 | 191k | if (sinfo->max_pixels && |
500 | 128k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) |
501 | 1.77k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); |
502 | | |
503 | 191k | cinfo->image_width = (JDIMENSION)ihdr.width; |
504 | 191k | cinfo->image_height = (JDIMENSION)ihdr.height; |
505 | 191k | source->png_bit_depth = ihdr.bit_depth; |
506 | 191k | source->png_color_type = ihdr.color_type; |
507 | | |
508 | | /* initialize flags to most common settings */ |
509 | 191k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ |
510 | | |
511 | 191k | switch (ihdr.color_type) { |
512 | 3.95k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: |
513 | 50.5k | case SPNG_COLOR_TYPE_GRAYSCALE: |
514 | 50.5k | if (cinfo->in_color_space == JCS_UNKNOWN || |
515 | 50.5k | cinfo->in_color_space == JCS_RGB) |
516 | 3.21k | cinfo->in_color_space = JCS_GRAYSCALE; |
517 | 50.5k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, |
518 | 50.5k | ihdr.bit_depth); |
519 | 50.5k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
520 | 10.1k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && |
521 | 9.24k | cinfo->data_precision == ihdr.bit_depth) { |
522 | 4.14k | source->pub.get_pixel_rows = get_raw_row; |
523 | 4.14k | use_raw_buffer = TRUE; |
524 | 4.14k | } else |
525 | 6.03k | source->pub.get_pixel_rows = get_gray_row; |
526 | 40.3k | } else if (IsExtRGB(cinfo->in_color_space)) |
527 | 34.8k | source->pub.get_pixel_rows = get_gray_rgb_row; |
528 | 5.53k | else if (cinfo->in_color_space == JCS_CMYK) |
529 | 5.53k | source->pub.get_pixel_rows = get_gray_cmyk_row; |
530 | 0 | else |
531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
532 | 50.5k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { |
533 | 3.95k | png_components = 2; |
534 | 3.95k | source->png_alpha = 1; |
535 | 46.5k | } else { |
536 | 46.5k | png_components = 1; |
537 | 46.5k | source->png_alpha = 0; |
538 | 46.5k | } |
539 | 50.5k | break; |
540 | | |
541 | 54.6k | case SPNG_COLOR_TYPE_TRUECOLOR: |
542 | 68.2k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: |
543 | 68.2k | if (cinfo->in_color_space == JCS_UNKNOWN) |
544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
545 | 68.2k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, |
546 | 68.2k | ihdr.bit_depth); |
547 | 68.2k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && |
548 | 54.6k | cinfo->data_precision == ihdr.bit_depth && |
549 | 19.1k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 |
550 | 19.1k | (cinfo->in_color_space == JCS_EXT_RGB || |
551 | 15.4k | cinfo->in_color_space == JCS_RGB)) { |
552 | | #else |
553 | | cinfo->in_color_space == JCS_EXT_RGB) { |
554 | | #endif |
555 | 4.09k | source->pub.get_pixel_rows = get_raw_row; |
556 | 4.09k | use_raw_buffer = TRUE; |
557 | 64.1k | } else if (IsExtRGB(cinfo->in_color_space)) |
558 | 46.5k | source->pub.get_pixel_rows = get_rgb_row; |
559 | 17.5k | else if (cinfo->in_color_space == JCS_CMYK) |
560 | 7.68k | source->pub.get_pixel_rows = get_rgb_cmyk_row; |
561 | 9.90k | else |
562 | 9.90k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
563 | 68.2k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { |
564 | 11.6k | png_components = 4; |
565 | 11.6k | source->png_alpha = 1; |
566 | 56.6k | } else { |
567 | 56.6k | png_components = 3; |
568 | 56.6k | source->png_alpha = 0; |
569 | 56.6k | } |
570 | 68.2k | break; |
571 | | |
572 | 8.38k | case SPNG_COLOR_TYPE_INDEXED: |
573 | 8.38k | { |
574 | 8.38k | int i, gray = 1; |
575 | | |
576 | 8.38k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, |
577 | 8.38k | ihdr.bit_depth); |
578 | 8.38k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); |
579 | 8.38k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) |
580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
581 | | |
582 | 144k | for (i = 0; i < (int)source->colormap.n_entries; i++) { |
583 | 136k | if (source->colormap.entries[i].red != |
584 | 136k | source->colormap.entries[i].green || |
585 | 44.8k | source->colormap.entries[i].green != |
586 | 44.8k | source->colormap.entries[i].blue) |
587 | 94.0k | gray = 0; |
588 | 136k | } |
589 | | |
590 | 8.38k | if ((cinfo->in_color_space == JCS_UNKNOWN || |
591 | 1.93k | cinfo->in_color_space == JCS_RGB) && gray) |
592 | 22 | cinfo->in_color_space = JCS_GRAYSCALE; |
593 | 8.38k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) |
594 | 195 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
595 | | |
596 | 8.38k | source->pub.get_pixel_rows = get_indexed_row; |
597 | 8.38k | png_components = 1; |
598 | 8.38k | source->png_alpha = 0; |
599 | 8.38k | break; |
600 | 54.6k | } |
601 | | |
602 | 0 | default: |
603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
604 | 191k | } |
605 | | |
606 | 110k | if (IsExtRGB(cinfo->in_color_space)) |
607 | 86.8k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; |
608 | 23.7k | else if (cinfo->in_color_space == JCS_GRAYSCALE) |
609 | 10.2k | cinfo->input_components = 1; |
610 | 13.4k | else if (cinfo->in_color_space == JCS_CMYK) |
611 | 13.4k | cinfo->input_components = 4; |
612 | | |
613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ |
614 | 110k | source->buffer_width = |
615 | 110k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; |
616 | 110k | source->iobuffer = (unsigned char *) |
617 | 110k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
618 | 110k | source->buffer_width); |
619 | | |
620 | | /* Create compressor input buffer. */ |
621 | 110k | if (use_raw_buffer) { |
622 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ |
623 | | /* Synthesize a _JSAMPARRAY pointer structure */ |
624 | 8.23k | source->pixrow = (_JSAMPROW)source->iobuffer; |
625 | 8.23k | source->pub._buffer = &source->pixrow; |
626 | 8.23k | source->pub.buffer_height = 1; |
627 | 102k | } else { |
628 | 102k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; |
629 | 102k | size_t val, half_maxval; |
630 | | |
631 | | /* Need to translate anyway, so make a separate sample buffer. */ |
632 | 102k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
633 | 102k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
634 | 102k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); |
635 | 102k | source->pub.buffer_height = 1; |
636 | | |
637 | | /* Compute the rescaling array. */ |
638 | 102k | source->rescale = (_JSAMPLE *) |
639 | 102k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
640 | 102k | (maxval + 1L) * sizeof(_JSAMPLE)); |
641 | 102k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); |
642 | 102k | half_maxval = maxval / 2; |
643 | 1.97G | for (val = 0; val <= maxval; val++) { |
644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ |
645 | 1.97G | source->rescale[val] = |
646 | 1.97G | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / |
647 | 1.97G | maxval); |
648 | 1.97G | } |
649 | 102k | } |
650 | | |
651 | 110k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, |
652 | 110k | SPNG_DECODE_PROGRESSIVE)); |
653 | 110k | } rdpng-8.c:start_input_png Line | Count | Source | 472 | 95.2k | { | 473 | 95.2k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 95.2k | struct spng_ihdr ihdr; | 475 | 95.2k | int png_components = 3; | 476 | 95.2k | boolean use_raw_buffer; | 477 | | #ifdef ZERO_BUFFERS | 478 | | struct spng_alloc alloc; | 479 | | | 480 | | alloc.malloc_fn = spng_malloc; | 481 | | alloc.realloc_fn = realloc; | 482 | | alloc.calloc_fn = calloc; | 483 | | alloc.free_fn = free; | 484 | | source->ctx = spng_ctx_new2(&alloc, 0); | 485 | | #else | 486 | 95.2k | source->ctx = spng_ctx_new(0); | 487 | 95.2k | #endif | 488 | 95.2k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 95.2k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 95.2k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 95.2k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 18.3k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 95.2k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 10.7k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 95.2k | if (sinfo->max_pixels && | 500 | 61.4k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 885 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 95.2k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 95.2k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 95.2k | source->png_bit_depth = ihdr.bit_depth; | 506 | 95.2k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 95.2k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 95.2k | switch (ihdr.color_type) { | 512 | 1.43k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 21.0k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 21.0k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 21.0k | cinfo->in_color_space == JCS_RGB) | 516 | 3.21k | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 21.0k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 21.0k | ihdr.bit_depth); | 519 | 21.0k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 5.96k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 5.39k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 3.62k | source->pub.get_pixel_rows = get_raw_row; | 523 | 3.62k | use_raw_buffer = TRUE; | 524 | 3.62k | } else | 525 | 2.33k | source->pub.get_pixel_rows = get_gray_row; | 526 | 15.0k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 13.7k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 1.32k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 1.32k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 21.0k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 1.43k | png_components = 2; | 534 | 1.43k | source->png_alpha = 1; | 535 | 19.6k | } else { | 536 | 19.6k | png_components = 1; | 537 | 19.6k | source->png_alpha = 0; | 538 | 19.6k | } | 539 | 21.0k | break; | 540 | | | 541 | 27.2k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 34.7k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 34.7k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 34.7k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 34.7k | ihdr.bit_depth); | 547 | 34.7k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 27.2k | cinfo->data_precision == ihdr.bit_depth && | 549 | 16.5k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 16.5k | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 13.5k | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 3.44k | source->pub.get_pixel_rows = get_raw_row; | 556 | 3.44k | use_raw_buffer = TRUE; | 557 | 31.2k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 23.2k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 8.00k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 2.88k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 5.11k | else | 562 | 5.11k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 34.7k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 6.32k | png_components = 4; | 565 | 6.32k | source->png_alpha = 1; | 566 | 28.3k | } else { | 567 | 28.3k | png_components = 3; | 568 | 28.3k | source->png_alpha = 0; | 569 | 28.3k | } | 570 | 34.7k | break; | 571 | | | 572 | 4.81k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 4.81k | { | 574 | 4.81k | int i, gray = 1; | 575 | | | 576 | 4.81k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 4.81k | ihdr.bit_depth); | 578 | 4.81k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 4.81k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 47.6k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 42.8k | if (source->colormap.entries[i].red != | 584 | 42.8k | source->colormap.entries[i].green || | 585 | 20.9k | source->colormap.entries[i].green != | 586 | 20.9k | source->colormap.entries[i].blue) | 587 | 22.7k | gray = 0; | 588 | 42.8k | } | 589 | | | 590 | 4.81k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 798 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 22 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 4.81k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 594 | 68 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 595 | | | 596 | 4.81k | source->pub.get_pixel_rows = get_indexed_row; | 597 | 4.81k | png_components = 1; | 598 | 4.81k | source->png_alpha = 0; | 599 | 4.81k | break; | 600 | 27.2k | } | 601 | | | 602 | 0 | default: | 603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 604 | 95.2k | } | 605 | | | 606 | 51.3k | if (IsExtRGB(cinfo->in_color_space)) | 607 | 41.0k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 608 | 10.3k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 609 | 6.03k | cinfo->input_components = 1; | 610 | 4.28k | else if (cinfo->in_color_space == JCS_CMYK) | 611 | 4.28k | cinfo->input_components = 4; | 612 | | | 613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 614 | 51.3k | source->buffer_width = | 615 | 51.3k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 616 | 51.3k | source->iobuffer = (unsigned char *) | 617 | 51.3k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 618 | 51.3k | source->buffer_width); | 619 | | | 620 | | /* Create compressor input buffer. */ | 621 | 51.3k | if (use_raw_buffer) { | 622 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 623 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 624 | 7.06k | source->pixrow = (_JSAMPROW)source->iobuffer; | 625 | 7.06k | source->pub._buffer = &source->pixrow; | 626 | 7.06k | source->pub.buffer_height = 1; | 627 | 44.3k | } else { | 628 | 44.3k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 629 | 44.3k | size_t val, half_maxval; | 630 | | | 631 | | /* Need to translate anyway, so make a separate sample buffer. */ | 632 | 44.3k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 633 | 44.3k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 634 | 44.3k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 635 | 44.3k | source->pub.buffer_height = 1; | 636 | | | 637 | | /* Compute the rescaling array. */ | 638 | 44.3k | source->rescale = (_JSAMPLE *) | 639 | 44.3k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 640 | 44.3k | (maxval + 1L) * sizeof(_JSAMPLE)); | 641 | 44.3k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 642 | 44.3k | half_maxval = maxval / 2; | 643 | 890M | for (val = 0; val <= maxval; val++) { | 644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 645 | 890M | source->rescale[val] = | 646 | 890M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 647 | 890M | maxval); | 648 | 890M | } | 649 | 44.3k | } | 650 | | | 651 | 51.3k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 652 | 51.3k | SPNG_DECODE_PROGRESSIVE)); | 653 | 51.3k | } |
rdpng-12.c:start_input_png Line | Count | Source | 472 | 64.9k | { | 473 | 64.9k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 64.9k | struct spng_ihdr ihdr; | 475 | 64.9k | int png_components = 3; | 476 | 64.9k | boolean use_raw_buffer; | 477 | | #ifdef ZERO_BUFFERS | 478 | | struct spng_alloc alloc; | 479 | | | 480 | | alloc.malloc_fn = spng_malloc; | 481 | | alloc.realloc_fn = realloc; | 482 | | alloc.calloc_fn = calloc; | 483 | | alloc.free_fn = free; | 484 | | source->ctx = spng_ctx_new2(&alloc, 0); | 485 | | #else | 486 | 64.9k | source->ctx = spng_ctx_new(0); | 487 | 64.9k | #endif | 488 | 64.9k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 64.9k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 64.9k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 64.9k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 4.17k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 64.9k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 14.9k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 64.9k | if (sinfo->max_pixels && | 500 | 43.1k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 532 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 64.9k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 64.9k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 64.9k | source->png_bit_depth = ihdr.bit_depth; | 506 | 64.9k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 64.9k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 64.9k | switch (ihdr.color_type) { | 512 | 1.16k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 19.5k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 19.5k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 19.5k | cinfo->in_color_space == JCS_RGB) | 516 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 19.5k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 19.5k | ihdr.bit_depth); | 519 | 19.5k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 2.79k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 2.63k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 0 | source->pub.get_pixel_rows = get_raw_row; | 523 | 0 | use_raw_buffer = TRUE; | 524 | 0 | } else | 525 | 2.79k | source->pub.get_pixel_rows = get_gray_row; | 526 | 16.7k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 13.9k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 2.79k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 2.79k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 19.5k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 1.16k | png_components = 2; | 534 | 1.16k | source->png_alpha = 1; | 535 | 18.4k | } else { | 536 | 18.4k | png_components = 1; | 537 | 18.4k | source->png_alpha = 0; | 538 | 18.4k | } | 539 | 19.5k | break; | 540 | | | 541 | 15.8k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 20.5k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 20.5k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 20.5k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 20.5k | ihdr.bit_depth); | 547 | 20.5k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 15.8k | cinfo->data_precision == ihdr.bit_depth && | 549 | 0 | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 0 | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 0 | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 0 | source->pub.get_pixel_rows = get_raw_row; | 556 | 0 | use_raw_buffer = TRUE; | 557 | 20.5k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 14.6k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 5.87k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 2.93k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 2.93k | else | 562 | 2.93k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 20.5k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 4.03k | png_components = 4; | 565 | 4.03k | source->png_alpha = 1; | 566 | 16.5k | } else { | 567 | 16.5k | png_components = 3; | 568 | 16.5k | source->png_alpha = 0; | 569 | 16.5k | } | 570 | 20.5k | break; | 571 | | | 572 | 2.47k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 2.47k | { | 574 | 2.47k | int i, gray = 1; | 575 | | | 576 | 2.47k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 2.47k | ihdr.bit_depth); | 578 | 2.47k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 2.47k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 79.3k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 76.8k | if (source->colormap.entries[i].red != | 584 | 76.8k | source->colormap.entries[i].green || | 585 | 13.9k | source->colormap.entries[i].green != | 586 | 13.9k | source->colormap.entries[i].blue) | 587 | 63.9k | gray = 0; | 588 | 76.8k | } | 589 | | | 590 | 2.47k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 700 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 2.47k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 594 | 75 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 595 | | | 596 | 2.47k | source->pub.get_pixel_rows = get_indexed_row; | 597 | 2.47k | png_components = 1; | 598 | 2.47k | source->png_alpha = 0; | 599 | 2.47k | break; | 600 | 15.8k | } | 601 | | | 602 | 0 | default: | 603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 604 | 64.9k | } | 605 | | | 606 | 37.8k | if (IsExtRGB(cinfo->in_color_space)) | 607 | 29.1k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 608 | 8.65k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 609 | 2.82k | cinfo->input_components = 1; | 610 | 5.83k | else if (cinfo->in_color_space == JCS_CMYK) | 611 | 5.83k | cinfo->input_components = 4; | 612 | | | 613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 614 | 37.8k | source->buffer_width = | 615 | 37.8k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 616 | 37.8k | source->iobuffer = (unsigned char *) | 617 | 37.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 618 | 37.8k | source->buffer_width); | 619 | | | 620 | | /* Create compressor input buffer. */ | 621 | 37.8k | if (use_raw_buffer) { | 622 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 623 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 624 | 0 | source->pixrow = (_JSAMPROW)source->iobuffer; | 625 | 0 | source->pub._buffer = &source->pixrow; | 626 | 0 | source->pub.buffer_height = 1; | 627 | 37.8k | } else { | 628 | 37.8k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 629 | 37.8k | size_t val, half_maxval; | 630 | | | 631 | | /* Need to translate anyway, so make a separate sample buffer. */ | 632 | 37.8k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 633 | 37.8k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 634 | 37.8k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 635 | 37.8k | source->pub.buffer_height = 1; | 636 | | | 637 | | /* Compute the rescaling array. */ | 638 | 37.8k | source->rescale = (_JSAMPLE *) | 639 | 37.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 640 | 37.8k | (maxval + 1L) * sizeof(_JSAMPLE)); | 641 | 37.8k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 642 | 37.8k | half_maxval = maxval / 2; | 643 | 574M | for (val = 0; val <= maxval; val++) { | 644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 645 | 574M | source->rescale[val] = | 646 | 574M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 647 | 574M | maxval); | 648 | 574M | } | 649 | 37.8k | } | 650 | | | 651 | 37.8k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 652 | 37.8k | SPNG_DECODE_PROGRESSIVE)); | 653 | 37.8k | } |
rdpng-16.c:start_input_png Line | Count | Source | 472 | 31.4k | { | 473 | 31.4k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 31.4k | struct spng_ihdr ihdr; | 475 | 31.4k | int png_components = 3; | 476 | 31.4k | boolean use_raw_buffer; | 477 | | #ifdef ZERO_BUFFERS | 478 | | struct spng_alloc alloc; | 479 | | | 480 | | alloc.malloc_fn = spng_malloc; | 481 | | alloc.realloc_fn = realloc; | 482 | | alloc.calloc_fn = calloc; | 483 | | alloc.free_fn = free; | 484 | | source->ctx = spng_ctx_new2(&alloc, 0); | 485 | | #else | 486 | 31.4k | source->ctx = spng_ctx_new(0); | 487 | 31.4k | #endif | 488 | 31.4k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 31.4k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 31.4k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 31.4k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 539 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 31.4k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 5.19k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 31.4k | if (sinfo->max_pixels && | 500 | 24.3k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 357 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 31.4k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 31.4k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 31.4k | source->png_bit_depth = ihdr.bit_depth; | 506 | 31.4k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 31.4k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 31.4k | switch (ihdr.color_type) { | 512 | 1.35k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 9.88k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 9.88k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 9.88k | cinfo->in_color_space == JCS_RGB) | 516 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 9.88k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 9.88k | ihdr.bit_depth); | 519 | 9.88k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 1.41k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 1.21k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 513 | source->pub.get_pixel_rows = get_raw_row; | 523 | 513 | use_raw_buffer = TRUE; | 524 | 513 | } else | 525 | 899 | source->pub.get_pixel_rows = get_gray_row; | 526 | 8.47k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 7.06k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 1.41k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 1.41k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 9.88k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 1.35k | png_components = 2; | 534 | 1.35k | source->png_alpha = 1; | 535 | 8.52k | } else { | 536 | 8.52k | png_components = 1; | 537 | 8.52k | source->png_alpha = 0; | 538 | 8.52k | } | 539 | 9.88k | break; | 540 | | | 541 | 11.5k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 12.9k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 12.9k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 12.9k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 12.9k | ihdr.bit_depth); | 547 | 12.9k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 11.5k | cinfo->data_precision == ihdr.bit_depth && | 549 | 2.60k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 2.60k | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 1.95k | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 650 | source->pub.get_pixel_rows = get_raw_row; | 556 | 650 | use_raw_buffer = TRUE; | 557 | 12.3k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 8.63k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 3.71k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 1.85k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 1.85k | else | 562 | 1.85k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 12.9k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 1.25k | png_components = 4; | 565 | 1.25k | source->png_alpha = 1; | 566 | 11.7k | } else { | 567 | 11.7k | png_components = 3; | 568 | 11.7k | source->png_alpha = 0; | 569 | 11.7k | } | 570 | 12.9k | break; | 571 | | | 572 | 1.08k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 1.08k | { | 574 | 1.08k | int i, gray = 1; | 575 | | | 576 | 1.08k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 1.08k | ihdr.bit_depth); | 578 | 1.08k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 1.08k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 17.4k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 16.3k | if (source->colormap.entries[i].red != | 584 | 16.3k | source->colormap.entries[i].green || | 585 | 9.91k | source->colormap.entries[i].green != | 586 | 9.91k | source->colormap.entries[i].blue) | 587 | 7.27k | gray = 0; | 588 | 16.3k | } | 589 | | | 590 | 1.08k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 441 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 1.08k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 594 | 52 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 595 | | | 596 | 1.08k | source->pub.get_pixel_rows = get_indexed_row; | 597 | 1.08k | png_components = 1; | 598 | 1.08k | source->png_alpha = 0; | 599 | 1.08k | break; | 600 | 11.5k | } | 601 | | | 602 | 0 | default: | 603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 604 | 31.4k | } | 605 | | | 606 | 21.4k | if (IsExtRGB(cinfo->in_color_space)) | 607 | 16.6k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 608 | 4.75k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 609 | 1.42k | cinfo->input_components = 1; | 610 | 3.33k | else if (cinfo->in_color_space == JCS_CMYK) | 611 | 3.33k | cinfo->input_components = 4; | 612 | | | 613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 614 | 21.4k | source->buffer_width = | 615 | 21.4k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 616 | 21.4k | source->iobuffer = (unsigned char *) | 617 | 21.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 618 | 21.4k | source->buffer_width); | 619 | | | 620 | | /* Create compressor input buffer. */ | 621 | 21.4k | if (use_raw_buffer) { | 622 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 623 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 624 | 1.16k | source->pixrow = (_JSAMPROW)source->iobuffer; | 625 | 1.16k | source->pub._buffer = &source->pixrow; | 626 | 1.16k | source->pub.buffer_height = 1; | 627 | 20.2k | } else { | 628 | 20.2k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 629 | 20.2k | size_t val, half_maxval; | 630 | | | 631 | | /* Need to translate anyway, so make a separate sample buffer. */ | 632 | 20.2k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 633 | 20.2k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 634 | 20.2k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 635 | 20.2k | source->pub.buffer_height = 1; | 636 | | | 637 | | /* Compute the rescaling array. */ | 638 | 20.2k | source->rescale = (_JSAMPLE *) | 639 | 20.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 640 | 20.2k | (maxval + 1L) * sizeof(_JSAMPLE)); | 641 | 20.2k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 642 | 20.2k | half_maxval = maxval / 2; | 643 | 514M | for (val = 0; val <= maxval; val++) { | 644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 645 | 514M | source->rescale[val] = | 646 | 514M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 647 | 514M | maxval); | 648 | 514M | } | 649 | 20.2k | } | 650 | | | 651 | 21.4k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 652 | 21.4k | SPNG_DECODE_PROGRESSIVE)); | 653 | 21.4k | } |
|
654 | | |
655 | | |
656 | | /* |
657 | | * Return the ICC profile (if any) embedded in the PNG image. |
658 | | */ |
659 | | |
660 | | METHODDEF(boolean) |
661 | | read_icc_profile_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo, |
662 | | JOCTET **icc_data_ptr, unsigned int *icc_data_len) |
663 | 39.6k | { |
664 | 39.6k | png_source_ptr source = (png_source_ptr)sinfo; |
665 | 39.6k | struct spng_iccp iccp; |
666 | | |
667 | 39.6k | if (!icc_data_ptr || !icc_data_len) |
668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); |
669 | | |
670 | 39.6k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { |
671 | 190 | *icc_data_ptr = (JOCTET *)iccp.profile; |
672 | 190 | *icc_data_len = (unsigned int)iccp.profile_len; |
673 | 190 | return TRUE; |
674 | 190 | } |
675 | | |
676 | 39.4k | return FALSE; |
677 | 39.6k | } rdpng-8.c:read_icc_profile_png Line | Count | Source | 663 | 18.0k | { | 664 | 18.0k | png_source_ptr source = (png_source_ptr)sinfo; | 665 | 18.0k | struct spng_iccp iccp; | 666 | | | 667 | 18.0k | if (!icc_data_ptr || !icc_data_len) | 668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 669 | | | 670 | 18.0k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 671 | 164 | *icc_data_ptr = (JOCTET *)iccp.profile; | 672 | 164 | *icc_data_len = (unsigned int)iccp.profile_len; | 673 | 164 | return TRUE; | 674 | 164 | } | 675 | | | 676 | 17.9k | return FALSE; | 677 | 18.0k | } |
rdpng-12.c:read_icc_profile_png Line | Count | Source | 663 | 13.9k | { | 664 | 13.9k | png_source_ptr source = (png_source_ptr)sinfo; | 665 | 13.9k | struct spng_iccp iccp; | 666 | | | 667 | 13.9k | if (!icc_data_ptr || !icc_data_len) | 668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 669 | | | 670 | 13.9k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 671 | 13 | *icc_data_ptr = (JOCTET *)iccp.profile; | 672 | 13 | *icc_data_len = (unsigned int)iccp.profile_len; | 673 | 13 | return TRUE; | 674 | 13 | } | 675 | | | 676 | 13.9k | return FALSE; | 677 | 13.9k | } |
rdpng-16.c:read_icc_profile_png Line | Count | Source | 663 | 7.64k | { | 664 | 7.64k | png_source_ptr source = (png_source_ptr)sinfo; | 665 | 7.64k | struct spng_iccp iccp; | 666 | | | 667 | 7.64k | if (!icc_data_ptr || !icc_data_len) | 668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 669 | | | 670 | 7.64k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 671 | 13 | *icc_data_ptr = (JOCTET *)iccp.profile; | 672 | 13 | *icc_data_len = (unsigned int)iccp.profile_len; | 673 | 13 | return TRUE; | 674 | 13 | } | 675 | | | 676 | 7.63k | return FALSE; | 677 | 7.64k | } |
|
678 | | |
679 | | |
680 | | /* |
681 | | * Finish up at the end of the file. |
682 | | */ |
683 | | |
684 | | METHODDEF(void) |
685 | | finish_input_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
686 | 191k | { |
687 | 191k | png_source_ptr source = (png_source_ptr)sinfo; |
688 | | |
689 | 191k | if (source->ctx) { |
690 | 191k | spng_decode_chunks(source->ctx); |
691 | 191k | spng_ctx_free(source->ctx); |
692 | 191k | source->ctx = NULL; |
693 | 191k | } |
694 | 191k | } rdpng-8.c:finish_input_png Line | Count | Source | 686 | 95.2k | { | 687 | 95.2k | png_source_ptr source = (png_source_ptr)sinfo; | 688 | | | 689 | 95.2k | if (source->ctx) { | 690 | 95.2k | spng_decode_chunks(source->ctx); | 691 | 95.2k | spng_ctx_free(source->ctx); | 692 | | source->ctx = NULL; | 693 | 95.2k | } | 694 | 95.2k | } |
rdpng-12.c:finish_input_png Line | Count | Source | 686 | 64.9k | { | 687 | 64.9k | png_source_ptr source = (png_source_ptr)sinfo; | 688 | | | 689 | 64.9k | if (source->ctx) { | 690 | 64.9k | spng_decode_chunks(source->ctx); | 691 | 64.9k | spng_ctx_free(source->ctx); | 692 | | source->ctx = NULL; | 693 | 64.9k | } | 694 | 64.9k | } |
rdpng-16.c:finish_input_png Line | Count | Source | 686 | 31.4k | { | 687 | 31.4k | png_source_ptr source = (png_source_ptr)sinfo; | 688 | | | 689 | 31.4k | if (source->ctx) { | 690 | 31.4k | spng_decode_chunks(source->ctx); | 691 | 31.4k | spng_ctx_free(source->ctx); | 692 | | source->ctx = NULL; | 693 | 31.4k | } | 694 | 31.4k | } |
|
695 | | |
696 | | |
697 | | /* |
698 | | * The module selection routine for PNG format input. |
699 | | */ |
700 | | |
701 | | GLOBAL(cjpeg_source_ptr) |
702 | | _jinit_read_png(j_compress_ptr cinfo) |
703 | 191k | { |
704 | 191k | png_source_ptr source; |
705 | | |
706 | | #if BITS_IN_JSAMPLE == 8 |
707 | 95.2k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
708 | | #else |
709 | 96.3k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
710 | 96.3k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
711 | 0 | #endif |
712 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
713 | | |
714 | | /* Create module interface object */ |
715 | 191k | source = (png_source_ptr) |
716 | 191k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
717 | 191k | sizeof(png_source_struct)); |
718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
719 | 191k | source->pub.start_input = start_input_png; |
720 | 191k | source->pub.read_icc_profile = read_icc_profile_png; |
721 | 191k | source->pub.finish_input = finish_input_png; |
722 | 191k | source->pub.max_pixels = 0; |
723 | | |
724 | 191k | return (cjpeg_source_ptr)source; |
725 | 191k | } Line | Count | Source | 703 | 95.2k | { | 704 | 95.2k | png_source_ptr source; | 705 | | | 706 | 95.2k | #if BITS_IN_JSAMPLE == 8 | 707 | 95.2k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 708 | | #else | 709 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 710 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 711 | | #endif | 712 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 713 | | | 714 | | /* Create module interface object */ | 715 | 95.2k | source = (png_source_ptr) | 716 | 95.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 717 | 95.2k | sizeof(png_source_struct)); | 718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 719 | 95.2k | source->pub.start_input = start_input_png; | 720 | 95.2k | source->pub.read_icc_profile = read_icc_profile_png; | 721 | 95.2k | source->pub.finish_input = finish_input_png; | 722 | 95.2k | source->pub.max_pixels = 0; | 723 | | | 724 | 95.2k | return (cjpeg_source_ptr)source; | 725 | 95.2k | } |
Line | Count | Source | 703 | 64.9k | { | 704 | 64.9k | png_source_ptr source; | 705 | | | 706 | | #if BITS_IN_JSAMPLE == 8 | 707 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 708 | | #else | 709 | 64.9k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 710 | 64.9k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 711 | 0 | #endif | 712 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 713 | | | 714 | | /* Create module interface object */ | 715 | 64.9k | source = (png_source_ptr) | 716 | 64.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 717 | 64.9k | sizeof(png_source_struct)); | 718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 719 | 64.9k | source->pub.start_input = start_input_png; | 720 | 64.9k | source->pub.read_icc_profile = read_icc_profile_png; | 721 | 64.9k | source->pub.finish_input = finish_input_png; | 722 | 64.9k | source->pub.max_pixels = 0; | 723 | | | 724 | 64.9k | return (cjpeg_source_ptr)source; | 725 | 64.9k | } |
Line | Count | Source | 703 | 31.4k | { | 704 | 31.4k | png_source_ptr source; | 705 | | | 706 | | #if BITS_IN_JSAMPLE == 8 | 707 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 708 | | #else | 709 | 31.4k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 710 | 31.4k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 711 | 0 | #endif | 712 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 713 | | | 714 | | /* Create module interface object */ | 715 | 31.4k | source = (png_source_ptr) | 716 | 31.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 717 | 31.4k | sizeof(png_source_struct)); | 718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 719 | 31.4k | source->pub.start_input = start_input_png; | 720 | 31.4k | source->pub.read_icc_profile = read_icc_profile_png; | 721 | 31.4k | source->pub.finish_input = finish_input_png; | 722 | 31.4k | source->pub.max_pixels = 0; | 723 | | | 724 | 31.4k | return (cjpeg_source_ptr)source; | 725 | 31.4k | } |
|
726 | | |
727 | | #endif /* defined(PNG_SUPPORTED) && |
728 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ |