/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 | 503k | #define TRY_SPNG(f) { \ |
34 | 503k | int __spng_error = (f); \ |
35 | 503k | if (__spng_error) \ |
36 | 503k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(__spng_error)); \ |
37 | 503k | } |
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 | 3.13M | { |
76 | 3.13M | png_source_ptr source = (png_source_ptr)sinfo; |
77 | 3.13M | int spng_error; |
78 | | |
79 | 3.13M | spng_error = spng_decode_row(source->ctx, source->iobuffer, |
80 | 3.13M | source->buffer_width); |
81 | 3.13M | if (spng_error && spng_error != SPNG_EOI) |
82 | 24.2k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ |
83 | 3.13M | return 1; |
84 | 3.13M | } Line | Count | Source | 75 | 1.26M | { | 76 | 1.26M | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 1.26M | int spng_error; | 78 | | | 79 | 1.26M | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 1.26M | source->buffer_width); | 81 | 1.26M | if (spng_error && spng_error != SPNG_EOI) | 82 | 10.7k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 1.26M | return 1; | 84 | 1.26M | } |
Line | Count | Source | 75 | 1.22M | { | 76 | 1.22M | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 1.22M | int spng_error; | 78 | | | 79 | 1.22M | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 1.22M | source->buffer_width); | 81 | 1.22M | if (spng_error && spng_error != SPNG_EOI) | 82 | 8.71k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 1.22M | return 1; | 84 | 1.22M | } |
Line | Count | Source | 75 | 649k | { | 76 | 649k | png_source_ptr source = (png_source_ptr)sinfo; | 77 | 649k | int spng_error; | 78 | | | 79 | 649k | spng_error = spng_decode_row(source->ctx, source->iobuffer, | 80 | 649k | source->buffer_width); | 81 | 649k | if (spng_error && spng_error != SPNG_EOI) | 82 | 4.78k | ERREXITS(cinfo, JERR_PNG_LIBSPNG, spng_strerror(spng_error)); \ | 83 | 649k | return 1; | 84 | 649k | } |
|
85 | | |
86 | | |
87 | 1.24M | #define GRAY_RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \ |
88 | 146M | for (col = cinfo->image_width; col > 0; col--) { \ |
89 | 145M | ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \ |
90 | 145M | alpha_set_op \ |
91 | 145M | ptr += ps; \ |
92 | 145M | pointer_op \ |
93 | 145M | } \ |
94 | 1.24M | } |
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 | 182k | { |
103 | 182k | png_source_ptr source = (png_source_ptr)sinfo; |
104 | 182k | register _JSAMPROW ptr; |
105 | 182k | register _JSAMPLE *rescale = source->rescale; |
106 | 182k | JDIMENSION col; |
107 | | |
108 | 182k | get_raw_row(cinfo, sinfo); |
109 | 182k | ptr = source->pub._buffer[0]; |
110 | | #if BITS_IN_JSAMPLE != 12 |
111 | 123k | if (source->png_bit_depth == cinfo->data_precision) { |
112 | 4.50k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
113 | 38.8k | for (col = cinfo->image_width; col > 0; col--) { |
114 | 34.3k | *ptr++ = *bufferptr++; |
115 | 34.3k | bufferptr += source->png_alpha; |
116 | 34.3k | } |
117 | 4.50k | } else |
118 | 118k | #endif |
119 | 178k | if (source->png_bit_depth == 16) { |
120 | 98.1k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
121 | 4.76M | for (col = cinfo->image_width; col > 0; col--) { |
122 | 4.66M | *ptr++ = rescale[*bufferptr++]; |
123 | 4.66M | bufferptr += source->png_alpha; |
124 | 4.66M | } |
125 | 98.1k | } else { |
126 | 79.9k | register unsigned char *bufferptr = source->iobuffer; |
127 | 16.8M | for (col = cinfo->image_width; col > 0; col--) { |
128 | 16.7M | *ptr++ = rescale[*bufferptr++]; |
129 | 16.7M | bufferptr += source->png_alpha; |
130 | 16.7M | } |
131 | 79.9k | } |
132 | 182k | return 1; |
133 | 182k | } Line | Count | Source | 102 | 91.2k | { | 103 | 91.2k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 91.2k | register _JSAMPROW ptr; | 105 | 91.2k | register _JSAMPLE *rescale = source->rescale; | 106 | 91.2k | JDIMENSION col; | 107 | | | 108 | 91.2k | get_raw_row(cinfo, sinfo); | 109 | 91.2k | ptr = source->pub._buffer[0]; | 110 | 91.2k | #if BITS_IN_JSAMPLE != 12 | 111 | 91.2k | if (source->png_bit_depth == cinfo->data_precision) { | 112 | 316 | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | 17.9k | for (col = cinfo->image_width; col > 0; col--) { | 114 | 17.6k | *ptr++ = *bufferptr++; | 115 | 17.6k | bufferptr += source->png_alpha; | 116 | 17.6k | } | 117 | 316 | } else | 118 | 90.9k | #endif | 119 | 90.9k | if (source->png_bit_depth == 16) { | 120 | 85.7k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 4.40M | for (col = cinfo->image_width; col > 0; col--) { | 122 | 4.32M | *ptr++ = rescale[*bufferptr++]; | 123 | 4.32M | bufferptr += source->png_alpha; | 124 | 4.32M | } | 125 | 85.7k | } else { | 126 | 5.18k | register unsigned char *bufferptr = source->iobuffer; | 127 | 363k | for (col = cinfo->image_width; col > 0; col--) { | 128 | 358k | *ptr++ = rescale[*bufferptr++]; | 129 | 358k | bufferptr += source->png_alpha; | 130 | 358k | } | 131 | 5.18k | } | 132 | 91.2k | return 1; | 133 | 91.2k | } |
Line | Count | Source | 102 | 59.4k | { | 103 | 59.4k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 59.4k | register _JSAMPROW ptr; | 105 | 59.4k | register _JSAMPLE *rescale = source->rescale; | 106 | 59.4k | JDIMENSION col; | 107 | | | 108 | 59.4k | get_raw_row(cinfo, sinfo); | 109 | 59.4k | 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 | 59.4k | if (source->png_bit_depth == 16) { | 120 | 12.3k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 355k | for (col = cinfo->image_width; col > 0; col--) { | 122 | 343k | *ptr++ = rescale[*bufferptr++]; | 123 | 343k | bufferptr += source->png_alpha; | 124 | 343k | } | 125 | 47.1k | } else { | 126 | 47.1k | register unsigned char *bufferptr = source->iobuffer; | 127 | 8.35M | for (col = cinfo->image_width; col > 0; col--) { | 128 | 8.30M | *ptr++ = rescale[*bufferptr++]; | 129 | 8.30M | bufferptr += source->png_alpha; | 130 | 8.30M | } | 131 | 47.1k | } | 132 | 59.4k | return 1; | 133 | 59.4k | } |
Line | Count | Source | 102 | 31.7k | { | 103 | 31.7k | png_source_ptr source = (png_source_ptr)sinfo; | 104 | 31.7k | register _JSAMPROW ptr; | 105 | 31.7k | register _JSAMPLE *rescale = source->rescale; | 106 | 31.7k | JDIMENSION col; | 107 | | | 108 | 31.7k | get_raw_row(cinfo, sinfo); | 109 | 31.7k | ptr = source->pub._buffer[0]; | 110 | 31.7k | #if BITS_IN_JSAMPLE != 12 | 111 | 31.7k | if (source->png_bit_depth == cinfo->data_precision) { | 112 | 4.18k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 113 | 20.8k | for (col = cinfo->image_width; col > 0; col--) { | 114 | 16.6k | *ptr++ = *bufferptr++; | 115 | 16.6k | bufferptr += source->png_alpha; | 116 | 16.6k | } | 117 | 4.18k | } else | 118 | 27.6k | #endif | 119 | 27.6k | if (source->png_bit_depth == 16) { | 120 | 0 | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 121 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 122 | 0 | *ptr++ = rescale[*bufferptr++]; | 123 | 0 | bufferptr += source->png_alpha; | 124 | 0 | } | 125 | 27.6k | } else { | 126 | 27.6k | register unsigned char *bufferptr = source->iobuffer; | 127 | 8.12M | for (col = cinfo->image_width; col > 0; col--) { | 128 | 8.09M | *ptr++ = rescale[*bufferptr++]; | 129 | 8.09M | bufferptr += source->png_alpha; | 130 | 8.09M | } | 131 | 27.6k | } | 132 | 31.7k | return 1; | 133 | 31.7k | } |
|
134 | | |
135 | | |
136 | | METHODDEF(JDIMENSION) |
137 | | get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
138 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
139 | | * grayscale or grayscale + alpha PNG files and converting to extended RGB. |
140 | | */ |
141 | 1.24M | { |
142 | 1.24M | png_source_ptr source = (png_source_ptr)sinfo; |
143 | 1.24M | register _JSAMPROW ptr; |
144 | 1.24M | register _JSAMPLE *rescale = source->rescale; |
145 | 1.24M | JDIMENSION col; |
146 | 1.24M | register int rindex = rgb_red[cinfo->in_color_space]; |
147 | 1.24M | register int gindex = rgb_green[cinfo->in_color_space]; |
148 | 1.24M | register int bindex = rgb_blue[cinfo->in_color_space]; |
149 | 1.24M | register int aindex = alpha_index[cinfo->in_color_space]; |
150 | 1.24M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
151 | | |
152 | 1.24M | get_raw_row(cinfo, sinfo); |
153 | 1.24M | ptr = source->pub._buffer[0]; |
154 | | #if BITS_IN_JSAMPLE != 12 |
155 | 949k | if (source->png_bit_depth == cinfo->data_precision) { |
156 | 244k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
157 | 244k | if (aindex >= 0) |
158 | 1.54k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, |
159 | 244k | bufferptr += source->png_alpha;) |
160 | 242k | else |
161 | 242k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) |
162 | 244k | } else |
163 | 705k | #endif |
164 | 1.00M | if (source->png_bit_depth == 16) { |
165 | 607k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
166 | 607k | if (aindex >= 0) |
167 | 57.3k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
168 | 607k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
169 | 607k | bufferptr += source->png_alpha;) |
170 | 550k | else |
171 | 550k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, |
172 | 607k | bufferptr += source->png_alpha;) |
173 | 607k | } else { |
174 | 394k | register unsigned char *bufferptr = source->iobuffer; |
175 | 394k | if (aindex >= 0) |
176 | 78.5k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], |
177 | 394k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
178 | 394k | bufferptr += source->png_alpha;) |
179 | 316k | else |
180 | 316k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, |
181 | 394k | bufferptr += source->png_alpha;) |
182 | 394k | } |
183 | 1.24M | return 1; |
184 | 1.24M | } rdpng-8.c:get_gray_rgb_row Line | Count | Source | 141 | 598k | { | 142 | 598k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 598k | register _JSAMPROW ptr; | 144 | 598k | register _JSAMPLE *rescale = source->rescale; | 145 | 598k | JDIMENSION col; | 146 | 598k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 598k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 598k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 598k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 598k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 598k | get_raw_row(cinfo, sinfo); | 153 | 598k | ptr = source->pub._buffer[0]; | 154 | 598k | #if BITS_IN_JSAMPLE != 12 | 155 | 598k | if (source->png_bit_depth == cinfo->data_precision) { | 156 | 159k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | 159k | if (aindex >= 0) | 158 | 1.54k | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | 159k | bufferptr += source->png_alpha;) | 160 | 157k | else | 161 | 157k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | 159k | } else | 163 | 439k | #endif | 164 | 439k | if (source->png_bit_depth == 16) { | 165 | 418k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 418k | if (aindex >= 0) | 167 | 2.48k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 418k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 418k | bufferptr += source->png_alpha;) | 170 | 415k | else | 171 | 415k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 418k | bufferptr += source->png_alpha;) | 173 | 418k | } else { | 174 | 20.7k | register unsigned char *bufferptr = source->iobuffer; | 175 | 20.7k | if (aindex >= 0) | 176 | 4.52k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 20.7k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 20.7k | bufferptr += source->png_alpha;) | 179 | 16.1k | else | 180 | 16.1k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 20.7k | bufferptr += source->png_alpha;) | 182 | 20.7k | } | 183 | 598k | return 1; | 184 | 598k | } |
rdpng-12.c:get_gray_rgb_row Line | Count | Source | 141 | 297k | { | 142 | 297k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 297k | register _JSAMPROW ptr; | 144 | 297k | register _JSAMPLE *rescale = source->rescale; | 145 | 297k | JDIMENSION col; | 146 | 297k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 297k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 297k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 297k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 297k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 297k | get_raw_row(cinfo, sinfo); | 153 | 297k | 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 | 297k | if (source->png_bit_depth == 16) { | 165 | 61.6k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 61.6k | if (aindex >= 0) | 167 | 12.3k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 61.6k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 61.6k | bufferptr += source->png_alpha;) | 170 | 49.3k | else | 171 | 49.3k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 61.6k | bufferptr += source->png_alpha;) | 173 | 235k | } else { | 174 | 235k | register unsigned char *bufferptr = source->iobuffer; | 175 | 235k | if (aindex >= 0) | 176 | 46.6k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 235k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 235k | bufferptr += source->png_alpha;) | 179 | 189k | else | 180 | 189k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 235k | bufferptr += source->png_alpha;) | 182 | 235k | } | 183 | 297k | return 1; | 184 | 297k | } |
rdpng-16.c:get_gray_rgb_row Line | Count | Source | 141 | 351k | { | 142 | 351k | png_source_ptr source = (png_source_ptr)sinfo; | 143 | 351k | register _JSAMPROW ptr; | 144 | 351k | register _JSAMPLE *rescale = source->rescale; | 145 | 351k | JDIMENSION col; | 146 | 351k | register int rindex = rgb_red[cinfo->in_color_space]; | 147 | 351k | register int gindex = rgb_green[cinfo->in_color_space]; | 148 | 351k | register int bindex = rgb_blue[cinfo->in_color_space]; | 149 | 351k | register int aindex = alpha_index[cinfo->in_color_space]; | 150 | 351k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 151 | | | 152 | 351k | get_raw_row(cinfo, sinfo); | 153 | 351k | ptr = source->pub._buffer[0]; | 154 | 351k | #if BITS_IN_JSAMPLE != 12 | 155 | 351k | if (source->png_bit_depth == cinfo->data_precision) { | 156 | 85.0k | _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 157 | 85.0k | if (aindex >= 0) | 158 | 0 | GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 159 | 85.0k | bufferptr += source->png_alpha;) | 160 | 85.0k | else | 161 | 85.0k | GRAY_RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 162 | 85.0k | } else | 163 | 266k | #endif | 164 | 266k | if (source->png_bit_depth == 16) { | 165 | 127k | register unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 166 | 127k | if (aindex >= 0) | 167 | 42.5k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 168 | 127k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 169 | 127k | bufferptr += source->png_alpha;) | 170 | 85.0k | else | 171 | 85.0k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 172 | 127k | bufferptr += source->png_alpha;) | 173 | 138k | } else { | 174 | 138k | register unsigned char *bufferptr = source->iobuffer; | 175 | 138k | if (aindex >= 0) | 176 | 27.3k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], | 177 | 138k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 178 | 138k | bufferptr += source->png_alpha;) | 179 | 111k | else | 180 | 111k | GRAY_RGB_READ_LOOP(rescale[*bufferptr++], {}, | 181 | 138k | bufferptr += source->png_alpha;) | 182 | 138k | } | 183 | 351k | return 1; | 184 | 351k | } |
|
185 | | |
186 | | |
187 | | METHODDEF(JDIMENSION) |
188 | | get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
189 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
190 | | * grayscale or grayscale + alpha PNG files and converting to CMYK. |
191 | | */ |
192 | 138k | { |
193 | 138k | png_source_ptr source = (png_source_ptr)sinfo; |
194 | 138k | register _JSAMPROW ptr; |
195 | 138k | register _JSAMPLE *rescale = source->rescale; |
196 | 138k | JDIMENSION col; |
197 | | |
198 | 138k | get_raw_row(cinfo, sinfo); |
199 | 138k | ptr = source->pub._buffer[0]; |
200 | | #if BITS_IN_JSAMPLE != 12 |
201 | 79.1k | if (source->png_bit_depth == cinfo->data_precision) { |
202 | 44.0k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
203 | 1.85M | for (col = cinfo->image_width; col > 0; col--) { |
204 | 1.80M | _JSAMPLE gray = *bufferptr++; |
205 | 1.80M | bufferptr += source->png_alpha; |
206 | 1.80M | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, |
207 | 1.80M | ptr + 3); |
208 | 1.80M | ptr += 4; |
209 | 1.80M | } |
210 | 44.0k | } else |
211 | 35.0k | #endif |
212 | 94.5k | if (source->png_bit_depth == 16) { |
213 | 14.8k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
214 | 583k | for (col = cinfo->image_width; col > 0; col--) { |
215 | 568k | _JSAMPLE gray = rescale[*bufferptr++]; |
216 | 568k | bufferptr += source->png_alpha; |
217 | 568k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
218 | 568k | ptr + 1, ptr + 2, ptr + 3); |
219 | 568k | ptr += 4; |
220 | 568k | } |
221 | 79.6k | } else { |
222 | 79.6k | register unsigned char *bufferptr = source->iobuffer; |
223 | 16.8M | for (col = cinfo->image_width; col > 0; col--) { |
224 | 16.7M | _JSAMPLE gray = rescale[*bufferptr++]; |
225 | 16.7M | bufferptr += source->png_alpha; |
226 | 16.7M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, |
227 | 16.7M | ptr + 1, ptr + 2, ptr + 3); |
228 | 16.7M | ptr += 4; |
229 | 16.7M | } |
230 | 79.6k | } |
231 | 138k | return 1; |
232 | 138k | } rdpng-8.c:get_gray_cmyk_row Line | Count | Source | 192 | 8.88k | { | 193 | 8.88k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 8.88k | register _JSAMPROW ptr; | 195 | 8.88k | register _JSAMPLE *rescale = source->rescale; | 196 | 8.88k | JDIMENSION col; | 197 | | | 198 | 8.88k | get_raw_row(cinfo, sinfo); | 199 | 8.88k | ptr = source->pub._buffer[0]; | 200 | 8.88k | #if BITS_IN_JSAMPLE != 12 | 201 | 8.88k | if (source->png_bit_depth == cinfo->data_precision) { | 202 | 1.54k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | 118k | for (col = cinfo->image_width; col > 0; col--) { | 204 | 117k | _JSAMPLE gray = *bufferptr++; | 205 | 117k | bufferptr += source->png_alpha; | 206 | 117k | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | 117k | ptr + 3); | 208 | 117k | ptr += 4; | 209 | 117k | } | 210 | 1.54k | } else | 211 | 7.33k | #endif | 212 | 7.33k | if (source->png_bit_depth == 16) { | 213 | 2.48k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 227k | for (col = cinfo->image_width; col > 0; col--) { | 215 | 225k | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 225k | bufferptr += source->png_alpha; | 217 | 225k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 225k | ptr + 1, ptr + 2, ptr + 3); | 219 | 225k | ptr += 4; | 220 | 225k | } | 221 | 4.85k | } else { | 222 | 4.85k | register unsigned char *bufferptr = source->iobuffer; | 223 | 363k | for (col = cinfo->image_width; col > 0; col--) { | 224 | 358k | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 358k | bufferptr += source->png_alpha; | 226 | 358k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 358k | ptr + 1, ptr + 2, ptr + 3); | 228 | 358k | ptr += 4; | 229 | 358k | } | 230 | 4.85k | } | 231 | 8.88k | return 1; | 232 | 8.88k | } |
rdpng-12.c:get_gray_cmyk_row Line | Count | Source | 192 | 59.4k | { | 193 | 59.4k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 59.4k | register _JSAMPROW ptr; | 195 | 59.4k | register _JSAMPLE *rescale = source->rescale; | 196 | 59.4k | JDIMENSION col; | 197 | | | 198 | 59.4k | get_raw_row(cinfo, sinfo); | 199 | 59.4k | 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 | 59.4k | if (source->png_bit_depth == 16) { | 213 | 12.3k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 355k | for (col = cinfo->image_width; col > 0; col--) { | 215 | 343k | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 343k | bufferptr += source->png_alpha; | 217 | 343k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 343k | ptr + 1, ptr + 2, ptr + 3); | 219 | 343k | ptr += 4; | 220 | 343k | } | 221 | 47.1k | } else { | 222 | 47.1k | register unsigned char *bufferptr = source->iobuffer; | 223 | 8.35M | for (col = cinfo->image_width; col > 0; col--) { | 224 | 8.30M | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 8.30M | bufferptr += source->png_alpha; | 226 | 8.30M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 8.30M | ptr + 1, ptr + 2, ptr + 3); | 228 | 8.30M | ptr += 4; | 229 | 8.30M | } | 230 | 47.1k | } | 231 | 59.4k | return 1; | 232 | 59.4k | } |
rdpng-16.c:get_gray_cmyk_row Line | Count | Source | 192 | 70.2k | { | 193 | 70.2k | png_source_ptr source = (png_source_ptr)sinfo; | 194 | 70.2k | register _JSAMPROW ptr; | 195 | 70.2k | register _JSAMPLE *rescale = source->rescale; | 196 | 70.2k | JDIMENSION col; | 197 | | | 198 | 70.2k | get_raw_row(cinfo, sinfo); | 199 | 70.2k | ptr = source->pub._buffer[0]; | 200 | 70.2k | #if BITS_IN_JSAMPLE != 12 | 201 | 70.2k | if (source->png_bit_depth == cinfo->data_precision) { | 202 | 42.5k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 203 | 1.73M | for (col = cinfo->image_width; col > 0; col--) { | 204 | 1.69M | _JSAMPLE gray = *bufferptr++; | 205 | 1.69M | bufferptr += source->png_alpha; | 206 | 1.69M | rgb_to_cmyk(_MAXJSAMPLE, gray, gray, gray, ptr, ptr + 1, ptr + 2, | 207 | 1.69M | ptr + 3); | 208 | 1.69M | ptr += 4; | 209 | 1.69M | } | 210 | 42.5k | } else | 211 | 27.6k | #endif | 212 | 27.6k | if (source->png_bit_depth == 16) { | 213 | 0 | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 214 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 215 | 0 | _JSAMPLE gray = rescale[*bufferptr++]; | 216 | 0 | bufferptr += source->png_alpha; | 217 | 0 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 218 | 0 | ptr + 1, ptr + 2, ptr + 3); | 219 | 0 | ptr += 4; | 220 | 0 | } | 221 | 27.6k | } else { | 222 | 27.6k | register unsigned char *bufferptr = source->iobuffer; | 223 | 8.12M | for (col = cinfo->image_width; col > 0; col--) { | 224 | 8.09M | _JSAMPLE gray = rescale[*bufferptr++]; | 225 | 8.09M | bufferptr += source->png_alpha; | 226 | 8.09M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, gray, gray, gray, ptr, | 227 | 8.09M | ptr + 1, ptr + 2, ptr + 3); | 228 | 8.09M | ptr += 4; | 229 | 8.09M | } | 230 | 27.6k | } | 231 | 70.2k | return 1; | 232 | 70.2k | } |
|
233 | | |
234 | | |
235 | 1.23M | #define RGB_READ_LOOP(read_op, alpha_set_op, pointer_op) { \ |
236 | 560M | for (col = cinfo->image_width; col > 0; col--) { \ |
237 | 559M | ptr[rindex] = read_op; \ |
238 | 559M | ptr[gindex] = read_op; \ |
239 | 559M | ptr[bindex] = read_op; \ |
240 | 559M | alpha_set_op \ |
241 | 559M | pointer_op \ |
242 | 559M | ptr += ps; \ |
243 | 559M | } \ |
244 | 1.23M | } |
245 | | |
246 | | |
247 | | METHODDEF(JDIMENSION) |
248 | | get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
249 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
250 | | * truecolor or truecolor + alpha PNG files and converting to extended RGB. |
251 | | */ |
252 | 1.23M | { |
253 | 1.23M | png_source_ptr source = (png_source_ptr)sinfo; |
254 | 1.23M | register _JSAMPROW ptr; |
255 | 1.23M | register _JSAMPLE *rescale = source->rescale; |
256 | 1.23M | JDIMENSION col; |
257 | 1.23M | register int rindex = rgb_red[cinfo->in_color_space]; |
258 | 1.23M | register int gindex = rgb_green[cinfo->in_color_space]; |
259 | 1.23M | register int bindex = rgb_blue[cinfo->in_color_space]; |
260 | 1.23M | register int aindex = alpha_index[cinfo->in_color_space]; |
261 | 1.23M | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
262 | | |
263 | 1.23M | get_raw_row(cinfo, sinfo); |
264 | 1.23M | ptr = source->pub._buffer[0]; |
265 | | #if BITS_IN_JSAMPLE != 12 |
266 | 573k | if (source->png_bit_depth == cinfo->data_precision) { |
267 | 319k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
268 | 319k | if (aindex >= 0) |
269 | 6.40k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, |
270 | 319k | bufferptr += source->png_alpha;) |
271 | 312k | else |
272 | 312k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) |
273 | 319k | } else |
274 | 254k | #endif |
275 | 919k | if (source->png_bit_depth == 16) { |
276 | 353k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
277 | 353k | if (aindex >= 0) |
278 | 66.3k | RGB_READ_LOOP(rescale[*bufferptr++], |
279 | 353k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
280 | 353k | bufferptr += source->png_alpha;) |
281 | 287k | else |
282 | 287k | RGB_READ_LOOP(rescale[*bufferptr++], {}, |
283 | 353k | bufferptr += source->png_alpha;) |
284 | 566k | } else { |
285 | 566k | register unsigned char *bufferptr = source->iobuffer; |
286 | 566k | if (aindex >= 0) |
287 | 114k | RGB_READ_LOOP(rescale[*bufferptr++], |
288 | 566k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, |
289 | 566k | bufferptr += source->png_alpha;) |
290 | 452k | else |
291 | 452k | RGB_READ_LOOP(rescale[*bufferptr++], {}, |
292 | 566k | bufferptr += source->png_alpha;) |
293 | 566k | } |
294 | 1.23M | return 1; |
295 | 1.23M | } Line | Count | Source | 252 | 446k | { | 253 | 446k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 446k | register _JSAMPROW ptr; | 255 | 446k | register _JSAMPLE *rescale = source->rescale; | 256 | 446k | JDIMENSION col; | 257 | 446k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 446k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 446k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 446k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 446k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 446k | get_raw_row(cinfo, sinfo); | 264 | 446k | ptr = source->pub._buffer[0]; | 265 | 446k | #if BITS_IN_JSAMPLE != 12 | 266 | 446k | if (source->png_bit_depth == cinfo->data_precision) { | 267 | 316k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | 316k | if (aindex >= 0) | 269 | 6.40k | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | 316k | bufferptr += source->png_alpha;) | 271 | 310k | else | 272 | 310k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | 316k | } else | 274 | 129k | #endif | 275 | 129k | if (source->png_bit_depth == 16) { | 276 | 58.4k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 58.4k | if (aindex >= 0) | 278 | 6.40k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 58.4k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 58.4k | bufferptr += source->png_alpha;) | 281 | 52.0k | else | 282 | 52.0k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 58.4k | bufferptr += source->png_alpha;) | 284 | 71.3k | } else { | 285 | 71.3k | register unsigned char *bufferptr = source->iobuffer; | 286 | 71.3k | if (aindex >= 0) | 287 | 16.5k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 71.3k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 71.3k | bufferptr += source->png_alpha;) | 290 | 54.8k | else | 291 | 54.8k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 71.3k | bufferptr += source->png_alpha;) | 293 | 71.3k | } | 294 | 446k | return 1; | 295 | 446k | } |
Line | Count | Source | 252 | 665k | { | 253 | 665k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 665k | register _JSAMPROW ptr; | 255 | 665k | register _JSAMPLE *rescale = source->rescale; | 256 | 665k | JDIMENSION col; | 257 | 665k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 665k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 665k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 665k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 665k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 665k | get_raw_row(cinfo, sinfo); | 264 | 665k | 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 | 665k | if (source->png_bit_depth == 16) { | 276 | 287k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 287k | if (aindex >= 0) | 278 | 57.5k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 287k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 287k | bufferptr += source->png_alpha;) | 281 | 230k | else | 282 | 230k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 287k | bufferptr += source->png_alpha;) | 284 | 378k | } else { | 285 | 378k | register unsigned char *bufferptr = source->iobuffer; | 286 | 378k | if (aindex >= 0) | 287 | 74.8k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 378k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 378k | bufferptr += source->png_alpha;) | 290 | 303k | else | 291 | 303k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 378k | bufferptr += source->png_alpha;) | 293 | 378k | } | 294 | 665k | return 1; | 295 | 665k | } |
Line | Count | Source | 252 | 126k | { | 253 | 126k | png_source_ptr source = (png_source_ptr)sinfo; | 254 | 126k | register _JSAMPROW ptr; | 255 | 126k | register _JSAMPLE *rescale = source->rescale; | 256 | 126k | JDIMENSION col; | 257 | 126k | register int rindex = rgb_red[cinfo->in_color_space]; | 258 | 126k | register int gindex = rgb_green[cinfo->in_color_space]; | 259 | 126k | register int bindex = rgb_blue[cinfo->in_color_space]; | 260 | 126k | register int aindex = alpha_index[cinfo->in_color_space]; | 261 | 126k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 262 | | | 263 | 126k | get_raw_row(cinfo, sinfo); | 264 | 126k | ptr = source->pub._buffer[0]; | 265 | 126k | #if BITS_IN_JSAMPLE != 12 | 266 | 126k | if (source->png_bit_depth == cinfo->data_precision) { | 267 | 2.66k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 268 | 2.66k | if (aindex >= 0) | 269 | 0 | RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;, | 270 | 2.66k | bufferptr += source->png_alpha;) | 271 | 2.66k | else | 272 | 2.66k | RGB_READ_LOOP(*bufferptr++, {}, bufferptr += source->png_alpha;) | 273 | 2.66k | } else | 274 | 124k | #endif | 275 | 124k | if (source->png_bit_depth == 16) { | 276 | 7.22k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 277 | 7.22k | if (aindex >= 0) | 278 | 2.40k | RGB_READ_LOOP(rescale[*bufferptr++], | 279 | 7.22k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 280 | 7.22k | bufferptr += source->png_alpha;) | 281 | 4.81k | else | 282 | 4.81k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 283 | 7.22k | bufferptr += source->png_alpha;) | 284 | 117k | } else { | 285 | 117k | register unsigned char *bufferptr = source->iobuffer; | 286 | 117k | if (aindex >= 0) | 287 | 22.9k | RGB_READ_LOOP(rescale[*bufferptr++], | 288 | 117k | ptr[aindex] = (1 << cinfo->data_precision) - 1;, | 289 | 117k | bufferptr += source->png_alpha;) | 290 | 94.0k | else | 291 | 94.0k | RGB_READ_LOOP(rescale[*bufferptr++], {}, | 292 | 117k | bufferptr += source->png_alpha;) | 293 | 117k | } | 294 | 126k | return 1; | 295 | 126k | } |
|
296 | | |
297 | | |
298 | | METHODDEF(JDIMENSION) |
299 | | get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
300 | | /* This version is for reading 8-bit-per-channel or 16-bit-per-channel |
301 | | * truecolor or truecolor + alpha PNG files and converting to CMYK. |
302 | | */ |
303 | 188k | { |
304 | 188k | png_source_ptr source = (png_source_ptr)sinfo; |
305 | 188k | register _JSAMPROW ptr; |
306 | 188k | register _JSAMPLE *rescale = source->rescale; |
307 | 188k | JDIMENSION col; |
308 | | |
309 | 188k | get_raw_row(cinfo, sinfo); |
310 | 188k | ptr = source->pub._buffer[0]; |
311 | | #if BITS_IN_JSAMPLE != 12 |
312 | 55.8k | if (source->png_bit_depth == cinfo->data_precision) { |
313 | 8.81k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; |
314 | 3.48M | for (col = cinfo->image_width; col > 0; col--) { |
315 | 3.47M | _JSAMPLE r = *bufferptr++; |
316 | 3.47M | _JSAMPLE g = *bufferptr++; |
317 | 3.47M | _JSAMPLE b = *bufferptr++; |
318 | 3.47M | bufferptr += source->png_alpha; |
319 | 3.47M | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); |
320 | 3.47M | ptr += 4; |
321 | 3.47M | } |
322 | 8.81k | } else |
323 | 46.9k | #endif |
324 | 180k | if (source->png_bit_depth == 16) { |
325 | 63.9k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; |
326 | 6.28M | for (col = cinfo->image_width; col > 0; col--) { |
327 | 6.22M | _JSAMPLE r = rescale[*bufferptr++]; |
328 | 6.22M | _JSAMPLE g = rescale[*bufferptr++]; |
329 | 6.22M | _JSAMPLE b = rescale[*bufferptr++]; |
330 | 6.22M | bufferptr += source->png_alpha; |
331 | 6.22M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
332 | 6.22M | ptr + 2, ptr + 3); |
333 | 6.22M | ptr += 4; |
334 | 6.22M | } |
335 | 116k | } else { |
336 | 116k | register unsigned char *bufferptr = source->iobuffer; |
337 | 44.9M | for (col = cinfo->image_width; col > 0; col--) { |
338 | 44.8M | _JSAMPLE r = rescale[*bufferptr++]; |
339 | 44.8M | _JSAMPLE g = rescale[*bufferptr++]; |
340 | 44.8M | _JSAMPLE b = rescale[*bufferptr++]; |
341 | 44.8M | bufferptr += source->png_alpha; |
342 | 44.8M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, |
343 | 44.8M | ptr + 2, ptr + 3); |
344 | 44.8M | ptr += 4; |
345 | 44.8M | } |
346 | 116k | } |
347 | 188k | return 1; |
348 | 188k | } rdpng-8.c:get_rgb_cmyk_row Line | Count | Source | 303 | 29.9k | { | 304 | 29.9k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 29.9k | register _JSAMPROW ptr; | 306 | 29.9k | register _JSAMPLE *rescale = source->rescale; | 307 | 29.9k | JDIMENSION col; | 308 | | | 309 | 29.9k | get_raw_row(cinfo, sinfo); | 310 | 29.9k | ptr = source->pub._buffer[0]; | 311 | 29.9k | #if BITS_IN_JSAMPLE != 12 | 312 | 29.9k | if (source->png_bit_depth == cinfo->data_precision) { | 313 | 6.40k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | 3.25M | for (col = cinfo->image_width; col > 0; col--) { | 315 | 3.24M | _JSAMPLE r = *bufferptr++; | 316 | 3.24M | _JSAMPLE g = *bufferptr++; | 317 | 3.24M | _JSAMPLE b = *bufferptr++; | 318 | 3.24M | bufferptr += source->png_alpha; | 319 | 3.24M | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | 3.24M | ptr += 4; | 321 | 3.24M | } | 322 | 6.40k | } else | 323 | 23.5k | #endif | 324 | 23.5k | if (source->png_bit_depth == 16) { | 325 | 6.40k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 534k | for (col = cinfo->image_width; col > 0; col--) { | 327 | 528k | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 528k | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 528k | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 528k | bufferptr += source->png_alpha; | 331 | 528k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 528k | ptr + 2, ptr + 3); | 333 | 528k | ptr += 4; | 334 | 528k | } | 335 | 17.1k | } else { | 336 | 17.1k | register unsigned char *bufferptr = source->iobuffer; | 337 | 16.0M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 16.0M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 16.0M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 16.0M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 16.0M | bufferptr += source->png_alpha; | 342 | 16.0M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 16.0M | ptr + 2, ptr + 3); | 344 | 16.0M | ptr += 4; | 345 | 16.0M | } | 346 | 17.1k | } | 347 | 29.9k | return 1; | 348 | 29.9k | } |
rdpng-12.c:get_rgb_cmyk_row Line | Count | Source | 303 | 133k | { | 304 | 133k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 133k | register _JSAMPROW ptr; | 306 | 133k | register _JSAMPLE *rescale = source->rescale; | 307 | 133k | JDIMENSION col; | 308 | | | 309 | 133k | get_raw_row(cinfo, sinfo); | 310 | 133k | 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 | 133k | if (source->png_bit_depth == 16) { | 325 | 57.5k | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 5.75M | for (col = cinfo->image_width; col > 0; col--) { | 327 | 5.69M | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 5.69M | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 5.69M | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 5.69M | bufferptr += source->png_alpha; | 331 | 5.69M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 5.69M | ptr + 2, ptr + 3); | 333 | 5.69M | ptr += 4; | 334 | 5.69M | } | 335 | 75.6k | } else { | 336 | 75.6k | register unsigned char *bufferptr = source->iobuffer; | 337 | 23.4M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 23.4M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 23.4M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 23.4M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 23.4M | bufferptr += source->png_alpha; | 342 | 23.4M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 23.4M | ptr + 2, ptr + 3); | 344 | 23.4M | ptr += 4; | 345 | 23.4M | } | 346 | 75.6k | } | 347 | 133k | return 1; | 348 | 133k | } |
rdpng-16.c:get_rgb_cmyk_row Line | Count | Source | 303 | 25.8k | { | 304 | 25.8k | png_source_ptr source = (png_source_ptr)sinfo; | 305 | 25.8k | register _JSAMPROW ptr; | 306 | 25.8k | register _JSAMPLE *rescale = source->rescale; | 307 | 25.8k | JDIMENSION col; | 308 | | | 309 | 25.8k | get_raw_row(cinfo, sinfo); | 310 | 25.8k | ptr = source->pub._buffer[0]; | 311 | 25.8k | #if BITS_IN_JSAMPLE != 12 | 312 | 25.8k | if (source->png_bit_depth == cinfo->data_precision) { | 313 | 2.40k | register _JSAMPLE *bufferptr = (_JSAMPLE *)source->iobuffer; | 314 | 227k | for (col = cinfo->image_width; col > 0; col--) { | 315 | 224k | _JSAMPLE r = *bufferptr++; | 316 | 224k | _JSAMPLE g = *bufferptr++; | 317 | 224k | _JSAMPLE b = *bufferptr++; | 318 | 224k | bufferptr += source->png_alpha; | 319 | 224k | rgb_to_cmyk(_MAXJSAMPLE, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); | 320 | 224k | ptr += 4; | 321 | 224k | } | 322 | 2.40k | } else | 323 | 23.4k | #endif | 324 | 23.4k | if (source->png_bit_depth == 16) { | 325 | 0 | unsigned short *bufferptr = (unsigned short *)source->iobuffer; | 326 | 0 | for (col = cinfo->image_width; col > 0; col--) { | 327 | 0 | _JSAMPLE r = rescale[*bufferptr++]; | 328 | 0 | _JSAMPLE g = rescale[*bufferptr++]; | 329 | 0 | _JSAMPLE b = rescale[*bufferptr++]; | 330 | 0 | bufferptr += source->png_alpha; | 331 | 0 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 332 | 0 | ptr + 2, ptr + 3); | 333 | 0 | ptr += 4; | 334 | 0 | } | 335 | 23.4k | } else { | 336 | 23.4k | register unsigned char *bufferptr = source->iobuffer; | 337 | 5.41M | for (col = cinfo->image_width; col > 0; col--) { | 338 | 5.39M | _JSAMPLE r = rescale[*bufferptr++]; | 339 | 5.39M | _JSAMPLE g = rescale[*bufferptr++]; | 340 | 5.39M | _JSAMPLE b = rescale[*bufferptr++]; | 341 | 5.39M | bufferptr += source->png_alpha; | 342 | 5.39M | rgb_to_cmyk((1 << cinfo->data_precision) - 1, r, g, b, ptr, ptr + 1, | 343 | 5.39M | ptr + 2, ptr + 3); | 344 | 5.39M | ptr += 4; | 345 | 5.39M | } | 346 | 23.4k | } | 347 | 25.8k | return 1; | 348 | 25.8k | } |
|
349 | | |
350 | | |
351 | | METHODDEF(JDIMENSION) |
352 | | get_indexed_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
353 | 16.0k | { |
354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and |
355 | | * converting to extended RGB or CMYK. |
356 | | */ |
357 | 16.0k | png_source_ptr source = (png_source_ptr)sinfo; |
358 | 16.0k | register _JSAMPROW ptr; |
359 | 16.0k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; |
360 | 16.0k | register _JSAMPLE *rescale = source->rescale; |
361 | 16.0k | JDIMENSION col; |
362 | | |
363 | 16.0k | get_raw_row(cinfo, sinfo); |
364 | 16.0k | ptr = source->pub._buffer[0]; |
365 | | #if BITS_IN_JSAMPLE == 8 |
366 | 2.75k | if (source->png_bit_depth == cinfo->data_precision) { |
367 | 1.93k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
368 | 1.24k | for (col = cinfo->image_width; col > 0; col--) { |
369 | 1.09k | JSAMPLE index = *bufferptr++; |
370 | | |
371 | 1.09k | if (index >= source->colormap.n_entries) |
372 | 22 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
373 | 1.09k | *ptr++ = source->colormap.entries[index].red; |
374 | 1.09k | } |
375 | 1.78k | } else if (cinfo->in_color_space == JCS_CMYK) { |
376 | 764 | for (col = cinfo->image_width; col > 0; col--) { |
377 | 676 | JSAMPLE index = *bufferptr++; |
378 | | |
379 | 676 | if (index >= source->colormap.n_entries) |
380 | 8 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
381 | 676 | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, |
382 | 676 | source->colormap.entries[index].green, |
383 | 676 | source->colormap.entries[index].blue, ptr, ptr + 1, |
384 | 676 | ptr + 2, ptr + 3); |
385 | 676 | ptr += 4; |
386 | 676 | } |
387 | 1.69k | } else { |
388 | 1.69k | register int rindex = rgb_red[cinfo->in_color_space]; |
389 | 1.69k | register int gindex = rgb_green[cinfo->in_color_space]; |
390 | 1.69k | register int bindex = rgb_blue[cinfo->in_color_space]; |
391 | 1.69k | register int aindex = alpha_index[cinfo->in_color_space]; |
392 | 1.69k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
393 | | |
394 | 28.3k | for (col = cinfo->image_width; col > 0; col--) { |
395 | 26.6k | JSAMPLE index = *bufferptr++; |
396 | | |
397 | 26.6k | if (index >= source->colormap.n_entries) |
398 | 156 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
399 | 26.6k | ptr[rindex] = source->colormap.entries[index].red; |
400 | 26.6k | ptr[gindex] = source->colormap.entries[index].green; |
401 | 26.6k | ptr[bindex] = source->colormap.entries[index].blue; |
402 | 26.6k | if (aindex >= 0) |
403 | 668 | ptr[aindex] = _MAXJSAMPLE; |
404 | 26.6k | ptr += ps; |
405 | 26.6k | } |
406 | 1.69k | } |
407 | 1.93k | } else |
408 | 820 | #endif |
409 | 820 | { |
410 | 14.1k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
411 | 1.06k | for (col = cinfo->image_width; col > 0; col--) { |
412 | 937 | JSAMPLE index = *bufferptr++; |
413 | | |
414 | 937 | if (index >= source->colormap.n_entries) |
415 | 21 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
416 | 937 | *ptr++ = rescale[source->colormap.entries[index].red]; |
417 | 937 | } |
418 | 13.9k | } else if (cinfo->in_color_space == JCS_CMYK) { |
419 | 192k | for (col = cinfo->image_width; col > 0; col--) { |
420 | 190k | JSAMPLE index = *bufferptr++; |
421 | | |
422 | 190k | if (index >= source->colormap.n_entries) |
423 | 110 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
424 | 190k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, |
425 | 190k | rescale[source->colormap.entries[index].red], |
426 | 190k | rescale[source->colormap.entries[index].green], |
427 | 190k | rescale[source->colormap.entries[index].blue], ptr, |
428 | 190k | ptr + 1, ptr + 2, ptr + 3); |
429 | 190k | ptr += 4; |
430 | 190k | } |
431 | 11.7k | } else { |
432 | 11.7k | register int rindex = rgb_red[cinfo->in_color_space]; |
433 | 11.7k | register int gindex = rgb_green[cinfo->in_color_space]; |
434 | 11.7k | register int bindex = rgb_blue[cinfo->in_color_space]; |
435 | 11.7k | register int aindex = alpha_index[cinfo->in_color_space]; |
436 | 11.7k | register int ps = rgb_pixelsize[cinfo->in_color_space]; |
437 | | |
438 | 965k | for (col = cinfo->image_width; col > 0; col--) { |
439 | 953k | JSAMPLE index = *bufferptr++; |
440 | | |
441 | 953k | if (index >= source->colormap.n_entries) |
442 | 530 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
443 | 953k | ptr[rindex] = rescale[source->colormap.entries[index].red]; |
444 | 953k | ptr[gindex] = rescale[source->colormap.entries[index].green]; |
445 | 953k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; |
446 | 953k | if (aindex >= 0) |
447 | 191k | ptr[aindex] = (1 << cinfo->data_precision) - 1; |
448 | 953k | ptr += ps; |
449 | 953k | } |
450 | 11.7k | } |
451 | 820 | } |
452 | 16.0k | return 1; |
453 | 16.0k | } rdpng-8.c:get_indexed_row Line | Count | Source | 353 | 2.75k | { | 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.75k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 2.75k | register _JSAMPROW ptr; | 359 | 2.75k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 2.75k | register _JSAMPLE *rescale = source->rescale; | 361 | 2.75k | JDIMENSION col; | 362 | | | 363 | 2.75k | get_raw_row(cinfo, sinfo); | 364 | 2.75k | ptr = source->pub._buffer[0]; | 365 | 2.75k | #if BITS_IN_JSAMPLE == 8 | 366 | 2.75k | if (source->png_bit_depth == cinfo->data_precision) { | 367 | 1.93k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 368 | 1.24k | for (col = cinfo->image_width; col > 0; col--) { | 369 | 1.09k | JSAMPLE index = *bufferptr++; | 370 | | | 371 | 1.09k | if (index >= source->colormap.n_entries) | 372 | 22 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 373 | 1.09k | *ptr++ = source->colormap.entries[index].red; | 374 | 1.09k | } | 375 | 1.78k | } else if (cinfo->in_color_space == JCS_CMYK) { | 376 | 764 | for (col = cinfo->image_width; col > 0; col--) { | 377 | 676 | JSAMPLE index = *bufferptr++; | 378 | | | 379 | 676 | if (index >= source->colormap.n_entries) | 380 | 8 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 381 | 676 | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, | 382 | 676 | source->colormap.entries[index].green, | 383 | 676 | source->colormap.entries[index].blue, ptr, ptr + 1, | 384 | 676 | ptr + 2, ptr + 3); | 385 | 676 | ptr += 4; | 386 | 676 | } | 387 | 1.69k | } else { | 388 | 1.69k | register int rindex = rgb_red[cinfo->in_color_space]; | 389 | 1.69k | register int gindex = rgb_green[cinfo->in_color_space]; | 390 | 1.69k | register int bindex = rgb_blue[cinfo->in_color_space]; | 391 | 1.69k | register int aindex = alpha_index[cinfo->in_color_space]; | 392 | 1.69k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 393 | | | 394 | 28.3k | for (col = cinfo->image_width; col > 0; col--) { | 395 | 26.6k | JSAMPLE index = *bufferptr++; | 396 | | | 397 | 26.6k | if (index >= source->colormap.n_entries) | 398 | 156 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 399 | 26.6k | ptr[rindex] = source->colormap.entries[index].red; | 400 | 26.6k | ptr[gindex] = source->colormap.entries[index].green; | 401 | 26.6k | ptr[bindex] = source->colormap.entries[index].blue; | 402 | 26.6k | if (aindex >= 0) | 403 | 668 | ptr[aindex] = _MAXJSAMPLE; | 404 | 26.6k | ptr += ps; | 405 | 26.6k | } | 406 | 1.69k | } | 407 | 1.93k | } else | 408 | 820 | #endif | 409 | 820 | { | 410 | 820 | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 397 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 350 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 350 | if (index >= source->colormap.n_entries) | 415 | 7 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 350 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 350 | } | 418 | 773 | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 927 | for (col = cinfo->image_width; col > 0; col--) { | 420 | 817 | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 817 | if (index >= source->colormap.n_entries) | 423 | 20 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 817 | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 817 | rescale[source->colormap.entries[index].red], | 426 | 817 | rescale[source->colormap.entries[index].green], | 427 | 817 | rescale[source->colormap.entries[index].blue], ptr, | 428 | 817 | ptr + 1, ptr + 2, ptr + 3); | 429 | 817 | ptr += 4; | 430 | 817 | } | 431 | 663 | } else { | 432 | 663 | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 663 | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 663 | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 663 | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 663 | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 3.93k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 3.26k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 3.26k | if (index >= source->colormap.n_entries) | 442 | 80 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 3.26k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 3.26k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 3.26k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 3.26k | if (aindex >= 0) | 447 | 797 | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 3.26k | ptr += ps; | 449 | 3.26k | } | 450 | 663 | } | 451 | 820 | } | 452 | 2.75k | return 1; | 453 | 2.75k | } |
rdpng-12.c:get_indexed_row Line | Count | Source | 353 | 10.3k | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 10.3k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 10.3k | register _JSAMPROW ptr; | 359 | 10.3k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 10.3k | register _JSAMPLE *rescale = source->rescale; | 361 | 10.3k | JDIMENSION col; | 362 | | | 363 | 10.3k | get_raw_row(cinfo, sinfo); | 364 | 10.3k | 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 | 10.3k | { | 410 | 10.3k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 415 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 364 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 364 | if (index >= source->colormap.n_entries) | 415 | 10 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 364 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 364 | } | 418 | 10.2k | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 179k | for (col = cinfo->image_width; col > 0; col--) { | 420 | 177k | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 177k | if (index >= source->colormap.n_entries) | 423 | 62 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 177k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 177k | rescale[source->colormap.entries[index].red], | 426 | 177k | rescale[source->colormap.entries[index].green], | 427 | 177k | rescale[source->colormap.entries[index].blue], ptr, | 428 | 177k | ptr + 1, ptr + 2, ptr + 3); | 429 | 177k | ptr += 4; | 430 | 177k | } | 431 | 8.59k | } else { | 432 | 8.59k | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 8.59k | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 8.59k | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 8.59k | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 8.59k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 900k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 892k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 892k | if (index >= source->colormap.n_entries) | 442 | 310 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 892k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 892k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 892k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 892k | if (aindex >= 0) | 447 | 178k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 892k | ptr += ps; | 449 | 892k | } | 450 | 8.59k | } | 451 | 10.3k | } | 452 | 10.3k | return 1; | 453 | 10.3k | } |
rdpng-16.c:get_indexed_row Line | Count | Source | 353 | 2.99k | { | 354 | | /* This version is for reading 8-bit-per-channel indexed-color PNG files and | 355 | | * converting to extended RGB or CMYK. | 356 | | */ | 357 | 2.99k | png_source_ptr source = (png_source_ptr)sinfo; | 358 | 2.99k | register _JSAMPROW ptr; | 359 | 2.99k | register JSAMPLE *bufferptr = (JSAMPLE *)source->iobuffer; | 360 | 2.99k | register _JSAMPLE *rescale = source->rescale; | 361 | 2.99k | JDIMENSION col; | 362 | | | 363 | 2.99k | get_raw_row(cinfo, sinfo); | 364 | 2.99k | ptr = source->pub._buffer[0]; | 365 | | #if BITS_IN_JSAMPLE == 8 | 366 | | if (source->png_bit_depth == cinfo->data_precision) { | 367 | | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 368 | | for (col = cinfo->image_width; col > 0; col--) { | 369 | | JSAMPLE index = *bufferptr++; | 370 | | | 371 | | if (index >= source->colormap.n_entries) | 372 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 373 | | *ptr++ = source->colormap.entries[index].red; | 374 | | } | 375 | | } else if (cinfo->in_color_space == JCS_CMYK) { | 376 | | for (col = cinfo->image_width; col > 0; col--) { | 377 | | JSAMPLE index = *bufferptr++; | 378 | | | 379 | | if (index >= source->colormap.n_entries) | 380 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 381 | | rgb_to_cmyk(_MAXJSAMPLE, source->colormap.entries[index].red, | 382 | | source->colormap.entries[index].green, | 383 | | source->colormap.entries[index].blue, ptr, ptr + 1, | 384 | | ptr + 2, ptr + 3); | 385 | | ptr += 4; | 386 | | } | 387 | | } else { | 388 | | register int rindex = rgb_red[cinfo->in_color_space]; | 389 | | register int gindex = rgb_green[cinfo->in_color_space]; | 390 | | register int bindex = rgb_blue[cinfo->in_color_space]; | 391 | | register int aindex = alpha_index[cinfo->in_color_space]; | 392 | | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 393 | | | 394 | | for (col = cinfo->image_width; col > 0; col--) { | 395 | | JSAMPLE index = *bufferptr++; | 396 | | | 397 | | if (index >= source->colormap.n_entries) | 398 | | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 399 | | ptr[rindex] = source->colormap.entries[index].red; | 400 | | ptr[gindex] = source->colormap.entries[index].green; | 401 | | ptr[bindex] = source->colormap.entries[index].blue; | 402 | | if (aindex >= 0) | 403 | | ptr[aindex] = _MAXJSAMPLE; | 404 | | ptr += ps; | 405 | | } | 406 | | } | 407 | | } else | 408 | | #endif | 409 | 2.99k | { | 410 | 2.99k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 411 | 253 | for (col = cinfo->image_width; col > 0; col--) { | 412 | 223 | JSAMPLE index = *bufferptr++; | 413 | | | 414 | 223 | if (index >= source->colormap.n_entries) | 415 | 4 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 416 | 223 | *ptr++ = rescale[source->colormap.entries[index].red]; | 417 | 223 | } | 418 | 2.96k | } else if (cinfo->in_color_space == JCS_CMYK) { | 419 | 12.0k | for (col = cinfo->image_width; col > 0; col--) { | 420 | 11.6k | JSAMPLE index = *bufferptr++; | 421 | | | 422 | 11.6k | if (index >= source->colormap.n_entries) | 423 | 28 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 424 | 11.6k | rgb_to_cmyk((1 << cinfo->data_precision) - 1, | 425 | 11.6k | rescale[source->colormap.entries[index].red], | 426 | 11.6k | rescale[source->colormap.entries[index].green], | 427 | 11.6k | rescale[source->colormap.entries[index].blue], ptr, | 428 | 11.6k | ptr + 1, ptr + 2, ptr + 3); | 429 | 11.6k | ptr += 4; | 430 | 11.6k | } | 431 | 2.48k | } else { | 432 | 2.48k | register int rindex = rgb_red[cinfo->in_color_space]; | 433 | 2.48k | register int gindex = rgb_green[cinfo->in_color_space]; | 434 | 2.48k | register int bindex = rgb_blue[cinfo->in_color_space]; | 435 | 2.48k | register int aindex = alpha_index[cinfo->in_color_space]; | 436 | 2.48k | register int ps = rgb_pixelsize[cinfo->in_color_space]; | 437 | | | 438 | 60.5k | for (col = cinfo->image_width; col > 0; col--) { | 439 | 58.0k | JSAMPLE index = *bufferptr++; | 440 | | | 441 | 58.0k | if (index >= source->colormap.n_entries) | 442 | 140 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 443 | 58.0k | ptr[rindex] = rescale[source->colormap.entries[index].red]; | 444 | 58.0k | ptr[gindex] = rescale[source->colormap.entries[index].green]; | 445 | 58.0k | ptr[bindex] = rescale[source->colormap.entries[index].blue]; | 446 | 58.0k | if (aindex >= 0) | 447 | 11.5k | ptr[aindex] = (1 << cinfo->data_precision) - 1; | 448 | 58.0k | ptr += ps; | 449 | 58.0k | } | 450 | 2.48k | } | 451 | 2.99k | } | 452 | 2.99k | return 1; | 453 | 2.99k | } |
|
454 | | |
455 | | |
456 | | #ifdef ZERO_BUFFERS |
457 | | |
458 | | static void *spng_malloc(size_t size) |
459 | | { |
460 | | return calloc(1, size); |
461 | | } |
462 | | |
463 | | #endif |
464 | | |
465 | | |
466 | | /* |
467 | | * Read the file header; return image size and component count. |
468 | | */ |
469 | | |
470 | | METHODDEF(void) |
471 | | start_input_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
472 | 191k | { |
473 | 191k | png_source_ptr source = (png_source_ptr)sinfo; |
474 | 191k | struct spng_ihdr ihdr; |
475 | 191k | int png_components = 3; |
476 | 191k | boolean use_raw_buffer; |
477 | | #ifdef ZERO_BUFFERS |
478 | | struct spng_alloc alloc; |
479 | | |
480 | | alloc.malloc_fn = spng_malloc; |
481 | | alloc.realloc_fn = realloc; |
482 | | alloc.calloc_fn = calloc; |
483 | | alloc.free_fn = free; |
484 | | source->ctx = spng_ctx_new2(&alloc, 0); |
485 | | #else |
486 | 191k | source->ctx = spng_ctx_new(0); |
487 | 191k | #endif |
488 | 191k | if (!source->ctx) |
489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); |
490 | | |
491 | 191k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); |
492 | | |
493 | 191k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); |
494 | | |
495 | 191k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) |
496 | 24.2k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); |
497 | 191k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) |
498 | 28.9k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); |
499 | 191k | if (sinfo->max_pixels && |
500 | 130k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) |
501 | 2.61k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); |
502 | | |
503 | 191k | cinfo->image_width = (JDIMENSION)ihdr.width; |
504 | 191k | cinfo->image_height = (JDIMENSION)ihdr.height; |
505 | 191k | source->png_bit_depth = ihdr.bit_depth; |
506 | 191k | source->png_color_type = ihdr.color_type; |
507 | | |
508 | | /* initialize flags to most common settings */ |
509 | 191k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ |
510 | | |
511 | 191k | switch (ihdr.color_type) { |
512 | 5.20k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: |
513 | 50.7k | case SPNG_COLOR_TYPE_GRAYSCALE: |
514 | 50.7k | if (cinfo->in_color_space == JCS_UNKNOWN || |
515 | 50.7k | cinfo->in_color_space == JCS_RGB) |
516 | 3.34k | cinfo->in_color_space = JCS_GRAYSCALE; |
517 | 50.7k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, |
518 | 50.7k | ihdr.bit_depth); |
519 | 50.7k | if (cinfo->in_color_space == JCS_GRAYSCALE) { |
520 | 10.3k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && |
521 | 9.22k | cinfo->data_precision == ihdr.bit_depth) { |
522 | 4.22k | source->pub.get_pixel_rows = get_raw_row; |
523 | 4.22k | use_raw_buffer = TRUE; |
524 | 4.22k | } else |
525 | 6.09k | source->pub.get_pixel_rows = get_gray_row; |
526 | 40.4k | } else if (IsExtRGB(cinfo->in_color_space)) |
527 | 34.9k | source->pub.get_pixel_rows = get_gray_rgb_row; |
528 | 5.56k | else if (cinfo->in_color_space == JCS_CMYK) |
529 | 5.56k | source->pub.get_pixel_rows = get_gray_cmyk_row; |
530 | 0 | else |
531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
532 | 50.7k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { |
533 | 5.20k | png_components = 2; |
534 | 5.20k | source->png_alpha = 1; |
535 | 45.5k | } else { |
536 | 45.5k | png_components = 1; |
537 | 45.5k | source->png_alpha = 0; |
538 | 45.5k | } |
539 | 50.7k | break; |
540 | | |
541 | 53.7k | case SPNG_COLOR_TYPE_TRUECOLOR: |
542 | 67.6k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: |
543 | 67.6k | if (cinfo->in_color_space == JCS_UNKNOWN) |
544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
545 | 67.6k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, |
546 | 67.6k | ihdr.bit_depth); |
547 | 67.6k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && |
548 | 53.7k | cinfo->data_precision == ihdr.bit_depth && |
549 | 18.8k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 |
550 | 18.8k | (cinfo->in_color_space == JCS_EXT_RGB || |
551 | 15.2k | cinfo->in_color_space == JCS_RGB)) { |
552 | | #else |
553 | | cinfo->in_color_space == JCS_EXT_RGB) { |
554 | | #endif |
555 | 4.02k | source->pub.get_pixel_rows = get_raw_row; |
556 | 4.02k | use_raw_buffer = TRUE; |
557 | 63.6k | } else if (IsExtRGB(cinfo->in_color_space)) |
558 | 46.1k | source->pub.get_pixel_rows = get_rgb_row; |
559 | 17.4k | else if (cinfo->in_color_space == JCS_CMYK) |
560 | 7.64k | source->pub.get_pixel_rows = get_rgb_cmyk_row; |
561 | 9.81k | else |
562 | 9.81k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
563 | 67.6k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { |
564 | 11.8k | png_components = 4; |
565 | 11.8k | source->png_alpha = 1; |
566 | 55.8k | } else { |
567 | 55.8k | png_components = 3; |
568 | 55.8k | source->png_alpha = 0; |
569 | 55.8k | } |
570 | 67.6k | break; |
571 | | |
572 | 8.92k | case SPNG_COLOR_TYPE_INDEXED: |
573 | 8.92k | { |
574 | 8.92k | int i, gray = 1; |
575 | | |
576 | 8.92k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, |
577 | 8.92k | ihdr.bit_depth); |
578 | 8.92k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); |
579 | 8.92k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) |
580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
581 | | |
582 | 148k | for (i = 0; i < (int)source->colormap.n_entries; i++) { |
583 | 139k | if (source->colormap.entries[i].red != |
584 | 139k | source->colormap.entries[i].green || |
585 | 46.4k | source->colormap.entries[i].green != |
586 | 46.4k | source->colormap.entries[i].blue) |
587 | 96.1k | gray = 0; |
588 | 139k | } |
589 | | |
590 | 8.92k | if ((cinfo->in_color_space == JCS_UNKNOWN || |
591 | 2.20k | cinfo->in_color_space == JCS_RGB) && gray) |
592 | 22 | cinfo->in_color_space = JCS_GRAYSCALE; |
593 | 8.90k | else if (cinfo->in_color_space == JCS_UNKNOWN) |
594 | 0 | cinfo->in_color_space = JCS_EXT_RGB; |
595 | 8.92k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) |
596 | 238 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
597 | | |
598 | 8.92k | source->pub.get_pixel_rows = get_indexed_row; |
599 | 8.92k | png_components = 1; |
600 | 8.92k | source->png_alpha = 0; |
601 | 8.92k | break; |
602 | 53.7k | } |
603 | | |
604 | 0 | default: |
605 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); |
606 | 191k | } |
607 | | |
608 | 110k | if (IsExtRGB(cinfo->in_color_space)) |
609 | 86.7k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; |
610 | 23.9k | else if (cinfo->in_color_space == JCS_GRAYSCALE) |
611 | 10.4k | cinfo->input_components = 1; |
612 | 13.4k | else if (cinfo->in_color_space == JCS_CMYK) |
613 | 13.4k | cinfo->input_components = 4; |
614 | | |
615 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ |
616 | 110k | source->buffer_width = |
617 | 110k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; |
618 | 110k | source->iobuffer = (unsigned char *) |
619 | 110k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
620 | 110k | source->buffer_width); |
621 | | |
622 | | /* Create compressor input buffer. */ |
623 | 110k | if (use_raw_buffer) { |
624 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ |
625 | | /* Synthesize a _JSAMPARRAY pointer structure */ |
626 | 8.24k | source->pixrow = (_JSAMPROW)source->iobuffer; |
627 | 8.24k | source->pub._buffer = &source->pixrow; |
628 | 8.24k | source->pub.buffer_height = 1; |
629 | 102k | } else { |
630 | 102k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; |
631 | 102k | size_t val, half_maxval; |
632 | | |
633 | | /* Need to translate anyway, so make a separate sample buffer. */ |
634 | 102k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
635 | 102k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
636 | 102k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); |
637 | 102k | source->pub.buffer_height = 1; |
638 | | |
639 | | /* Compute the rescaling array. */ |
640 | 102k | source->rescale = (_JSAMPLE *) |
641 | 102k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
642 | 102k | (maxval + 1L) * sizeof(_JSAMPLE)); |
643 | 102k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); |
644 | 102k | half_maxval = maxval / 2; |
645 | 1.99G | for (val = 0; val <= maxval; val++) { |
646 | | /* The multiplication here must be done in 32 bits to avoid overflow */ |
647 | 1.99G | source->rescale[val] = |
648 | 1.99G | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / |
649 | 1.99G | maxval); |
650 | 1.99G | } |
651 | 102k | } |
652 | | |
653 | 110k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, |
654 | 110k | SPNG_DECODE_PROGRESSIVE)); |
655 | 110k | } rdpng-8.c:start_input_png Line | Count | Source | 472 | 94.8k | { | 473 | 94.8k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 94.8k | struct spng_ihdr ihdr; | 475 | 94.8k | int png_components = 3; | 476 | 94.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 | 94.8k | source->ctx = spng_ctx_new(0); | 487 | 94.8k | #endif | 488 | 94.8k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 94.8k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 94.8k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 94.8k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 18.3k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 94.8k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 10.6k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 94.8k | if (sinfo->max_pixels && | 500 | 61.1k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 925 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 94.8k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 94.8k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 94.8k | source->png_bit_depth = ihdr.bit_depth; | 506 | 94.8k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 94.8k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 94.8k | switch (ihdr.color_type) { | 512 | 1.51k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 21.1k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 21.1k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 21.1k | cinfo->in_color_space == JCS_RGB) | 516 | 3.34k | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 21.1k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 21.1k | ihdr.bit_depth); | 519 | 21.1k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 6.08k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 5.50k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 3.71k | source->pub.get_pixel_rows = get_raw_row; | 523 | 3.71k | use_raw_buffer = TRUE; | 524 | 3.71k | } else | 525 | 2.36k | source->pub.get_pixel_rows = get_gray_row; | 526 | 15.0k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 13.7k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 1.32k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 1.32k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 21.1k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 1.51k | png_components = 2; | 534 | 1.51k | source->png_alpha = 1; | 535 | 19.6k | } else { | 536 | 19.6k | png_components = 1; | 537 | 19.6k | source->png_alpha = 0; | 538 | 19.6k | } | 539 | 21.1k | break; | 540 | | | 541 | 26.9k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 34.3k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 34.3k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 34.3k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 34.3k | ihdr.bit_depth); | 547 | 34.3k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 26.9k | cinfo->data_precision == ihdr.bit_depth && | 549 | 16.2k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 16.2k | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 13.2k | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 3.37k | source->pub.get_pixel_rows = get_raw_row; | 556 | 3.37k | use_raw_buffer = TRUE; | 557 | 30.9k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 23.0k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 7.94k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 2.88k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 5.05k | else | 562 | 5.05k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 34.3k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 6.27k | png_components = 4; | 565 | 6.27k | source->png_alpha = 1; | 566 | 28.0k | } else { | 567 | 28.0k | png_components = 3; | 568 | 28.0k | source->png_alpha = 0; | 569 | 28.0k | } | 570 | 34.3k | break; | 571 | | | 572 | 4.75k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 4.75k | { | 574 | 4.75k | int i, gray = 1; | 575 | | | 576 | 4.75k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 4.75k | ihdr.bit_depth); | 578 | 4.75k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 4.75k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 45.6k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 40.9k | if (source->colormap.entries[i].red != | 584 | 40.9k | source->colormap.entries[i].green || | 585 | 20.7k | source->colormap.entries[i].green != | 586 | 20.7k | source->colormap.entries[i].blue) | 587 | 20.8k | gray = 0; | 588 | 40.9k | } | 589 | | | 590 | 4.75k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 780 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 22 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 4.73k | else if (cinfo->in_color_space == JCS_UNKNOWN) | 594 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 595 | 4.75k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 596 | 67 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 597 | | | 598 | 4.75k | source->pub.get_pixel_rows = get_indexed_row; | 599 | 4.75k | png_components = 1; | 600 | 4.75k | source->png_alpha = 0; | 601 | 4.75k | break; | 602 | 26.9k | } | 603 | | | 604 | 0 | default: | 605 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 606 | 94.8k | } | 607 | | | 608 | 51.1k | if (IsExtRGB(cinfo->in_color_space)) | 609 | 40.6k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 610 | 10.4k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 611 | 6.15k | cinfo->input_components = 1; | 612 | 4.28k | else if (cinfo->in_color_space == JCS_CMYK) | 613 | 4.28k | cinfo->input_components = 4; | 614 | | | 615 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 616 | 51.1k | source->buffer_width = | 617 | 51.1k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 618 | 51.1k | source->iobuffer = (unsigned char *) | 619 | 51.1k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 620 | 51.1k | source->buffer_width); | 621 | | | 622 | | /* Create compressor input buffer. */ | 623 | 51.1k | if (use_raw_buffer) { | 624 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 625 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 626 | 7.08k | source->pixrow = (_JSAMPROW)source->iobuffer; | 627 | 7.08k | source->pub._buffer = &source->pixrow; | 628 | 7.08k | source->pub.buffer_height = 1; | 629 | 44.0k | } else { | 630 | 44.0k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 631 | 44.0k | size_t val, half_maxval; | 632 | | | 633 | | /* Need to translate anyway, so make a separate sample buffer. */ | 634 | 44.0k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 635 | 44.0k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 636 | 44.0k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 637 | 44.0k | source->pub.buffer_height = 1; | 638 | | | 639 | | /* Compute the rescaling array. */ | 640 | 44.0k | source->rescale = (_JSAMPLE *) | 641 | 44.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 642 | 44.0k | (maxval + 1L) * sizeof(_JSAMPLE)); | 643 | 44.0k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 644 | 44.0k | half_maxval = maxval / 2; | 645 | 893M | for (val = 0; val <= maxval; val++) { | 646 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 647 | 893M | source->rescale[val] = | 648 | 893M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 649 | 893M | maxval); | 650 | 893M | } | 651 | 44.0k | } | 652 | | | 653 | 51.1k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 654 | 51.1k | SPNG_DECODE_PROGRESSIVE)); | 655 | 51.1k | } |
rdpng-12.c:start_input_png Line | Count | Source | 472 | 65.6k | { | 473 | 65.6k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 65.6k | struct spng_ihdr ihdr; | 475 | 65.6k | int png_components = 3; | 476 | 65.6k | 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 | 65.6k | source->ctx = spng_ctx_new(0); | 487 | 65.6k | #endif | 488 | 65.6k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 65.6k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 65.6k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 65.6k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 5.32k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 65.6k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 13.1k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 65.6k | if (sinfo->max_pixels && | 500 | 44.5k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 1.33k | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 65.6k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 65.6k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 65.6k | source->png_bit_depth = ihdr.bit_depth; | 506 | 65.6k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 65.6k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 65.6k | switch (ihdr.color_type) { | 512 | 2.33k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 19.8k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 19.8k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 19.8k | cinfo->in_color_space == JCS_RGB) | 516 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 19.8k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 19.8k | ihdr.bit_depth); | 519 | 19.8k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 2.82k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 2.49k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 0 | source->pub.get_pixel_rows = get_raw_row; | 523 | 0 | use_raw_buffer = TRUE; | 524 | 0 | } else | 525 | 2.82k | source->pub.get_pixel_rows = get_gray_row; | 526 | 16.9k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 14.1k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 2.82k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 2.82k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 19.8k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 2.33k | png_components = 2; | 534 | 2.33k | source->png_alpha = 1; | 535 | 17.4k | } else { | 536 | 17.4k | png_components = 1; | 537 | 17.4k | source->png_alpha = 0; | 538 | 17.4k | } | 539 | 19.8k | break; | 540 | | | 541 | 15.3k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 20.3k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 20.3k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 20.3k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 20.3k | ihdr.bit_depth); | 547 | 20.3k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 15.3k | cinfo->data_precision == ihdr.bit_depth && | 549 | 0 | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 0 | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 0 | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 0 | source->pub.get_pixel_rows = get_raw_row; | 556 | 0 | use_raw_buffer = TRUE; | 557 | 20.3k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 14.5k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 5.81k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 2.90k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 2.90k | else | 562 | 2.90k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 20.3k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 4.30k | png_components = 4; | 565 | 4.30k | source->png_alpha = 1; | 566 | 16.0k | } else { | 567 | 16.0k | png_components = 3; | 568 | 16.0k | source->png_alpha = 0; | 569 | 16.0k | } | 570 | 20.3k | break; | 571 | | | 572 | 3.08k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 3.08k | { | 574 | 3.08k | int i, gray = 1; | 575 | | | 576 | 3.08k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 3.08k | ihdr.bit_depth); | 578 | 3.08k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 3.08k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 85.1k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 82.0k | if (source->colormap.entries[i].red != | 584 | 82.0k | source->colormap.entries[i].green || | 585 | 15.7k | source->colormap.entries[i].green != | 586 | 15.7k | source->colormap.entries[i].blue) | 587 | 67.9k | gray = 0; | 588 | 82.0k | } | 589 | | | 590 | 3.08k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 980 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 3.08k | else if (cinfo->in_color_space == JCS_UNKNOWN) | 594 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 595 | 3.08k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 596 | 119 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 597 | | | 598 | 3.08k | source->pub.get_pixel_rows = get_indexed_row; | 599 | 3.08k | png_components = 1; | 600 | 3.08k | source->png_alpha = 0; | 601 | 3.08k | break; | 602 | 15.3k | } | 603 | | | 604 | 0 | default: | 605 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 606 | 65.6k | } | 607 | | | 608 | 38.0k | if (IsExtRGB(cinfo->in_color_space)) | 609 | 29.3k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 610 | 8.72k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 611 | 2.85k | cinfo->input_components = 1; | 612 | 5.87k | else if (cinfo->in_color_space == JCS_CMYK) | 613 | 5.87k | cinfo->input_components = 4; | 614 | | | 615 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 616 | 38.0k | source->buffer_width = | 617 | 38.0k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 618 | 38.0k | source->iobuffer = (unsigned char *) | 619 | 38.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 620 | 38.0k | source->buffer_width); | 621 | | | 622 | | /* Create compressor input buffer. */ | 623 | 38.0k | if (use_raw_buffer) { | 624 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 625 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 626 | 0 | source->pixrow = (_JSAMPROW)source->iobuffer; | 627 | 0 | source->pub._buffer = &source->pixrow; | 628 | 0 | source->pub.buffer_height = 1; | 629 | 38.0k | } else { | 630 | 38.0k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 631 | 38.0k | size_t val, half_maxval; | 632 | | | 633 | | /* Need to translate anyway, so make a separate sample buffer. */ | 634 | 38.0k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 635 | 38.0k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 636 | 38.0k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 637 | 38.0k | source->pub.buffer_height = 1; | 638 | | | 639 | | /* Compute the rescaling array. */ | 640 | 38.0k | source->rescale = (_JSAMPLE *) | 641 | 38.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 642 | 38.0k | (maxval + 1L) * sizeof(_JSAMPLE)); | 643 | 38.0k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 644 | 38.0k | half_maxval = maxval / 2; | 645 | 584M | for (val = 0; val <= maxval; val++) { | 646 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 647 | 584M | source->rescale[val] = | 648 | 584M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 649 | 584M | maxval); | 650 | 584M | } | 651 | 38.0k | } | 652 | | | 653 | 38.0k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 654 | 38.0k | SPNG_DECODE_PROGRESSIVE)); | 655 | 38.0k | } |
rdpng-16.c:start_input_png Line | Count | Source | 472 | 31.4k | { | 473 | 31.4k | png_source_ptr source = (png_source_ptr)sinfo; | 474 | 31.4k | struct spng_ihdr ihdr; | 475 | 31.4k | int png_components = 3; | 476 | 31.4k | boolean use_raw_buffer; | 477 | | #ifdef ZERO_BUFFERS | 478 | | struct spng_alloc alloc; | 479 | | | 480 | | alloc.malloc_fn = spng_malloc; | 481 | | alloc.realloc_fn = realloc; | 482 | | alloc.calloc_fn = calloc; | 483 | | alloc.free_fn = free; | 484 | | source->ctx = spng_ctx_new2(&alloc, 0); | 485 | | #else | 486 | 31.4k | source->ctx = spng_ctx_new(0); | 487 | 31.4k | #endif | 488 | 31.4k | if (!source->ctx) | 489 | 0 | ERREXITS(cinfo, JERR_PNG_LIBSPNG, "Could not create context"); | 490 | | | 491 | 31.4k | TRY_SPNG(spng_set_png_file(source->ctx, sinfo->input_file)); | 492 | | | 493 | 31.4k | TRY_SPNG(spng_get_ihdr(source->ctx, &ihdr)); | 494 | | | 495 | 31.4k | if (ihdr.width > JPEG_MAX_DIMENSION || ihdr.height > JPEG_MAX_DIMENSION) | 496 | 539 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, JPEG_MAX_DIMENSION); | 497 | 31.4k | if (ihdr.bit_depth != 8 && ihdr.bit_depth != 16) | 498 | 5.19k | ERREXIT(cinfo, JERR_PNG_BADDEPTH); | 499 | 31.4k | if (sinfo->max_pixels && | 500 | 24.3k | (unsigned long long)ihdr.width * ihdr.height > sinfo->max_pixels) | 501 | 357 | ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); | 502 | | | 503 | 31.4k | cinfo->image_width = (JDIMENSION)ihdr.width; | 504 | 31.4k | cinfo->image_height = (JDIMENSION)ihdr.height; | 505 | 31.4k | source->png_bit_depth = ihdr.bit_depth; | 506 | 31.4k | source->png_color_type = ihdr.color_type; | 507 | | | 508 | | /* initialize flags to most common settings */ | 509 | 31.4k | use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ | 510 | | | 511 | 31.4k | switch (ihdr.color_type) { | 512 | 1.35k | case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: | 513 | 9.88k | case SPNG_COLOR_TYPE_GRAYSCALE: | 514 | 9.88k | if (cinfo->in_color_space == JCS_UNKNOWN || | 515 | 9.88k | cinfo->in_color_space == JCS_RGB) | 516 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 517 | 9.88k | TRACEMS3(cinfo, 1, JTRC_PNG_GRAYSCALE, ihdr.width, ihdr.height, | 518 | 9.88k | ihdr.bit_depth); | 519 | 9.88k | if (cinfo->in_color_space == JCS_GRAYSCALE) { | 520 | 1.41k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE && | 521 | 1.21k | cinfo->data_precision == ihdr.bit_depth) { | 522 | 513 | source->pub.get_pixel_rows = get_raw_row; | 523 | 513 | use_raw_buffer = TRUE; | 524 | 513 | } else | 525 | 899 | source->pub.get_pixel_rows = get_gray_row; | 526 | 8.47k | } else if (IsExtRGB(cinfo->in_color_space)) | 527 | 7.06k | source->pub.get_pixel_rows = get_gray_rgb_row; | 528 | 1.41k | else if (cinfo->in_color_space == JCS_CMYK) | 529 | 1.41k | source->pub.get_pixel_rows = get_gray_cmyk_row; | 530 | 0 | else | 531 | 0 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 532 | 9.88k | if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) { | 533 | 1.35k | png_components = 2; | 534 | 1.35k | source->png_alpha = 1; | 535 | 8.52k | } else { | 536 | 8.52k | png_components = 1; | 537 | 8.52k | source->png_alpha = 0; | 538 | 8.52k | } | 539 | 9.88k | break; | 540 | | | 541 | 11.5k | case SPNG_COLOR_TYPE_TRUECOLOR: | 542 | 12.9k | case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: | 543 | 12.9k | if (cinfo->in_color_space == JCS_UNKNOWN) | 544 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 545 | 12.9k | TRACEMS3(cinfo, 1, JTRC_PNG_TRUECOLOR, ihdr.width, ihdr.height, | 546 | 12.9k | ihdr.bit_depth); | 547 | 12.9k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR && | 548 | 11.5k | cinfo->data_precision == ihdr.bit_depth && | 549 | 2.60k | #if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 | 550 | 2.60k | (cinfo->in_color_space == JCS_EXT_RGB || | 551 | 1.95k | cinfo->in_color_space == JCS_RGB)) { | 552 | | #else | 553 | | cinfo->in_color_space == JCS_EXT_RGB) { | 554 | | #endif | 555 | 650 | source->pub.get_pixel_rows = get_raw_row; | 556 | 650 | use_raw_buffer = TRUE; | 557 | 12.3k | } else if (IsExtRGB(cinfo->in_color_space)) | 558 | 8.63k | source->pub.get_pixel_rows = get_rgb_row; | 559 | 3.71k | else if (cinfo->in_color_space == JCS_CMYK) | 560 | 1.85k | source->pub.get_pixel_rows = get_rgb_cmyk_row; | 561 | 1.85k | else | 562 | 1.85k | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 563 | 12.9k | if (ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA) { | 564 | 1.25k | png_components = 4; | 565 | 1.25k | source->png_alpha = 1; | 566 | 11.7k | } else { | 567 | 11.7k | png_components = 3; | 568 | 11.7k | source->png_alpha = 0; | 569 | 11.7k | } | 570 | 12.9k | break; | 571 | | | 572 | 1.08k | case SPNG_COLOR_TYPE_INDEXED: | 573 | 1.08k | { | 574 | 1.08k | int i, gray = 1; | 575 | | | 576 | 1.08k | TRACEMS3(cinfo, 1, JTRC_PNG_INDEXED, ihdr.width, ihdr.height, | 577 | 1.08k | ihdr.bit_depth); | 578 | 1.08k | TRY_SPNG(spng_get_plte(source->ctx, &source->colormap)); | 579 | 1.08k | if (source->png_bit_depth != 8 || source->colormap.n_entries > 256) | 580 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 581 | | | 582 | 17.4k | for (i = 0; i < (int)source->colormap.n_entries; i++) { | 583 | 16.3k | if (source->colormap.entries[i].red != | 584 | 16.3k | source->colormap.entries[i].green || | 585 | 9.91k | source->colormap.entries[i].green != | 586 | 9.91k | source->colormap.entries[i].blue) | 587 | 7.27k | gray = 0; | 588 | 16.3k | } | 589 | | | 590 | 1.08k | if ((cinfo->in_color_space == JCS_UNKNOWN || | 591 | 441 | cinfo->in_color_space == JCS_RGB) && gray) | 592 | 0 | cinfo->in_color_space = JCS_GRAYSCALE; | 593 | 1.08k | else if (cinfo->in_color_space == JCS_UNKNOWN) | 594 | 0 | cinfo->in_color_space = JCS_EXT_RGB; | 595 | 1.08k | if (cinfo->in_color_space == JCS_GRAYSCALE && !gray) | 596 | 52 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); | 597 | | | 598 | 1.08k | source->pub.get_pixel_rows = get_indexed_row; | 599 | 1.08k | png_components = 1; | 600 | 1.08k | source->png_alpha = 0; | 601 | 1.08k | break; | 602 | 11.5k | } | 603 | | | 604 | 0 | default: | 605 | 0 | ERREXIT(cinfo, JERR_PNG_OUTOFRANGE); | 606 | 31.4k | } | 607 | | | 608 | 21.4k | if (IsExtRGB(cinfo->in_color_space)) | 609 | 16.6k | cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; | 610 | 4.75k | else if (cinfo->in_color_space == JCS_GRAYSCALE) | 611 | 1.42k | cinfo->input_components = 1; | 612 | 3.33k | else if (cinfo->in_color_space == JCS_CMYK) | 613 | 3.33k | cinfo->input_components = 4; | 614 | | | 615 | | /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ | 616 | 21.4k | source->buffer_width = | 617 | 21.4k | (size_t)ihdr.width * png_components * source->png_bit_depth / 8; | 618 | 21.4k | source->iobuffer = (unsigned char *) | 619 | 21.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 620 | 21.4k | source->buffer_width); | 621 | | | 622 | | /* Create compressor input buffer. */ | 623 | 21.4k | if (use_raw_buffer) { | 624 | | /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ | 625 | | /* Synthesize a _JSAMPARRAY pointer structure */ | 626 | 1.16k | source->pixrow = (_JSAMPROW)source->iobuffer; | 627 | 1.16k | source->pub._buffer = &source->pixrow; | 628 | 1.16k | source->pub.buffer_height = 1; | 629 | 20.2k | } else { | 630 | 20.2k | unsigned int maxval = source->png_bit_depth == 16 ? 65535 : 255; | 631 | 20.2k | size_t val, half_maxval; | 632 | | | 633 | | /* Need to translate anyway, so make a separate sample buffer. */ | 634 | 20.2k | source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 635 | 20.2k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 636 | 20.2k | (JDIMENSION)ihdr.width * cinfo->input_components, (JDIMENSION)1); | 637 | 20.2k | source->pub.buffer_height = 1; | 638 | | | 639 | | /* Compute the rescaling array. */ | 640 | 20.2k | source->rescale = (_JSAMPLE *) | 641 | 20.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 642 | 20.2k | (maxval + 1L) * sizeof(_JSAMPLE)); | 643 | 20.2k | memset(source->rescale, 0, (maxval + 1L) * sizeof(_JSAMPLE)); | 644 | 20.2k | half_maxval = maxval / 2; | 645 | 514M | for (val = 0; val <= maxval; val++) { | 646 | | /* The multiplication here must be done in 32 bits to avoid overflow */ | 647 | 514M | source->rescale[val] = | 648 | 514M | (_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) / | 649 | 514M | maxval); | 650 | 514M | } | 651 | 20.2k | } | 652 | | | 653 | 21.4k | TRY_SPNG(spng_decode_image(source->ctx, NULL, 0, SPNG_FMT_PNG, | 654 | 21.4k | SPNG_DECODE_PROGRESSIVE)); | 655 | 21.4k | } |
|
656 | | |
657 | | |
658 | | /* |
659 | | * Return the ICC profile (if any) embedded in the PNG image. |
660 | | */ |
661 | | |
662 | | METHODDEF(boolean) |
663 | | read_icc_profile_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo, |
664 | | JOCTET **icc_data_ptr, unsigned int *icc_data_len) |
665 | 40.9k | { |
666 | 40.9k | png_source_ptr source = (png_source_ptr)sinfo; |
667 | 40.9k | struct spng_iccp iccp; |
668 | | |
669 | 40.9k | if (!icc_data_ptr || !icc_data_len) |
670 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); |
671 | | |
672 | 40.9k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { |
673 | 200 | *icc_data_ptr = (JOCTET *)iccp.profile; |
674 | 200 | *icc_data_len = (unsigned int)iccp.profile_len; |
675 | 200 | return TRUE; |
676 | 200 | } |
677 | | |
678 | 40.7k | return FALSE; |
679 | 40.9k | } rdpng-8.c:read_icc_profile_png Line | Count | Source | 665 | 17.9k | { | 666 | 17.9k | png_source_ptr source = (png_source_ptr)sinfo; | 667 | 17.9k | struct spng_iccp iccp; | 668 | | | 669 | 17.9k | if (!icc_data_ptr || !icc_data_len) | 670 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 671 | | | 672 | 17.9k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 673 | 174 | *icc_data_ptr = (JOCTET *)iccp.profile; | 674 | 174 | *icc_data_len = (unsigned int)iccp.profile_len; | 675 | 174 | return TRUE; | 676 | 174 | } | 677 | | | 678 | 17.7k | return FALSE; | 679 | 17.9k | } |
rdpng-12.c:read_icc_profile_png Line | Count | Source | 665 | 15.3k | { | 666 | 15.3k | png_source_ptr source = (png_source_ptr)sinfo; | 667 | 15.3k | struct spng_iccp iccp; | 668 | | | 669 | 15.3k | if (!icc_data_ptr || !icc_data_len) | 670 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 671 | | | 672 | 15.3k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 673 | 13 | *icc_data_ptr = (JOCTET *)iccp.profile; | 674 | 13 | *icc_data_len = (unsigned int)iccp.profile_len; | 675 | 13 | return TRUE; | 676 | 13 | } | 677 | | | 678 | 15.3k | return FALSE; | 679 | 15.3k | } |
rdpng-16.c:read_icc_profile_png Line | Count | Source | 665 | 7.64k | { | 666 | 7.64k | png_source_ptr source = (png_source_ptr)sinfo; | 667 | 7.64k | struct spng_iccp iccp; | 668 | | | 669 | 7.64k | if (!icc_data_ptr || !icc_data_len) | 670 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); | 671 | | | 672 | 7.64k | if (source->ctx && spng_get_iccp(source->ctx, &iccp) == 0) { | 673 | 13 | *icc_data_ptr = (JOCTET *)iccp.profile; | 674 | 13 | *icc_data_len = (unsigned int)iccp.profile_len; | 675 | 13 | return TRUE; | 676 | 13 | } | 677 | | | 678 | 7.63k | return FALSE; | 679 | 7.64k | } |
|
680 | | |
681 | | |
682 | | /* |
683 | | * Finish up at the end of the file. |
684 | | */ |
685 | | |
686 | | METHODDEF(void) |
687 | | finish_input_png(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
688 | 191k | { |
689 | 191k | png_source_ptr source = (png_source_ptr)sinfo; |
690 | | |
691 | 191k | if (source->ctx) { |
692 | 191k | spng_decode_chunks(source->ctx); |
693 | 191k | spng_ctx_free(source->ctx); |
694 | 191k | source->ctx = NULL; |
695 | 191k | } |
696 | 191k | } rdpng-8.c:finish_input_png Line | Count | Source | 688 | 94.8k | { | 689 | 94.8k | png_source_ptr source = (png_source_ptr)sinfo; | 690 | | | 691 | 94.8k | if (source->ctx) { | 692 | 94.8k | spng_decode_chunks(source->ctx); | 693 | 94.8k | spng_ctx_free(source->ctx); | 694 | | source->ctx = NULL; | 695 | 94.8k | } | 696 | 94.8k | } |
rdpng-12.c:finish_input_png Line | Count | Source | 688 | 65.6k | { | 689 | 65.6k | png_source_ptr source = (png_source_ptr)sinfo; | 690 | | | 691 | 65.6k | if (source->ctx) { | 692 | 65.6k | spng_decode_chunks(source->ctx); | 693 | 65.6k | spng_ctx_free(source->ctx); | 694 | | source->ctx = NULL; | 695 | 65.6k | } | 696 | 65.6k | } |
rdpng-16.c:finish_input_png Line | Count | Source | 688 | 31.4k | { | 689 | 31.4k | png_source_ptr source = (png_source_ptr)sinfo; | 690 | | | 691 | 31.4k | if (source->ctx) { | 692 | 31.4k | spng_decode_chunks(source->ctx); | 693 | 31.4k | spng_ctx_free(source->ctx); | 694 | | source->ctx = NULL; | 695 | 31.4k | } | 696 | 31.4k | } |
|
697 | | |
698 | | |
699 | | /* |
700 | | * The module selection routine for PNG format input. |
701 | | */ |
702 | | |
703 | | GLOBAL(cjpeg_source_ptr) |
704 | | _jinit_read_png(j_compress_ptr cinfo) |
705 | 191k | { |
706 | 191k | png_source_ptr source; |
707 | | |
708 | | #if BITS_IN_JSAMPLE == 8 |
709 | 94.8k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
710 | | #else |
711 | 97.1k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
712 | 97.1k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
713 | 0 | #endif |
714 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
715 | | |
716 | | /* Create module interface object */ |
717 | 191k | source = (png_source_ptr) |
718 | 191k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
719 | 191k | sizeof(png_source_struct)); |
720 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
721 | 191k | source->pub.start_input = start_input_png; |
722 | 191k | source->pub.read_icc_profile = read_icc_profile_png; |
723 | 191k | source->pub.finish_input = finish_input_png; |
724 | 191k | source->pub.max_pixels = 0; |
725 | | |
726 | 191k | return (cjpeg_source_ptr)source; |
727 | 191k | } Line | Count | Source | 705 | 94.8k | { | 706 | 94.8k | png_source_ptr source; | 707 | | | 708 | 94.8k | #if BITS_IN_JSAMPLE == 8 | 709 | 94.8k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 710 | | #else | 711 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 712 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 713 | | #endif | 714 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 715 | | | 716 | | /* Create module interface object */ | 717 | 94.8k | source = (png_source_ptr) | 718 | 94.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 719 | 94.8k | sizeof(png_source_struct)); | 720 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 721 | 94.8k | source->pub.start_input = start_input_png; | 722 | 94.8k | source->pub.read_icc_profile = read_icc_profile_png; | 723 | 94.8k | source->pub.finish_input = finish_input_png; | 724 | 94.8k | source->pub.max_pixels = 0; | 725 | | | 726 | 94.8k | return (cjpeg_source_ptr)source; | 727 | 94.8k | } |
Line | Count | Source | 705 | 65.6k | { | 706 | 65.6k | png_source_ptr source; | 707 | | | 708 | | #if BITS_IN_JSAMPLE == 8 | 709 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 710 | | #else | 711 | 65.6k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 712 | 65.6k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 713 | 0 | #endif | 714 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 715 | | | 716 | | /* Create module interface object */ | 717 | 65.6k | source = (png_source_ptr) | 718 | 65.6k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 719 | 65.6k | sizeof(png_source_struct)); | 720 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 721 | 65.6k | source->pub.start_input = start_input_png; | 722 | 65.6k | source->pub.read_icc_profile = read_icc_profile_png; | 723 | 65.6k | source->pub.finish_input = finish_input_png; | 724 | 65.6k | source->pub.max_pixels = 0; | 725 | | | 726 | 65.6k | return (cjpeg_source_ptr)source; | 727 | 65.6k | } |
Line | Count | Source | 705 | 31.4k | { | 706 | 31.4k | png_source_ptr source; | 707 | | | 708 | | #if BITS_IN_JSAMPLE == 8 | 709 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 710 | | #else | 711 | 31.4k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 712 | 31.4k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 713 | 0 | #endif | 714 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 715 | | | 716 | | /* Create module interface object */ | 717 | 31.4k | source = (png_source_ptr) | 718 | 31.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 719 | 31.4k | sizeof(png_source_struct)); | 720 | | /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 721 | 31.4k | source->pub.start_input = start_input_png; | 722 | 31.4k | source->pub.read_icc_profile = read_icc_profile_png; | 723 | 31.4k | source->pub.finish_input = finish_input_png; | 724 | 31.4k | source->pub.max_pixels = 0; | 725 | | | 726 | 31.4k | return (cjpeg_source_ptr)source; | 727 | 31.4k | } |
|
728 | | |
729 | | #endif /* defined(PNG_SUPPORTED) && |
730 | | (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ |