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