Bumping manifests a=b2g-bump
[gecko.git] / media / libpng / apng.patch
bloba80f51ff36bb941b27989270721d39cfb762142e
1 Index: pngread.c
2 ===================================================================
3 --- pngread.c
4 +++ pngread.c
5 @@ -158,6 +158,9 @@
7 else if (chunk_name == png_IDAT)
9 +#ifdef PNG_READ_APNG_SUPPORTED
10 + png_have_info(png_ptr, info_ptr);
11 +#endif
12 png_ptr->idat_size = length;
13 break;
15 @@ -247,6 +250,17 @@
16 png_handle_iTXt(png_ptr, info_ptr, length);
17 #endif
19 +#ifdef PNG_READ_APNG_SUPPORTED
20 + else if (chunk_name == png_acTL)
21 + png_handle_acTL(png_ptr, info_ptr, length);
23 + else if (chunk_name == png_fcTL)
24 + png_handle_fcTL(png_ptr, info_ptr, length);
26 + else if (chunk_name == png_fdAT)
27 + png_handle_fdAT(png_ptr, info_ptr, length);
28 +#endif
30 else
31 png_handle_unknown(png_ptr, info_ptr, length,
32 PNG_HANDLE_CHUNK_AS_DEFAULT);
33 @@ -254,6 +268,72 @@
35 #endif /* SEQUENTIAL_READ */
37 +#ifdef PNG_READ_APNG_SUPPORTED
38 +void PNGAPI
39 +png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
41 + png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
43 + png_debug(0, "Reading frame head");
45 + if ((png_ptr->mode & PNG_HAVE_acTL) == 0)
46 + png_error(png_ptr, "attempt to png_read_frame_head() but "
47 + "no acTL present");
49 + /* do nothing for the main IDAT */
50 + if (png_ptr->num_frames_read == 0)
51 + return;
53 + png_read_reset(png_ptr);
54 + png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
55 + png_ptr->mode &= ~PNG_HAVE_fcTL;
57 + have_chunk_after_DAT = 0;
58 + for (;;)
59 + {
60 + png_uint_32 length = png_read_chunk_header(png_ptr);
62 + if (png_ptr->chunk_name == png_IDAT)
63 + {
64 + /* discard trailing IDATs for the first frame */
65 + if (have_chunk_after_DAT != 0 || png_ptr->num_frames_read > 1)
66 + png_error(png_ptr, "png_read_frame_head(): out of place IDAT");
67 + png_crc_finish(png_ptr, length);
68 + }
70 + else if (png_ptr->chunk_name == png_fcTL)
71 + {
72 + png_handle_fcTL(png_ptr, info_ptr, length);
73 + have_chunk_after_DAT = 1;
74 + }
76 + else if (png_ptr->chunk_name == png_fdAT)
77 + {
78 + png_ensure_sequence_number(png_ptr, length);
80 + /* discard trailing fdATs for frames other than the first */
81 + if (have_chunk_after_DAT == 0 && png_ptr->num_frames_read > 1)
82 + png_crc_finish(png_ptr, length - 4);
83 + else if(png_ptr->mode & PNG_HAVE_fcTL)
84 + {
85 + png_ptr->idat_size = length - 4;
86 + png_ptr->mode |= PNG_HAVE_IDAT;
88 + break;
89 + }
90 + else
91 + png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
92 + }
93 + else
94 + {
95 + png_warning(png_ptr, "Skipped (ignored) a chunk "
96 + "between APNG chunks");
97 + png_crc_finish(png_ptr, length);
98 + }
99 + }
101 +#endif /* READ_APNG */
103 /* Optional call to update the users info_ptr structure */
104 void PNGAPI
105 png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
106 Index: pngget.c
107 ===================================================================
108 --- pngget.c
109 +++ pngget.c
110 @@ -1210,4 +1210,166 @@
111 # endif
112 #endif
114 +#ifdef PNG_APNG_SUPPORTED
115 +png_uint_32 PNGAPI
116 +png_get_acTL(png_structp png_ptr, png_infop info_ptr,
117 + png_uint_32 *num_frames, png_uint_32 *num_plays)
119 + png_debug1(1, "in %s retrieval function", "acTL");
121 + if (png_ptr != NULL && info_ptr != NULL &&
122 + (info_ptr->valid & PNG_INFO_acTL) != 0 &&
123 + num_frames != NULL && num_plays != NULL)
125 + *num_frames = info_ptr->num_frames;
126 + *num_plays = info_ptr->num_plays;
127 + return (1);
130 + return (0);
133 +png_uint_32 PNGAPI
134 +png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
136 + png_debug(1, "in png_get_num_frames()");
138 + if (png_ptr != NULL && info_ptr != NULL)
139 + return (info_ptr->num_frames);
140 + return (0);
143 +png_uint_32 PNGAPI
144 +png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
146 + png_debug(1, "in png_get_num_plays()");
148 + if (png_ptr != NULL && info_ptr != NULL)
149 + return (info_ptr->num_plays);
150 + return (0);
153 +png_uint_32 PNGAPI
154 +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
155 + png_uint_32 *width, png_uint_32 *height,
156 + png_uint_32 *x_offset, png_uint_32 *y_offset,
157 + png_uint_16 *delay_num, png_uint_16 *delay_den,
158 + png_byte *dispose_op, png_byte *blend_op)
160 + png_debug1(1, "in %s retrieval function", "fcTL");
162 + if (png_ptr != NULL && info_ptr != NULL &&
163 + (info_ptr->valid & PNG_INFO_fcTL) != 0 &&
164 + width != NULL && height != NULL &&
165 + x_offset != NULL && y_offset != NULL &&
166 + delay_num != NULL && delay_den != NULL &&
167 + dispose_op != NULL && blend_op != NULL)
169 + *width = info_ptr->next_frame_width;
170 + *height = info_ptr->next_frame_height;
171 + *x_offset = info_ptr->next_frame_x_offset;
172 + *y_offset = info_ptr->next_frame_y_offset;
173 + *delay_num = info_ptr->next_frame_delay_num;
174 + *delay_den = info_ptr->next_frame_delay_den;
175 + *dispose_op = info_ptr->next_frame_dispose_op;
176 + *blend_op = info_ptr->next_frame_blend_op;
177 + return (1);
180 + return (0);
183 +png_uint_32 PNGAPI
184 +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
186 + png_debug(1, "in png_get_next_frame_width()");
188 + if (png_ptr != NULL && info_ptr != NULL)
189 + return (info_ptr->next_frame_width);
190 + return (0);
193 +png_uint_32 PNGAPI
194 +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
196 + png_debug(1, "in png_get_next_frame_height()");
198 + if (png_ptr != NULL && info_ptr != NULL)
199 + return (info_ptr->next_frame_height);
200 + return (0);
203 +png_uint_32 PNGAPI
204 +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
206 + png_debug(1, "in png_get_next_frame_x_offset()");
208 + if (png_ptr != NULL && info_ptr != NULL)
209 + return (info_ptr->next_frame_x_offset);
210 + return (0);
213 +png_uint_32 PNGAPI
214 +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
216 + png_debug(1, "in png_get_next_frame_y_offset()");
218 + if (png_ptr != NULL && info_ptr != NULL)
219 + return (info_ptr->next_frame_y_offset);
220 + return (0);
223 +png_uint_16 PNGAPI
224 +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
226 + png_debug(1, "in png_get_next_frame_delay_num()");
228 + if (png_ptr != NULL && info_ptr != NULL)
229 + return (info_ptr->next_frame_delay_num);
230 + return (0);
233 +png_uint_16 PNGAPI
234 +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
236 + png_debug(1, "in png_get_next_frame_delay_den()");
238 + if (png_ptr != NULL && info_ptr != NULL)
239 + return (info_ptr->next_frame_delay_den);
240 + return (0);
243 +png_byte PNGAPI
244 +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
246 + png_debug(1, "in png_get_next_frame_dispose_op()");
248 + if (png_ptr != NULL && info_ptr != NULL)
249 + return (info_ptr->next_frame_dispose_op);
250 + return (0);
253 +png_byte PNGAPI
254 +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
256 + png_debug(1, "in png_get_next_frame_blend_op()");
258 + if (png_ptr != NULL && info_ptr != NULL)
259 + return (info_ptr->next_frame_blend_op);
260 + return (0);
263 +png_byte PNGAPI
264 +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
266 + png_debug(1, "in png_first_frame_is_hidden()");
268 + if (png_ptr != NULL)
269 + return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
271 + PNG_UNUSED(info_ptr)
273 + return 0;
275 +#endif /* APNG */
276 #endif /* READ || WRITE */
277 Index: png.h
278 ===================================================================
279 --- png.h
280 +++ png.h
281 @@ -476,6 +476,10 @@
282 # include "pnglibconf.h"
283 #endif
285 +#define PNG_APNG_SUPPORTED
286 +#define PNG_READ_APNG_SUPPORTED
287 +#define PNG_WRITE_APNG_SUPPORTED
289 #ifndef PNG_VERSION_INFO_ONLY
290 /* Machine specific configuration. */
291 # include "pngconf.h"
292 @@ -566,6 +570,17 @@
293 * See pngconf.h for base types that vary by machine/system
296 +#ifdef PNG_APNG_SUPPORTED
297 +/* dispose_op flags from inside fcTL */
298 +#define PNG_DISPOSE_OP_NONE 0x00
299 +#define PNG_DISPOSE_OP_BACKGROUND 0x01
300 +#define PNG_DISPOSE_OP_PREVIOUS 0x02
302 +/* blend_op flags from inside fcTL */
303 +#define PNG_BLEND_OP_SOURCE 0x00
304 +#define PNG_BLEND_OP_OVER 0x01
305 +#endif /* APNG */
307 /* This triggers a compiler error in png.c, if png.c and png.h
308 * do not agree upon the version number.
310 @@ -886,6 +901,10 @@
311 #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
312 #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
313 #define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */
314 +#ifdef PNG_APNG_SUPPORTED
315 +#define PNG_INFO_acTL 0x10000
316 +#define PNG_INFO_fcTL 0x20000
317 +#endif
319 /* This is used for the transformation routines, as some of them
320 * change these values for the row. It also should enable using
321 @@ -923,6 +942,10 @@
322 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
323 typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));
324 typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));
325 +#ifdef PNG_APNG_SUPPORTED
326 +typedef PNG_CALLBACK(void, *png_progressive_frame_ptr, (png_structp,
327 + png_uint_32));
328 +#endif
330 /* The following callback receives png_uint_32 row_number, int pass for the
331 * png_bytep data of the row. When transforming an interlaced image the
332 @@ -3262,6 +3285,75 @@
333 * END OF HARDWARE AND SOFTWARE OPTIONS
334 ******************************************************************************/
336 +#ifdef PNG_APNG_SUPPORTED
337 +PNG_EXPORT(245, png_uint_32, png_get_acTL, (png_structp png_ptr,
338 + png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays));
340 +PNG_EXPORT(246, png_uint_32, png_set_acTL, (png_structp png_ptr,
341 + png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays));
343 +PNG_EXPORT(247, png_uint_32, png_get_num_frames, (png_structp png_ptr,
344 + png_infop info_ptr));
346 +PNG_EXPORT(248, png_uint_32, png_get_num_plays, (png_structp png_ptr,
347 + png_infop info_ptr));
349 +PNG_EXPORT(249, png_uint_32, png_get_next_frame_fcTL,
350 + (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width,
351 + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset,
352 + png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op,
353 + png_byte *blend_op));
355 +PNG_EXPORT(250, png_uint_32, png_set_next_frame_fcTL,
356 + (png_structp png_ptr, png_infop info_ptr, png_uint_32 width,
357 + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset,
358 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
359 + png_byte blend_op));
361 +PNG_EXPORT(251, png_uint_32, png_get_next_frame_width,
362 + (png_structp png_ptr, png_infop info_ptr));
363 +PNG_EXPORT(252, png_uint_32, png_get_next_frame_height,
364 + (png_structp png_ptr, png_infop info_ptr));
365 +PNG_EXPORT(253, png_uint_32, png_get_next_frame_x_offset,
366 + (png_structp png_ptr, png_infop info_ptr));
367 +PNG_EXPORT(254, png_uint_32, png_get_next_frame_y_offset,
368 + (png_structp png_ptr, png_infop info_ptr));
369 +PNG_EXPORT(255, png_uint_16, png_get_next_frame_delay_num,
370 + (png_structp png_ptr, png_infop info_ptr));
371 +PNG_EXPORT(256, png_uint_16, png_get_next_frame_delay_den,
372 + (png_structp png_ptr, png_infop info_ptr));
373 +PNG_EXPORT(257, png_byte, png_get_next_frame_dispose_op,
374 + (png_structp png_ptr, png_infop info_ptr));
375 +PNG_EXPORT(258, png_byte, png_get_next_frame_blend_op,
376 + (png_structp png_ptr, png_infop info_ptr));
377 +PNG_EXPORT(259, png_byte, png_get_first_frame_is_hidden,
378 + (png_structp png_ptr, png_infop info_ptr));
379 +PNG_EXPORT(260, png_uint_32, png_set_first_frame_is_hidden,
380 + (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden));
382 +#ifdef PNG_READ_APNG_SUPPORTED
383 +PNG_EXPORT(261, void, png_read_frame_head, (png_structp png_ptr,
384 + png_infop info_ptr));
385 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
386 +PNG_EXPORT(262, void, png_set_progressive_frame_fn, (png_structp png_ptr,
387 + png_progressive_frame_ptr frame_info_fn,
388 + png_progressive_frame_ptr frame_end_fn));
389 +#endif /* PROGRESSIVE_READ */
390 +#endif /* READ_APNG */
392 +#ifdef PNG_WRITE_APNG_SUPPORTED
393 +PNG_EXPORT(263, void, png_write_frame_head, (png_structp png_ptr,
394 + png_infop info_ptr, png_bytepp row_pointers,
395 + png_uint_32 width, png_uint_32 height,
396 + png_uint_32 x_offset, png_uint_32 y_offset,
397 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
398 + png_byte blend_op));
400 +PNG_EXPORT(264, void, png_write_frame_tail, (png_structp png_ptr,
401 + png_infop info_ptr));
402 +#endif /* WRITE_APNG */
403 +#endif /* APNG */
405 /* Maintainer: Put new public prototypes here ^, in libpng.3, in project
406 * defs, and in scripts/symbols.def.
408 @@ -3270,7 +3362,11 @@
409 * one to use is one more than this.)
411 #ifdef PNG_EXPORT_LAST_ORDINAL
412 +#ifdef PNG_APNG_SUPPORTED
413 + PNG_EXPORT_LAST_ORDINAL(264);
414 +#else
415 PNG_EXPORT_LAST_ORDINAL(244);
416 +#endif /* APNG */
417 #endif
419 #ifdef __cplusplus
420 Index: pngpriv.h
421 ===================================================================
422 --- pngpriv.h
423 +++ pngpriv.h
424 @@ -555,6 +555,10 @@
425 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
426 /* 0x4000 (unused) */
427 #define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */
428 +#ifdef PNG_APNG_SUPPORTED
429 +#define PNG_HAVE_acTL 0x10000
430 +#define PNG_HAVE_fcTL 0x20000
431 +#endif
433 /* Flags for the transformations the PNG library does on the image data */
434 #define PNG_BGR 0x0001
435 @@ -776,6 +780,16 @@
436 #define png_tRNS PNG_U32(116, 82, 78, 83)
437 #define png_zTXt PNG_U32(122, 84, 88, 116)
439 +#ifdef PNG_APNG_SUPPORTED
440 +#define png_acTL PNG_U32( 97, 99, 84, 76)
441 +#define png_fcTL PNG_U32(102, 99, 84, 76)
442 +#define png_fdAT PNG_U32(102, 100, 65, 84)
444 +/* For png_struct.apng_flags: */
445 +#define PNG_FIRST_FRAME_HIDDEN 0x0001
446 +#define PNG_APNG_APP 0x0002
447 +#endif
449 /* The following will work on (signed char*) strings, whereas the get_uint_32
450 * macro will fail on top-bit-set values because of the sign extension.
452 @@ -1456,6 +1470,49 @@
454 #endif /* PROGRESSIVE_READ */
456 +#ifdef PNG_APNG_SUPPORTED
457 +PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr,
458 + png_uint_32 width, png_uint_32 height,
459 + png_uint_32 x_offset, png_uint_32 y_offset,
460 + png_uint_16 delay_num, png_uint_16 delay_den,
461 + png_byte dispose_op, png_byte blend_op),PNG_EMPTY);
463 +#ifdef PNG_READ_APNG_SUPPORTED
464 +PNG_INTERNAL_FUNCTION(void,png_handle_acTL,(png_structp png_ptr,
465 + png_infop info_ptr, png_uint_32 length),PNG_EMPTY);
466 +PNG_INTERNAL_FUNCTION(void,png_handle_fcTL,(png_structp png_ptr,
467 + png_infop info_ptr, png_uint_32 length),PNG_EMPTY);
468 +PNG_INTERNAL_FUNCTION(void,png_handle_fdAT,(png_structp png_ptr,
469 + png_infop info_ptr, png_uint_32 length),PNG_EMPTY);
470 +PNG_INTERNAL_FUNCTION(void,png_have_info,(png_structp png_ptr,
471 + png_infop info_ptr),PNG_EMPTY);
472 +PNG_INTERNAL_FUNCTION(void,png_ensure_sequence_number,(png_structp png_ptr,
473 + png_uint_32 length),PNG_EMPTY);
474 +PNG_INTERNAL_FUNCTION(void,png_read_reset,(png_structp png_ptr),PNG_EMPTY);
475 +PNG_INTERNAL_FUNCTION(void,png_read_reinit,(png_structp png_ptr,
476 + png_infop info_ptr),PNG_EMPTY);
477 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
478 +PNG_INTERNAL_FUNCTION(void,png_progressive_read_reset,(png_structp png_ptr),
479 + PNG_EMPTY);
480 +#endif /* PROGRESSIVE_READ */
481 +#endif /* READ_APNG */
483 +#ifdef PNG_WRITE_APNG_SUPPORTED
484 +PNG_INTERNAL_FUNCTION(void,png_write_acTL,(png_structp png_ptr,
485 + png_uint_32 num_frames, png_uint_32 num_plays),PNG_EMPTY);
486 +PNG_INTERNAL_FUNCTION(void,png_write_fcTL,(png_structp png_ptr,
487 + png_uint_32 width, png_uint_32 height,
488 + png_uint_32 x_offset, png_uint_32 y_offset,
489 + png_uint_16 delay_num, png_uint_16 delay_den,
490 + png_byte dispose_op, png_byte blend_op),PNG_EMPTY);
491 +PNG_INTERNAL_FUNCTION(void,png_write_fdAT,(png_structp png_ptr,
492 + png_const_bytep data, png_size_t length),PNG_EMPTY);
493 +PNG_INTERNAL_FUNCTION(void,png_write_reset,(png_structp png_ptr),PNG_EMPTY);
494 +PNG_INTERNAL_FUNCTION(void,png_write_reinit,(png_structp png_ptr,
495 + png_infop info_ptr, png_uint_32 width, png_uint_32 height),PNG_EMPTY);
496 +#endif /* WRITE_APNG */
497 +#endif /* APNG */
499 /* Added at libpng version 1.6.0 */
500 #ifdef PNG_GAMMA_SUPPORTED
501 PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,
502 Index: pnginfo.h
503 ===================================================================
504 --- pnginfo.h
505 +++ pnginfo.h
506 @@ -256,5 +256,18 @@
507 png_bytepp row_pointers; /* the image bits */
508 #endif
510 +#ifdef PNG_APNG_SUPPORTED
511 + png_uint_32 num_frames; /* including default image */
512 + png_uint_32 num_plays;
513 + png_uint_32 next_frame_width;
514 + png_uint_32 next_frame_height;
515 + png_uint_32 next_frame_x_offset;
516 + png_uint_32 next_frame_y_offset;
517 + png_uint_16 next_frame_delay_num;
518 + png_uint_16 next_frame_delay_den;
519 + png_byte next_frame_dispose_op;
520 + png_byte next_frame_blend_op;
521 +#endif
524 #endif /* PNGINFO_H */
525 Index: pngstruct.h
526 ===================================================================
527 --- pngstruct.h
528 +++ pngstruct.h
529 @@ -409,6 +409,27 @@
530 png_byte filter_type;
531 #endif
533 +#ifdef PNG_APNG_SUPPORTED
534 + png_uint_32 apng_flags;
535 + png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */
536 + png_uint_32 first_frame_width;
537 + png_uint_32 first_frame_height;
539 +#ifdef PNG_READ_APNG_SUPPORTED
540 + png_uint_32 num_frames_read; /* incremented after all image data of */
541 + /* a frame is read */
542 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
543 + png_progressive_frame_ptr frame_info_fn; /* frame info read callback */
544 + png_progressive_frame_ptr frame_end_fn; /* frame data read callback */
545 +#endif
546 +#endif
548 +#ifdef PNG_WRITE_APNG_SUPPORTED
549 + png_uint_32 num_frames_to_write;
550 + png_uint_32 num_frames_written;
551 +#endif
552 +#endif /* APNG */
554 /* New members added in libpng-1.2.0 */
556 /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
557 Index: pngwrite.c
558 ===================================================================
559 --- pngwrite.c
560 +++ pngwrite.c
561 @@ -127,6 +127,10 @@
562 * application continues writing the PNG. So check the 'invalid' flag here
563 * too.
565 +#ifdef PNG_WRITE_APNG_SUPPORTED
566 + if ((info_ptr->valid & PNG_INFO_acTL) != 0)
567 + png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
568 +#endif
569 #ifdef PNG_GAMMA_SUPPORTED
570 # ifdef PNG_WRITE_gAMA_SUPPORTED
571 if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
572 @@ -354,6 +358,11 @@
573 if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)
574 png_error(png_ptr, "No IDATs written into file");
576 +#ifdef PNG_WRITE_APNG_SUPPORTED
577 + if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
578 + png_error(png_ptr, "Not enough frames written");
579 +#endif
581 #ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
582 if (png_ptr->num_palette_max > png_ptr->num_palette)
583 png_benign_error(png_ptr, "Wrote palette index exceeding num_palette");
584 @@ -2452,4 +2461,42 @@
586 #endif /* STDIO */
587 #endif /* SIMPLIFIED_WRITE */
589 +#ifdef PNG_WRITE_APNG_SUPPORTED
590 +void PNGAPI
591 +png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
592 + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height,
593 + png_uint_32 x_offset, png_uint_32 y_offset,
594 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
595 + png_byte blend_op)
597 + png_debug(1, "in png_write_frame_head");
599 + /* there is a chance this has been set after png_write_info was called,
600 + * so it would be set but not written. is there a way to be sure? */
601 + if ((info_ptr->valid & PNG_INFO_acTL) == 0)
602 + png_error(png_ptr, "png_write_frame_head(): acTL not set");
604 + png_write_reset(png_ptr);
606 + png_write_reinit(png_ptr, info_ptr, width, height);
608 + if ((png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) == 0 ||
609 + png_ptr->num_frames_written != 0)
610 + png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
611 + delay_num, delay_den, dispose_op, blend_op);
613 + PNG_UNUSED(row_pointers)
616 +void PNGAPI
617 +png_write_frame_tail(png_structp png_ptr, png_infop info_ptr)
619 + png_debug(1, "in png_write_frame_tail");
621 + png_ptr->num_frames_written++;
623 + PNG_UNUSED(info_ptr)
625 +#endif /* WRITE_APNG */
626 #endif /* WRITE */
627 Index: pngpread.c
628 ===================================================================
629 --- pngpread.c
630 +++ pngpread.c
631 @@ -219,6 +219,86 @@
633 chunk_name = png_ptr->chunk_name;
635 +#ifdef PNG_READ_APNG_SUPPORTED
636 + if (png_ptr->num_frames_read > 0 &&
637 + png_ptr->num_frames_read < info_ptr->num_frames)
639 + if (chunk_name == png_IDAT)
641 + /* Discard trailing IDATs for the first frame */
642 + if ((png_ptr->mode & PNG_HAVE_fcTL) != 0 ||
643 + png_ptr->num_frames_read > 1)
644 + png_error(png_ptr, "out of place IDAT");
646 + PNG_PUSH_SAVE_BUFFER_IF_FULL
647 + png_push_crc_skip(png_ptr, png_ptr->push_length);
648 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
649 + return;
651 + else if (chunk_name == png_fdAT)
653 + PNG_PUSH_SAVE_BUFFER_IF_LT(4)
654 + png_ensure_sequence_number(png_ptr, 4);
656 + if ((png_ptr->mode & PNG_HAVE_fcTL) == 0)
658 + /* Discard trailing fdATs for frames other than the first */
659 + if (png_ptr->num_frames_read < 2)
660 + png_error(png_ptr, "out of place fdAT");
662 + PNG_PUSH_SAVE_BUFFER_IF_FULL
663 + png_push_crc_skip(png_ptr, png_ptr->push_length);
664 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
665 + return;
668 + else
670 + /* frame data follows */
671 + png_ptr->idat_size = png_ptr->push_length - 4;
672 + png_ptr->mode |= PNG_HAVE_IDAT;
673 + png_ptr->process_mode = PNG_READ_IDAT_MODE;
675 + return;
679 + else if (chunk_name == png_fcTL)
681 + PNG_PUSH_SAVE_BUFFER_IF_FULL
682 + png_read_reset(png_ptr);
683 + png_ptr->mode &= ~PNG_HAVE_fcTL;
685 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
687 + if ((png_ptr->mode & PNG_HAVE_fcTL) == 0)
688 + png_error(png_ptr, "missing required fcTL chunk");
690 + png_read_reinit(png_ptr, info_ptr);
691 + png_progressive_read_reset(png_ptr);
693 + if (png_ptr->frame_info_fn != NULL)
694 + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read);
696 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
698 + return;
701 + else
703 + PNG_PUSH_SAVE_BUFFER_IF_FULL
704 + png_warning(png_ptr, "Skipped (ignored) a chunk "
705 + "between APNG chunks");
706 + png_push_crc_skip(png_ptr, png_ptr->push_length);
707 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
708 + return;
711 + return;
713 +#endif /* READ_APNG */
715 if (chunk_name == png_IDAT)
717 if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
718 @@ -283,6 +363,9 @@
720 else if (chunk_name == png_IDAT)
722 +#ifdef PNG_READ_APNG_SUPPORTED
723 + png_have_info(png_ptr, info_ptr);
724 +#endif
725 png_ptr->idat_size = png_ptr->push_length;
726 png_ptr->process_mode = PNG_READ_IDAT_MODE;
727 png_push_have_info(png_ptr, info_ptr);
728 @@ -429,6 +512,20 @@
730 #endif
732 +#ifdef PNG_READ_APNG_SUPPORTED
733 + else if (chunk_name == png_acTL)
735 + PNG_PUSH_SAVE_BUFFER_IF_FULL
736 + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
739 + else if (chunk_name == png_fcTL)
741 + PNG_PUSH_SAVE_BUFFER_IF_FULL
742 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
745 +#endif /* READ_APNG */
746 else
748 PNG_PUSH_SAVE_BUFFER_IF_FULL
749 @@ -623,7 +720,11 @@
750 png_byte chunk_tag[4];
752 /* TODO: this code can be commoned up with the same code in push_read */
753 +#ifdef PNG_READ_APNG_SUPPORTED
754 + PNG_PUSH_SAVE_BUFFER_IF_LT(12)
755 +#else
756 PNG_PUSH_SAVE_BUFFER_IF_LT(8)
757 +#endif
758 png_push_fill_buffer(png_ptr, chunk_length, 4);
759 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
760 png_reset_crc(png_ptr);
761 @@ -631,17 +732,60 @@
762 png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
763 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
765 +#ifdef PNG_READ_APNG_SUPPORTED
766 + if (png_ptr->chunk_name != png_fdAT && png_ptr->num_frames_read > 0)
768 + if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) != 0)
770 + png_ptr->process_mode = PNG_READ_CHUNK_MODE;
771 + if (png_ptr->frame_end_fn != NULL)
772 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
773 + png_ptr->num_frames_read++;
774 + return;
776 + else
778 + if (png_ptr->chunk_name == png_IEND)
779 + png_error(png_ptr, "Not enough image data");
780 + PNG_PUSH_SAVE_BUFFER_IF_FULL
781 + png_warning(png_ptr, "Skipping (ignoring) a chunk between "
782 + "APNG chunks");
783 + png_crc_finish(png_ptr, png_ptr->push_length);
784 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
785 + return;
788 + else
789 +#endif
790 +#ifdef PNG_READ_APNG_SUPPORTED
791 + if (png_ptr->chunk_name != png_IDAT && png_ptr->num_frames_read == 0)
792 +#else
793 if (png_ptr->chunk_name != png_IDAT)
794 +#endif
796 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
798 if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
799 png_error(png_ptr, "Not enough compressed data");
801 +#ifdef PNG_READ_APNG_SUPPORTED
802 + if (png_ptr->frame_end_fn != NULL)
803 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
804 + png_ptr->num_frames_read++;
805 +#endif
807 return;
810 png_ptr->idat_size = png_ptr->push_length;
812 +#ifdef PNG_READ_APNG_SUPPORTED
813 + if (png_ptr->num_frames_read > 0)
815 + png_ensure_sequence_number(png_ptr, 4);
816 + png_ptr->idat_size -= 4;
818 +#endif
821 if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)
822 @@ -714,6 +858,16 @@
823 if (!(buffer_length > 0) || buffer == NULL)
824 png_error(png_ptr, "No IDAT data (internal error)");
826 +#ifdef PNG_READ_APNG_SUPPORTED
827 + /* If the app is not APNG-aware, decode only the first frame */
828 + if ((png_ptr->apng_flags & PNG_APNG_APP) == 0 &&
829 + png_ptr->num_frames_read > 0)
831 + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
832 + return;
834 +#endif
836 /* This routine must process all the data it has been given
837 * before returning, calling the row callback as required to
838 * handle the uncompressed results.
839 @@ -1157,6 +1311,18 @@
840 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
843 +#ifdef PNG_READ_APNG_SUPPORTED
844 +void PNGAPI
845 +png_set_progressive_frame_fn(png_structp png_ptr,
846 + png_progressive_frame_ptr frame_info_fn,
847 + png_progressive_frame_ptr frame_end_fn)
849 + png_ptr->frame_info_fn = frame_info_fn;
850 + png_ptr->frame_end_fn = frame_end_fn;
851 + png_ptr->apng_flags |= PNG_APNG_APP;
853 +#endif
855 png_voidp PNGAPI
856 png_get_progressive_ptr(png_const_structrp png_ptr)
858 Index: pngset.c
859 ===================================================================
860 --- pngset.c
861 +++ pngset.c
862 @@ -240,6 +240,11 @@
863 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
865 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
867 +#ifdef PNG_APNG_SUPPORTED
868 + /* for non-animated png. this may be overwritten from an acTL chunk later */
869 + info_ptr->num_frames = 1;
870 +#endif
873 #ifdef PNG_oFFs_SUPPORTED
874 @@ -1071,6 +1076,147 @@
876 #endif /* sPLT */
878 +#ifdef PNG_APNG_SUPPORTED
879 +png_uint_32 PNGAPI
880 +png_set_acTL(png_structp png_ptr, png_infop info_ptr,
881 + png_uint_32 num_frames, png_uint_32 num_plays)
883 + png_debug1(1, "in %s storage function", "acTL");
885 + if (png_ptr == NULL || info_ptr == NULL)
887 + png_warning(png_ptr,
888 + "Call to png_set_acTL() with NULL png_ptr "
889 + "or info_ptr ignored");
890 + return (0);
892 + if (num_frames == 0)
894 + png_warning(png_ptr,
895 + "Ignoring attempt to set acTL with num_frames zero");
896 + return (0);
898 + if (num_frames > PNG_UINT_31_MAX)
900 + png_warning(png_ptr,
901 + "Ignoring attempt to set acTL with num_frames > 2^31-1");
902 + return (0);
904 + if (num_plays > PNG_UINT_31_MAX)
906 + png_warning(png_ptr,
907 + "Ignoring attempt to set acTL with num_plays "
908 + "> 2^31-1");
909 + return (0);
912 + info_ptr->num_frames = num_frames;
913 + info_ptr->num_plays = num_plays;
915 + info_ptr->valid |= PNG_INFO_acTL;
917 + return (1);
920 +/* delay_num and delay_den can hold any 16-bit values including zero */
921 +png_uint_32 PNGAPI
922 +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
923 + png_uint_32 width, png_uint_32 height,
924 + png_uint_32 x_offset, png_uint_32 y_offset,
925 + png_uint_16 delay_num, png_uint_16 delay_den,
926 + png_byte dispose_op, png_byte blend_op)
928 + png_debug1(1, "in %s storage function", "fcTL");
930 + if (png_ptr == NULL || info_ptr == NULL)
932 + png_warning(png_ptr,
933 + "Call to png_set_fcTL() with NULL png_ptr or info_ptr "
934 + "ignored");
935 + return (0);
938 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
939 + delay_num, delay_den, dispose_op, blend_op);
941 + if (blend_op == PNG_BLEND_OP_OVER)
943 + if ((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0 &&
944 + png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) == 0)
946 + png_warning(png_ptr, "PNG_BLEND_OP_OVER is meaningless "
947 + "and wasteful for opaque images, ignored");
948 + blend_op = PNG_BLEND_OP_SOURCE;
952 + info_ptr->next_frame_width = width;
953 + info_ptr->next_frame_height = height;
954 + info_ptr->next_frame_x_offset = x_offset;
955 + info_ptr->next_frame_y_offset = y_offset;
956 + info_ptr->next_frame_delay_num = delay_num;
957 + info_ptr->next_frame_delay_den = delay_den;
958 + info_ptr->next_frame_dispose_op = dispose_op;
959 + info_ptr->next_frame_blend_op = blend_op;
961 + info_ptr->valid |= PNG_INFO_fcTL;
963 + return (1);
966 +void /* PRIVATE */
967 +png_ensure_fcTL_is_valid(png_structp png_ptr,
968 + png_uint_32 width, png_uint_32 height,
969 + png_uint_32 x_offset, png_uint_32 y_offset,
970 + png_uint_16 delay_num, png_uint_16 delay_den,
971 + png_byte dispose_op, png_byte blend_op)
973 + if (width > PNG_UINT_31_MAX)
974 + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)");
975 + if (height > PNG_UINT_31_MAX)
976 + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)");
977 + if (x_offset > PNG_UINT_31_MAX)
978 + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)");
979 + if (y_offset > PNG_UINT_31_MAX)
980 + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)");
981 + if (width + x_offset > png_ptr->first_frame_width ||
982 + height + y_offset > png_ptr->first_frame_height)
983 + png_error(png_ptr, "dimensions of a frame are greater than"
984 + "the ones in IHDR");
986 + if (dispose_op != PNG_DISPOSE_OP_NONE &&
987 + dispose_op != PNG_DISPOSE_OP_BACKGROUND &&
988 + dispose_op != PNG_DISPOSE_OP_PREVIOUS)
989 + png_error(png_ptr, "invalid dispose_op in fcTL");
991 + if (blend_op != PNG_BLEND_OP_SOURCE &&
992 + blend_op != PNG_BLEND_OP_OVER)
993 + png_error(png_ptr, "invalid blend_op in fcTL");
995 + PNG_UNUSED(delay_num)
996 + PNG_UNUSED(delay_den)
999 +png_uint_32 PNGAPI
1000 +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
1001 + png_byte is_hidden)
1003 + png_debug(1, "in png_first_frame_is_hidden()");
1005 + if (png_ptr == NULL)
1006 + return 0;
1008 + if (is_hidden != 0)
1009 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1010 + else
1011 + png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN;
1013 + PNG_UNUSED(info_ptr)
1015 + return 1;
1017 +#endif /* APNG */
1019 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1020 static png_byte
1021 check_location(png_const_structrp png_ptr, int location)
1022 Index: pngrutil.c
1023 ===================================================================
1024 --- pngrutil.c
1025 +++ pngrutil.c
1026 @@ -819,6 +819,11 @@
1027 filter_type = buf[11];
1028 interlace_type = buf[12];
1030 +#ifdef PNG_READ_APNG_SUPPORTED
1031 + png_ptr->first_frame_width = width;
1032 + png_ptr->first_frame_height = height;
1033 +#endif
1035 /* Set internal variables */
1036 png_ptr->width = width;
1037 png_ptr->height = height;
1038 @@ -2700,6 +2705,180 @@
1040 #endif
1042 +#ifdef PNG_READ_APNG_SUPPORTED
1043 +void /* PRIVATE */
1044 +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1046 + png_byte data[8];
1047 + png_uint_32 num_frames;
1048 + png_uint_32 num_plays;
1049 + png_uint_32 didSet;
1051 + png_debug(1, "in png_handle_acTL");
1053 + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1055 + png_error(png_ptr, "Missing IHDR before acTL");
1057 + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
1059 + png_warning(png_ptr, "Invalid acTL after IDAT skipped");
1060 + png_crc_finish(png_ptr, length);
1061 + return;
1063 + else if ((png_ptr->mode & PNG_HAVE_acTL) != 0)
1065 + png_warning(png_ptr, "Duplicate acTL skipped");
1066 + png_crc_finish(png_ptr, length);
1067 + return;
1069 + else if (length != 8)
1071 + png_warning(png_ptr, "acTL with invalid length skipped");
1072 + png_crc_finish(png_ptr, length);
1073 + return;
1076 + png_crc_read(png_ptr, data, 8);
1077 + png_crc_finish(png_ptr, 0);
1079 + num_frames = png_get_uint_31(png_ptr, data);
1080 + num_plays = png_get_uint_31(png_ptr, data + 4);
1082 + /* the set function will do error checking on num_frames */
1083 + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
1084 + if (didSet != 0)
1085 + png_ptr->mode |= PNG_HAVE_acTL;
1088 +void /* PRIVATE */
1089 +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1091 + png_byte data[22];
1092 + png_uint_32 width;
1093 + png_uint_32 height;
1094 + png_uint_32 x_offset;
1095 + png_uint_32 y_offset;
1096 + png_uint_16 delay_num;
1097 + png_uint_16 delay_den;
1098 + png_byte dispose_op;
1099 + png_byte blend_op;
1101 + png_debug(1, "in png_handle_fcTL");
1103 + png_ensure_sequence_number(png_ptr, length);
1105 + if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
1107 + png_error(png_ptr, "Missing IHDR before fcTL");
1109 + else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
1111 + /* for any frames other then the first this message may be misleading,
1112 + * but correct. PNG_HAVE_IDAT is unset before the frame head is read
1113 + * i can't think of a better message */
1114 + png_warning(png_ptr, "Invalid fcTL after IDAT skipped");
1115 + png_crc_finish(png_ptr, length-4);
1116 + return;
1118 + else if ((png_ptr->mode & PNG_HAVE_fcTL) != 0)
1120 + png_warning(png_ptr, "Duplicate fcTL within one frame skipped");
1121 + png_crc_finish(png_ptr, length-4);
1122 + return;
1124 + else if (length != 26)
1126 + png_warning(png_ptr, "fcTL with invalid length skipped");
1127 + png_crc_finish(png_ptr, length-4);
1128 + return;
1131 + png_crc_read(png_ptr, data, 22);
1132 + png_crc_finish(png_ptr, 0);
1134 + width = png_get_uint_31(png_ptr, data);
1135 + height = png_get_uint_31(png_ptr, data + 4);
1136 + x_offset = png_get_uint_31(png_ptr, data + 8);
1137 + y_offset = png_get_uint_31(png_ptr, data + 12);
1138 + delay_num = png_get_uint_16(data + 16);
1139 + delay_den = png_get_uint_16(data + 18);
1140 + dispose_op = data[20];
1141 + blend_op = data[21];
1143 + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
1145 + png_warning(png_ptr, "fcTL for the first frame must have zero offset");
1146 + return;
1149 + if (info_ptr != NULL)
1151 + if (png_ptr->num_frames_read == 0 &&
1152 + (width != info_ptr->width || height != info_ptr->height))
1154 + png_warning(png_ptr, "size in first frame's fcTL must match "
1155 + "the size in IHDR");
1156 + return;
1159 + /* The set function will do more error checking */
1160 + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
1161 + x_offset, y_offset, delay_num, delay_den,
1162 + dispose_op, blend_op);
1164 + png_read_reinit(png_ptr, info_ptr);
1166 + png_ptr->mode |= PNG_HAVE_fcTL;
1170 +void /* PRIVATE */
1171 +png_have_info(png_structp png_ptr, png_infop info_ptr)
1173 + if ((info_ptr->valid & PNG_INFO_acTL) != 0 &&
1174 + (info_ptr->valid & PNG_INFO_fcTL) == 0)
1176 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1177 + info_ptr->num_frames++;
1181 +void /* PRIVATE */
1182 +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1184 + png_ensure_sequence_number(png_ptr, length);
1186 + /* This function is only called from png_read_end(), png_read_info(),
1187 + * and png_push_read_chunk() which means that:
1188 + * - the user doesn't want to read this frame
1189 + * - or this is an out-of-place fdAT
1190 + * in either case it is safe to ignore the chunk with a warning */
1191 + png_warning(png_ptr, "ignoring fdAT chunk");
1192 + png_crc_finish(png_ptr, length - 4);
1193 + PNG_UNUSED(info_ptr)
1196 +void /* PRIVATE */
1197 +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
1199 + png_byte data[4];
1200 + png_uint_32 sequence_number;
1202 + if (length < 4)
1203 + png_error(png_ptr, "invalid fcTL or fdAT chunk found");
1205 + png_crc_read(png_ptr, data, 4);
1206 + sequence_number = png_get_uint_31(png_ptr, data);
1208 + if (sequence_number != png_ptr->next_seq_num)
1209 + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
1210 + "number found");
1212 + png_ptr->next_seq_num++;
1214 +#endif /* READ_APNG */
1216 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1217 /* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
1218 static int
1219 @@ -3959,6 +4138,38 @@
1220 uInt avail_in;
1221 png_bytep buffer;
1223 +#ifdef PNG_READ_APNG_SUPPORTED
1224 + png_uint_32 bytes_to_skip = 0;
1226 + while (png_ptr->idat_size == 0 || bytes_to_skip != 0)
1228 + png_crc_finish(png_ptr, bytes_to_skip);
1229 + bytes_to_skip = 0;
1231 + png_ptr->idat_size = png_read_chunk_header(png_ptr);
1232 + if (png_ptr->num_frames_read == 0)
1234 + if (png_ptr->chunk_name != png_IDAT)
1235 + png_error(png_ptr, "Not enough image data");
1237 + else
1239 + if (png_ptr->chunk_name == png_IEND)
1240 + png_error(png_ptr, "Not enough image data");
1241 + if (png_ptr->chunk_name != png_fdAT)
1243 + png_warning(png_ptr, "Skipped (ignored) a chunk "
1244 + "between APNG chunks");
1245 + bytes_to_skip = png_ptr->idat_size;
1246 + continue;
1249 + png_ensure_sequence_number(png_ptr, png_ptr->idat_size);
1251 + png_ptr->idat_size -= 4;
1254 +#else
1255 while (png_ptr->idat_size == 0)
1257 png_crc_finish(png_ptr, 0);
1258 @@ -3970,6 +4181,7 @@
1259 if (png_ptr->chunk_name != png_IDAT)
1260 png_error(png_ptr, "Not enough image data");
1262 +#endif /* READ_APNG */
1264 avail_in = png_ptr->IDAT_read_size;
1266 @@ -4033,6 +4245,9 @@
1268 png_ptr->mode |= PNG_AFTER_IDAT;
1269 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
1270 +#ifdef PNG_READ_APNG_SUPPORTED
1271 + png_ptr->num_frames_read++;
1272 +#endif
1274 if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
1275 png_chunk_benign_error(png_ptr, "Extra compressed data");
1276 @@ -4471,4 +4686,80 @@
1278 png_ptr->flags |= PNG_FLAG_ROW_INIT;
1281 +#ifdef PNG_READ_APNG_SUPPORTED
1282 +/* This function is to be called after the main IDAT set has been read and
1283 + * before a new IDAT is read. It resets some parts of png_ptr
1284 + * to make them usable by the read functions again */
1285 +void /* PRIVATE */
1286 +png_read_reset(png_structp png_ptr)
1288 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1289 + png_ptr->mode &= ~PNG_AFTER_IDAT;
1290 + png_ptr->row_number = 0;
1291 + png_ptr->pass = 0;
1294 +void /* PRIVATE */
1295 +png_read_reinit(png_structp png_ptr, png_infop info_ptr)
1297 + png_ptr->width = info_ptr->next_frame_width;
1298 + png_ptr->height = info_ptr->next_frame_height;
1299 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
1300 + png_ptr->info_rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,
1301 + png_ptr->width);
1302 + if (png_ptr->prev_row != NULL)
1303 + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
1306 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1307 +/* same as png_read_reset() but for the progressive reader */
1308 +void /* PRIVATE */
1309 +png_progressive_read_reset(png_structp png_ptr)
1311 +#ifdef PNG_READ_INTERLACING_SUPPORTED
1312 + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1314 + /* Start of interlace block */
1315 + static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1317 + /* Offset to next interlace block */
1318 + static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1320 + /* Start of interlace block in the y direction */
1321 + static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1323 + /* Offset to next interlace block in the y direction */
1324 + static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1326 + if (png_ptr->interlaced != 0)
1328 + if ((png_ptr->transformations & PNG_INTERLACE) == 0)
1329 + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1330 + png_pass_ystart[0]) / png_pass_yinc[0];
1331 + else
1332 + png_ptr->num_rows = png_ptr->height;
1334 + png_ptr->iwidth = (png_ptr->width +
1335 + png_pass_inc[png_ptr->pass] - 1 -
1336 + png_pass_start[png_ptr->pass]) /
1337 + png_pass_inc[png_ptr->pass];
1339 + else
1340 +#endif /* READ_INTERLACING */
1342 + png_ptr->num_rows = png_ptr->height;
1343 + png_ptr->iwidth = png_ptr->width;
1345 + png_ptr->flags &= ~PNG_FLAG_ZSTREAM_ENDED;
1346 + if (inflateReset(&(png_ptr->zstream)) != Z_OK)
1347 + png_error(png_ptr, "inflateReset failed");
1348 + png_ptr->zstream.avail_in = 0;
1349 + png_ptr->zstream.next_in = 0;
1350 + png_ptr->zstream.next_out = png_ptr->row_buf;
1351 + png_ptr->zstream.avail_out = (uInt)PNG_ROWBYTES(png_ptr->pixel_depth,
1352 + png_ptr->iwidth) + 1;
1354 +#endif /* PROGRESSIVE_READ */
1355 +#endif /* READ_APNG */
1356 #endif /* READ */
1357 Index: pngwutil.c
1358 ===================================================================
1359 --- pngwutil.c
1360 +++ pngwutil.c
1361 @@ -901,6 +901,11 @@
1362 /* Write the chunk */
1363 png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
1365 +#ifdef PNG_WRITE_APNG_SUPPORTED
1366 + png_ptr->first_frame_width = width;
1367 + png_ptr->first_frame_height = height;
1368 +#endif
1370 if ((png_ptr->do_filter) == PNG_NO_FILTERS)
1372 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
1373 @@ -1079,7 +1084,15 @@
1374 optimize_cmf(data, png_image_size(png_ptr));
1375 #endif
1377 +#ifdef PNG_WRITE_APNG_SUPPORTED
1378 + if (png_ptr->num_frames_written == 0)
1379 +#endif
1380 png_write_complete_chunk(png_ptr, png_IDAT, data, size);
1381 +#ifdef PNG_WRITE_APNG_SUPPORTED
1382 + else
1383 + png_write_fdAT(png_ptr, data, size);
1384 +#endif /* WRITE_APNG */
1386 png_ptr->mode |= PNG_HAVE_IDAT;
1388 png_ptr->zstream.next_out = data;
1389 @@ -1125,7 +1138,15 @@
1390 optimize_cmf(data, png_image_size(png_ptr));
1391 #endif
1393 +#ifdef PNG_WRITE_APNG_SUPPORTED
1394 + if (png_ptr->num_frames_written == 0)
1395 +#endif
1396 png_write_complete_chunk(png_ptr, png_IDAT, data, size);
1397 +#ifdef PNG_WRITE_APNG_SUPPORTED
1398 + else
1399 + png_write_fdAT(png_ptr, data, size);
1400 +#endif /* WRITE_APNG */
1402 png_ptr->zstream.avail_out = 0;
1403 png_ptr->zstream.next_out = NULL;
1404 png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT;
1405 @@ -1938,6 +1959,82 @@
1407 #endif
1409 +#ifdef PNG_WRITE_APNG_SUPPORTED
1410 +void /* PRIVATE */
1411 +png_write_acTL(png_structp png_ptr,
1412 + png_uint_32 num_frames, png_uint_32 num_plays)
1414 + png_byte buf[8];
1416 + png_debug(1, "in png_write_acTL");
1418 + png_ptr->num_frames_to_write = num_frames;
1420 + if ((png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) != 0)
1421 + num_frames--;
1423 + png_save_uint_32(buf, num_frames);
1424 + png_save_uint_32(buf + 4, num_plays);
1426 + png_write_complete_chunk(png_ptr, png_acTL, buf, (png_size_t)8);
1429 +void /* PRIVATE */
1430 +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
1431 + png_uint_32 x_offset, png_uint_32 y_offset,
1432 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
1433 + png_byte blend_op)
1435 + png_byte buf[26];
1437 + png_debug(1, "in png_write_fcTL");
1439 + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0))
1440 + png_error(png_ptr, "x and/or y offset for the first frame aren't 0");
1441 + if (png_ptr->num_frames_written == 0 &&
1442 + (width != png_ptr->first_frame_width ||
1443 + height != png_ptr->first_frame_height))
1444 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1445 + "don't match the ones in IHDR");
1447 + /* more error checking */
1448 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1449 + delay_num, delay_den, dispose_op, blend_op);
1451 + png_save_uint_32(buf, png_ptr->next_seq_num);
1452 + png_save_uint_32(buf + 4, width);
1453 + png_save_uint_32(buf + 8, height);
1454 + png_save_uint_32(buf + 12, x_offset);
1455 + png_save_uint_32(buf + 16, y_offset);
1456 + png_save_uint_16(buf + 20, delay_num);
1457 + png_save_uint_16(buf + 22, delay_den);
1458 + buf[24] = dispose_op;
1459 + buf[25] = blend_op;
1461 + png_write_complete_chunk(png_ptr, png_fcTL, buf, (png_size_t)26);
1463 + png_ptr->next_seq_num++;
1466 +void /* PRIVATE */
1467 +png_write_fdAT(png_structp png_ptr,
1468 + png_const_bytep data, png_size_t length)
1470 + png_byte buf[4];
1472 + png_write_chunk_header(png_ptr, png_fdAT, (png_uint_32)(4 + length));
1474 + png_save_uint_32(buf, png_ptr->next_seq_num);
1475 + png_write_chunk_data(png_ptr, buf, 4);
1477 + png_write_chunk_data(png_ptr, data, length);
1479 + png_write_chunk_end(png_ptr);
1481 + png_ptr->next_seq_num++;
1483 +#endif /* WRITE_APNG */
1485 /* Initializes the row writing capability of libpng */
1486 void /* PRIVATE */
1487 png_write_start_row(png_structrp png_ptr)
1488 @@ -3026,4 +3123,39 @@
1490 #endif /* WRITE_FLUSH */
1493 +#ifdef PNG_WRITE_APNG_SUPPORTED
1494 +void /* PRIVATE */
1495 +png_write_reset(png_structp png_ptr)
1497 + png_ptr->row_number = 0;
1498 + png_ptr->pass = 0;
1499 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1502 +void /* PRIVATE */
1503 +png_write_reinit(png_structp png_ptr, png_infop info_ptr,
1504 + png_uint_32 width, png_uint_32 height)
1506 + if (png_ptr->num_frames_written == 0 &&
1507 + (width != png_ptr->first_frame_width ||
1508 + height != png_ptr->first_frame_height))
1509 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1510 + "don't match the ones in IHDR");
1511 + if (width > png_ptr->first_frame_width ||
1512 + height > png_ptr->first_frame_height)
1513 + png_error(png_ptr, "width and/or height for a frame greater than"
1514 + "the ones in IHDR");
1516 + png_set_IHDR(png_ptr, info_ptr, width, height,
1517 + info_ptr->bit_depth, info_ptr->color_type,
1518 + info_ptr->interlace_type, info_ptr->compression_type,
1519 + info_ptr->filter_type);
1521 + png_ptr->width = width;
1522 + png_ptr->height = height;
1523 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
1524 + png_ptr->usr_width = png_ptr->width;
1526 +#endif /* WRITE_APNG */
1527 #endif /* WRITE */
1528 Index: scripts/symbols.def
1529 ===================================================================
1530 --- scripts/symbols.def
1531 +++ scripts/symbols.def
1532 @@ -249,3 +249,23 @@
1533 png_set_check_for_invalid_index @242
1534 png_get_palette_max @243
1535 png_set_option @244
1536 + png_get_acTL @245
1537 + png_set_acTL @246
1538 + png_get_num_frames @247
1539 + png_get_num_plays @248
1540 + png_get_next_frame_fcTL @249
1541 + png_set_next_frame_fcTL @250
1542 + png_get_next_frame_width @251
1543 + png_get_next_frame_height @252
1544 + png_get_next_frame_x_offset @253
1545 + png_get_next_frame_y_offset @254
1546 + png_get_next_frame_delay_num @255
1547 + png_get_next_frame_delay_den @256
1548 + png_get_next_frame_dispose_op @257
1549 + png_get_next_frame_blend_op @258
1550 + png_get_first_frame_is_hidden @259
1551 + png_set_first_frame_is_hidden @260
1552 + png_read_frame_head @261
1553 + png_set_progressive_frame_fn @262
1554 + png_write_frame_head @263
1555 + png_write_frame_tail @264