/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 | 299k | #define TRY_SPNG(f) { \ |
34 | 299k | int __spng_error = (f); \ |
35 | 299k | if (__spng_error) \ |
36 | 299k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(__spng_error)); \ |
37 | 299k | } |
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 | 283k | { |
76 | 283k | png_source_ptr source = (png_source_ptr)sinfo; |
77 | 283k | int spng_error; |
78 | | |
79 | 283k | spng_error = spng_decode_row(source->ctx, source->iobuffer, |
80 | 283k | source->buffer_width); |
81 | 283k | if (spng_error && spng_error != SPNG_EOI) |
82 | 9.14k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ |
83 | 283k | return 1; |
84 | 283k | } Line | Count | Source | 75 | 153k | { | 76 | 153k | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 153k | int spng_error; | 78 | | | 79 | 153k | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 153k | source->buffer_width); | 81 | 153k | if (spng_error && spng_error != SPNG_EOI) | 82 | 4.81k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 153k | return 1; | 84 | 153k | } |
Line | Count | Source | 75 | 84.7k | { | 76 | 84.7k | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 84.7k | int spng_error; | 78 | | | 79 | 84.7k | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 84.7k | source->buffer_width); | 81 | 84.7k | if (spng_error && spng_error != SPNG_EOI) | 82 | 2.91k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 84.7k | return 1; | 84 | 84.7k | } |
Line | Count | Source | 75 | 45.6k | { | 76 | 45.6k | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 45.6k | int spng_error; | 78 | | | 79 | 45.6k | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 45.6k | source->buffer_width); | 81 | 45.6k | if (spng_error && spng_error != SPNG_EOI) | 82 | 1.42k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 45.6k | return 1; | 84 | 45.6k | } |
|
85 | | |
86 | | |
87 | 91.3k | #define GRAY_RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \ |
88 | 8.22M | for (col = cinfo->image_width; col > 0; col--) { \ |
89 | 8.13M | ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \ |
90 | 8.13M | alpha_set_op \ |
91 | 8.13M | ptr += ps; \ |
92 | 8.13M | pointer_op \ |
93 | 8.13M | } \ |
94 | 91.3k | } |
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 | 14.3k | { |
103 | 14.3k | png_source_ptr source = (png_source_ptr)sinfo; |
104 | 14.3k | register _JSAMPROW ptr; |
105 | 14.3k | register _JSAMPLE *rescale = source->rescale; |
106 | 14.3k | JDIMENSION col; |
107 | | |
108 | 14.3k | get_raw_row(cinfo, sinfo); |
109 | 14.3k | ptr = source->pub._buffer[0]; |
110 | | #if BITS_IN_JSAMPLE != 12 |
111 | 8.05k | if (source->png_bit_depth == cinfo->data_precision) { |
112 | 0 | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
113 | 0 | for (col = cinfo->image_width; col > 0; col--) { |
114 | 0 | *ptr++ = *bufferptr++; |
115 | 0 | bufferptr += source->png_alpha; |
116 | 0 | } |
117 | 0 | } else |
118 | 8.05k | #endif |
119 | 14.3k | if (source->png_bit_depth == 16) { |
120 | 6.54k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
121 | 642k | for (col = cinfo->image_width; col > 0; col--) { |
122 | 635k | *ptr++ = rescale[*bufferptr++]; |
123 | 635k | bufferptr += source->png_alpha; |
124 | 635k | } |
125 | 7.76k | } else { |
126 | 7.76k | register unsigned char *bufferptr = source->iobuffer; |
127 | 644k | for (col = cinfo->image_width; col > 0; col--) { |
128 | 636k | *ptr++ = rescale[*bufferptr++]; |
129 | 636k | bufferptr += source->png_alpha; |
130 | 636k | } |
131 | 7.76k | } |
132 | 14.3k | return 1; |
133 | 14.3k | } Line | Count | Source | 102 | 6.54k | { | 103 | 6.54k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 6.54k | register _JSAMPROW ptr; | 105 | 6.54k | register _JSAMPLE *rescale = source->rescale; | 106 | 6.54k | JDIMENSION col; | 107 | | | 108 | 6.54k | get_raw_row(cinfo, sinfo); | 109 | 6.54k | ptr = source->pub._buffer[0]; | 110 | 6.54k | #if BITS_IN_JSAMPLE != 12 | 111 | 6.54k | if (source->png_bit_depth == cinfo->data_precision) { | 112 | 0 | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 114 | 0 | *ptr++ = *bufferptr++; | 115 | 0 | bufferptr += source->png_alpha; | 116 | 0 | } | 117 | 0 | } else | 118 | 6.54k | #endif | 119 | 6.54k | if (source->png_bit_depth == 16) { | 120 | 4.49k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 441k | for (col = cinfo->image_width; col > 0; col--) { | 122 | 436k | *ptr++ = rescale[*bufferptr++]; | 123 | 436k | bufferptr += source->png_alpha; | 124 | 436k | } | 125 | 4.49k | } else { | 126 | 2.05k | register unsigned char *bufferptr = source->iobuffer; | 127 | 132k | for (col = cinfo->image_width; col > 0; col--) { | 128 | 130k | *ptr++ = rescale[*bufferptr++]; | 129 | 130k | bufferptr += source->png_alpha; | 130 | 130k | } | 131 | 2.05k | } | 132 | 6.54k | return 1; | 133 | 6.54k | } |
Line | Count | Source | 102 | 6.25k | { | 103 | 6.25k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 6.25k | register _JSAMPROW ptr; | 105 | 6.25k | register _JSAMPLE *rescale = source->rescale; | 106 | 6.25k | JDIMENSION col; | 107 | | | 108 | 6.25k | get_raw_row(cinfo, sinfo); | 109 | 6.25k | 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 | 6.25k | if (source->png_bit_depth == 16) { | 120 | 2.05k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 200k | for (col = cinfo->image_width; col > 0; col--) { | 122 | 198k | *ptr++ = rescale[*bufferptr++]; | 123 | 198k | bufferptr += source->png_alpha; | 124 | 198k | } | 125 | 4.19k | } else { | 126 | 4.19k | register unsigned char *bufferptr = source->iobuffer; | 127 | 372k | for (col = cinfo->image_width; col > 0; col--) { | 128 | 368k | *ptr++ = rescale[*bufferptr++]; | 129 | 368k | bufferptr += source->png_alpha; | 130 | 368k | } | 131 | 4.19k | } | 132 | 6.25k | return 1; | 133 | 6.25k | } |
Line | Count | Source | 102 | 1.51k | { | 103 | 1.51k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 1.51k | register _JSAMPROW ptr; | 105 | 1.51k | register _JSAMPLE *rescale = source->rescale; | 106 | 1.51k | JDIMENSION col; | 107 | | | 108 | 1.51k | get_raw_row(cinfo, sinfo); | 109 | 1.51k | ptr = source->pub._buffer[0]; | 110 | 1.51k | #if BITS_IN_JSAMPLE != 12 | 111 | 1.51k | if (source->png_bit_depth == cinfo->data_precision) { | 112 | 0 | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 114 | 0 | *ptr++ = *bufferptr++; | 115 | 0 | bufferptr += source->png_alpha; | 116 | 0 | } | 117 | 0 | } else | 118 | 1.51k | #endif | 119 | 1.51k | 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 | 1.51k | } else { | 126 | 1.51k | register unsigned char *bufferptr = source->iobuffer; | 127 | 139k | for (col = cinfo->image_width; col > 0; col--) { | 128 | 137k | *ptr++ = rescale[*bufferptr++]; | 129 | 137k | bufferptr += source->png_alpha; | 130 | 137k | } | 131 | 1.51k | } | 132 | 1.51k | return 1; | 133 | 1.51k | } |
|
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 | 91.3k | { |
142 | 91.3k | png_source_ptr source = (png_source_ptr)sinfo; |
143 | 91.3k | register _JSAMPROW ptr; |
144 | 91.3k | register _JSAMPLE *rescale = source->rescale; |
145 | 91.3k | JDIMENSION col; |
146 | 91.3k | register int rindex = rgb_red[cinfo->in_color_space]; |
147 | 91.3k | register int gindex = rgb_green[cinfo->in_color_space]; |
148 | 91.3k | register int bindex = rgb_blue[cinfo->in_color_space]; |
149 | 91.3k | register int aindex = alpha_index[cinfo->in_color_space]; |
150 | 91.3k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
151 | | |
152 | 91.3k | get_raw_row(cinfo, sinfo); |
153 | 91.3k | ptr = source->pub._buffer[0]; |
154 | | #if BITS_IN_JSAMPLE != 12 |
155 | 60.0k | if (source->png_bit_depth == cinfo->data_precision) { |
156 | 22.7k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
157 | 22.7k | if (aindex >= 0) |
158 | 2.01k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, |
159 | 22.7k | bufferptr += source->png_alpha;) |
160 | 20.7k | else |
161 | 20.7k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) |
162 | 22.7k | } else |
163 | 37.3k | #endif |
164 | 68.6k | if (source->png_bit_depth == 16) { |
165 | 31.1k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
166 | 31.1k | if (aindex >= 0) |
167 | 5.85k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
168 | 31.1k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
169 | 31.1k | bufferptr += source->png_alpha;) |
170 | 25.3k | else |
171 | 25.3k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, |
172 | 31.1k | bufferptr += source->png_alpha;) |
173 | 37.4k | } else { |
174 | 37.4k | register unsigned char *bufferptr = source->iobuffer; |
175 | 37.4k | if (aindex >= 0) |
176 | 7.35k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
177 | 37.4k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
178 | 37.4k | bufferptr += source->png_alpha;) |
179 | 30.0k | else |
180 | 30.0k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, |
181 | 37.4k | bufferptr += source->png_alpha;) |
182 | 37.4k | } |
183 | 91.3k | return 1; |
184 | 91.3k | } rdpng-8.c:get_gray_rgb_row Line | Count | Source | 141 | 44.3k | { | 142 | 44.3k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 44.3k | register _JSAMPROW ptr; | 144 | 44.3k | register _JSAMPLE *rescale = source->rescale; | 145 | 44.3k | JDIMENSION col; | 146 | 44.3k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 44.3k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 44.3k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 44.3k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 44.3k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 44.3k | get_raw_row(cinfo, sinfo); | 153 | 44.3k | ptr = source->pub._buffer[0]; | 154 | 44.3k | #if BITS_IN_JSAMPLE != 12 | 155 | 44.3k | if (source->png_bit_depth == cinfo->data_precision) { | 156 | 19.5k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | 19.5k | if (aindex >= 0) | 158 | 2.01k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | 19.5k | bufferptr += source->png_alpha;) | 160 | 17.5k | else | 161 | 17.5k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | 19.5k | } else | 163 | 24.8k | #endif | 164 | 24.8k | if (source->png_bit_depth == 16) { | 165 | 16.1k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 16.1k | if (aindex >= 0) | 167 | 2.21k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 16.1k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 16.1k | bufferptr += source->png_alpha;) | 170 | 13.9k | else | 171 | 13.9k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 16.1k | bufferptr += source->png_alpha;) | 173 | 16.1k | } else { | 174 | 8.67k | register unsigned char *bufferptr = source->iobuffer; | 175 | 8.67k | if (aindex >= 0) | 176 | 1.84k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 8.67k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 8.67k | bufferptr += source->png_alpha;) | 179 | 6.83k | else | 180 | 6.83k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 8.67k | bufferptr += source->png_alpha;) | 182 | 8.67k | } | 183 | 44.3k | return 1; | 184 | 44.3k | } |
rdpng-12.c:get_gray_rgb_row Line | Count | Source | 141 | 31.2k | { | 142 | 31.2k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 31.2k | register _JSAMPROW ptr; | 144 | 31.2k | register _JSAMPLE *rescale = source->rescale; | 145 | 31.2k | JDIMENSION col; | 146 | 31.2k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 31.2k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 31.2k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 31.2k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 31.2k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 31.2k | get_raw_row(cinfo, sinfo); | 153 | 31.2k | 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 | 31.2k | if (source->png_bit_depth == 16) { | 165 | 10.2k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 10.2k | if (aindex >= 0) | 167 | 2.05k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 10.2k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 10.2k | bufferptr += source->png_alpha;) | 170 | 8.21k | else | 171 | 8.21k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 10.2k | bufferptr += source->png_alpha;) | 173 | 20.9k | } else { | 174 | 20.9k | register unsigned char *bufferptr = source->iobuffer; | 175 | 20.9k | if (aindex >= 0) | 176 | 4.02k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 20.9k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 20.9k | bufferptr += source->png_alpha;) | 179 | 16.9k | else | 180 | 16.9k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 20.9k | bufferptr += source->png_alpha;) | 182 | 20.9k | } | 183 | 31.2k | return 1; | 184 | 31.2k | } |
rdpng-16.c:get_gray_rgb_row Line | Count | Source | 141 | 15.7k | { | 142 | 15.7k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 15.7k | register _JSAMPROW ptr; | 144 | 15.7k | register _JSAMPLE *rescale = source->rescale; | 145 | 15.7k | JDIMENSION col; | 146 | 15.7k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 15.7k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 15.7k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 15.7k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 15.7k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 15.7k | get_raw_row(cinfo, sinfo); | 153 | 15.7k | ptr = source->pub._buffer[0]; | 154 | 15.7k | #if BITS_IN_JSAMPLE != 12 | 155 | 15.7k | if (source->png_bit_depth == cinfo->data_precision) { | 156 | 3.17k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | 3.17k | if (aindex >= 0) | 158 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | 3.17k | bufferptr += source->png_alpha;) | 160 | 3.17k | else | 161 | 3.17k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | 3.17k | } else | 163 | 12.5k | #endif | 164 | 12.5k | if (source->png_bit_depth == 16) { | 165 | 4.76k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 4.76k | if (aindex >= 0) | 167 | 1.58k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 4.76k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 4.76k | bufferptr += source->png_alpha;) | 170 | 3.17k | else | 171 | 3.17k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 4.76k | bufferptr += source->png_alpha;) | 173 | 7.78k | } else { | 174 | 7.78k | register unsigned char *bufferptr = source->iobuffer; | 175 | 7.78k | if (aindex >= 0) | 176 | 1.48k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 7.78k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 7.78k | bufferptr += source->png_alpha;) | 179 | 6.30k | else | 180 | 6.30k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 7.78k | bufferptr += source->png_alpha;) | 182 | 7.78k | } | 183 | 15.7k | return 1; | 184 | 15.7k | } |
|
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 | 15.6k | { |
193 | 15.6k | png_source_ptr source = (png_source_ptr)sinfo; |
194 | 15.6k | register _JSAMPROW ptr; |
195 | 15.6k | register _JSAMPLE *rescale = source->rescale; |
196 | 15.6k | JDIMENSION col; |
197 | | |
198 | 15.6k | get_raw_row(cinfo, sinfo); |
199 | 15.6k | ptr = source->pub._buffer[0]; |
200 | | #if BITS_IN_JSAMPLE != 12 |
201 | 9.39k | if (source->png_bit_depth == cinfo->data_precision) { |
202 | 3.60k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
203 | 344k | for (col = cinfo->image_width; col > 0; col--) { |
204 | 340k | _JSAMPLE gray = *bufferptr++; |
205 | 340k | bufferptr += source->png_alpha; |
206 | 340k | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, |
207 | 340k | ptr + 3); |
208 | 340k | ptr += 4; |
209 | 340k | } |
210 | 3.60k | } else |
211 | 5.79k | #endif |
212 | 12.0k | if (source->png_bit_depth == 16) { |
213 | 4.27k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
214 | 417k | for (col = cinfo->image_width; col > 0; col--) { |
215 | 412k | _JSAMPLE gray = rescale[*bufferptr++]; |
216 | 412k | bufferptr += source->png_alpha; |
217 | 412k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
218 | 412k | ptr + 1, ptr + 2, ptr + 3); |
219 | 412k | ptr += 4; |
220 | 412k | } |
221 | 7.77k | } else { |
222 | 7.77k | register unsigned char *bufferptr = source->iobuffer; |
223 | 644k | for (col = cinfo->image_width; col > 0; col--) { |
224 | 636k | _JSAMPLE gray = rescale[*bufferptr++]; |
225 | 636k | bufferptr += source->png_alpha; |
226 | 636k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
227 | 636k | ptr + 1, ptr + 2, ptr + 3); |
228 | 636k | ptr += 4; |
229 | 636k | } |
230 | 7.77k | } |
231 | 15.6k | return 1; |
232 | 15.6k | } rdpng-8.c:get_gray_cmyk_row Line | Count | Source | 192 | 6.25k | { | 193 | 6.25k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 6.25k | register _JSAMPROW ptr; | 195 | 6.25k | register _JSAMPLE *rescale = source->rescale; | 196 | 6.25k | JDIMENSION col; | 197 | | | 198 | 6.25k | get_raw_row(cinfo, sinfo); | 199 | 6.25k | ptr = source->pub._buffer[0]; | 200 | 6.25k | #if BITS_IN_JSAMPLE != 12 | 201 | 6.25k | if (source->png_bit_depth == cinfo->data_precision) { | 202 | 2.01k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | 190k | for (col = cinfo->image_width; col > 0; col--) { | 204 | 188k | _JSAMPLE gray = *bufferptr++; | 205 | 188k | bufferptr += source->png_alpha; | 206 | 188k | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | 188k | ptr + 3); | 208 | 188k | ptr += 4; | 209 | 188k | } | 210 | 2.01k | } else | 211 | 4.23k | #endif | 212 | 4.23k | if (source->png_bit_depth == 16) { | 213 | 2.21k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 216k | for (col = cinfo->image_width; col > 0; col--) { | 215 | 214k | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 214k | bufferptr += source->png_alpha; | 217 | 214k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 214k | ptr + 1, ptr + 2, ptr + 3); | 219 | 214k | ptr += 4; | 220 | 214k | } | 221 | 2.21k | } else { | 222 | 2.02k | register unsigned char *bufferptr = source->iobuffer; | 223 | 132k | for (col = cinfo->image_width; col > 0; col--) { | 224 | 130k | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 130k | bufferptr += source->png_alpha; | 226 | 130k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 130k | ptr + 1, ptr + 2, ptr + 3); | 228 | 130k | ptr += 4; | 229 | 130k | } | 230 | 2.02k | } | 231 | 6.25k | return 1; | 232 | 6.25k | } |
rdpng-12.c:get_gray_cmyk_row Line | Count | Source | 192 | 6.25k | { | 193 | 6.25k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 6.25k | register _JSAMPROW ptr; | 195 | 6.25k | register _JSAMPLE *rescale = source->rescale; | 196 | 6.25k | JDIMENSION col; | 197 | | | 198 | 6.25k | get_raw_row(cinfo, sinfo); | 199 | 6.25k | 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 | 6.25k | if (source->png_bit_depth == 16) { | 213 | 2.05k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 200k | for (col = cinfo->image_width; col > 0; col--) { | 215 | 198k | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 198k | bufferptr += source->png_alpha; | 217 | 198k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 198k | ptr + 1, ptr + 2, ptr + 3); | 219 | 198k | ptr += 4; | 220 | 198k | } | 221 | 4.19k | } else { | 222 | 4.19k | register unsigned char *bufferptr = source->iobuffer; | 223 | 372k | for (col = cinfo->image_width; col > 0; col--) { | 224 | 368k | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 368k | bufferptr += source->png_alpha; | 226 | 368k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 368k | ptr + 1, ptr + 2, ptr + 3); | 228 | 368k | ptr += 4; | 229 | 368k | } | 230 | 4.19k | } | 231 | 6.25k | return 1; | 232 | 6.25k | } |
rdpng-16.c:get_gray_cmyk_row Line | Count | Source | 192 | 3.14k | { | 193 | 3.14k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 3.14k | register _JSAMPROW ptr; | 195 | 3.14k | register _JSAMPLE *rescale = source->rescale; | 196 | 3.14k | JDIMENSION col; | 197 | | | 198 | 3.14k | get_raw_row(cinfo, sinfo); | 199 | 3.14k | ptr = source->pub._buffer[0]; | 200 | 3.14k | #if BITS_IN_JSAMPLE != 12 | 201 | 3.14k | if (source->png_bit_depth == cinfo->data_precision) { | 202 | 1.58k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | 153k | for (col = cinfo->image_width; col > 0; col--) { | 204 | 152k | _JSAMPLE gray = *bufferptr++; | 205 | 152k | bufferptr += source->png_alpha; | 206 | 152k | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | 152k | ptr + 3); | 208 | 152k | ptr += 4; | 209 | 152k | } | 210 | 1.58k | } else | 211 | 1.55k | #endif | 212 | 1.55k | 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 | 1.55k | } else { | 222 | 1.55k | register unsigned char *bufferptr = source->iobuffer; | 223 | 139k | for (col = cinfo->image_width; col > 0; col--) { | 224 | 137k | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 137k | bufferptr += source->png_alpha; | 226 | 137k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 137k | ptr + 1, ptr + 2, ptr + 3); | 228 | 137k | ptr += 4; | 229 | 137k | } | 230 | 1.55k | } | 231 | 3.14k | return 1; | 232 | 3.14k | } |
|
233 | | |
234 | | |
235 | 117k | #define RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \ |
236 | 14.5M | for (col = cinfo->image_width; col > 0; col--) { \ |
237 | 14.3M | ptr[rindex] = read_op; \ |
238 | 14.3M | ptr[gindex] = read_op; \ |
239 | 14.3M | ptr[bindex] = read_op; \ |
240 | 14.3M | alpha_set_op \ |
241 | 14.3M | pointer_op \ |
242 | 14.3M | ptr += ps; \ |
243 | 14.3M | } \ |
244 | 117k | } |
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 | 117k | { |
253 | 117k | png_source_ptr source = (png_source_ptr)sinfo; |
254 | 117k | register _JSAMPROW ptr; |
255 | 117k | register _JSAMPLE *rescale = source->rescale; |
256 | 117k | JDIMENSION col; |
257 | 117k | register int rindex = rgb_red[cinfo->in_color_space]; |
258 | 117k | register int gindex = rgb_green[cinfo->in_color_space]; |
259 | 117k | register int bindex = rgb_blue[cinfo->in_color_space]; |
260 | 117k | register int aindex = alpha_index[cinfo->in_color_space]; |
261 | 117k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
262 | | |
263 | 117k | get_raw_row(cinfo, sinfo); |
264 | 117k | ptr = source->pub._buffer[0]; |
265 | | #if BITS_IN_JSAMPLE != 12 |
266 | 85.7k | if (source->png_bit_depth == cinfo->data_precision) { |
267 | 14.3k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
268 | 14.3k | if (aindex >= 0) |
269 | 1.28k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, |
270 | 14.3k | bufferptr += source->png_alpha;) |
271 | 13.0k | else |
272 | 13.0k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) |
273 | 14.3k | } else |
274 | 71.4k | #endif |
275 | 103k | if (source->png_bit_depth == 16) { |
276 | 67.7k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
277 | 67.7k | if (aindex >= 0) |
278 | 12.1k | RGB_READ_LOOP(rescale[*bufferptr++], |
279 | 67.7k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
280 | 67.7k | bufferptr += source->png_alpha;) |
281 | 55.5k | else |
282 | 55.5k | RGB_READ_LOOP(rescale[*bufferptr++], {}, |
283 | 67.7k | bufferptr += source->png_alpha;) |
284 | 67.7k | } else { |
285 | 35.8k | register unsigned char *bufferptr = source->iobuffer; |
286 | 35.8k | if (aindex >= 0) |
287 | 6.82k | RGB_READ_LOOP(rescale[*bufferptr++], |
288 | 35.8k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
289 | 35.8k | bufferptr += source->png_alpha;) |
290 | 29.0k | else |
291 | 29.0k | RGB_READ_LOOP(rescale[*bufferptr++], {}, |
292 | 35.8k | bufferptr += source->png_alpha;) |
293 | 35.8k | } |
294 | 117k | return 1; |
295 | 117k | } Line | Count | Source | 252 | 68.8k | { | 253 | 68.8k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 68.8k | register _JSAMPROW ptr; | 255 | 68.8k | register _JSAMPLE *rescale = source->rescale; | 256 | 68.8k | JDIMENSION col; | 257 | 68.8k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 68.8k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 68.8k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 68.8k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 68.8k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 68.8k | get_raw_row(cinfo, sinfo); | 264 | 68.8k | ptr = source->pub._buffer[0]; | 265 | 68.8k | #if BITS_IN_JSAMPLE != 12 | 266 | 68.8k | if (source->png_bit_depth == cinfo->data_precision) { | 267 | 12.3k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | 12.3k | if (aindex >= 0) | 269 | 1.28k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | 12.3k | bufferptr += source->png_alpha;) | 271 | 11.1k | else | 272 | 11.1k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | 12.3k | } else | 274 | 56.4k | #endif | 275 | 56.4k | if (source->png_bit_depth == 16) { | 276 | 46.3k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 46.3k | if (aindex >= 0) | 278 | 7.09k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 46.3k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 46.3k | bufferptr += source->png_alpha;) | 281 | 39.2k | else | 282 | 39.2k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 46.3k | bufferptr += source->png_alpha;) | 284 | 46.3k | } else { | 285 | 10.0k | register unsigned char *bufferptr = source->iobuffer; | 286 | 10.0k | if (aindex >= 0) | 287 | 2.01k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 10.0k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 10.0k | bufferptr += source->png_alpha;) | 290 | 8.05k | else | 291 | 8.05k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 10.0k | bufferptr += source->png_alpha;) | 293 | 10.0k | } | 294 | 68.8k | return 1; | 295 | 68.8k | } |
Line | Count | Source | 252 | 32.1k | { | 253 | 32.1k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 32.1k | register _JSAMPROW ptr; | 255 | 32.1k | register _JSAMPLE *rescale = source->rescale; | 256 | 32.1k | JDIMENSION col; | 257 | 32.1k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 32.1k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 32.1k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 32.1k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 32.1k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 32.1k | get_raw_row(cinfo, sinfo); | 264 | 32.1k | 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 | 32.1k | if (source->png_bit_depth == 16) { | 276 | 15.3k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 15.3k | if (aindex >= 0) | 278 | 3.07k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 15.3k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 15.3k | bufferptr += source->png_alpha;) | 281 | 12.3k | else | 282 | 12.3k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 15.3k | bufferptr += source->png_alpha;) | 284 | 16.8k | } else { | 285 | 16.8k | register unsigned char *bufferptr = source->iobuffer; | 286 | 16.8k | if (aindex >= 0) | 287 | 3.12k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 16.8k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 16.8k | bufferptr += source->png_alpha;) | 290 | 13.6k | else | 291 | 13.6k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 16.8k | bufferptr += source->png_alpha;) | 293 | 16.8k | } | 294 | 32.1k | return 1; | 295 | 32.1k | } |
Line | Count | Source | 252 | 16.9k | { | 253 | 16.9k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 16.9k | register _JSAMPROW ptr; | 255 | 16.9k | register _JSAMPLE *rescale = source->rescale; | 256 | 16.9k | JDIMENSION col; | 257 | 16.9k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 16.9k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 16.9k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 16.9k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 16.9k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 16.9k | get_raw_row(cinfo, sinfo); | 264 | 16.9k | ptr = source->pub._buffer[0]; | 265 | 16.9k | #if BITS_IN_JSAMPLE != 12 | 266 | 16.9k | if (source->png_bit_depth == cinfo->data_precision) { | 267 | 1.98k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | 1.98k | if (aindex >= 0) | 269 | 0 | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | 1.98k | bufferptr += source->png_alpha;) | 271 | 1.98k | else | 272 | 1.98k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | 1.98k | } else | 274 | 14.9k | #endif | 275 | 14.9k | if (source->png_bit_depth == 16) { | 276 | 5.94k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 5.94k | if (aindex >= 0) | 278 | 1.98k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 5.94k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 5.94k | bufferptr += source->png_alpha;) | 281 | 3.96k | else | 282 | 3.96k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 5.94k | bufferptr += source->png_alpha;) | 284 | 9.00k | } else { | 285 | 9.00k | register unsigned char *bufferptr = source->iobuffer; | 286 | 9.00k | if (aindex >= 0) | 287 | 1.68k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 9.00k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 9.00k | bufferptr += source->png_alpha;) | 290 | 7.31k | else | 291 | 7.31k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 9.00k | bufferptr += source->png_alpha;) | 293 | 9.00k | } | 294 | 16.9k | return 1; | 295 | 16.9k | } |
|
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 | 20.9k | { |
304 | 20.9k | png_source_ptr source = (png_source_ptr)sinfo; |
305 | 20.9k | register _JSAMPROW ptr; |
306 | 20.9k | register _JSAMPLE *rescale = source->rescale; |
307 | 20.9k | JDIMENSION col; |
308 | | |
309 | 20.9k | get_raw_row(cinfo, sinfo); |
310 | 20.9k | ptr = source->pub._buffer[0]; |
311 | | #if BITS_IN_JSAMPLE != 12 |
312 | 14.5k | if (source->png_bit_depth == cinfo->data_precision) { |
313 | 3.26k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
314 | 300k | for (col = cinfo->image_width; col > 0; col--) { |
315 | 296k | _JSAMPLE r = *bufferptr++; |
316 | 296k | _JSAMPLE g = *bufferptr++; |
317 | 296k | _JSAMPLE b = *bufferptr++; |
318 | 296k | bufferptr += source->png_alpha; |
319 | 296k | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
320 | 296k | ptr += 4; |
321 | 296k | } |
322 | 3.26k | } else |
323 | 11.2k | #endif |
324 | 17.6k | if (source->png_bit_depth == 16) { |
325 | 10.1k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
326 | 1.05M | for (col = cinfo->image_width; col > 0; col--) { |
327 | 1.04M | _JSAMPLE r = rescale[*bufferptr++]; |
328 | 1.04M | _JSAMPLE g = rescale[*bufferptr++]; |
329 | 1.04M | _JSAMPLE b = rescale[*bufferptr++]; |
330 | 1.04M | bufferptr += source->png_alpha; |
331 | 1.04M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
332 | 1.04M | ptr + 2, ptr + 3); |
333 | 1.04M | ptr += 4; |
334 | 1.04M | } |
335 | 10.1k | } else { |
336 | 7.51k | register unsigned char *bufferptr = source->iobuffer; |
337 | 1.46M | for (col = cinfo->image_width; col > 0; col--) { |
338 | 1.45M | _JSAMPLE r = rescale[*bufferptr++]; |
339 | 1.45M | _JSAMPLE g = rescale[*bufferptr++]; |
340 | 1.45M | _JSAMPLE b = rescale[*bufferptr++]; |
341 | 1.45M | bufferptr += source->png_alpha; |
342 | 1.45M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
343 | 1.45M | ptr + 2, ptr + 3); |
344 | 1.45M | ptr += 4; |
345 | 1.45M | } |
346 | 7.51k | } |
347 | 20.9k | return 1; |
348 | 20.9k | } rdpng-8.c:get_rgb_cmyk_row Line | Count | Source | 303 | 10.7k | { | 304 | 10.7k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 10.7k | register _JSAMPROW ptr; | 306 | 10.7k | register _JSAMPLE *rescale = source->rescale; | 307 | 10.7k | JDIMENSION col; | 308 | | | 309 | 10.7k | get_raw_row(cinfo, sinfo); | 310 | 10.7k | ptr = source->pub._buffer[0]; | 311 | 10.7k | #if BITS_IN_JSAMPLE != 12 | 312 | 10.7k | if (source->png_bit_depth == cinfo->data_precision) { | 313 | 1.28k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | 109k | for (col = cinfo->image_width; col > 0; col--) { | 315 | 107k | _JSAMPLE r = *bufferptr++; | 316 | 107k | _JSAMPLE g = *bufferptr++; | 317 | 107k | _JSAMPLE b = *bufferptr++; | 318 | 107k | bufferptr += source->png_alpha; | 319 | 107k | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | 107k | ptr += 4; | 321 | 107k | } | 322 | 1.28k | } else | 323 | 9.43k | #endif | 324 | 9.43k | if (source->png_bit_depth == 16) { | 325 | 7.09k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 755k | for (col = cinfo->image_width; col > 0; col--) { | 327 | 748k | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 748k | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 748k | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 748k | bufferptr += source->png_alpha; | 331 | 748k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 748k | ptr + 2, ptr + 3); | 333 | 748k | ptr += 4; | 334 | 748k | } | 335 | 7.09k | } else { | 336 | 2.33k | register unsigned char *bufferptr = source->iobuffer; | 337 | 1.01M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 1.01M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 1.01M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 1.01M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 1.01M | bufferptr += source->png_alpha; | 342 | 1.01M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 1.01M | ptr + 2, ptr + 3); | 344 | 1.01M | ptr += 4; | 345 | 1.01M | } | 346 | 2.33k | } | 347 | 10.7k | return 1; | 348 | 10.7k | } |
rdpng-12.c:get_rgb_cmyk_row Line | Count | Source | 303 | 6.43k | { | 304 | 6.43k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 6.43k | register _JSAMPROW ptr; | 306 | 6.43k | register _JSAMPLE *rescale = source->rescale; | 307 | 6.43k | JDIMENSION col; | 308 | | | 309 | 6.43k | get_raw_row(cinfo, sinfo); | 310 | 6.43k | 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 | 6.43k | if (source->png_bit_depth == 16) { | 325 | 3.07k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 297k | for (col = cinfo->image_width; col > 0; col--) { | 327 | 294k | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 294k | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 294k | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 294k | bufferptr += source->png_alpha; | 331 | 294k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 294k | ptr + 2, ptr + 3); | 333 | 294k | ptr += 4; | 334 | 294k | } | 335 | 3.36k | } else { | 336 | 3.36k | register unsigned char *bufferptr = source->iobuffer; | 337 | 294k | for (col = cinfo->image_width; col > 0; col--) { | 338 | 290k | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 290k | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 290k | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 290k | bufferptr += source->png_alpha; | 342 | 290k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 290k | ptr + 2, ptr + 3); | 344 | 290k | ptr += 4; | 345 | 290k | } | 346 | 3.36k | } | 347 | 6.43k | return 1; | 348 | 6.43k | } |
rdpng-16.c:get_rgb_cmyk_row Line | Count | Source | 303 | 3.79k | { | 304 | 3.79k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 3.79k | register _JSAMPROW ptr; | 306 | 3.79k | register _JSAMPLE *rescale = source->rescale; | 307 | 3.79k | JDIMENSION col; | 308 | | | 309 | 3.79k | get_raw_row(cinfo, sinfo); | 310 | 3.79k | ptr = source->pub._buffer[0]; | 311 | 3.79k | #if BITS_IN_JSAMPLE != 12 | 312 | 3.79k | if (source->png_bit_depth == cinfo->data_precision) { | 313 | 1.98k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | 191k | for (col = cinfo->image_width; col > 0; col--) { | 315 | 189k | _JSAMPLE r = *bufferptr++; | 316 | 189k | _JSAMPLE g = *bufferptr++; | 317 | 189k | _JSAMPLE b = *bufferptr++; | 318 | 189k | bufferptr += source->png_alpha; | 319 | 189k | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | 189k | ptr += 4; | 321 | 189k | } | 322 | 1.98k | } else | 323 | 1.81k | #endif | 324 | 1.81k | 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 | 1.81k | } else { | 336 | 1.81k | register unsigned char *bufferptr = source->iobuffer; | 337 | 154k | for (col = cinfo->image_width; col > 0; col--) { | 338 | 152k | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 152k | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 152k | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 152k | bufferptr += source->png_alpha; | 342 | 152k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 152k | ptr + 2, ptr + 3); | 344 | 152k | ptr += 4; | 345 | 152k | } | 346 | 1.81k | } | 347 | 3.79k | return 1; | 348 | 3.79k | } |
|
349 | | |
350 | | |
351 | | METHODDEF(JDIMENSION) |
352 | | get_indexed_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
353 | 6.36k | { |
354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and |
355 | | * converting to extended RGB or CMYK. |
356 | | */ |
357 | 6.36k | png_source_ptr source = (png_source_ptr)sinfo; |
358 | 6.36k | register _JSAMPROW ptr; |
359 | 6.36k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; |
360 | 6.36k | register _JSAMPLE *rescale = source->rescale; |
361 | 6.36k | JDIMENSION col; |
362 | | |
363 | 6.36k | get_raw_row(cinfo, sinfo); |
364 | 6.36k | ptr = source->pub._buffer[0]; |
365 | | #if BITS_IN_JSAMPLE == 8 |
366 | 3.13k | if (source->png_bit_depth == cinfo->data_precision) { |
367 | 2.16k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
368 | 3.27k | for (col = cinfo->image_width; col > 0; col--) { |
369 | 2.89k | JSAMPLE index = *bufferptr++; |
370 | | |
371 | 2.89k | if (index >= source->colormap.n_entries) |
372 | 32 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
373 | 2.89k | *ptr++ = source->colormap.entries[index].red; |
374 | 2.89k | } |
375 | 1.78k | } else if (cinfo->in_color_space == JCS_CMYK) { |
376 | 761 | for (col = cinfo->image_width; col > 0; col--) { |
377 | 671 | JSAMPLE index = *bufferptr++; |
378 | | |
379 | 671 | if (index >= source->colormap.n_entries) |
380 | 12 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
381 | 671 | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, |
382 | 671 | source->colormap.entries[index].green, |
383 | 671 | source->colormap.entries[index].blue, ptr, ptr + 1, |
384 | 671 | ptr + 2, ptr + 3); |
385 | 671 | ptr += 4; |
386 | 671 | } |
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 | 14.7k | for (col = cinfo->image_width; col > 0; col--) { |
395 | 13.0k | JSAMPLE index = *bufferptr++; |
396 | | |
397 | 13.0k | if (index >= source->colormap.n_entries) |
398 | 142 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
399 | 13.0k | ptr[rindex] = source->colormap.entries[index].red; |
400 | 13.0k | ptr[gindex] = source->colormap.entries[index].green; |
401 | 13.0k | ptr[bindex] = source->colormap.entries[index].blue; |
402 | 13.0k | if (aindex >= 0) |
403 | 659 | ptr[aindex] = _MAXJSAMPLE; |
404 | 13.0k | ptr += ps; |
405 | 13.0k | } |
406 | 1.69k | } |
407 | 2.16k | } else |
408 | 968 | #endif |
409 | 968 | { |
410 | 4.20k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
411 | 2.53k | for (col = cinfo->image_width; col > 0; col--) { |
412 | 2.24k | JSAMPLE index = *bufferptr++; |
413 | | |
414 | 2.24k | if (index >= source->colormap.n_entries) |
415 | 32 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
416 | 2.24k | *ptr++ = rescale[source->colormap.entries[index].red]; |
417 | 2.24k | } |
418 | 3.90k | } else if (cinfo->in_color_space == JCS_CMYK) { |
419 | 4.67k | for (col = cinfo->image_width; col > 0; col--) { |
420 | 4.13k | JSAMPLE index = *bufferptr++; |
421 | | |
422 | 4.13k | if (index >= source->colormap.n_entries) |
423 | 59 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
424 | 4.13k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, |
425 | 4.13k | rescale[source->colormap.entries[index].red], |
426 | 4.13k | rescale[source->colormap.entries[index].green], |
427 | 4.13k | rescale[source->colormap.entries[index].blue], ptr, |
428 | 4.13k | ptr + 1, ptr + 2, ptr + 3); |
429 | 4.13k | ptr += 4; |
430 | 4.13k | } |
431 | 3.36k | } else { |
432 | 3.36k | register int rindex = rgb_red[cinfo->in_color_space]; |
433 | 3.36k | register int gindex = rgb_green[cinfo->in_color_space]; |
434 | 3.36k | register int bindex = rgb_blue[cinfo->in_color_space]; |
435 | 3.36k | register int aindex = alpha_index[cinfo->in_color_space]; |
436 | 3.36k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
437 | | |
438 | 23.1k | for (col = cinfo->image_width; col > 0; col--) { |
439 | 19.8k | JSAMPLE index = *bufferptr++; |
440 | | |
441 | 19.8k | if (index >= source->colormap.n_entries) |
442 | 282 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
443 | 19.8k | ptr[rindex] = rescale[source->colormap.entries[index].red]; |
444 | 19.8k | ptr[gindex] = rescale[source->colormap.entries[index].green]; |
445 | 19.8k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; |
446 | 19.8k | if (aindex >= 0) |
447 | 4.07k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
448 | 19.8k | ptr += ps; |
449 | 19.8k | } |
450 | 3.36k | } |
451 | 968 | } |
452 | 6.36k | return 1; |
453 | 6.36k | } rdpng-8.c:get_indexed_row Line | Count | Source | 353 | 3.13k | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 3.13k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 3.13k | register _JSAMPROW ptr; | 359 | 3.13k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 3.13k | register _JSAMPLE *rescale = source->rescale; | 361 | 3.13k | JDIMENSION col; | 362 | | | 363 | 3.13k | get_raw_row(cinfo, sinfo); | 364 | 3.13k | ptr = source->pub._buffer[0]; | 365 | 3.13k | #if BITS_IN_JSAMPLE == 8 | 366 | 3.13k | if (source->png_bit_depth == cinfo->data_precision) { | 367 | 2.16k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 368 | 3.27k | for (col = cinfo->image_width; col > 0; col--) { | 369 | 2.89k | JSAMPLE index = *bufferptr++; | 370 | | | 371 | 2.89k | if (index >= source->colormap.n_entries) | 372 | 32 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 373 | 2.89k | *ptr++ = source->colormap.entries[index].red; | 374 | 2.89k | } | 375 | 1.78k | } else if (cinfo->in_color_space == JCS_CMYK) { | 376 | 761 | for (col = cinfo->image_width; col > 0; col--) { | 377 | 671 | JSAMPLE index = *bufferptr++; | 378 | | | 379 | 671 | if (index >= source->colormap.n_entries) | 380 | 12 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 381 | 671 | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, | 382 | 671 | source->colormap.entries[index].green, | 383 | 671 | source->colormap.entries[index].blue, ptr, ptr + 1, | 384 | 671 | ptr + 2, ptr + 3); | 385 | 671 | ptr += 4; | 386 | 671 | } | 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 | 14.7k | for (col = cinfo->image_width; col > 0; col--) { | 395 | 13.0k | JSAMPLE index = *bufferptr++; | 396 | | | 397 | 13.0k | if (index >= source->colormap.n_entries) | 398 | 142 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 399 | 13.0k | ptr[rindex] = source->colormap.entries[index].red; | 400 | 13.0k | ptr[gindex] = source->colormap.entries[index].green; | 401 | 13.0k | ptr[bindex] = source->colormap.entries[index].blue; | 402 | 13.0k | if (aindex >= 0) | 403 | 659 | ptr[aindex] = _MAXJSAMPLE; | 404 | 13.0k | ptr += ps; | 405 | 13.0k | } | 406 | 1.69k | } | 407 | 2.16k | } else | 408 | 968 | #endif | 409 | 968 | { | 410 | 968 | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 384 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 339 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 339 | if (index >= source->colormap.n_entries) | 415 | 6 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 339 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 339 | } | 418 | 923 | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 945 | for (col = cinfo->image_width; col > 0; col--) { | 420 | 835 | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 835 | if (index >= source->colormap.n_entries) | 423 | 13 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 835 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 835 | rescale[source->colormap.entries[index].red], | 426 | 835 | rescale[source->colormap.entries[index].green], | 427 | 835 | rescale[source->colormap.entries[index].blue], ptr, | 428 | 835 | ptr + 1, ptr + 2, ptr + 3); | 429 | 835 | ptr += 4; | 430 | 835 | } | 431 | 813 | } else { | 432 | 813 | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 813 | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 813 | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 813 | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 813 | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 4.15k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 3.34k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 3.34k | if (index >= source->colormap.n_entries) | 442 | 52 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 3.34k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 3.34k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 3.34k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 3.34k | if (aindex >= 0) | 447 | 822 | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 3.34k | ptr += ps; | 449 | 3.34k | } | 450 | 813 | } | 451 | 968 | } | 452 | 3.13k | return 1; | 453 | 3.13k | } |
rdpng-12.c:get_indexed_row Line | Count | Source | 353 | 2.34k | { | 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.34k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 2.34k | register _JSAMPROW ptr; | 359 | 2.34k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 2.34k | register _JSAMPLE *rescale = source->rescale; | 361 | 2.34k | JDIMENSION col; | 362 | | | 363 | 2.34k | get_raw_row(cinfo, sinfo); | 364 | 2.34k | 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.34k | { | 410 | 2.34k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 1.62k | for (col = cinfo->image_width; col > 0; col--) { | 412 | 1.44k | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 1.44k | if (index >= source->colormap.n_entries) | 415 | 18 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 1.44k | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 1.44k | } | 418 | 2.15k | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 2.70k | for (col = cinfo->image_width; col > 0; col--) { | 420 | 2.39k | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 2.39k | if (index >= source->colormap.n_entries) | 423 | 31 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 2.39k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 2.39k | rescale[source->colormap.entries[index].red], | 426 | 2.39k | rescale[source->colormap.entries[index].green], | 427 | 2.39k | rescale[source->colormap.entries[index].blue], ptr, | 428 | 2.39k | ptr + 1, ptr + 2, ptr + 3); | 429 | 2.39k | ptr += 4; | 430 | 2.39k | } | 431 | 1.83k | } else { | 432 | 1.83k | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 1.83k | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 1.83k | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 1.83k | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 1.83k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 13.8k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 11.9k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 11.9k | if (index >= source->colormap.n_entries) | 442 | 155 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 11.9k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 11.9k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 11.9k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 11.9k | if (aindex >= 0) | 447 | 2.36k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 11.9k | ptr += ps; | 449 | 11.9k | } | 450 | 1.83k | } | 451 | 2.34k | } | 452 | 2.34k | return 1; | 453 | 2.34k | } |
rdpng-16.c:get_indexed_row Line | Count | Source | 353 | 895 | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 895 | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 895 | register _JSAMPROW ptr; | 359 | 895 | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 895 | register _JSAMPLE *rescale = source->rescale; | 361 | 895 | JDIMENSION col; | 362 | | | 363 | 895 | get_raw_row(cinfo, sinfo); | 364 | 895 | 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 | 895 | { | 410 | 895 | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 527 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 464 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 464 | if (index >= source->colormap.n_entries) | 415 | 8 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 464 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 464 | } | 418 | 832 | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 1.02k | for (col = cinfo->image_width; col > 0; col--) { | 420 | 901 | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 901 | if (index >= source->colormap.n_entries) | 423 | 15 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 901 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 901 | rescale[source->colormap.entries[index].red], | 426 | 901 | rescale[source->colormap.entries[index].green], | 427 | 901 | rescale[source->colormap.entries[index].blue], ptr, | 428 | 901 | ptr + 1, ptr + 2, ptr + 3); | 429 | 901 | ptr += 4; | 430 | 901 | } | 431 | 711 | } else { | 432 | 711 | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 711 | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 711 | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 711 | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 711 | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 5.21k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 4.50k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 4.50k | if (index >= source->colormap.n_entries) | 442 | 75 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 4.50k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 4.50k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 4.50k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 4.50k | if (aindex >= 0) | 447 | 886 | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 4.50k | ptr += ps; | 449 | 4.50k | } | 450 | 711 | } | 451 | 895 | } | 452 | 895 | return 1; | 453 | 895 | } |
|
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 | 119k | { |
473 | 119k | png_source_ptr source = (png_source_ptr)sinfo; |
474 | 119k | struct spng_ihdr ihdr; |
475 | 119k | int png_components = 3; |
476 | 119k | 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 | 119k | source->ctx = spng_ctx_new(0); |
487 | 119k | #endif |
488 | 119k | if (!source->ctx) |
489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); |
490 | | |
491 | 119k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); |
492 | | |
493 | 119k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); |
494 | | |
495 | 119k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) |
496 | 20.4k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); |
497 | 119k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) |
498 | 24.2k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); |
499 | 119k | if (sinfo->max_pixels && |
500 | 64.9k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) |
501 | 1.24k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); |
502 | | |
503 | 119k | cinfo->image_width = (JDIMENSION)ihdr.width; |
504 | 119k | cinfo->image_height = (JDIMENSION)ihdr.height; |
505 | 119k | source->png_bit_depth = ihdr.bit_depth; |
506 | 119k | source->png_color_type = ihdr.color_type; |
507 | | |
508 | | /* initialize flags to most common settings */ |
509 | 119k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ |
510 | | |
511 | 119k | switch (ihdr.color_type) { |
512 | 276 | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: |
513 | 20.1k | case SPNG_COLOR_TYPE_GRAYSCALE: |
514 | 20.1k | if (cinfo->in_color_space == JCS_UNKNOWN || |
515 | 20.1k | cinfo->in_color_space == JCS_RGB) |
516 | 1.52k | cinfo->in_color_space = JCS_GRAYSCALE; |
517 | 20.1k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, |
518 | 20.1k | ihdr.bit_depth); |
519 | 20.1k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
520 | 4.25k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && |
521 | 4.21k | cinfo->data_precision == ihdr.bit_depth) { |
522 | 2.09k | source->pub.get_pixel_rows = get_raw_row; |
523 | 2.09k | use_raw_buffer = TRUE; |
524 | 2.09k | } else |
525 | 2.16k | source->pub.get_pixel_rows = get_gray_row; |
526 | 15.8k | } else if (IsExtRGB(cinfo->in_color_space)) |
527 | 13.6k | source->pub.get_pixel_rows = get_gray_rgb_row; |
528 | 2.21k | else if (cinfo->in_color_space == JCS_CMYK) |
529 | 2.21k | source->pub.get_pixel_rows = get_gray_cmyk_row; |
530 | 0 | else |
531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
532 | 20.1k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { |
533 | 276 | png_components = 2; |
534 | 276 | source->png_alpha = 1; |
535 | 19.8k | } else { |
536 | 19.8k | png_components = 1; |
537 | 19.8k | source->png_alpha = 0; |
538 | 19.8k | } |
539 | 20.1k | break; |
540 | | |
541 | 34.3k | case SPNG_COLOR_TYPE_TRUECOLOR: |
542 | 36.4k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: |
543 | 36.4k | if (cinfo->in_color_space == JCS_UNKNOWN) |
544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
545 | 36.4k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, |
546 | 36.4k | ihdr.bit_depth); |
547 | 36.4k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && |
548 | 34.3k | cinfo->data_precision == ihdr.bit_depth && |
549 | 10.4k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 |
550 | 10.4k | (cinfo->in_color_space == JCS_EXT_RGB || |
551 | 8.42k | cinfo->in_color_space == JCS_RGB)) { |
552 | | #else |
553 | | cinfo->in_color_space == JCS_EXT_RGB) { |
554 | | #endif |
555 | 2.46k | source->pub.get_pixel_rows = get_raw_row; |
556 | 2.46k | use_raw_buffer = TRUE; |
557 | 33.9k | } else if (IsExtRGB(cinfo->in_color_space)) |
558 | 24.5k | source->pub.get_pixel_rows = get_rgb_row; |
559 | 9.39k | else if (cinfo->in_color_space == JCS_CMYK) |
560 | 4.15k | source->pub.get_pixel_rows = get_rgb_cmyk_row; |
561 | 5.24k | else |
562 | 5.24k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
563 | 36.4k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { |
564 | 1.83k | png_components = 4; |
565 | 1.83k | source->png_alpha = 1; |
566 | 34.6k | } else { |
567 | 34.6k | png_components = 3; |
568 | 34.6k | source->png_alpha = 0; |
569 | 34.6k | } |
570 | 36.4k | break; |
571 | | |
572 | 7.06k | case SPNG_COLOR_TYPE_INDEXED: |
573 | 7.06k | { |
574 | 7.06k | int i, gray = 1; |
575 | | |
576 | 7.06k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, |
577 | 7.06k | ihdr.bit_depth); |
578 | 7.06k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); |
579 | 7.06k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) |
580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
581 | | |
582 | 111k | for (i = 0; i < (int)source->colormap.n_entries; i++) { |
583 | 104k | if (source->colormap.entries[i].red != |
584 | 104k | source->colormap.entries[i].green || |
585 | 60.1k | source->colormap.entries[i].green != |
586 | 60.1k | source->colormap.entries[i].blue) |
587 | 45.0k | gray = 0; |
588 | 104k | } |
589 | | |
590 | 7.06k | if ((cinfo->in_color_space == JCS_UNKNOWN || |
591 | 1.73k | cinfo->in_color_space == JCS_RGB) && gray) |
592 | 38 | cinfo->in_color_space = JCS_GRAYSCALE; |
593 | 7.06k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) |
594 | 98 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
595 | | |
596 | 7.06k | source->pub.get_pixel_rows = get_indexed_row; |
597 | 7.06k | png_components = 1; |
598 | 7.06k | source->png_alpha = 0; |
599 | 7.06k | break; |
600 | 34.3k | } |
601 | | |
602 | 0 | default: |
603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
604 | 119k | } |
605 | | |
606 | 52.9k | if (IsExtRGB(cinfo->in_color_space)) |
607 | 41.9k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; |
608 | 10.9k | else if (cinfo->in_color_space == JCS_GRAYSCALE) |
609 | 4.44k | cinfo->input_components = 1; |
610 | 6.55k | else if (cinfo->in_color_space == JCS_CMYK) |
611 | 6.55k | cinfo->input_components = 4; |
612 | | |
613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ |
614 | 52.9k | source->buffer_width = |
615 | 52.9k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; |
616 | 52.9k | source->iobuffer = (unsigned char *) |
617 | 52.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
618 | 52.9k | source->buffer_width); |
619 | | |
620 | | /* Create compressor input buffer. */ |
621 | 52.9k | 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 | 4.55k | source->pixrow = (_JSAMPROW)source->iobuffer; |
625 | 4.55k | source->pub._buffer = &source->pixrow; |
626 | 4.55k | source->pub.buffer_height = 1; |
627 | 48.4k | } else { |
628 | 48.4k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; |
629 | 48.4k | size_t val, half_maxval; |
630 | | |
631 | | /* Need to translate anyway, so make a separate sample buffer. */ |
632 | 48.4k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
633 | 48.4k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
634 | 48.4k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); |
635 | 48.4k | source->pub.buffer_height = 1; |
636 | | |
637 | | /* Compute the rescaling array. */ |
638 | 48.4k | source->rescale = (_JSAMPLE *) |
639 | 48.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
640 | 48.4k | (maxval + 1L) * sizeof(_JSAMPLE)); |
641 | 48.4k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); |
642 | 48.4k | half_maxval = maxval / 2; |
643 | 1.01G | for (val = 0; val <= maxval; val++) { |
644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ |
645 | 1.01G | source->rescale[val] = |
646 | 1.01G | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / |
647 | 1.01G | maxval); |
648 | 1.01G | } |
649 | 48.4k | } |
650 | | |
651 | 52.9k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, |
652 | 52.9k | SPNG_DECODE_PROGRESSIVE)); |
653 | 52.9k | } rdpng-8.c:start_input_png Line | Count | Source | 472 | 61.0k | { | 473 | 61.0k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 61.0k | struct spng_ihdr ihdr; | 475 | 61.0k | int png_components = 3; | 476 | 61.0k | 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 | 61.0k | source->ctx = spng_ctx_new(0); | 487 | 61.0k | #endif | 488 | 61.0k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 61.0k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 61.0k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 61.0k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 15.8k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 61.0k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 8.87k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 61.0k | if (sinfo->max_pixels && | 500 | 31.1k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 549 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 61.0k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 61.0k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 61.0k | source->png_bit_depth = ihdr.bit_depth; | 506 | 61.0k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 61.0k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 61.0k | switch (ihdr.color_type) { | 512 | 255 | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 9.08k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 9.08k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 9.08k | cinfo->in_color_space == JCS_RGB) | 516 | 1.52k | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 9.08k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 9.08k | ihdr.bit_depth); | 519 | 9.08k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 2.67k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 2.63k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 2.00k | source->pub.get_pixel_rows = get_raw_row; | 523 | 2.00k | use_raw_buffer = TRUE; | 524 | 2.00k | } else | 525 | 671 | source->pub.get_pixel_rows = get_gray_row; | 526 | 6.40k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 5.77k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 638 | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 638 | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 9.08k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 255 | png_components = 2; | 534 | 255 | source->png_alpha = 1; | 535 | 8.82k | } else { | 536 | 8.82k | png_components = 1; | 537 | 8.82k | source->png_alpha = 0; | 538 | 8.82k | } | 539 | 9.08k | break; | 540 | | | 541 | 15.5k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 17.6k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 17.6k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 17.6k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 17.6k | ihdr.bit_depth); | 547 | 17.6k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 15.5k | cinfo->data_precision == ihdr.bit_depth && | 549 | 8.03k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 8.03k | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 6.60k | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 1.85k | source->pub.get_pixel_rows = get_raw_row; | 556 | 1.85k | use_raw_buffer = TRUE; | 557 | 15.8k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 11.7k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 4.03k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 1.46k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 2.56k | else | 562 | 2.56k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 17.6k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 1.80k | png_components = 4; | 565 | 1.80k | source->png_alpha = 1; | 566 | 15.8k | } else { | 567 | 15.8k | png_components = 3; | 568 | 15.8k | source->png_alpha = 0; | 569 | 15.8k | } | 570 | 17.6k | break; | 571 | | | 572 | 3.82k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 3.82k | { | 574 | 3.82k | int i, gray = 1; | 575 | | | 576 | 3.82k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 3.82k | ihdr.bit_depth); | 578 | 3.82k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 3.82k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 55.8k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 52.0k | if (source->colormap.entries[i].red != | 584 | 52.0k | source->colormap.entries[i].green || | 585 | 32.1k | source->colormap.entries[i].green != | 586 | 32.1k | source->colormap.entries[i].blue) | 587 | 20.3k | gray = 0; | 588 | 52.0k | } | 589 | | | 590 | 3.82k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 874 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 38 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 3.82k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 594 | 43 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 595 | | | 596 | 3.82k | source->pub.get_pixel_rows = get_indexed_row; | 597 | 3.82k | png_components = 1; | 598 | 3.82k | source->png_alpha = 0; | 599 | 3.82k | break; | 600 | 15.5k | } | 601 | | | 602 | 0 | default: | 603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 604 | 61.0k | } | 605 | | | 606 | 25.0k | if (IsExtRGB(cinfo->in_color_space)) | 607 | 20.0k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 608 | 4.96k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 609 | 2.79k | cinfo->input_components = 1; | 610 | 2.17k | else if (cinfo->in_color_space == JCS_CMYK) | 611 | 2.17k | cinfo->input_components = 4; | 612 | | | 613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 614 | 25.0k | source->buffer_width = | 615 | 25.0k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 616 | 25.0k | source->iobuffer = (unsigned char *) | 617 | 25.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 618 | 25.0k | source->buffer_width); | 619 | | | 620 | | /* Create compressor input buffer. */ | 621 | 25.0k | 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 | 3.86k | source->pixrow = (_JSAMPROW)source->iobuffer; | 625 | 3.86k | source->pub._buffer = &source->pixrow; | 626 | 3.86k | source->pub.buffer_height = 1; | 627 | 21.1k | } else { | 628 | 21.1k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 629 | 21.1k | size_t val, half_maxval; | 630 | | | 631 | | /* Need to translate anyway, so make a separate sample buffer. */ | 632 | 21.1k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 633 | 21.1k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 634 | 21.1k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 635 | 21.1k | source->pub.buffer_height = 1; | 636 | | | 637 | | /* Compute the rescaling array. */ | 638 | 21.1k | source->rescale = (_JSAMPLE *) | 639 | 21.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 640 | 21.1k | (maxval + 1L) * sizeof(_JSAMPLE)); | 641 | 21.1k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 642 | 21.1k | half_maxval = maxval / 2; | 643 | 516M | for (val = 0; val <= maxval; val++) { | 644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 645 | 516M | source->rescale[val] = | 646 | 516M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 647 | 516M | maxval); | 648 | 516M | } | 649 | 21.1k | } | 650 | | | 651 | 25.0k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 652 | 25.0k | SPNG_DECODE_PROGRESSIVE)); | 653 | 25.0k | } |
rdpng-12.c:start_input_png Line | Count | Source | 472 | 39.8k | { | 473 | 39.8k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 39.8k | struct spng_ihdr ihdr; | 475 | 39.8k | int png_components = 3; | 476 | 39.8k | 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 | 39.8k | source->ctx = spng_ctx_new(0); | 487 | 39.8k | #endif | 488 | 39.8k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 39.8k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 39.8k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 39.8k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 4.13k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 39.8k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 9.89k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 39.8k | if (sinfo->max_pixels && | 500 | 22.5k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 441 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 39.8k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 39.8k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 39.8k | source->png_bit_depth = ihdr.bit_depth; | 506 | 39.8k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 39.8k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 39.8k | switch (ihdr.color_type) { | 512 | 14 | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 8.75k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 8.75k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 8.75k | cinfo->in_color_space == JCS_RGB) | 516 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 8.75k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 8.75k | ihdr.bit_depth); | 519 | 8.75k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 1.25k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 1.24k | 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 | 1.25k | source->pub.get_pixel_rows = get_gray_row; | 526 | 7.50k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 6.25k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 1.25k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 1.25k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 8.75k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 14 | png_components = 2; | 534 | 14 | source->png_alpha = 1; | 535 | 8.74k | } else { | 536 | 8.74k | png_components = 1; | 537 | 8.74k | source->png_alpha = 0; | 538 | 8.74k | } | 539 | 8.75k | break; | 540 | | | 541 | 10.6k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 10.6k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 10.6k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 10.6k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 10.6k | ihdr.bit_depth); | 547 | 10.6k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 10.6k | 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 | 10.6k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 7.61k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 3.04k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 1.52k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 1.52k | else | 562 | 1.52k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 10.6k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 18 | png_components = 4; | 565 | 18 | source->png_alpha = 1; | 566 | 10.6k | } else { | 567 | 10.6k | png_components = 3; | 568 | 10.6k | source->png_alpha = 0; | 569 | 10.6k | } | 570 | 10.6k | break; | 571 | | | 572 | 2.72k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 2.72k | { | 574 | 2.72k | int i, gray = 1; | 575 | | | 576 | 2.72k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 2.72k | ihdr.bit_depth); | 578 | 2.72k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 2.72k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 39.0k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 36.3k | if (source->colormap.entries[i].red != | 584 | 36.3k | source->colormap.entries[i].green || | 585 | 19.3k | source->colormap.entries[i].green != | 586 | 19.3k | source->colormap.entries[i].blue) | 587 | 17.0k | gray = 0; | 588 | 36.3k | } | 589 | | | 590 | 2.72k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 595 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 2.72k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 594 | 38 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 595 | | | 596 | 2.72k | source->pub.get_pixel_rows = get_indexed_row; | 597 | 2.72k | png_components = 1; | 598 | 2.72k | source->png_alpha = 0; | 599 | 2.72k | break; | 600 | 10.6k | } | 601 | | | 602 | 0 | default: | 603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 604 | 39.8k | } | 605 | | | 606 | 18.4k | if (IsExtRGB(cinfo->in_color_space)) | 607 | 14.2k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 608 | 4.15k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 609 | 1.29k | cinfo->input_components = 1; | 610 | 2.85k | else if (cinfo->in_color_space == JCS_CMYK) | 611 | 2.85k | cinfo->input_components = 4; | 612 | | | 613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 614 | 18.4k | source->buffer_width = | 615 | 18.4k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 616 | 18.4k | source->iobuffer = (unsigned char *) | 617 | 18.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 618 | 18.4k | source->buffer_width); | 619 | | | 620 | | /* Create compressor input buffer. */ | 621 | 18.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 | 0 | source->pixrow = (_JSAMPROW)source->iobuffer; | 625 | 0 | source->pub._buffer = &source->pixrow; | 626 | 0 | source->pub.buffer_height = 1; | 627 | 18.4k | } else { | 628 | 18.4k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 629 | 18.4k | size_t val, half_maxval; | 630 | | | 631 | | /* Need to translate anyway, so make a separate sample buffer. */ | 632 | 18.4k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 633 | 18.4k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 634 | 18.4k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 635 | 18.4k | source->pub.buffer_height = 1; | 636 | | | 637 | | /* Compute the rescaling array. */ | 638 | 18.4k | source->rescale = (_JSAMPLE *) | 639 | 18.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 640 | 18.4k | (maxval + 1L) * sizeof(_JSAMPLE)); | 641 | 18.4k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 642 | 18.4k | half_maxval = maxval / 2; | 643 | 265M | for (val = 0; val <= maxval; val++) { | 644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 645 | 265M | source->rescale[val] = | 646 | 265M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 647 | 265M | maxval); | 648 | 265M | } | 649 | 18.4k | } | 650 | | | 651 | 18.4k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 652 | 18.4k | SPNG_DECODE_PROGRESSIVE)); | 653 | 18.4k | } |
rdpng-16.c:start_input_png Line | Count | Source | 472 | 18.8k | { | 473 | 18.8k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 18.8k | struct spng_ihdr ihdr; | 475 | 18.8k | int png_components = 3; | 476 | 18.8k | 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 | 18.8k | source->ctx = spng_ctx_new(0); | 487 | 18.8k | #endif | 488 | 18.8k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 18.8k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 18.8k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 18.8k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 455 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 18.8k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 5.46k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 18.8k | if (sinfo->max_pixels && | 500 | 11.2k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 259 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 18.8k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 18.8k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 18.8k | source->png_bit_depth = ihdr.bit_depth; | 506 | 18.8k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 18.8k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 18.8k | switch (ihdr.color_type) { | 512 | 7 | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 2.29k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 2.29k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 2.29k | cinfo->in_color_space == JCS_RGB) | 516 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 2.29k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 2.29k | ihdr.bit_depth); | 519 | 2.29k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 328 | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 327 | cinfo->data_precision == ihdr.bit_depth) { | 522 | 88 | source->pub.get_pixel_rows = get_raw_row; | 523 | 88 | use_raw_buffer = TRUE; | 524 | 88 | } else | 525 | 240 | source->pub.get_pixel_rows = get_gray_row; | 526 | 1.96k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 1.64k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 328 | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 328 | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 2.29k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 7 | png_components = 2; | 534 | 7 | source->png_alpha = 1; | 535 | 2.28k | } else { | 536 | 2.28k | png_components = 1; | 537 | 2.28k | source->png_alpha = 0; | 538 | 2.28k | } | 539 | 2.29k | break; | 540 | | | 541 | 8.11k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 8.12k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 8.12k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 8.12k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 8.12k | ihdr.bit_depth); | 547 | 8.12k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 8.11k | cinfo->data_precision == ihdr.bit_depth && | 549 | 2.42k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 2.42k | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 1.81k | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 606 | source->pub.get_pixel_rows = get_raw_row; | 556 | 606 | use_raw_buffer = TRUE; | 557 | 7.52k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 5.19k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 2.32k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 1.16k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 1.16k | else | 562 | 1.16k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 8.12k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 12 | png_components = 4; | 565 | 12 | source->png_alpha = 1; | 566 | 8.11k | } else { | 567 | 8.11k | png_components = 3; | 568 | 8.11k | source->png_alpha = 0; | 569 | 8.11k | } | 570 | 8.12k | break; | 571 | | | 572 | 518 | case SPNG_COLOR_TYPE_INDEXED: | 573 | 518 | { | 574 | 518 | int i, gray = 1; | 575 | | | 576 | 518 | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 518 | ihdr.bit_depth); | 578 | 518 | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 518 | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 16.7k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 16.2k | if (source->colormap.entries[i].red != | 584 | 16.2k | source->colormap.entries[i].green || | 585 | 8.64k | source->colormap.entries[i].green != | 586 | 8.64k | source->colormap.entries[i].blue) | 587 | 7.61k | gray = 0; | 588 | 16.2k | } | 589 | | | 590 | 518 | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 266 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 518 | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 594 | 17 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 595 | | | 596 | 518 | source->pub.get_pixel_rows = get_indexed_row; | 597 | 518 | png_components = 1; | 598 | 518 | source->png_alpha = 0; | 599 | 518 | break; | 600 | 8.11k | } | 601 | | | 602 | 0 | default: | 603 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 604 | 18.8k | } | 605 | | | 606 | 9.51k | if (IsExtRGB(cinfo->in_color_space)) | 607 | 7.63k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 608 | 1.87k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 609 | 349 | cinfo->input_components = 1; | 610 | 1.52k | else if (cinfo->in_color_space == JCS_CMYK) | 611 | 1.52k | cinfo->input_components = 4; | 612 | | | 613 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 614 | 9.51k | source->buffer_width = | 615 | 9.51k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 616 | 9.51k | source->iobuffer = (unsigned char *) | 617 | 9.51k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 618 | 9.51k | source->buffer_width); | 619 | | | 620 | | /* Create compressor input buffer. */ | 621 | 9.51k | 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 | 694 | source->pixrow = (_JSAMPROW)source->iobuffer; | 625 | 694 | source->pub._buffer = &source->pixrow; | 626 | 694 | source->pub.buffer_height = 1; | 627 | 8.81k | } else { | 628 | 8.81k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 629 | 8.81k | size_t val, half_maxval; | 630 | | | 631 | | /* Need to translate anyway, so make a separate sample buffer. */ | 632 | 8.81k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 633 | 8.81k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 634 | 8.81k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 635 | 8.81k | source->pub.buffer_height = 1; | 636 | | | 637 | | /* Compute the rescaling array. */ | 638 | 8.81k | source->rescale = (_JSAMPLE *) | 639 | 8.81k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 640 | 8.81k | (maxval + 1L) * sizeof(_JSAMPLE)); | 641 | 8.81k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 642 | 8.81k | half_maxval = maxval / 2; | 643 | 234M | for (val = 0; val <= maxval; val++) { | 644 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 645 | 234M | source->rescale[val] = | 646 | 234M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 647 | 234M | maxval); | 648 | 234M | } | 649 | 8.81k | } | 650 | | | 651 | 9.51k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 652 | 9.51k | SPNG_DECODE_PROGRESSIVE)); | 653 | 9.51k | } |
|
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 | 14.0k | { |
664 | 14.0k | png_source_ptr source = (png_source_ptr)sinfo; |
665 | 14.0k | struct spng_iccp iccp; |
666 | | |
667 | 14.0k | if (!icc_data_ptr || !icc_data_len) |
668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); |
669 | | |
670 | 14.0k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { |
671 | 215 | *icc_data_ptr = (JOCTET *)iccp.profile; |
672 | 215 | *icc_data_len = (unsigned int)iccp.profile_len; |
673 | 215 | return TRUE; |
674 | 215 | } |
675 | | |
676 | 13.8k | return FALSE; |
677 | 14.0k | } rdpng-8.c:read_icc_profile_png Line | Count | Source | 663 | 7.40k | { | 664 | 7.40k | png_source_ptr source = (png_source_ptr)sinfo; | 665 | 7.40k | struct spng_iccp iccp; | 666 | | | 667 | 7.40k | if (!icc_data_ptr || !icc_data_len) | 668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 669 | | | 670 | 7.40k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 671 | 119 | *icc_data_ptr = (JOCTET *)iccp.profile; | 672 | 119 | *icc_data_len = (unsigned int)iccp.profile_len; | 673 | 119 | return TRUE; | 674 | 119 | } | 675 | | | 676 | 7.28k | return FALSE; | 677 | 7.40k | } |
rdpng-12.c:read_icc_profile_png Line | Count | Source | 663 | 4.58k | { | 664 | 4.58k | png_source_ptr source = (png_source_ptr)sinfo; | 665 | 4.58k | struct spng_iccp iccp; | 666 | | | 667 | 4.58k | if (!icc_data_ptr || !icc_data_len) | 668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 669 | | | 670 | 4.58k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 671 | 30 | *icc_data_ptr = (JOCTET *)iccp.profile; | 672 | 30 | *icc_data_len = (unsigned int)iccp.profile_len; | 673 | 30 | return TRUE; | 674 | 30 | } | 675 | | | 676 | 4.55k | return FALSE; | 677 | 4.58k | } |
rdpng-16.c:read_icc_profile_png Line | Count | Source | 663 | 2.08k | { | 664 | 2.08k | png_source_ptr source = (png_source_ptr)sinfo; | 665 | 2.08k | struct spng_iccp iccp; | 666 | | | 667 | 2.08k | if (!icc_data_ptr || !icc_data_len) | 668 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 669 | | | 670 | 2.08k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 671 | 66 | *icc_data_ptr = (JOCTET *)iccp.profile; | 672 | 66 | *icc_data_len = (unsigned int)iccp.profile_len; | 673 | 66 | return TRUE; | 674 | 66 | } | 675 | | | 676 | 2.01k | return FALSE; | 677 | 2.08k | } |
|
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 | 119k | { |
687 | 119k | png_source_ptr source = (png_source_ptr)sinfo; |
688 | | |
689 | 119k | if (source->ctx) { |
690 | 119k | spng_decode_chunks(source->ctx); |
691 | 119k | spng_ctx_free(source->ctx); |
692 | 119k | source->ctx = NULL; |
693 | 119k | } |
694 | 119k | } rdpng-8.c:finish_input_png Line | Count | Source | 686 | 61.0k | { | 687 | 61.0k | png_source_ptr source = (png_source_ptr)sinfo; | 688 | | | 689 | 61.0k | if (source->ctx) { | 690 | 61.0k | spng_decode_chunks(source->ctx); | 691 | 61.0k | spng_ctx_free(source->ctx); | 692 | | source->ctx = NULL; | 693 | 61.0k | } | 694 | 61.0k | } |
rdpng-12.c:finish_input_png Line | Count | Source | 686 | 39.8k | { | 687 | 39.8k | png_source_ptr source = (png_source_ptr)sinfo; | 688 | | | 689 | 39.8k | if (source->ctx) { | 690 | 39.8k | spng_decode_chunks(source->ctx); | 691 | 39.8k | spng_ctx_free(source->ctx); | 692 | | source->ctx = NULL; | 693 | 39.8k | } | 694 | 39.8k | } |
rdpng-16.c:finish_input_png Line | Count | Source | 686 | 18.8k | { | 687 | 18.8k | png_source_ptr source = (png_source_ptr)sinfo; | 688 | | | 689 | 18.8k | if (source->ctx) { | 690 | 18.8k | spng_decode_chunks(source->ctx); | 691 | 18.8k | spng_ctx_free(source->ctx); | 692 | | source->ctx = NULL; | 693 | 18.8k | } | 694 | 18.8k | } |
|
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 | 119k | { |
704 | 119k | png_source_ptr source; |
705 | | |
706 | | #if BITS_IN_JSAMPLE == 8 |
707 | 61.0k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
708 | | #else |
709 | 58.6k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
710 | 58.6k | 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 | 119k | source = (png_source_ptr) |
716 | 119k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
717 | 119k | sizeof(png_source_struct)); |
718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
719 | 119k | source->pub.start_input = start_input_png; |
720 | 119k | source->pub.read_icc_profile = read_icc_profile_png; |
721 | 119k | source->pub.finish_input = finish_input_png; |
722 | 119k | source->pub.max_pixels = 0; |
723 | | |
724 | 119k | return (cjpeg_source_ptr)source; |
725 | 119k | } Line | Count | Source | 703 | 61.0k | { | 704 | 61.0k | png_source_ptr source; | 705 | | | 706 | 61.0k | #if BITS_IN_JSAMPLE == 8 | 707 | 61.0k | 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 | 61.0k | source = (png_source_ptr) | 716 | 61.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 717 | 61.0k | sizeof(png_source_struct)); | 718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 719 | 61.0k | source->pub.start_input = start_input_png; | 720 | 61.0k | source->pub.read_icc_profile = read_icc_profile_png; | 721 | 61.0k | source->pub.finish_input = finish_input_png; | 722 | 61.0k | source->pub.max_pixels = 0; | 723 | | | 724 | 61.0k | return (cjpeg_source_ptr)source; | 725 | 61.0k | } |
Line | Count | Source | 703 | 39.8k | { | 704 | 39.8k | 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 | 39.8k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 710 | 39.8k | 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 | 39.8k | source = (png_source_ptr) | 716 | 39.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 717 | 39.8k | sizeof(png_source_struct)); | 718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 719 | 39.8k | source->pub.start_input = start_input_png; | 720 | 39.8k | source->pub.read_icc_profile = read_icc_profile_png; | 721 | 39.8k | source->pub.finish_input = finish_input_png; | 722 | 39.8k | source->pub.max_pixels = 0; | 723 | | | 724 | 39.8k | return (cjpeg_source_ptr)source; | 725 | 39.8k | } |
Line | Count | Source | 703 | 18.8k | { | 704 | 18.8k | 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 | 18.8k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 710 | 18.8k | 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 | 18.8k | source = (png_source_ptr) | 716 | 18.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 717 | 18.8k | sizeof(png_source_struct)); | 718 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 719 | 18.8k | source->pub.start_input = start_input_png; | 720 | 18.8k | source->pub.read_icc_profile = read_icc_profile_png; | 721 | 18.8k | source->pub.finish_input = finish_input_png; | 722 | 18.8k | source->pub.max_pixels = 0; | 723 | | | 724 | 18.8k | return (cjpeg_source_ptr)source; | 725 | 18.8k | } |
|
726 | | |
727 | | #endif /* defined(PNG_SUPPORTED) && |
728 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ |