OLD | NEW |
1 | 1 |
2 /* pngtrans.c - transforms the data in a row (used by both readers and writers) | 2 /* pngtrans.c - transforms the data in a row (used by both readers and writers) |
3 * | 3 * |
4 * Last changed in libpng 1.6.2 [April 25, 2013] | 4 * Last changed in libpng 1.2.41 [December 3, 2009] |
5 * Copyright (c) 1998-2013 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson |
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
8 * | 8 * |
9 * This code is released under the libpng license. | 9 * This code is released under the libpng license. |
10 * For conditions of distribution and use, see the disclaimer | 10 * For conditions of distribution and use, see the disclaimer |
11 * and license in png.h | 11 * and license in png.h |
12 */ | 12 */ |
13 | 13 |
14 #include "pngpriv.h" | 14 #define PNG_INTERNAL |
15 | 15 #define PNG_NO_PEDANTIC_WARNINGS |
| 16 #include "png.h" |
16 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 17 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
17 | 18 |
18 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 19 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
19 /* Turn on BGR-to-RGB mapping */ | 20 /* Turn on BGR-to-RGB mapping */ |
20 void PNGAPI | 21 void PNGAPI |
21 png_set_bgr(png_structrp png_ptr) | 22 png_set_bgr(png_structp png_ptr) |
22 { | 23 { |
23 png_debug(1, "in png_set_bgr"); | 24 png_debug(1, "in png_set_bgr"); |
24 | 25 |
25 if (png_ptr == NULL) | 26 if (png_ptr == NULL) |
26 return; | 27 return; |
27 | |
28 png_ptr->transformations |= PNG_BGR; | 28 png_ptr->transformations |= PNG_BGR; |
29 } | 29 } |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | 32 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) |
33 /* Turn on 16 bit byte swapping */ | 33 /* Turn on 16 bit byte swapping */ |
34 void PNGAPI | 34 void PNGAPI |
35 png_set_swap(png_structrp png_ptr) | 35 png_set_swap(png_structp png_ptr) |
36 { | 36 { |
37 png_debug(1, "in png_set_swap"); | 37 png_debug(1, "in png_set_swap"); |
38 | 38 |
39 if (png_ptr == NULL) | 39 if (png_ptr == NULL) |
40 return; | 40 return; |
41 | |
42 if (png_ptr->bit_depth == 16) | 41 if (png_ptr->bit_depth == 16) |
43 png_ptr->transformations |= PNG_SWAP_BYTES; | 42 png_ptr->transformations |= PNG_SWAP_BYTES; |
44 } | 43 } |
45 #endif | 44 #endif |
46 | 45 |
47 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) | 46 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) |
48 /* Turn on pixel packing */ | 47 /* Turn on pixel packing */ |
49 void PNGAPI | 48 void PNGAPI |
50 png_set_packing(png_structrp png_ptr) | 49 png_set_packing(png_structp png_ptr) |
51 { | 50 { |
52 png_debug(1, "in png_set_packing"); | 51 png_debug(1, "in png_set_packing"); |
53 | 52 |
54 if (png_ptr == NULL) | 53 if (png_ptr == NULL) |
55 return; | 54 return; |
56 | |
57 if (png_ptr->bit_depth < 8) | 55 if (png_ptr->bit_depth < 8) |
58 { | 56 { |
59 png_ptr->transformations |= PNG_PACK; | 57 png_ptr->transformations |= PNG_PACK; |
60 png_ptr->usr_bit_depth = 8; | 58 png_ptr->usr_bit_depth = 8; |
61 } | 59 } |
62 } | 60 } |
63 #endif | 61 #endif |
64 | 62 |
65 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 63 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
66 /* Turn on packed pixel swapping */ | 64 /* Turn on packed pixel swapping */ |
67 void PNGAPI | 65 void PNGAPI |
68 png_set_packswap(png_structrp png_ptr) | 66 png_set_packswap(png_structp png_ptr) |
69 { | 67 { |
70 png_debug(1, "in png_set_packswap"); | 68 png_debug(1, "in png_set_packswap"); |
71 | 69 |
72 if (png_ptr == NULL) | 70 if (png_ptr == NULL) |
73 return; | 71 return; |
74 | |
75 if (png_ptr->bit_depth < 8) | 72 if (png_ptr->bit_depth < 8) |
76 png_ptr->transformations |= PNG_PACKSWAP; | 73 png_ptr->transformations |= PNG_PACKSWAP; |
77 } | 74 } |
78 #endif | 75 #endif |
79 | 76 |
80 #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) | 77 #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) |
81 void PNGAPI | 78 void PNGAPI |
82 png_set_shift(png_structrp png_ptr, png_const_color_8p true_bits) | 79 png_set_shift(png_structp png_ptr, png_color_8p true_bits) |
83 { | 80 { |
84 png_debug(1, "in png_set_shift"); | 81 png_debug(1, "in png_set_shift"); |
85 | 82 |
86 if (png_ptr == NULL) | 83 if (png_ptr == NULL) |
87 return; | 84 return; |
88 | |
89 png_ptr->transformations |= PNG_SHIFT; | 85 png_ptr->transformations |= PNG_SHIFT; |
90 png_ptr->shift = *true_bits; | 86 png_ptr->shift = *true_bits; |
91 } | 87 } |
92 #endif | 88 #endif |
93 | 89 |
94 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ | 90 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ |
95 defined(PNG_WRITE_INTERLACING_SUPPORTED) | 91 defined(PNG_WRITE_INTERLACING_SUPPORTED) |
96 int PNGAPI | 92 int PNGAPI |
97 png_set_interlace_handling(png_structrp png_ptr) | 93 png_set_interlace_handling(png_structp png_ptr) |
98 { | 94 { |
99 png_debug(1, "in png_set_interlace handling"); | 95 png_debug(1, "in png_set_interlace handling"); |
100 | 96 |
101 if (png_ptr && png_ptr->interlaced) | 97 if (png_ptr && png_ptr->interlaced) |
102 { | 98 { |
103 png_ptr->transformations |= PNG_INTERLACE; | 99 png_ptr->transformations |= PNG_INTERLACE; |
104 return (7); | 100 return (7); |
105 } | 101 } |
106 | 102 |
107 return (1); | 103 return (1); |
108 } | 104 } |
109 #endif | 105 #endif |
110 | 106 |
111 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) | 107 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) |
112 /* Add a filler byte on read, or remove a filler or alpha byte on write. | 108 /* Add a filler byte on read, or remove a filler or alpha byte on write. |
113 * The filler type has changed in v0.95 to allow future 2-byte fillers | 109 * The filler type has changed in v0.95 to allow future 2-byte fillers |
114 * for 48-bit input data, as well as to avoid problems with some compilers | 110 * for 48-bit input data, as well as to avoid problems with some compilers |
115 * that don't like bytes as parameters. | 111 * that don't like bytes as parameters. |
116 */ | 112 */ |
117 void PNGAPI | 113 void PNGAPI |
118 png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc) | 114 png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) |
119 { | 115 { |
120 png_debug(1, "in png_set_filler"); | 116 png_debug(1, "in png_set_filler"); |
121 | 117 |
122 if (png_ptr == NULL) | 118 if (png_ptr == NULL) |
123 return; | 119 return; |
| 120 png_ptr->transformations |= PNG_FILLER; |
| 121 #ifdef PNG_LEGACY_SUPPORTED |
| 122 png_ptr->filler = (png_byte)filler; |
| 123 #else |
| 124 png_ptr->filler = (png_uint_16)filler; |
| 125 #endif |
| 126 if (filler_loc == PNG_FILLER_AFTER) |
| 127 png_ptr->flags |= PNG_FLAG_FILLER_AFTER; |
| 128 else |
| 129 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; |
124 | 130 |
125 /* In libpng 1.6 it is possible to determine whether this is a read or write | 131 /* This should probably go in the "do_read_filler" routine. |
126 * operation and therefore to do more checking here for a valid call. | 132 * I attempted to do that in libpng-1.0.1a but that caused problems |
127 */ | 133 * so I restored it in libpng-1.0.2a |
128 if (png_ptr->mode & PNG_IS_READ_STRUCT) | 134 */ |
| 135 |
| 136 if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) |
129 { | 137 { |
130 # ifdef PNG_READ_FILLER_SUPPORTED | 138 png_ptr->usr_channels = 4; |
131 /* On read png_set_filler is always valid, regardless of the base PNG | |
132 * format, because other transformations can give a format where the | |
133 * filler code can execute (basically an 8 or 16-bit component RGB or G | |
134 * format.) | |
135 * | |
136 * NOTE: usr_channels is not used by the read code! (This has led to | |
137 * confusion in the past.) The filler is only used in the read code. | |
138 */ | |
139 png_ptr->filler = (png_uint_16)filler; | |
140 # else | |
141 png_app_error(png_ptr, "png_set_filler not supported on read"); | |
142 PNG_UNUSED(filler) /* not used in the write case */ | |
143 return; | |
144 # endif | |
145 } | 139 } |
146 | 140 |
147 else /* write */ | 141 /* Also I added this in libpng-1.0.2a (what happens when we expand |
| 142 * a less-than-8-bit grayscale to GA? */ |
| 143 |
| 144 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8) |
148 { | 145 { |
149 # ifdef PNG_WRITE_FILLER_SUPPORTED | 146 png_ptr->usr_channels = 2; |
150 /* On write the usr_channels parameter must be set correctly at the | |
151 * start to record the number of channels in the app-supplied data. | |
152 */ | |
153 switch (png_ptr->color_type) | |
154 { | |
155 case PNG_COLOR_TYPE_RGB: | |
156 png_ptr->usr_channels = 4; | |
157 break; | |
158 | |
159 case PNG_COLOR_TYPE_GRAY: | |
160 if (png_ptr->bit_depth >= 8) | |
161 { | |
162 png_ptr->usr_channels = 2; | |
163 break; | |
164 } | |
165 | |
166 else | |
167 { | |
168 /* There simply isn't any code in libpng to strip out bits | |
169 * from bytes when the components are less than a byte in | |
170 * size! | |
171 */ | |
172 png_app_error(png_ptr, | |
173 "png_set_filler is invalid for low bit depth gray output"); | |
174 return; | |
175 } | |
176 | |
177 default: | |
178 png_app_error(png_ptr, | |
179 "png_set_filler: inappropriate color type"); | |
180 return; | |
181 } | |
182 # else | |
183 png_app_error(png_ptr, "png_set_filler not supported on write"); | |
184 return; | |
185 # endif | |
186 } | 147 } |
187 | |
188 /* Here on success - libpng supports the operation, set the transformation | |
189 * and the flag to say where the filler channel is. | |
190 */ | |
191 png_ptr->transformations |= PNG_FILLER; | |
192 | |
193 if (filler_loc == PNG_FILLER_AFTER) | |
194 png_ptr->flags |= PNG_FLAG_FILLER_AFTER; | |
195 | |
196 else | |
197 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; | |
198 } | 148 } |
199 | 149 |
| 150 #ifndef PNG_1_0_X |
200 /* Added to libpng-1.2.7 */ | 151 /* Added to libpng-1.2.7 */ |
201 void PNGAPI | 152 void PNGAPI |
202 png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc) | 153 png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) |
203 { | 154 { |
204 png_debug(1, "in png_set_add_alpha"); | 155 png_debug(1, "in png_set_add_alpha"); |
205 | 156 |
206 if (png_ptr == NULL) | 157 if (png_ptr == NULL) |
207 return; | 158 return; |
208 | |
209 png_set_filler(png_ptr, filler, filler_loc); | 159 png_set_filler(png_ptr, filler, filler_loc); |
210 /* The above may fail to do anything. */ | 160 png_ptr->transformations |= PNG_ADD_ALPHA; |
211 if (png_ptr->transformations & PNG_FILLER) | |
212 png_ptr->transformations |= PNG_ADD_ALPHA; | |
213 } | 161 } |
| 162 #endif |
214 | 163 |
215 #endif | 164 #endif |
216 | 165 |
217 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ | 166 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ |
218 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) | 167 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
219 void PNGAPI | 168 void PNGAPI |
220 png_set_swap_alpha(png_structrp png_ptr) | 169 png_set_swap_alpha(png_structp png_ptr) |
221 { | 170 { |
222 png_debug(1, "in png_set_swap_alpha"); | 171 png_debug(1, "in png_set_swap_alpha"); |
223 | 172 |
224 if (png_ptr == NULL) | 173 if (png_ptr == NULL) |
225 return; | 174 return; |
226 | |
227 png_ptr->transformations |= PNG_SWAP_ALPHA; | 175 png_ptr->transformations |= PNG_SWAP_ALPHA; |
228 } | 176 } |
229 #endif | 177 #endif |
230 | 178 |
231 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ | 179 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ |
232 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) | 180 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
233 void PNGAPI | 181 void PNGAPI |
234 png_set_invert_alpha(png_structrp png_ptr) | 182 png_set_invert_alpha(png_structp png_ptr) |
235 { | 183 { |
236 png_debug(1, "in png_set_invert_alpha"); | 184 png_debug(1, "in png_set_invert_alpha"); |
237 | 185 |
238 if (png_ptr == NULL) | 186 if (png_ptr == NULL) |
239 return; | 187 return; |
240 | |
241 png_ptr->transformations |= PNG_INVERT_ALPHA; | 188 png_ptr->transformations |= PNG_INVERT_ALPHA; |
242 } | 189 } |
243 #endif | 190 #endif |
244 | 191 |
245 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) | 192 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) |
246 void PNGAPI | 193 void PNGAPI |
247 png_set_invert_mono(png_structrp png_ptr) | 194 png_set_invert_mono(png_structp png_ptr) |
248 { | 195 { |
249 png_debug(1, "in png_set_invert_mono"); | 196 png_debug(1, "in png_set_invert_mono"); |
250 | 197 |
251 if (png_ptr == NULL) | 198 if (png_ptr == NULL) |
252 return; | 199 return; |
253 | |
254 png_ptr->transformations |= PNG_INVERT_MONO; | 200 png_ptr->transformations |= PNG_INVERT_MONO; |
255 } | 201 } |
256 | 202 |
257 /* Invert monochrome grayscale data */ | 203 /* Invert monochrome grayscale data */ |
258 void /* PRIVATE */ | 204 void /* PRIVATE */ |
259 png_do_invert(png_row_infop row_info, png_bytep row) | 205 png_do_invert(png_row_infop row_info, png_bytep row) |
260 { | 206 { |
261 png_debug(1, "in png_do_invert"); | 207 png_debug(1, "in png_do_invert"); |
262 | 208 |
263 /* This test removed from libpng version 1.0.13 and 1.2.0: | 209 /* This test removed from libpng version 1.0.13 and 1.2.0: |
264 * if (row_info->bit_depth == 1 && | 210 * if (row_info->bit_depth == 1 && |
265 */ | 211 */ |
| 212 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 213 if (row == NULL || row_info == NULL) |
| 214 return; |
| 215 #endif |
266 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) | 216 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) |
267 { | 217 { |
268 png_bytep rp = row; | 218 png_bytep rp = row; |
269 png_size_t i; | 219 png_uint_32 i; |
270 png_size_t istop = row_info->rowbytes; | 220 png_uint_32 istop = row_info->rowbytes; |
271 | 221 |
272 for (i = 0; i < istop; i++) | 222 for (i = 0; i < istop; i++) |
273 { | 223 { |
274 *rp = (png_byte)(~(*rp)); | 224 *rp = (png_byte)(~(*rp)); |
275 rp++; | 225 rp++; |
276 } | 226 } |
277 } | 227 } |
278 | |
279 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && | 228 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && |
280 row_info->bit_depth == 8) | 229 row_info->bit_depth == 8) |
281 { | 230 { |
282 png_bytep rp = row; | 231 png_bytep rp = row; |
283 png_size_t i; | 232 png_uint_32 i; |
284 png_size_t istop = row_info->rowbytes; | 233 png_uint_32 istop = row_info->rowbytes; |
285 | 234 |
286 for (i = 0; i < istop; i += 2) | 235 for (i = 0; i < istop; i+=2) |
287 { | 236 { |
288 *rp = (png_byte)(~(*rp)); | 237 *rp = (png_byte)(~(*rp)); |
289 rp += 2; | 238 rp+=2; |
290 } | 239 } |
291 } | 240 } |
292 | |
293 #ifdef PNG_16BIT_SUPPORTED | |
294 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && | 241 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && |
295 row_info->bit_depth == 16) | 242 row_info->bit_depth == 16) |
296 { | 243 { |
297 png_bytep rp = row; | 244 png_bytep rp = row; |
298 png_size_t i; | 245 png_uint_32 i; |
299 png_size_t istop = row_info->rowbytes; | 246 png_uint_32 istop = row_info->rowbytes; |
300 | 247 |
301 for (i = 0; i < istop; i += 4) | 248 for (i = 0; i < istop; i+=4) |
302 { | 249 { |
303 *rp = (png_byte)(~(*rp)); | 250 *rp = (png_byte)(~(*rp)); |
304 *(rp + 1) = (png_byte)(~(*(rp + 1))); | 251 *(rp+1) = (png_byte)(~(*(rp+1))); |
305 rp += 4; | 252 rp+=4; |
306 } | 253 } |
307 } | 254 } |
308 #endif | |
309 } | 255 } |
310 #endif | 256 #endif |
311 | 257 |
312 #ifdef PNG_16BIT_SUPPORTED | |
313 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | 258 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) |
314 /* Swaps byte order on 16 bit depth images */ | 259 /* Swaps byte order on 16 bit depth images */ |
315 void /* PRIVATE */ | 260 void /* PRIVATE */ |
316 png_do_swap(png_row_infop row_info, png_bytep row) | 261 png_do_swap(png_row_infop row_info, png_bytep row) |
317 { | 262 { |
318 png_debug(1, "in png_do_swap"); | 263 png_debug(1, "in png_do_swap"); |
319 | 264 |
320 if (row_info->bit_depth == 16) | 265 if ( |
| 266 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 267 row != NULL && row_info != NULL && |
| 268 #endif |
| 269 row_info->bit_depth == 16) |
321 { | 270 { |
322 png_bytep rp = row; | 271 png_bytep rp = row; |
323 png_uint_32 i; | 272 png_uint_32 i; |
324 png_uint_32 istop= row_info->width * row_info->channels; | 273 png_uint_32 istop= row_info->width * row_info->channels; |
325 | 274 |
326 for (i = 0; i < istop; i++, rp += 2) | 275 for (i = 0; i < istop; i++, rp += 2) |
327 { | 276 { |
328 png_byte t = *rp; | 277 png_byte t = *rp; |
329 *rp = *(rp + 1); | 278 *rp = *(rp + 1); |
330 *(rp + 1) = t; | 279 *(rp + 1) = t; |
331 } | 280 } |
332 } | 281 } |
333 } | 282 } |
334 #endif | 283 #endif |
335 #endif | |
336 | 284 |
337 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 285 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
338 static PNG_CONST png_byte onebppswaptable[256] = { | 286 static PNG_CONST png_byte onebppswaptable[256] = { |
339 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, | 287 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, |
340 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, | 288 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, |
341 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, | 289 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, |
342 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, | 290 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, |
343 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, | 291 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, |
344 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, | 292 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, |
345 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, | 293 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, | 387 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, |
440 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF | 388 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF |
441 }; | 389 }; |
442 | 390 |
443 /* Swaps pixel packing order within bytes */ | 391 /* Swaps pixel packing order within bytes */ |
444 void /* PRIVATE */ | 392 void /* PRIVATE */ |
445 png_do_packswap(png_row_infop row_info, png_bytep row) | 393 png_do_packswap(png_row_infop row_info, png_bytep row) |
446 { | 394 { |
447 png_debug(1, "in png_do_packswap"); | 395 png_debug(1, "in png_do_packswap"); |
448 | 396 |
449 if (row_info->bit_depth < 8) | 397 if ( |
| 398 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 399 row != NULL && row_info != NULL && |
| 400 #endif |
| 401 row_info->bit_depth < 8) |
450 { | 402 { |
451 png_bytep rp; | 403 png_bytep rp, end, table; |
452 png_const_bytep end, table; | |
453 | 404 |
454 end = row + row_info->rowbytes; | 405 end = row + row_info->rowbytes; |
455 | 406 |
456 if (row_info->bit_depth == 1) | 407 if (row_info->bit_depth == 1) |
457 table = onebppswaptable; | 408 table = (png_bytep)onebppswaptable; |
458 | |
459 else if (row_info->bit_depth == 2) | 409 else if (row_info->bit_depth == 2) |
460 table = twobppswaptable; | 410 table = (png_bytep)twobppswaptable; |
461 | |
462 else if (row_info->bit_depth == 4) | 411 else if (row_info->bit_depth == 4) |
463 table = fourbppswaptable; | 412 table = (png_bytep)fourbppswaptable; |
464 | |
465 else | 413 else |
466 return; | 414 return; |
467 | 415 |
468 for (rp = row; rp < end; rp++) | 416 for (rp = row; rp < end; rp++) |
469 *rp = table[*rp]; | 417 *rp = table[*rp]; |
470 } | 418 } |
471 } | 419 } |
472 #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ | 420 #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ |
473 | 421 |
474 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ | 422 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ |
475 defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 423 defined(PNG_READ_STRIP_ALPHA_SUPPORTED) |
476 /* Remove a channel - this used to be 'png_do_strip_filler' but it used a | 424 /* Remove filler or alpha byte(s) */ |
477 * somewhat weird combination of flags to determine what to do. All the calls | |
478 * to png_do_strip_filler are changed in 1.5.2 to call this instead with the | |
479 * correct arguments. | |
480 * | |
481 * The routine isn't general - the channel must be the channel at the start or | |
482 * end (not in the middle) of each pixel. | |
483 */ | |
484 void /* PRIVATE */ | 425 void /* PRIVATE */ |
485 png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) | 426 png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) |
486 { | 427 { |
487 png_bytep sp = row; /* source pointer */ | 428 png_debug(1, "in png_do_strip_filler"); |
488 png_bytep dp = row; /* destination pointer */ | |
489 png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */ | |
490 | 429 |
491 /* At the start sp will point to the first byte to copy and dp to where | 430 #ifdef PNG_USELESS_TESTS_SUPPORTED |
492 * it is copied to. ep always points just beyond the end of the row, so | 431 if (row != NULL && row_info != NULL) |
493 * the loop simply copies (channels-1) channels until sp reaches ep. | 432 #endif |
494 * | 433 { |
495 * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. | 434 png_bytep sp=row; |
496 * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. | 435 png_bytep dp=row; |
497 */ | 436 png_uint_32 row_width=row_info->width; |
| 437 png_uint_32 i; |
498 | 438 |
499 /* GA, GX, XG cases */ | 439 if ((row_info->color_type == PNG_COLOR_TYPE_RGB || |
500 if (row_info->channels == 2) | 440 (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && |
501 { | 441 (flags & PNG_FLAG_STRIP_ALPHA))) && |
502 if (row_info->bit_depth == 8) | 442 row_info->channels == 4) |
503 { | 443 { |
504 if (at_start) /* Skip initial filler */ | 444 if (row_info->bit_depth == 8) |
505 ++sp; | 445 { |
506 else /* Skip initial channel and, for sp, the filler */ | 446 /* This converts from RGBX or RGBA to RGB */ |
507 sp += 2, ++dp; | 447 if (flags & PNG_FLAG_FILLER_AFTER) |
| 448 { |
| 449 dp+=3; sp+=4; |
| 450 for (i = 1; i < row_width; i++) |
| 451 { |
| 452 *dp++ = *sp++; |
| 453 *dp++ = *sp++; |
| 454 *dp++ = *sp++; |
| 455 sp++; |
| 456 } |
| 457 } |
| 458 /* This converts from XRGB or ARGB to RGB */ |
| 459 else |
| 460 { |
| 461 for (i = 0; i < row_width; i++) |
| 462 { |
| 463 sp++; |
| 464 *dp++ = *sp++; |
| 465 *dp++ = *sp++; |
| 466 *dp++ = *sp++; |
| 467 } |
| 468 } |
| 469 row_info->pixel_depth = 24; |
| 470 row_info->rowbytes = row_width * 3; |
| 471 } |
| 472 else /* if (row_info->bit_depth == 16) */ |
| 473 { |
| 474 if (flags & PNG_FLAG_FILLER_AFTER) |
| 475 { |
| 476 /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */ |
| 477 sp += 8; dp += 6; |
| 478 for (i = 1; i < row_width; i++) |
| 479 { |
| 480 /* This could be (although png_memcpy is probably slower): |
| 481 png_memcpy(dp, sp, 6); |
| 482 sp += 8; |
| 483 dp += 6; |
| 484 */ |
508 | 485 |
509 /* For a 1 pixel wide image there is nothing to do */ | 486 *dp++ = *sp++; |
510 while (sp < ep) | 487 *dp++ = *sp++; |
511 *dp++ = *sp, sp += 2; | 488 *dp++ = *sp++; |
| 489 *dp++ = *sp++; |
| 490 *dp++ = *sp++; |
| 491 *dp++ = *sp++; |
| 492 sp += 2; |
| 493 } |
| 494 } |
| 495 else |
| 496 { |
| 497 /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */ |
| 498 for (i = 0; i < row_width; i++) |
| 499 { |
| 500 /* This could be (although png_memcpy is probably slower): |
| 501 png_memcpy(dp, sp, 6); |
| 502 sp += 8; |
| 503 dp += 6; |
| 504 */ |
512 | 505 |
513 row_info->pixel_depth = 8; | 506 sp+=2; |
| 507 *dp++ = *sp++; |
| 508 *dp++ = *sp++; |
| 509 *dp++ = *sp++; |
| 510 *dp++ = *sp++; |
| 511 *dp++ = *sp++; |
| 512 *dp++ = *sp++; |
| 513 } |
| 514 } |
| 515 row_info->pixel_depth = 48; |
| 516 row_info->rowbytes = row_width * 6; |
| 517 } |
| 518 row_info->channels = 3; |
514 } | 519 } |
515 | 520 else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY || |
516 else if (row_info->bit_depth == 16) | 521 (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && |
| 522 (flags & PNG_FLAG_STRIP_ALPHA))) && |
| 523 row_info->channels == 2) |
517 { | 524 { |
518 if (at_start) /* Skip initial filler */ | 525 if (row_info->bit_depth == 8) |
519 sp += 2; | 526 { |
520 else /* Skip initial channel and, for sp, the filler */ | 527 /* This converts from GX or GA to G */ |
521 sp += 4, dp += 2; | 528 if (flags & PNG_FLAG_FILLER_AFTER) |
522 | 529 { |
523 while (sp < ep) | 530 for (i = 0; i < row_width; i++) |
524 *dp++ = *sp++, *dp++ = *sp, sp += 3; | 531 { |
525 | 532 *dp++ = *sp++; |
526 row_info->pixel_depth = 16; | 533 sp++; |
| 534 } |
| 535 } |
| 536 /* This converts from XG or AG to G */ |
| 537 else |
| 538 { |
| 539 for (i = 0; i < row_width; i++) |
| 540 { |
| 541 sp++; |
| 542 *dp++ = *sp++; |
| 543 } |
| 544 } |
| 545 row_info->pixel_depth = 8; |
| 546 row_info->rowbytes = row_width; |
| 547 } |
| 548 else /* if (row_info->bit_depth == 16) */ |
| 549 { |
| 550 if (flags & PNG_FLAG_FILLER_AFTER) |
| 551 { |
| 552 /* This converts from GGXX or GGAA to GG */ |
| 553 sp += 4; dp += 2; |
| 554 for (i = 1; i < row_width; i++) |
| 555 { |
| 556 *dp++ = *sp++; |
| 557 *dp++ = *sp++; |
| 558 sp += 2; |
| 559 } |
| 560 } |
| 561 else |
| 562 { |
| 563 /* This converts from XXGG or AAGG to GG */ |
| 564 for (i = 0; i < row_width; i++) |
| 565 { |
| 566 sp += 2; |
| 567 *dp++ = *sp++; |
| 568 *dp++ = *sp++; |
| 569 } |
| 570 } |
| 571 row_info->pixel_depth = 16; |
| 572 row_info->rowbytes = row_width * 2; |
| 573 } |
| 574 row_info->channels = 1; |
527 } | 575 } |
528 | 576 if (flags & PNG_FLAG_STRIP_ALPHA) |
529 else | 577 row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; |
530 return; /* bad bit depth */ | |
531 | |
532 row_info->channels = 1; | |
533 | |
534 /* Finally fix the color type if it records an alpha channel */ | |
535 if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | |
536 row_info->color_type = PNG_COLOR_TYPE_GRAY; | |
537 } | 578 } |
538 | |
539 /* RGBA, RGBX, XRGB cases */ | |
540 else if (row_info->channels == 4) | |
541 { | |
542 if (row_info->bit_depth == 8) | |
543 { | |
544 if (at_start) /* Skip initial filler */ | |
545 ++sp; | |
546 else /* Skip initial channels and, for sp, the filler */ | |
547 sp += 4, dp += 3; | |
548 | |
549 /* Note that the loop adds 3 to dp and 4 to sp each time. */ | |
550 while (sp < ep) | |
551 *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; | |
552 | |
553 row_info->pixel_depth = 24; | |
554 } | |
555 | |
556 else if (row_info->bit_depth == 16) | |
557 { | |
558 if (at_start) /* Skip initial filler */ | |
559 sp += 2; | |
560 else /* Skip initial channels and, for sp, the filler */ | |
561 sp += 8, dp += 6; | |
562 | |
563 while (sp < ep) | |
564 { | |
565 /* Copy 6 bytes, skip 2 */ | |
566 *dp++ = *sp++, *dp++ = *sp++; | |
567 *dp++ = *sp++, *dp++ = *sp++; | |
568 *dp++ = *sp++, *dp++ = *sp, sp += 3; | |
569 } | |
570 | |
571 row_info->pixel_depth = 48; | |
572 } | |
573 | |
574 else | |
575 return; /* bad bit depth */ | |
576 | |
577 row_info->channels = 3; | |
578 | |
579 /* Finally fix the color type if it records an alpha channel */ | |
580 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | |
581 row_info->color_type = PNG_COLOR_TYPE_RGB; | |
582 } | |
583 | |
584 else | |
585 return; /* The filler channel has gone already */ | |
586 | |
587 /* Fix the rowbytes value. */ | |
588 row_info->rowbytes = dp-row; | |
589 } | 579 } |
590 #endif | 580 #endif |
591 | 581 |
592 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 582 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
593 /* Swaps red and blue bytes within a pixel */ | 583 /* Swaps red and blue bytes within a pixel */ |
594 void /* PRIVATE */ | 584 void /* PRIVATE */ |
595 png_do_bgr(png_row_infop row_info, png_bytep row) | 585 png_do_bgr(png_row_infop row_info, png_bytep row) |
596 { | 586 { |
597 png_debug(1, "in png_do_bgr"); | 587 png_debug(1, "in png_do_bgr"); |
598 | 588 |
599 if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) | 589 if ( |
| 590 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 591 row != NULL && row_info != NULL && |
| 592 #endif |
| 593 (row_info->color_type & PNG_COLOR_MASK_COLOR)) |
600 { | 594 { |
601 png_uint_32 row_width = row_info->width; | 595 png_uint_32 row_width = row_info->width; |
602 if (row_info->bit_depth == 8) | 596 if (row_info->bit_depth == 8) |
603 { | 597 { |
604 if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 598 if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
605 { | 599 { |
606 png_bytep rp; | 600 png_bytep rp; |
607 png_uint_32 i; | 601 png_uint_32 i; |
608 | 602 |
609 for (i = 0, rp = row; i < row_width; i++, rp += 3) | 603 for (i = 0, rp = row; i < row_width; i++, rp += 3) |
610 { | 604 { |
611 png_byte save = *rp; | 605 png_byte save = *rp; |
612 *rp = *(rp + 2); | 606 *rp = *(rp + 2); |
613 *(rp + 2) = save; | 607 *(rp + 2) = save; |
614 } | 608 } |
615 } | 609 } |
616 | |
617 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 610 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
618 { | 611 { |
619 png_bytep rp; | 612 png_bytep rp; |
620 png_uint_32 i; | 613 png_uint_32 i; |
621 | 614 |
622 for (i = 0, rp = row; i < row_width; i++, rp += 4) | 615 for (i = 0, rp = row; i < row_width; i++, rp += 4) |
623 { | 616 { |
624 png_byte save = *rp; | 617 png_byte save = *rp; |
625 *rp = *(rp + 2); | 618 *rp = *(rp + 2); |
626 *(rp + 2) = save; | 619 *(rp + 2) = save; |
627 } | 620 } |
628 } | 621 } |
629 } | 622 } |
630 | |
631 #ifdef PNG_16BIT_SUPPORTED | |
632 else if (row_info->bit_depth == 16) | 623 else if (row_info->bit_depth == 16) |
633 { | 624 { |
634 if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 625 if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
635 { | 626 { |
636 png_bytep rp; | 627 png_bytep rp; |
637 png_uint_32 i; | 628 png_uint_32 i; |
638 | 629 |
639 for (i = 0, rp = row; i < row_width; i++, rp += 6) | 630 for (i = 0, rp = row; i < row_width; i++, rp += 6) |
640 { | 631 { |
641 png_byte save = *rp; | 632 png_byte save = *rp; |
642 *rp = *(rp + 4); | 633 *rp = *(rp + 4); |
643 *(rp + 4) = save; | 634 *(rp + 4) = save; |
644 save = *(rp + 1); | 635 save = *(rp + 1); |
645 *(rp + 1) = *(rp + 5); | 636 *(rp + 1) = *(rp + 5); |
646 *(rp + 5) = save; | 637 *(rp + 5) = save; |
647 } | 638 } |
648 } | 639 } |
649 | |
650 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 640 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
651 { | 641 { |
652 png_bytep rp; | 642 png_bytep rp; |
653 png_uint_32 i; | 643 png_uint_32 i; |
654 | 644 |
655 for (i = 0, rp = row; i < row_width; i++, rp += 8) | 645 for (i = 0, rp = row; i < row_width; i++, rp += 8) |
656 { | 646 { |
657 png_byte save = *rp; | 647 png_byte save = *rp; |
658 *rp = *(rp + 4); | 648 *rp = *(rp + 4); |
659 *(rp + 4) = save; | 649 *(rp + 4) = save; |
660 save = *(rp + 1); | 650 save = *(rp + 1); |
661 *(rp + 1) = *(rp + 5); | 651 *(rp + 1) = *(rp + 5); |
662 *(rp + 5) = save; | 652 *(rp + 5) = save; |
663 } | 653 } |
664 } | 654 } |
665 } | 655 } |
666 #endif | |
667 } | 656 } |
668 } | 657 } |
669 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ | 658 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ |
670 | 659 |
671 #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ | |
672 defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) | |
673 /* Added at libpng-1.5.10 */ | |
674 void /* PRIVATE */ | |
675 png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) | |
676 { | |
677 if (png_ptr->num_palette < (1 << row_info->bit_depth) && | |
678 png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ | |
679 { | |
680 /* Calculations moved outside switch in an attempt to stop different | |
681 * compiler warnings. 'padding' is in *bits* within the last byte, it is | |
682 * an 'int' because pixel_depth becomes an 'int' in the expression below, | |
683 * and this calculation is used because it avoids warnings that other | |
684 * forms produced on either GCC or MSVC. | |
685 */ | |
686 int padding = (-row_info->pixel_depth * row_info->width) & 7; | |
687 png_bytep rp = png_ptr->row_buf + row_info->rowbytes; | |
688 | |
689 switch (row_info->bit_depth) | |
690 { | |
691 case 1: | |
692 { | |
693 /* in this case, all bytes must be 0 so we don't need | |
694 * to unpack the pixels except for the rightmost one. | |
695 */ | |
696 for (; rp > png_ptr->row_buf; rp--) | |
697 { | |
698 if (*rp >> padding != 0) | |
699 png_ptr->num_palette_max = 1; | |
700 padding = 0; | |
701 } | |
702 | |
703 break; | |
704 } | |
705 | |
706 case 2: | |
707 { | |
708 for (; rp > png_ptr->row_buf; rp--) | |
709 { | |
710 int i = ((*rp >> padding) & 0x03); | |
711 | |
712 if (i > png_ptr->num_palette_max) | |
713 png_ptr->num_palette_max = i; | |
714 | |
715 i = (((*rp >> padding) >> 2) & 0x03); | |
716 | |
717 if (i > png_ptr->num_palette_max) | |
718 png_ptr->num_palette_max = i; | |
719 | |
720 i = (((*rp >> padding) >> 4) & 0x03); | |
721 | |
722 if (i > png_ptr->num_palette_max) | |
723 png_ptr->num_palette_max = i; | |
724 | |
725 i = (((*rp >> padding) >> 6) & 0x03); | |
726 | |
727 if (i > png_ptr->num_palette_max) | |
728 png_ptr->num_palette_max = i; | |
729 | |
730 padding = 0; | |
731 } | |
732 | |
733 break; | |
734 } | |
735 | |
736 case 4: | |
737 { | |
738 for (; rp > png_ptr->row_buf; rp--) | |
739 { | |
740 int i = ((*rp >> padding) & 0x0f); | |
741 | |
742 if (i > png_ptr->num_palette_max) | |
743 png_ptr->num_palette_max = i; | |
744 | |
745 i = (((*rp >> padding) >> 4) & 0x0f); | |
746 | |
747 if (i > png_ptr->num_palette_max) | |
748 png_ptr->num_palette_max = i; | |
749 | |
750 padding = 0; | |
751 } | |
752 | |
753 break; | |
754 } | |
755 | |
756 case 8: | |
757 { | |
758 for (; rp > png_ptr->row_buf; rp--) | |
759 { | |
760 if (*rp > png_ptr->num_palette_max) | |
761 png_ptr->num_palette_max = (int) *rp; | |
762 } | |
763 | |
764 break; | |
765 } | |
766 | |
767 default: | |
768 break; | |
769 } | |
770 } | |
771 } | |
772 #endif /* PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED */ | |
773 | |
774 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | 660 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ |
| 661 defined(PNG_LEGACY_SUPPORTED) || \ |
775 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) | 662 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
776 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | |
777 void PNGAPI | 663 void PNGAPI |
778 png_set_user_transform_info(png_structrp png_ptr, png_voidp | 664 png_set_user_transform_info(png_structp png_ptr, png_voidp |
779 user_transform_ptr, int user_transform_depth, int user_transform_channels) | 665 user_transform_ptr, int user_transform_depth, int user_transform_channels) |
780 { | 666 { |
781 png_debug(1, "in png_set_user_transform_info"); | 667 png_debug(1, "in png_set_user_transform_info"); |
782 | 668 |
783 if (png_ptr == NULL) | 669 if (png_ptr == NULL) |
784 return; | 670 return; |
785 | 671 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED |
786 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED | |
787 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && | |
788 (png_ptr->flags & PNG_FLAG_ROW_INIT) != 0) | |
789 { | |
790 png_app_error(png_ptr, | |
791 "info change after png_start_read_image or png_read_update_info"); | |
792 return; | |
793 } | |
794 #endif | |
795 | |
796 png_ptr->user_transform_ptr = user_transform_ptr; | 672 png_ptr->user_transform_ptr = user_transform_ptr; |
797 png_ptr->user_transform_depth = (png_byte)user_transform_depth; | 673 png_ptr->user_transform_depth = (png_byte)user_transform_depth; |
798 png_ptr->user_transform_channels = (png_byte)user_transform_channels; | 674 png_ptr->user_transform_channels = (png_byte)user_transform_channels; |
| 675 #else |
| 676 if (user_transform_ptr || user_transform_depth || user_transform_channels) |
| 677 png_warning(png_ptr, |
| 678 "This version of libpng does not support user transform info"); |
| 679 #endif |
799 } | 680 } |
800 #endif | 681 #endif |
801 | 682 |
802 /* This function returns a pointer to the user_transform_ptr associated with | 683 /* This function returns a pointer to the user_transform_ptr associated with |
803 * the user transform functions. The application should free any memory | 684 * the user transform functions. The application should free any memory |
804 * associated with this pointer before png_write_destroy and png_read_destroy | 685 * associated with this pointer before png_write_destroy and png_read_destroy |
805 * are called. | 686 * are called. |
806 */ | 687 */ |
807 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | |
808 png_voidp PNGAPI | 688 png_voidp PNGAPI |
809 png_get_user_transform_ptr(png_const_structrp png_ptr) | 689 png_get_user_transform_ptr(png_structp png_ptr) |
810 { | 690 { |
811 if (png_ptr == NULL) | 691 if (png_ptr == NULL) |
812 return (NULL); | 692 return (NULL); |
813 | 693 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED |
814 return png_ptr->user_transform_ptr; | 694 return ((png_voidp)png_ptr->user_transform_ptr); |
| 695 #else |
| 696 return (NULL); |
| 697 #endif |
815 } | 698 } |
816 #endif | |
817 | |
818 #ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED | |
819 png_uint_32 PNGAPI | |
820 png_get_current_row_number(png_const_structrp png_ptr) | |
821 { | |
822 /* See the comments in png.h - this is the sub-image row when reading and | |
823 * interlaced image. | |
824 */ | |
825 if (png_ptr != NULL) | |
826 return png_ptr->row_number; | |
827 | |
828 return PNG_UINT_32_MAX; /* help the app not to fail silently */ | |
829 } | |
830 | |
831 png_byte PNGAPI | |
832 png_get_current_pass_number(png_const_structrp png_ptr) | |
833 { | |
834 if (png_ptr != NULL) | |
835 return png_ptr->pass; | |
836 return 8; /* invalid */ | |
837 } | |
838 #endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */ | |
839 #endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || | |
840 PNG_WRITE_USER_TRANSFORM_SUPPORTED */ | |
841 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 699 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ |
OLD | NEW |