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.2.41 [December 3, 2009] | 4 * Last changed in libpng 1.6.2 [April 25, 2013] |
5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2013 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 #define PNG_INTERNAL | 14 #include "pngpriv.h" |
15 #define PNG_NO_PEDANTIC_WARNINGS | 15 |
16 #include "png.h" | |
17 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 16 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
18 | 17 |
19 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 18 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
20 /* Turn on BGR-to-RGB mapping */ | 19 /* Turn on BGR-to-RGB mapping */ |
21 void PNGAPI | 20 void PNGAPI |
22 png_set_bgr(png_structp png_ptr) | 21 png_set_bgr(png_structrp png_ptr) |
23 { | 22 { |
24 png_debug(1, "in png_set_bgr"); | 23 png_debug(1, "in png_set_bgr"); |
25 | 24 |
26 if (png_ptr == NULL) | 25 if (png_ptr == NULL) |
27 return; | 26 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_structp png_ptr) | 35 png_set_swap(png_structrp 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 |
41 if (png_ptr->bit_depth == 16) | 42 if (png_ptr->bit_depth == 16) |
42 png_ptr->transformations |= PNG_SWAP_BYTES; | 43 png_ptr->transformations |= PNG_SWAP_BYTES; |
43 } | 44 } |
44 #endif | 45 #endif |
45 | 46 |
46 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) | 47 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) |
47 /* Turn on pixel packing */ | 48 /* Turn on pixel packing */ |
48 void PNGAPI | 49 void PNGAPI |
49 png_set_packing(png_structp png_ptr) | 50 png_set_packing(png_structrp png_ptr) |
50 { | 51 { |
51 png_debug(1, "in png_set_packing"); | 52 png_debug(1, "in png_set_packing"); |
52 | 53 |
53 if (png_ptr == NULL) | 54 if (png_ptr == NULL) |
54 return; | 55 return; |
| 56 |
55 if (png_ptr->bit_depth < 8) | 57 if (png_ptr->bit_depth < 8) |
56 { | 58 { |
57 png_ptr->transformations |= PNG_PACK; | 59 png_ptr->transformations |= PNG_PACK; |
58 png_ptr->usr_bit_depth = 8; | 60 png_ptr->usr_bit_depth = 8; |
59 } | 61 } |
60 } | 62 } |
61 #endif | 63 #endif |
62 | 64 |
63 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 65 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
64 /* Turn on packed pixel swapping */ | 66 /* Turn on packed pixel swapping */ |
65 void PNGAPI | 67 void PNGAPI |
66 png_set_packswap(png_structp png_ptr) | 68 png_set_packswap(png_structrp png_ptr) |
67 { | 69 { |
68 png_debug(1, "in png_set_packswap"); | 70 png_debug(1, "in png_set_packswap"); |
69 | 71 |
70 if (png_ptr == NULL) | 72 if (png_ptr == NULL) |
71 return; | 73 return; |
| 74 |
72 if (png_ptr->bit_depth < 8) | 75 if (png_ptr->bit_depth < 8) |
73 png_ptr->transformations |= PNG_PACKSWAP; | 76 png_ptr->transformations |= PNG_PACKSWAP; |
74 } | 77 } |
75 #endif | 78 #endif |
76 | 79 |
77 #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) | 80 #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) |
78 void PNGAPI | 81 void PNGAPI |
79 png_set_shift(png_structp png_ptr, png_color_8p true_bits) | 82 png_set_shift(png_structrp png_ptr, png_const_color_8p true_bits) |
80 { | 83 { |
81 png_debug(1, "in png_set_shift"); | 84 png_debug(1, "in png_set_shift"); |
82 | 85 |
83 if (png_ptr == NULL) | 86 if (png_ptr == NULL) |
84 return; | 87 return; |
| 88 |
85 png_ptr->transformations |= PNG_SHIFT; | 89 png_ptr->transformations |= PNG_SHIFT; |
86 png_ptr->shift = *true_bits; | 90 png_ptr->shift = *true_bits; |
87 } | 91 } |
88 #endif | 92 #endif |
89 | 93 |
90 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ | 94 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ |
91 defined(PNG_WRITE_INTERLACING_SUPPORTED) | 95 defined(PNG_WRITE_INTERLACING_SUPPORTED) |
92 int PNGAPI | 96 int PNGAPI |
93 png_set_interlace_handling(png_structp png_ptr) | 97 png_set_interlace_handling(png_structrp png_ptr) |
94 { | 98 { |
95 png_debug(1, "in png_set_interlace handling"); | 99 png_debug(1, "in png_set_interlace handling"); |
96 | 100 |
97 if (png_ptr && png_ptr->interlaced) | 101 if (png_ptr && png_ptr->interlaced) |
98 { | 102 { |
99 png_ptr->transformations |= PNG_INTERLACE; | 103 png_ptr->transformations |= PNG_INTERLACE; |
100 return (7); | 104 return (7); |
101 } | 105 } |
102 | 106 |
103 return (1); | 107 return (1); |
104 } | 108 } |
105 #endif | 109 #endif |
106 | 110 |
107 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) | 111 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) |
108 /* Add a filler byte on read, or remove a filler or alpha byte on write. | 112 /* Add a filler byte on read, or remove a filler or alpha byte on write. |
109 * The filler type has changed in v0.95 to allow future 2-byte fillers | 113 * The filler type has changed in v0.95 to allow future 2-byte fillers |
110 * for 48-bit input data, as well as to avoid problems with some compilers | 114 * for 48-bit input data, as well as to avoid problems with some compilers |
111 * that don't like bytes as parameters. | 115 * that don't like bytes as parameters. |
112 */ | 116 */ |
113 void PNGAPI | 117 void PNGAPI |
114 png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) | 118 png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc) |
115 { | 119 { |
116 png_debug(1, "in png_set_filler"); | 120 png_debug(1, "in png_set_filler"); |
117 | 121 |
118 if (png_ptr == NULL) | 122 if (png_ptr == NULL) |
119 return; | 123 return; |
| 124 |
| 125 /* In libpng 1.6 it is possible to determine whether this is a read or write |
| 126 * operation and therefore to do more checking here for a valid call. |
| 127 */ |
| 128 if (png_ptr->mode & PNG_IS_READ_STRUCT) |
| 129 { |
| 130 # ifdef PNG_READ_FILLER_SUPPORTED |
| 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 } |
| 146 |
| 147 else /* write */ |
| 148 { |
| 149 # ifdef PNG_WRITE_FILLER_SUPPORTED |
| 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 } |
| 187 |
| 188 /* Here on success - libpng supports the operation, set the transformation |
| 189 * and the flag to say where the filler channel is. |
| 190 */ |
120 png_ptr->transformations |= PNG_FILLER; | 191 png_ptr->transformations |= PNG_FILLER; |
121 #ifdef PNG_LEGACY_SUPPORTED | 192 |
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) | 193 if (filler_loc == PNG_FILLER_AFTER) |
127 png_ptr->flags |= PNG_FLAG_FILLER_AFTER; | 194 png_ptr->flags |= PNG_FLAG_FILLER_AFTER; |
| 195 |
128 else | 196 else |
129 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; | 197 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; |
130 | |
131 /* This should probably go in the "do_read_filler" routine. | |
132 * I attempted to do that in libpng-1.0.1a but that caused problems | |
133 * so I restored it in libpng-1.0.2a | |
134 */ | |
135 | |
136 if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) | |
137 { | |
138 png_ptr->usr_channels = 4; | |
139 } | |
140 | |
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) | |
145 { | |
146 png_ptr->usr_channels = 2; | |
147 } | |
148 } | 198 } |
149 | 199 |
150 #ifndef PNG_1_0_X | |
151 /* Added to libpng-1.2.7 */ | 200 /* Added to libpng-1.2.7 */ |
152 void PNGAPI | 201 void PNGAPI |
153 png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) | 202 png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc) |
154 { | 203 { |
155 png_debug(1, "in png_set_add_alpha"); | 204 png_debug(1, "in png_set_add_alpha"); |
156 | 205 |
157 if (png_ptr == NULL) | 206 if (png_ptr == NULL) |
158 return; | 207 return; |
| 208 |
159 png_set_filler(png_ptr, filler, filler_loc); | 209 png_set_filler(png_ptr, filler, filler_loc); |
160 png_ptr->transformations |= PNG_ADD_ALPHA; | 210 /* The above may fail to do anything. */ |
| 211 if (png_ptr->transformations & PNG_FILLER) |
| 212 png_ptr->transformations |= PNG_ADD_ALPHA; |
161 } | 213 } |
162 #endif | |
163 | 214 |
164 #endif | 215 #endif |
165 | 216 |
166 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ | 217 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ |
167 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) | 218 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
168 void PNGAPI | 219 void PNGAPI |
169 png_set_swap_alpha(png_structp png_ptr) | 220 png_set_swap_alpha(png_structrp png_ptr) |
170 { | 221 { |
171 png_debug(1, "in png_set_swap_alpha"); | 222 png_debug(1, "in png_set_swap_alpha"); |
172 | 223 |
173 if (png_ptr == NULL) | 224 if (png_ptr == NULL) |
174 return; | 225 return; |
| 226 |
175 png_ptr->transformations |= PNG_SWAP_ALPHA; | 227 png_ptr->transformations |= PNG_SWAP_ALPHA; |
176 } | 228 } |
177 #endif | 229 #endif |
178 | 230 |
179 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ | 231 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ |
180 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) | 232 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
181 void PNGAPI | 233 void PNGAPI |
182 png_set_invert_alpha(png_structp png_ptr) | 234 png_set_invert_alpha(png_structrp png_ptr) |
183 { | 235 { |
184 png_debug(1, "in png_set_invert_alpha"); | 236 png_debug(1, "in png_set_invert_alpha"); |
185 | 237 |
186 if (png_ptr == NULL) | 238 if (png_ptr == NULL) |
187 return; | 239 return; |
| 240 |
188 png_ptr->transformations |= PNG_INVERT_ALPHA; | 241 png_ptr->transformations |= PNG_INVERT_ALPHA; |
189 } | 242 } |
190 #endif | 243 #endif |
191 | 244 |
192 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) | 245 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) |
193 void PNGAPI | 246 void PNGAPI |
194 png_set_invert_mono(png_structp png_ptr) | 247 png_set_invert_mono(png_structrp png_ptr) |
195 { | 248 { |
196 png_debug(1, "in png_set_invert_mono"); | 249 png_debug(1, "in png_set_invert_mono"); |
197 | 250 |
198 if (png_ptr == NULL) | 251 if (png_ptr == NULL) |
199 return; | 252 return; |
| 253 |
200 png_ptr->transformations |= PNG_INVERT_MONO; | 254 png_ptr->transformations |= PNG_INVERT_MONO; |
201 } | 255 } |
202 | 256 |
203 /* Invert monochrome grayscale data */ | 257 /* Invert monochrome grayscale data */ |
204 void /* PRIVATE */ | 258 void /* PRIVATE */ |
205 png_do_invert(png_row_infop row_info, png_bytep row) | 259 png_do_invert(png_row_infop row_info, png_bytep row) |
206 { | 260 { |
207 png_debug(1, "in png_do_invert"); | 261 png_debug(1, "in png_do_invert"); |
208 | 262 |
209 /* This test removed from libpng version 1.0.13 and 1.2.0: | 263 /* This test removed from libpng version 1.0.13 and 1.2.0: |
210 * if (row_info->bit_depth == 1 && | 264 * if (row_info->bit_depth == 1 && |
211 */ | 265 */ |
212 #ifdef PNG_USELESS_TESTS_SUPPORTED | |
213 if (row == NULL || row_info == NULL) | |
214 return; | |
215 #endif | |
216 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) | 266 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) |
217 { | 267 { |
218 png_bytep rp = row; | 268 png_bytep rp = row; |
219 png_uint_32 i; | 269 png_size_t i; |
220 png_uint_32 istop = row_info->rowbytes; | 270 png_size_t istop = row_info->rowbytes; |
221 | 271 |
222 for (i = 0; i < istop; i++) | 272 for (i = 0; i < istop; i++) |
223 { | 273 { |
224 *rp = (png_byte)(~(*rp)); | 274 *rp = (png_byte)(~(*rp)); |
225 rp++; | 275 rp++; |
226 } | 276 } |
227 } | 277 } |
| 278 |
228 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && | 279 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && |
229 row_info->bit_depth == 8) | 280 row_info->bit_depth == 8) |
230 { | 281 { |
231 png_bytep rp = row; | 282 png_bytep rp = row; |
232 png_uint_32 i; | 283 png_size_t i; |
233 png_uint_32 istop = row_info->rowbytes; | 284 png_size_t istop = row_info->rowbytes; |
234 | 285 |
235 for (i = 0; i < istop; i+=2) | 286 for (i = 0; i < istop; i += 2) |
236 { | 287 { |
237 *rp = (png_byte)(~(*rp)); | 288 *rp = (png_byte)(~(*rp)); |
238 rp+=2; | 289 rp += 2; |
239 } | 290 } |
240 } | 291 } |
| 292 |
| 293 #ifdef PNG_16BIT_SUPPORTED |
241 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && | 294 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && |
242 row_info->bit_depth == 16) | 295 row_info->bit_depth == 16) |
243 { | 296 { |
244 png_bytep rp = row; | 297 png_bytep rp = row; |
245 png_uint_32 i; | 298 png_size_t i; |
246 png_uint_32 istop = row_info->rowbytes; | 299 png_size_t istop = row_info->rowbytes; |
247 | 300 |
248 for (i = 0; i < istop; i+=4) | 301 for (i = 0; i < istop; i += 4) |
249 { | 302 { |
250 *rp = (png_byte)(~(*rp)); | 303 *rp = (png_byte)(~(*rp)); |
251 *(rp+1) = (png_byte)(~(*(rp+1))); | 304 *(rp + 1) = (png_byte)(~(*(rp + 1))); |
252 rp+=4; | 305 rp += 4; |
253 } | 306 } |
254 } | 307 } |
| 308 #endif |
255 } | 309 } |
256 #endif | 310 #endif |
257 | 311 |
| 312 #ifdef PNG_16BIT_SUPPORTED |
258 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | 313 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) |
259 /* Swaps byte order on 16 bit depth images */ | 314 /* Swaps byte order on 16 bit depth images */ |
260 void /* PRIVATE */ | 315 void /* PRIVATE */ |
261 png_do_swap(png_row_infop row_info, png_bytep row) | 316 png_do_swap(png_row_infop row_info, png_bytep row) |
262 { | 317 { |
263 png_debug(1, "in png_do_swap"); | 318 png_debug(1, "in png_do_swap"); |
264 | 319 |
265 if ( | 320 if (row_info->bit_depth == 16) |
266 #ifdef PNG_USELESS_TESTS_SUPPORTED | |
267 row != NULL && row_info != NULL && | |
268 #endif | |
269 row_info->bit_depth == 16) | |
270 { | 321 { |
271 png_bytep rp = row; | 322 png_bytep rp = row; |
272 png_uint_32 i; | 323 png_uint_32 i; |
273 png_uint_32 istop= row_info->width * row_info->channels; | 324 png_uint_32 istop= row_info->width * row_info->channels; |
274 | 325 |
275 for (i = 0; i < istop; i++, rp += 2) | 326 for (i = 0; i < istop; i++, rp += 2) |
276 { | 327 { |
277 png_byte t = *rp; | 328 png_byte t = *rp; |
278 *rp = *(rp + 1); | 329 *rp = *(rp + 1); |
279 *(rp + 1) = t; | 330 *(rp + 1) = t; |
280 } | 331 } |
281 } | 332 } |
282 } | 333 } |
283 #endif | 334 #endif |
| 335 #endif |
284 | 336 |
285 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 337 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
286 static PNG_CONST png_byte onebppswaptable[256] = { | 338 static PNG_CONST png_byte onebppswaptable[256] = { |
287 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, | 339 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, |
288 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, | 340 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, |
289 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, | 341 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, |
290 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, | 342 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, |
291 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, | 343 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, |
292 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, | 344 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, |
293 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, | 345 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, | 439 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, |
388 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF | 440 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF |
389 }; | 441 }; |
390 | 442 |
391 /* Swaps pixel packing order within bytes */ | 443 /* Swaps pixel packing order within bytes */ |
392 void /* PRIVATE */ | 444 void /* PRIVATE */ |
393 png_do_packswap(png_row_infop row_info, png_bytep row) | 445 png_do_packswap(png_row_infop row_info, png_bytep row) |
394 { | 446 { |
395 png_debug(1, "in png_do_packswap"); | 447 png_debug(1, "in png_do_packswap"); |
396 | 448 |
397 if ( | 449 if (row_info->bit_depth < 8) |
398 #ifdef PNG_USELESS_TESTS_SUPPORTED | |
399 row != NULL && row_info != NULL && | |
400 #endif | |
401 row_info->bit_depth < 8) | |
402 { | 450 { |
403 png_bytep rp, end, table; | 451 png_bytep rp; |
| 452 png_const_bytep end, table; |
404 | 453 |
405 end = row + row_info->rowbytes; | 454 end = row + row_info->rowbytes; |
406 | 455 |
407 if (row_info->bit_depth == 1) | 456 if (row_info->bit_depth == 1) |
408 table = (png_bytep)onebppswaptable; | 457 table = onebppswaptable; |
| 458 |
409 else if (row_info->bit_depth == 2) | 459 else if (row_info->bit_depth == 2) |
410 table = (png_bytep)twobppswaptable; | 460 table = twobppswaptable; |
| 461 |
411 else if (row_info->bit_depth == 4) | 462 else if (row_info->bit_depth == 4) |
412 table = (png_bytep)fourbppswaptable; | 463 table = fourbppswaptable; |
| 464 |
413 else | 465 else |
414 return; | 466 return; |
415 | 467 |
416 for (rp = row; rp < end; rp++) | 468 for (rp = row; rp < end; rp++) |
417 *rp = table[*rp]; | 469 *rp = table[*rp]; |
418 } | 470 } |
419 } | 471 } |
420 #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ | 472 #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ |
421 | 473 |
422 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ | 474 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ |
423 defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 475 defined(PNG_READ_STRIP_ALPHA_SUPPORTED) |
424 /* Remove filler or alpha byte(s) */ | 476 /* Remove a channel - this used to be 'png_do_strip_filler' but it used a |
| 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 */ |
425 void /* PRIVATE */ | 484 void /* PRIVATE */ |
426 png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) | 485 png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) |
427 { | 486 { |
428 png_debug(1, "in png_do_strip_filler"); | 487 png_bytep sp = row; /* source pointer */ |
| 488 png_bytep dp = row; /* destination pointer */ |
| 489 png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */ |
429 | 490 |
430 #ifdef PNG_USELESS_TESTS_SUPPORTED | 491 /* At the start sp will point to the first byte to copy and dp to where |
431 if (row != NULL && row_info != NULL) | 492 * it is copied to. ep always points just beyond the end of the row, so |
432 #endif | 493 * the loop simply copies (channels-1) channels until sp reaches ep. |
| 494 * |
| 495 * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. |
| 496 * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. |
| 497 */ |
| 498 |
| 499 /* GA, GX, XG cases */ |
| 500 if (row_info->channels == 2) |
433 { | 501 { |
434 png_bytep sp=row; | 502 if (row_info->bit_depth == 8) |
435 png_bytep dp=row; | 503 { |
436 png_uint_32 row_width=row_info->width; | 504 if (at_start) /* Skip initial filler */ |
437 png_uint_32 i; | 505 ++sp; |
| 506 else /* Skip initial channel and, for sp, the filler */ |
| 507 sp += 2, ++dp; |
438 | 508 |
439 if ((row_info->color_type == PNG_COLOR_TYPE_RGB || | 509 /* For a 1 pixel wide image there is nothing to do */ |
440 (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && | 510 while (sp < ep) |
441 (flags & PNG_FLAG_STRIP_ALPHA))) && | 511 *dp++ = *sp, sp += 2; |
442 row_info->channels == 4) | 512 |
| 513 row_info->pixel_depth = 8; |
| 514 } |
| 515 |
| 516 else if (row_info->bit_depth == 16) |
443 { | 517 { |
444 if (row_info->bit_depth == 8) | 518 if (at_start) /* Skip initial filler */ |
| 519 sp += 2; |
| 520 else /* Skip initial channel and, for sp, the filler */ |
| 521 sp += 4, dp += 2; |
| 522 |
| 523 while (sp < ep) |
| 524 *dp++ = *sp++, *dp++ = *sp, sp += 3; |
| 525 |
| 526 row_info->pixel_depth = 16; |
| 527 } |
| 528 |
| 529 else |
| 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 } |
| 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) |
445 { | 564 { |
446 /* This converts from RGBX or RGBA to RGB */ | 565 /* Copy 6 bytes, skip 2 */ |
447 if (flags & PNG_FLAG_FILLER_AFTER) | 566 *dp++ = *sp++, *dp++ = *sp++; |
448 { | 567 *dp++ = *sp++, *dp++ = *sp++; |
449 dp+=3; sp+=4; | 568 *dp++ = *sp++, *dp++ = *sp, sp += 3; |
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 } | 569 } |
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 */ | |
485 | 570 |
486 *dp++ = *sp++; | 571 row_info->pixel_depth = 48; |
487 *dp++ = *sp++; | 572 } |
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 */ | |
505 | 573 |
506 sp+=2; | 574 else |
507 *dp++ = *sp++; | 575 return; /* bad bit depth */ |
508 *dp++ = *sp++; | 576 |
509 *dp++ = *sp++; | 577 row_info->channels = 3; |
510 *dp++ = *sp++; | 578 |
511 *dp++ = *sp++; | 579 /* Finally fix the color type if it records an alpha channel */ |
512 *dp++ = *sp++; | 580 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
513 } | 581 row_info->color_type = PNG_COLOR_TYPE_RGB; |
514 } | |
515 row_info->pixel_depth = 48; | |
516 row_info->rowbytes = row_width * 6; | |
517 } | |
518 row_info->channels = 3; | |
519 } | |
520 else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY || | |
521 (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && | |
522 (flags & PNG_FLAG_STRIP_ALPHA))) && | |
523 row_info->channels == 2) | |
524 { | |
525 if (row_info->bit_depth == 8) | |
526 { | |
527 /* This converts from GX or GA to G */ | |
528 if (flags & PNG_FLAG_FILLER_AFTER) | |
529 { | |
530 for (i = 0; i < row_width; i++) | |
531 { | |
532 *dp++ = *sp++; | |
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; | |
575 } | |
576 if (flags & PNG_FLAG_STRIP_ALPHA) | |
577 row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; | |
578 } | 582 } |
| 583 |
| 584 else |
| 585 return; /* The filler channel has gone already */ |
| 586 |
| 587 /* Fix the rowbytes value. */ |
| 588 row_info->rowbytes = dp-row; |
579 } | 589 } |
580 #endif | 590 #endif |
581 | 591 |
582 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 592 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
583 /* Swaps red and blue bytes within a pixel */ | 593 /* Swaps red and blue bytes within a pixel */ |
584 void /* PRIVATE */ | 594 void /* PRIVATE */ |
585 png_do_bgr(png_row_infop row_info, png_bytep row) | 595 png_do_bgr(png_row_infop row_info, png_bytep row) |
586 { | 596 { |
587 png_debug(1, "in png_do_bgr"); | 597 png_debug(1, "in png_do_bgr"); |
588 | 598 |
589 if ( | 599 if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) |
590 #ifdef PNG_USELESS_TESTS_SUPPORTED | |
591 row != NULL && row_info != NULL && | |
592 #endif | |
593 (row_info->color_type & PNG_COLOR_MASK_COLOR)) | |
594 { | 600 { |
595 png_uint_32 row_width = row_info->width; | 601 png_uint_32 row_width = row_info->width; |
596 if (row_info->bit_depth == 8) | 602 if (row_info->bit_depth == 8) |
597 { | 603 { |
598 if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 604 if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
599 { | 605 { |
600 png_bytep rp; | 606 png_bytep rp; |
601 png_uint_32 i; | 607 png_uint_32 i; |
602 | 608 |
603 for (i = 0, rp = row; i < row_width; i++, rp += 3) | 609 for (i = 0, rp = row; i < row_width; i++, rp += 3) |
604 { | 610 { |
605 png_byte save = *rp; | 611 png_byte save = *rp; |
606 *rp = *(rp + 2); | 612 *rp = *(rp + 2); |
607 *(rp + 2) = save; | 613 *(rp + 2) = save; |
608 } | 614 } |
609 } | 615 } |
| 616 |
610 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 617 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
611 { | 618 { |
612 png_bytep rp; | 619 png_bytep rp; |
613 png_uint_32 i; | 620 png_uint_32 i; |
614 | 621 |
615 for (i = 0, rp = row; i < row_width; i++, rp += 4) | 622 for (i = 0, rp = row; i < row_width; i++, rp += 4) |
616 { | 623 { |
617 png_byte save = *rp; | 624 png_byte save = *rp; |
618 *rp = *(rp + 2); | 625 *rp = *(rp + 2); |
619 *(rp + 2) = save; | 626 *(rp + 2) = save; |
620 } | 627 } |
621 } | 628 } |
622 } | 629 } |
| 630 |
| 631 #ifdef PNG_16BIT_SUPPORTED |
623 else if (row_info->bit_depth == 16) | 632 else if (row_info->bit_depth == 16) |
624 { | 633 { |
625 if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 634 if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
626 { | 635 { |
627 png_bytep rp; | 636 png_bytep rp; |
628 png_uint_32 i; | 637 png_uint_32 i; |
629 | 638 |
630 for (i = 0, rp = row; i < row_width; i++, rp += 6) | 639 for (i = 0, rp = row; i < row_width; i++, rp += 6) |
631 { | 640 { |
632 png_byte save = *rp; | 641 png_byte save = *rp; |
633 *rp = *(rp + 4); | 642 *rp = *(rp + 4); |
634 *(rp + 4) = save; | 643 *(rp + 4) = save; |
635 save = *(rp + 1); | 644 save = *(rp + 1); |
636 *(rp + 1) = *(rp + 5); | 645 *(rp + 1) = *(rp + 5); |
637 *(rp + 5) = save; | 646 *(rp + 5) = save; |
638 } | 647 } |
639 } | 648 } |
| 649 |
640 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 650 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
641 { | 651 { |
642 png_bytep rp; | 652 png_bytep rp; |
643 png_uint_32 i; | 653 png_uint_32 i; |
644 | 654 |
645 for (i = 0, rp = row; i < row_width; i++, rp += 8) | 655 for (i = 0, rp = row; i < row_width; i++, rp += 8) |
646 { | 656 { |
647 png_byte save = *rp; | 657 png_byte save = *rp; |
648 *rp = *(rp + 4); | 658 *rp = *(rp + 4); |
649 *(rp + 4) = save; | 659 *(rp + 4) = save; |
650 save = *(rp + 1); | 660 save = *(rp + 1); |
651 *(rp + 1) = *(rp + 5); | 661 *(rp + 1) = *(rp + 5); |
652 *(rp + 5) = save; | 662 *(rp + 5) = save; |
653 } | 663 } |
654 } | 664 } |
655 } | 665 } |
| 666 #endif |
656 } | 667 } |
657 } | 668 } |
658 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ | 669 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ |
659 | 670 |
| 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 |
660 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | 774 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ |
661 defined(PNG_LEGACY_SUPPORTED) || \ | |
662 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) | 775 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 776 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED |
663 void PNGAPI | 777 void PNGAPI |
664 png_set_user_transform_info(png_structp png_ptr, png_voidp | 778 png_set_user_transform_info(png_structrp png_ptr, png_voidp |
665 user_transform_ptr, int user_transform_depth, int user_transform_channels) | 779 user_transform_ptr, int user_transform_depth, int user_transform_channels) |
666 { | 780 { |
667 png_debug(1, "in png_set_user_transform_info"); | 781 png_debug(1, "in png_set_user_transform_info"); |
668 | 782 |
669 if (png_ptr == NULL) | 783 if (png_ptr == NULL) |
670 return; | 784 return; |
671 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | 785 |
| 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 |
672 png_ptr->user_transform_ptr = user_transform_ptr; | 796 png_ptr->user_transform_ptr = user_transform_ptr; |
673 png_ptr->user_transform_depth = (png_byte)user_transform_depth; | 797 png_ptr->user_transform_depth = (png_byte)user_transform_depth; |
674 png_ptr->user_transform_channels = (png_byte)user_transform_channels; | 798 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 | |
680 } | 799 } |
681 #endif | 800 #endif |
682 | 801 |
683 /* This function returns a pointer to the user_transform_ptr associated with | 802 /* This function returns a pointer to the user_transform_ptr associated with |
684 * the user transform functions. The application should free any memory | 803 * the user transform functions. The application should free any memory |
685 * associated with this pointer before png_write_destroy and png_read_destroy | 804 * associated with this pointer before png_write_destroy and png_read_destroy |
686 * are called. | 805 * are called. |
687 */ | 806 */ |
| 807 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED |
688 png_voidp PNGAPI | 808 png_voidp PNGAPI |
689 png_get_user_transform_ptr(png_structp png_ptr) | 809 png_get_user_transform_ptr(png_const_structrp png_ptr) |
690 { | 810 { |
691 if (png_ptr == NULL) | 811 if (png_ptr == NULL) |
692 return (NULL); | 812 return (NULL); |
693 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | 813 |
694 return ((png_voidp)png_ptr->user_transform_ptr); | 814 return png_ptr->user_transform_ptr; |
695 #else | 815 } |
696 return (NULL); | |
697 #endif | 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 */ |
698 } | 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 */ |
699 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 841 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ |
OLD | NEW |