2 ===================================================================
3 --- pngread.c (révision 149)
4 +++ pngread.c (copie de travail)
6 #if defined(PNG_READ_zTXt_SUPPORTED)
9 +#if defined(PNG_READ_APNG_SUPPORTED)
14 #endif /* PNG_USE_LOCAL_ARRAYS */
15 png_byte chunk_length[4];
18 !(png_ptr->mode & PNG_HAVE_PLTE))
19 png_error(png_ptr, "Missing PLTE before IDAT");
21 +#if defined(PNG_READ_APNG_SUPPORTED)
22 + png_have_info(png_ptr, info_ptr);
24 png_ptr->idat_size = length;
25 png_ptr->mode |= PNG_HAVE_IDAT;
28 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
29 png_handle_iTXt(png_ptr, info_ptr, length);
31 +#if defined(PNG_READ_APNG_SUPPORTED)
32 + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
33 + png_handle_acTL(png_ptr, info_ptr, length);
34 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
35 + png_handle_fcTL(png_ptr, info_ptr, length);
36 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
37 + png_handle_fdAT(png_ptr, info_ptr, length);
40 png_handle_unknown(png_ptr, info_ptr, length);
43 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
45 +#if defined(PNG_READ_APNG_SUPPORTED)
47 +png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
49 + png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
51 + png_debug(0, "Reading frame head\n");
53 + if (!(png_ptr->mode & PNG_HAVE_acTL))
54 + png_error(png_ptr, "attempt to png_read_frame_head() but "
57 + /* do nothing for the main IDAT */
58 + if (png_ptr->num_frames_read == 0)
61 + png_crc_finish(png_ptr, 0); /* CRC from last IDAT or fdAT chunk */
63 + png_read_reset(png_ptr);
64 + png_ptr->mode &= ~PNG_HAVE_fcTL;
66 + have_chunk_after_DAT = 0;
69 +#ifdef PNG_USE_LOCAL_ARRAYS
74 + png_byte chunk_length[4];
77 + png_read_data(png_ptr, chunk_length, 4);
78 + length = png_get_uint_31(png_ptr, chunk_length);
80 + png_reset_crc(png_ptr);
81 + png_crc_read(png_ptr, png_ptr->chunk_name, 4);
83 + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
85 + /* discard trailing IDATs for the first frame */
86 + if (have_chunk_after_DAT || png_ptr->num_frames_read > 1)
87 + png_error(png_ptr, "png_read_frame_head(): out of place IDAT");
88 + png_crc_finish(png_ptr, length);
90 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
92 + png_handle_fcTL(png_ptr, info_ptr, length);
93 + have_chunk_after_DAT = 1;
95 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
97 + png_ensure_sequence_number(png_ptr, length);
99 + /* discard trailing fdATs for frames other than the first */
100 + if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1)
101 + png_crc_finish(png_ptr, length - 4);
102 + else if(png_ptr->mode & PNG_HAVE_fcTL)
104 + png_ptr->idat_size = length - 4;
105 + png_ptr->mode |= PNG_HAVE_IDAT;
110 + png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
114 + png_warning(png_ptr, "Skipped (ignored) a chunk "
115 + "between APNG chunks");
116 + png_crc_finish(png_ptr, length);
120 +#endif /* PNG_READ_APNG_SUPPORTED */
122 /* optional call to update the users info_ptr structure */
124 png_read_update_info(png_structp png_ptr, png_infop info_ptr)
127 #ifdef PNG_USE_LOCAL_ARRAYS
129 +#if defined(PNG_READ_APNG_SUPPORTED)
130 + PNG_CONST PNG_fdAT;
131 + PNG_CONST PNG_IEND;
133 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
135 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
136 @@ -701,19 +798,46 @@
138 if (!(png_ptr->zstream.avail_in))
140 - while (!png_ptr->idat_size)
141 + png_uint_32 bytes_to_skip = 0;
143 + while (!png_ptr->idat_size || bytes_to_skip != 0)
145 png_byte chunk_length[4];
147 - png_crc_finish(png_ptr, 0);
149 + png_crc_finish(png_ptr, bytes_to_skip);
152 png_read_data(png_ptr, chunk_length, 4);
153 png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
156 png_reset_crc(png_ptr);
157 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
158 - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
159 - png_error(png_ptr, "Not enough image data");
161 +#if defined(PNG_READ_APNG_SUPPORTED)
162 + if (png_ptr->num_frames_read == 0)
165 + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
166 + png_error(png_ptr, "Not enough image data");
167 +#if defined(PNG_READ_APNG_SUPPORTED)
171 + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
172 + png_error(png_ptr, "Not enough image data");
173 + if (png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
175 + png_warning(png_ptr, "Skipped (ignored) a chunk "
176 + "between APNG chunks");
177 + bytes_to_skip = png_ptr->idat_size;
181 + png_ensure_sequence_number(png_ptr, png_ptr->idat_size);
183 + png_ptr->idat_size -= 4;
187 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
188 png_ptr->zstream.next_in = png_ptr->zbuf;
190 png_error(png_ptr, "Extra compressed data");
191 png_ptr->mode |= PNG_AFTER_IDAT;
192 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
193 +#if defined(PNG_READ_APNG_SUPPORTED)
194 + png_ptr->num_frames_read++;
199 @@ -985,6 +1112,11 @@
200 #if defined(PNG_READ_zTXt_SUPPORTED)
203 +#if defined(PNG_READ_APNG_SUPPORTED)
204 + PNG_CONST PNG_acTL;
205 + PNG_CONST PNG_fcTL;
206 + PNG_CONST PNG_fdAT;
208 #endif /* PNG_USE_LOCAL_ARRAYS */
210 png_read_data(png_ptr, chunk_length, 4);
211 @@ -1091,6 +1223,14 @@
212 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
213 png_handle_iTXt(png_ptr, info_ptr, length);
215 +#if defined(PNG_READ_APNG_SUPPORTED)
216 + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
217 + png_handle_acTL(png_ptr, info_ptr, length);
218 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
219 + png_handle_fcTL(png_ptr, info_ptr, length);
220 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
221 + png_handle_fdAT(png_ptr, info_ptr, length);
224 png_handle_unknown(png_ptr, info_ptr, length);
225 } while (!(png_ptr->mode & PNG_HAVE_IEND));
227 ===================================================================
228 --- pngget.c (révision 149)
229 +++ pngget.c (copie de travail)
230 @@ -797,6 +797,167 @@
234 +#if defined(PNG_APNG_SUPPORTED)
236 +png_get_acTL(png_structp png_ptr, png_infop info_ptr,
237 + png_uint_32 *num_frames, png_uint_32 *num_plays)
239 + png_debug1(1, "in %s retrieval function\n", "acTL");
241 + if (png_ptr != NULL && info_ptr != NULL &&
242 + (info_ptr->valid & PNG_INFO_acTL) &&
243 + num_frames != NULL && num_plays != NULL)
245 + *num_frames = info_ptr->num_frames;
246 + *num_plays = info_ptr->num_plays;
254 +png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
256 + png_debug(1, "in png_get_num_frames()\n");
258 + if (png_ptr != NULL && info_ptr != NULL)
259 + return (info_ptr->num_frames);
264 +png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
266 + png_debug(1, "in png_get_num_plays()\n");
268 + if (png_ptr != NULL && info_ptr != NULL)
269 + return (info_ptr->num_plays);
274 +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
275 + png_uint_32 *width, png_uint_32 *height,
276 + png_uint_32 *x_offset, png_uint_32 *y_offset,
277 + png_uint_16 *delay_num, png_uint_16 *delay_den,
278 + png_byte *dispose_op, png_byte *blend_op)
280 + png_debug1(1, "in %s retrieval function\n", "fcTL");
282 + if (png_ptr != NULL && info_ptr != NULL &&
283 + (info_ptr->valid & PNG_INFO_fcTL) &&
284 + width != NULL && height != NULL &&
285 + x_offset != NULL && x_offset != NULL &&
286 + delay_num != NULL && delay_den != NULL &&
287 + dispose_op != NULL && blend_op != NULL)
289 + *width = info_ptr->next_frame_width;
290 + *height = info_ptr->next_frame_height;
291 + *x_offset = info_ptr->next_frame_x_offset;
292 + *y_offset = info_ptr->next_frame_y_offset;
293 + *delay_num = info_ptr->next_frame_delay_num;
294 + *delay_den = info_ptr->next_frame_delay_den;
295 + *dispose_op = info_ptr->next_frame_dispose_op;
296 + *blend_op = info_ptr->next_frame_blend_op;
304 +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
306 + png_debug(1, "in png_get_next_frame_width()\n");
308 + if (png_ptr != NULL && info_ptr != NULL)
309 + return (info_ptr->next_frame_width);
314 +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
316 + png_debug(1, "in png_get_next_frame_height()\n");
318 + if (png_ptr != NULL && info_ptr != NULL)
319 + return (info_ptr->next_frame_height);
324 +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
326 + png_debug(1, "in png_get_next_frame_x_offset()\n");
328 + if (png_ptr != NULL && info_ptr != NULL)
329 + return (info_ptr->next_frame_x_offset);
334 +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
336 + png_debug(1, "in png_get_next_frame_y_offset()\n");
338 + if (png_ptr != NULL && info_ptr != NULL)
339 + return (info_ptr->next_frame_y_offset);
344 +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
346 + png_debug(1, "in png_get_next_frame_delay_num()\n");
348 + if (png_ptr != NULL && info_ptr != NULL)
349 + return (info_ptr->next_frame_delay_num);
354 +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
356 + png_debug(1, "in png_get_next_frame_delay_den()\n");
358 + if (png_ptr != NULL && info_ptr != NULL)
359 + return (info_ptr->next_frame_delay_den);
364 +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
366 + png_debug(1, "in png_get_next_frame_dispose_op()\n");
368 + if (png_ptr != NULL && info_ptr != NULL)
369 + return (info_ptr->next_frame_dispose_op);
374 +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
376 + png_debug(1, "in png_get_next_frame_blend_op()\n");
378 + if (png_ptr != NULL && info_ptr != NULL)
379 + return (info_ptr->next_frame_blend_op);
384 +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
386 + png_debug(1, "in png_first_frame_is_hidden()\n");
388 + if (png_ptr != NULL)
389 + return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
393 +#endif /* PNG_APNG_SUPPORTED */
395 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
397 png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
399 ===================================================================
400 --- png.c (révision 149)
401 +++ png.c (copie de travail)
410 #ifdef PNG_READ_SUPPORTED
411 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
413 ===================================================================
414 --- png.h (révision 149)
415 +++ png.h (copie de travail)
417 png_fixed_point int_y_blue;
420 +#if defined(PNG_APNG_SUPPORTED)
421 + png_uint_32 num_frames; /* including default image */
422 + png_uint_32 num_plays;
423 + png_uint_32 next_frame_width;
424 + png_uint_32 next_frame_height;
425 + png_uint_32 next_frame_x_offset;
426 + png_uint_32 next_frame_y_offset;
427 + png_uint_16 next_frame_delay_num;
428 + png_uint_16 next_frame_delay_den;
429 + png_byte next_frame_dispose_op;
430 + png_byte next_frame_blend_op;
435 typedef png_info FAR * png_infop;
436 @@ -1050,6 +1063,8 @@
437 #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
438 #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
439 #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
440 +#define PNG_INFO_acTL 0x10000L
441 +#define PNG_INFO_fcTL 0x20000L
443 /* This is used for the transformation routines, as some of them
444 * change these values for the row. It also should enable using
445 @@ -1090,7 +1105,11 @@
446 typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
447 typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
449 +#if defined(PNG_APNG_SUPPORTED)
450 +typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp,
455 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
456 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
457 @@ -1421,6 +1440,39 @@
458 png_uint_32 user_height_max;
461 +#if defined(PNG_APNG_SUPPORTED)
462 + png_uint_32 apng_flags;
463 + png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */
464 + png_uint_32 first_frame_width;
465 + png_uint_32 first_frame_height;
467 +#if defined(PNG_READ_APNG_SUPPORTED)
468 + png_uint_32 num_frames_read; /* incremented after all image data of */
469 + /* a frame is read */
470 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
471 + png_progressive_frame_ptr frame_info_fn; /* frame info read callback */
472 + png_progressive_frame_ptr frame_end_fn; /* frame data read callback */
476 +#if defined(PNG_WRITE_APNG_SUPPORTED)
477 + png_uint_32 num_frames_to_write;
478 + png_uint_32 num_frames_written;
482 +/* For png_struct.apng_flags: */
483 +#define PNG_FIRST_FRAME_HIDDEN 0x0001
485 +/* dispose_op flags from inside fcTL */
486 +#define PNG_DISPOSE_OP_NONE 0x00
487 +#define PNG_DISPOSE_OP_BACKGROUND 0x01
488 +#define PNG_DISPOSE_OP_PREVIOUS 0x02
490 +/* blend_op flags from inside fcTL */
491 +#define PNG_BLEND_OP_SOURCE 0x00
492 +#define PNG_BLEND_OP_OVER 0x01
494 /* New member added in libpng-1.0.25 and 1.2.17 */
495 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
496 /* storage for unknown chunk that the library doesn't recognize. */
497 @@ -1747,6 +1799,18 @@
498 extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
501 +#if defined(PNG_WRITE_APNG_SUPPORTED)
502 +extern PNG_EXPORT (void,png_write_frame_head) PNGARG((png_structp png_ptr,
503 + png_infop png_info, png_bytepp row_pointers,
504 + png_uint_32 width, png_uint_32 height,
505 + png_uint_32 x_offset, png_uint_32 y_offset,
506 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
507 + png_byte blend_op));
509 +extern PNG_EXPORT (void,png_write_frame_tail) PNGARG((png_structp png_ptr,
510 + png_infop png_info));
513 /* writes the end of the PNG file. */
514 extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
515 png_infop info_ptr));
516 @@ -1995,6 +2059,11 @@
517 png_voidp progressive_ptr,
518 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
519 png_progressive_end_ptr end_fn));
520 +#if defined(PNG_READ_APNG_SUPPORTED)
521 +extern PNG_EXPORT(void,png_set_progressive_frame_fn) PNGARG((png_structp png_ptr,
522 + png_progressive_frame_ptr frame_info_fn,
523 + png_progressive_frame_ptr frame_end_fn));
526 /* returns the user pointer associated with the push read functions */
527 extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
528 @@ -2432,6 +2501,59 @@
530 #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
532 +#if defined(PNG_APNG_SUPPORTED)
533 +extern PNG_EXPORT(png_uint_32,png_get_acTL) PNGARG((png_structp png_ptr,
534 + png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays));
535 +extern PNG_EXPORT(png_uint_32,png_set_acTL) PNGARG((png_structp png_ptr,
536 + png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays));
537 +extern PNG_EXPORT(png_uint_32,png_get_num_frames) PNGARG((png_structp png_ptr,
538 + png_infop info_ptr));
539 +extern PNG_EXPORT(png_uint_32,png_get_num_plays)
540 + PNGARG((png_structp png_ptr, png_infop info_ptr));
542 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_fcTL)
543 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width,
544 + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset,
545 + png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op,
546 + png_byte *blend_op));
547 +extern PNG_EXPORT(png_uint_32,png_set_next_frame_fcTL)
548 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width,
549 + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset,
550 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
551 + png_byte blend_op));
552 +extern PNG_EXPORT(void,png_ensure_fcTL_is_valid)
553 + PNGARG((png_structp png_ptr,
554 + png_uint_32 width, png_uint_32 height,
555 + png_uint_32 x_offset, png_uint_32 y_offset,
556 + png_uint_16 delay_num, png_uint_16 delay_den,
557 + png_byte dispose_op, png_byte blend_op));
558 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_width)
559 + PNGARG((png_structp png_ptr, png_infop info_ptr));
560 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_height)
561 + PNGARG((png_structp png_ptr, png_infop info_ptr));
562 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_x_offset)
563 + PNGARG((png_structp png_ptr, png_infop info_ptr));
564 +extern PNG_EXPORT(png_uint_32,png_get_next_frame_y_offset)
565 + PNGARG((png_structp png_ptr, png_infop info_ptr));
566 +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_num)
567 + PNGARG((png_structp png_ptr, png_infop info_ptr));
568 +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_den)
569 + PNGARG((png_structp png_ptr, png_infop info_ptr));
570 +extern PNG_EXPORT(png_byte,png_get_next_frame_dispose_op)
571 + PNGARG((png_structp png_ptr, png_infop info_ptr));
572 +extern PNG_EXPORT(png_byte,png_get_next_frame_blend_op)
573 + PNGARG((png_structp png_ptr, png_infop info_ptr));
574 +extern PNG_EXPORT(png_byte,png_get_first_frame_is_hidden)
575 + PNGARG((png_structp png_ptr, png_infop info_ptr));
576 +extern PNG_EXPORT(png_uint_32,png_set_first_frame_is_hidden)
577 + PNGARG((png_structp png_ptr, png_infop info_ptr, png_byte is_hidden));
578 +#endif /* PNG_APNG_SUPPORTED */
580 +#if defined(PNG_READ_APNG_SUPPORTED)
581 +extern PNG_EXPORT(void,png_read_frame_head) PNGARG((png_structp png_ptr,
582 + png_infop info_ptr));
585 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
586 /* provide a list of chunks and how they are to be handled, if the built-in
587 handling or default unknown chunk handling is not desired. Any chunks not
588 @@ -2738,6 +2860,8 @@
589 #define PNG_BACKGROUND_IS_GRAY 0x800
590 #define PNG_HAVE_PNG_SIGNATURE 0x1000
591 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
592 +#define PNG_HAVE_acTL 0x4000
593 +#define PNG_HAVE_fcTL 0x8000L
595 /* flags for the transformations the PNG library does on the image data */
596 #define PNG_BGR 0x0001
597 @@ -2878,6 +3002,9 @@
598 #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
599 #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
600 #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
601 +#define PNG_acTL png_byte png_acTL[5] = { 97, 99, 84, 76, '\0'}
602 +#define PNG_fcTL png_byte png_fcTL[5] = {102, 99, 84, 76, '\0'}
603 +#define PNG_fdAT png_byte png_fdAT[5] = {102, 100, 65, 84, '\0'}
605 #ifdef PNG_USE_GLOBAL_ARRAYS
606 PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
607 @@ -2901,6 +3028,9 @@
608 PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
609 PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
610 PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
611 +PNG_EXPORT_VAR (png_byte FARDATA) png_acTL[5];
612 +PNG_EXPORT_VAR (png_byte FARDATA) png_fcTL[5];
613 +PNG_EXPORT_VAR (png_byte FARDATA) png_fdAT[5];
614 #endif /* PNG_USE_GLOBAL_ARRAYS */
616 #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
617 @@ -3175,6 +3305,17 @@
621 +#if defined(PNG_WRITE_APNG_SUPPORTED)
622 +PNG_EXTERN void png_write_acTL PNGARG((png_structp png_ptr,
623 + png_uint_32 num_frames, png_uint_32 num_plays));
625 +PNG_EXTERN void png_write_fcTL PNGARG((png_structp png_ptr,
626 + png_uint_32 width, png_uint_32 height,
627 + png_uint_32 x_offset, png_uint_32 y_offset,
628 + png_uint_16 delay_num, png_uint_16 delay_den,
629 + png_byte dispose_op, png_byte blend_op));
632 /* Called when finished processing a row of data */
633 PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
635 @@ -3226,6 +3367,20 @@
636 PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
637 png_infop info_ptr));
639 +#if defined(PNG_READ_APNG_SUPPORTED)
640 +/* private, reset some things to become ready for reading next frame */
641 +PNG_EXTERN void png_read_reset PNGARG((png_structp png_ptr));
642 +PNG_EXTERN void png_read_reinit PNGARG((png_structp png_ptr,
643 + png_infop info_ptr));
644 +PNG_EXTERN void png_progressive_read_reset PNGARG((png_structp png_ptr));
646 +#if defined(PNG_WRITE_APNG_SUPPORTED)
647 +/* private, reset some things to become ready for writing next frame */
648 +PNG_EXTERN void png_write_reset PNGARG((png_structp png_ptr));
649 +PNG_EXTERN void png_write_reinit PNGARG((png_structp png_ptr,
650 + png_infop info_ptr, png_uint_32 width, png_uint_32 height));
653 /* these are the functions that do the transformations */
654 #if defined(PNG_READ_FILLER_SUPPORTED)
655 PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
656 @@ -3441,6 +3596,18 @@
657 png_uint_32 length));
660 +#if defined(PNG_READ_APNG_SUPPORTED)
661 +PNG_EXTERN void png_handle_acTL PNGARG((png_structp png_ptr, png_infop info_ptr,
662 + png_uint_32 length));
663 +PNG_EXTERN void png_handle_fcTL PNGARG((png_structp png_ptr, png_infop info_ptr,
664 + png_uint_32 length));
665 +PNG_EXTERN void png_have_info PNGARG((png_structp png_ptr, png_infop info_ptr));
666 +PNG_EXTERN void png_handle_fdAT PNGARG((png_structp png_ptr, png_infop info_ptr,
667 + png_uint_32 length));
668 +PNG_EXTERN void png_ensure_sequence_number PNGARG((png_structp png_ptr,
669 + png_uint_32 length));
672 PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
673 png_infop info_ptr, png_uint_32 length));
676 ===================================================================
677 --- pngtrans.c (révision 149)
678 +++ pngtrans.c (copie de travail)
679 @@ -652,11 +652,10 @@
681 png_get_user_transform_ptr(png_structp png_ptr)
683 -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
684 if (png_ptr == NULL) return (NULL);
685 +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
686 return ((png_voidp)png_ptr->user_transform_ptr);
692 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
694 ===================================================================
695 --- pngwrite.c (révision 149)
696 +++ pngwrite.c (copie de travail)
701 +#if defined(PNG_WRITE_APNG_SUPPORTED)
702 + if (info_ptr->valid & PNG_INFO_acTL)
703 + png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
705 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
706 if (info_ptr->unknown_chunks_num)
710 if (!(png_ptr->mode & PNG_HAVE_IDAT))
711 png_error(png_ptr, "No IDATs written into file");
712 +#if defined(PNG_WRITE_APNG_SUPPORTED)
713 + if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
714 + png_error(png_ptr, "Not enough frames written");
717 /* see if user wants us to write information chunks */
718 if (info_ptr != NULL)
719 @@ -1527,4 +1535,39 @@
724 +#if defined(PNG_WRITE_APNG_SUPPORTED)
726 +png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
727 + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height,
728 + png_uint_32 x_offset, png_uint_32 y_offset,
729 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
732 + png_debug(1, "in png_write_frame_head\n");
734 + /* there is a chance this has been set after png_write_info was called,
735 + * so it would be set but not written. is there a way to be sure? */
736 + if (!(info_ptr->valid & PNG_INFO_acTL))
737 + png_error(png_ptr, "png_write_frame_head(): acTL not set");
739 + png_write_reset(png_ptr);
741 + png_write_reinit(png_ptr, info_ptr, width, height);
743 + if ( !(png_ptr->num_frames_written == 0 &&
744 + (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) )
745 + png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
746 + delay_num, delay_den, dispose_op, blend_op);
750 +png_write_frame_tail(png_structp png_ptr, png_infop png_info)
752 + png_debug(1, "in png_write_frame_tail\n");
754 + png_ptr->num_frames_written++;
756 +#endif /* PNG_WRITE_APNG_SUPPORTED */
758 #endif /* PNG_WRITE_SUPPORTED */
760 ===================================================================
761 --- pngconf.h (révision 149)
762 +++ pngconf.h (copie de travail)
764 # define PNG_READ_zTXt_SUPPORTED
765 # define PNG_zTXt_SUPPORTED
767 +#ifndef PNG_NO_READ_APNG
768 +# define PNG_READ_APNG_SUPPORTED
769 +# define PNG_APNG_SUPPORTED
771 #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
772 # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
773 # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
774 @@ -1067,6 +1071,12 @@
775 # define PNG_zTXt_SUPPORTED
778 +#ifndef PNG_NO_WRITE_APNG
779 +# define PNG_WRITE_APNG_SUPPORTED
780 +# ifndef PNG_APNG_SUPPORTED
781 +# define PNG_APNG_SUPPORTED
784 #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
785 # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
786 # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
788 ===================================================================
789 --- pngpread.c (révision 149)
790 +++ pngpread.c (copie de travail)
792 #if defined(PNG_READ_zTXt_SUPPORTED)
795 +#if defined(PNG_READ_APNG_SUPPORTED)
796 + PNG_CONST PNG_acTL;
797 + PNG_CONST PNG_fcTL;
798 + PNG_CONST PNG_fdAT;
800 #endif /* PNG_USE_LOCAL_ARRAYS */
801 /* First we make sure we have enough data for the 4 byte chunk name
802 * and the 4 byte chunk length before proceeding with decoding the
803 @@ -215,7 +220,104 @@
804 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
805 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
809 +#if defined(PNG_READ_APNG_SUPPORTED)
810 + if (png_ptr->num_frames_read > 0 &&
811 + png_ptr->num_frames_read < info_ptr->num_frames)
813 + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
815 + /* discard trailing IDATs for the first frame */
816 + if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1)
817 + png_error(png_ptr, "out of place IDAT");
819 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
821 + png_push_save_buffer(png_ptr);
824 + png_push_crc_skip(png_ptr, png_ptr->push_length);
825 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
828 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
830 + if (png_ptr->buffer_size < 4)
832 + png_push_save_buffer(png_ptr);
835 + png_ensure_sequence_number(png_ptr, 4);
837 + if (!(png_ptr->mode & PNG_HAVE_fcTL))
839 + /* discard trailing fdATs for frames other than the first */
840 + if (png_ptr->num_frames_read < 2)
841 + png_error(png_ptr, "out of place fdAT");
843 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
845 + png_push_save_buffer(png_ptr);
848 + png_push_crc_skip(png_ptr, png_ptr->push_length);
849 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
854 + /* frame data follows */
855 + png_ptr->idat_size = png_ptr->push_length - 4;
856 + png_ptr->mode |= PNG_HAVE_IDAT;
857 + png_ptr->process_mode = PNG_READ_IDAT_MODE;
862 + else if(!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
864 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
866 + png_push_save_buffer(png_ptr);
870 + png_read_reset(png_ptr);
871 + png_ptr->mode &= ~PNG_HAVE_fcTL;
873 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
875 + if (!(png_ptr->mode & PNG_HAVE_fcTL))
876 + png_error(png_ptr, "missing required fcTL chunk");
878 + png_read_reinit(png_ptr, info_ptr);
879 + png_progressive_read_reset(png_ptr);
881 + if (png_ptr->frame_info_fn != NULL)
882 + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read);
884 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
890 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
892 + png_push_save_buffer(png_ptr);
895 + png_warning(png_ptr, "Skipped (ignored) a chunk "
896 + "between APNG chunks");
897 + png_push_crc_skip(png_ptr, png_ptr->push_length);
898 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
904 +#endif /* PNG_READ_APNG_SUPPORTED */
906 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
907 if(png_ptr->mode & PNG_AFTER_IDAT)
908 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
910 png_error(png_ptr, "Too many IDAT's found");
913 +#if defined(PNG_READ_APNG_SUPPORTED)
914 + png_have_info(png_ptr, info_ptr);
916 png_ptr->idat_size = png_ptr->push_length;
917 png_ptr->mode |= PNG_HAVE_IDAT;
918 png_ptr->process_mode = PNG_READ_IDAT_MODE;
920 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
923 +#if defined(PNG_READ_APNG_SUPPORTED)
924 + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
926 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
928 + png_push_save_buffer(png_ptr);
931 + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
933 + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
935 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
937 + png_push_save_buffer(png_ptr);
940 + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
942 + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
944 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
946 + png_push_save_buffer(png_ptr);
949 + png_handle_fdAT(png_ptr, info_ptr, png_ptr->push_length);
951 +#endif /* PNG_READ_APNG_SUPPORTED */
954 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
955 @@ -660,13 +794,17 @@
956 png_push_read_IDAT(png_structp png_ptr)
958 #ifdef PNG_USE_LOCAL_ARRAYS
959 - PNG_CONST PNG_IDAT;
961 +#if defined(PNG_READ_APNG_SUPPORTED)
966 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
968 png_byte chunk_length[4];
970 - if (png_ptr->buffer_size < 8)
971 + if (png_ptr->buffer_size < 12)
973 png_push_save_buffer(png_ptr);
975 @@ -678,15 +816,59 @@
976 png_crc_read(png_ptr, png_ptr->chunk_name, 4);
977 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
979 - if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
980 +#if defined(PNG_READ_APNG_SUPPORTED)
981 + if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_fdAT, 4)
982 + && png_ptr->num_frames_read > 0)
984 + if (png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)
986 + png_ptr->process_mode = PNG_READ_CHUNK_MODE;
987 + if (png_ptr->frame_end_fn != NULL)
988 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
989 + png_ptr->num_frames_read++;
994 + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
995 + png_error(png_ptr, "Not enough image data");
996 + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
998 + png_push_save_buffer(png_ptr);
1001 + png_warning(png_ptr, "Skipping (ignoring) a chunk between "
1003 + png_crc_finish(png_ptr, png_ptr->push_length);
1004 + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
1010 + if ( png_memcmp(png_ptr->chunk_name, png_IDAT, 4)
1011 + && (png_ptr->num_frames_read == 0) )
1013 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
1014 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
1015 png_error(png_ptr, "Not enough compressed data");
1016 +#if defined(PNG_READ_APNG_SUPPORTED)
1017 + if (png_ptr->frame_end_fn != NULL)
1018 + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
1019 + png_ptr->num_frames_read++;
1024 png_ptr->idat_size = png_ptr->push_length;
1026 +#if defined(PNG_READ_APNG_SUPPORTED)
1027 + if(png_ptr->num_frames_read > 0)
1029 + png_ensure_sequence_number(png_ptr, 4);
1030 + png_ptr->idat_size -= 4;
1034 if (png_ptr->idat_size && png_ptr->save_buffer_size)
1036 @@ -1582,6 +1764,17 @@
1037 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1040 +#if defined(PNG_READ_APNG_SUPPORTED)
1042 +png_set_progressive_frame_fn(png_structp png_ptr,
1043 + png_progressive_frame_ptr frame_info_fn,
1044 + png_progressive_frame_ptr frame_end_fn)
1046 + png_ptr->frame_info_fn = frame_info_fn;
1047 + png_ptr->frame_end_fn = frame_end_fn;
1052 png_get_progressive_ptr(png_structp png_ptr)
1055 ===================================================================
1056 --- pngset.c (révision 149)
1057 +++ pngset.c (copie de travail)
1058 @@ -364,6 +364,11 @@
1059 info_ptr->rowbytes = (png_size_t)0;
1061 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
1063 +#if defined(PNG_APNG_SUPPORTED)
1064 + /* for non-animated png. this may be overritten from an acTL chunk later */
1065 + info_ptr->num_frames = 1;
1069 #if defined(PNG_oFFs_SUPPORTED)
1070 @@ -1012,6 +1017,141 @@
1072 #endif /* PNG_sPLT_SUPPORTED */
1074 +#if defined(PNG_APNG_SUPPORTED)
1076 +png_set_acTL(png_structp png_ptr, png_infop info_ptr,
1077 + png_uint_32 num_frames, png_uint_32 num_plays)
1079 + png_debug1(1, "in %s storage function\n", "acTL");
1081 + if (png_ptr == NULL || info_ptr == NULL)
1083 + png_warning(png_ptr,
1084 + "Call to png_set_acTL() with NULL png_ptr "
1085 + "or info_ptr ignored");
1088 + if (num_frames == 0)
1090 + png_warning(png_ptr,
1091 + "Ignoring attempt to set acTL with num_frames zero");
1094 + if (num_frames > PNG_UINT_31_MAX)
1096 + png_warning(png_ptr,
1097 + "Ignoring attempt to set acTL with num_frames > 2^31-1");
1100 + if (num_plays > PNG_UINT_31_MAX)
1102 + png_warning(png_ptr,
1103 + "Ignoring attempt to set acTL with num_plays "
1108 + info_ptr->num_frames = num_frames;
1109 + info_ptr->num_plays = num_plays;
1111 + info_ptr->valid |= PNG_INFO_acTL;
1116 +/* delay_num and delay_den can hold any 16-bit values including zero */
1118 +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
1119 + png_uint_32 width, png_uint_32 height,
1120 + png_uint_32 x_offset, png_uint_32 y_offset,
1121 + png_uint_16 delay_num, png_uint_16 delay_den,
1122 + png_byte dispose_op, png_byte blend_op)
1124 + png_debug1(1, "in %s storage function\n", "fcTL");
1126 + if (png_ptr == NULL || info_ptr == NULL)
1128 + png_warning(png_ptr,
1129 + "Call to png_set_fcTL() with NULL png_ptr or info_ptr "
1134 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1135 + delay_num, delay_den, dispose_op, blend_op);
1137 + info_ptr->next_frame_width = width;
1138 + info_ptr->next_frame_height = height;
1139 + info_ptr->next_frame_x_offset = x_offset;
1140 + info_ptr->next_frame_y_offset = y_offset;
1141 + info_ptr->next_frame_delay_num = delay_num;
1142 + info_ptr->next_frame_delay_den = delay_den;
1143 + info_ptr->next_frame_dispose_op = dispose_op;
1144 + info_ptr->next_frame_blend_op = blend_op;
1146 + info_ptr->valid |= PNG_INFO_fcTL;
1152 +png_ensure_fcTL_is_valid(png_structp png_ptr,
1153 + png_uint_32 width, png_uint_32 height,
1154 + png_uint_32 x_offset, png_uint_32 y_offset,
1155 + png_uint_16 delay_num, png_uint_16 delay_den,
1156 + png_byte dispose_op, png_byte blend_op)
1158 + if (width + x_offset > png_ptr->first_frame_width ||
1159 + height + y_offset > png_ptr->first_frame_height)
1160 + png_error(png_ptr, "dimensions of a frame are greater than"
1161 + "the ones in IHDR");
1162 + if (width > PNG_UINT_31_MAX)
1163 + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)");
1164 + if (height > PNG_UINT_31_MAX)
1165 + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)");
1166 + if (x_offset > PNG_UINT_31_MAX)
1167 + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)");
1168 + if (y_offset > PNG_UINT_31_MAX)
1169 + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)");
1171 + if (dispose_op != PNG_DISPOSE_OP_NONE &&
1172 + dispose_op != PNG_DISPOSE_OP_BACKGROUND &&
1173 + dispose_op != PNG_DISPOSE_OP_PREVIOUS)
1174 + png_error(png_ptr, "invalid dispose_op in fcTL");
1176 + if (blend_op != PNG_BLEND_OP_SOURCE &&
1177 + blend_op != PNG_BLEND_OP_OVER)
1178 + png_error(png_ptr, "invalid blend_op in fcTL");
1180 + if (blend_op == PNG_BLEND_OP_OVER) {
1181 + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
1182 + png_error(png_ptr, "PNG_BLEND_OP_OVER is not valid for "
1183 + "color type 'greyscale without alpha'");
1184 + else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) &&
1185 + !(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))
1186 + png_error(png_ptr, "PNG_BLEND_OP_OVER is not valid for "
1187 + "color type 'truecolor without alpha'");
1192 +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
1193 + png_byte is_hidden)
1195 + png_debug(1, "in png_first_frame_is_hidden()\n");
1197 + if (png_ptr == NULL)
1201 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1203 + png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN;
1207 +#endif /* PNG_APNG_SUPPORTED */
1209 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1211 png_set_unknown_chunks(png_structp png_ptr,
1213 ===================================================================
1214 --- pngrutil.c (révision 149)
1215 +++ pngrutil.c (copie de travail)
1216 @@ -374,6 +374,11 @@
1217 filter_type = buf[11];
1218 interlace_type = buf[12];
1220 +#if defined(PNG_READ_APNG_SUPPORTED)
1221 + png_ptr->first_frame_width = width;
1222 + png_ptr->first_frame_height = height;
1225 /* set internal variables */
1226 png_ptr->width = width;
1227 png_ptr->height = height;
1228 @@ -2175,6 +2180,168 @@
1232 +#if defined(PNG_READ_APNG_SUPPORTED)
1234 +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1237 + png_uint_32 num_frames;
1238 + png_uint_32 num_plays;
1239 + png_uint_32 didSet;
1241 + png_debug(1, "in png_handle_acTL\n");
1243 + if (!(png_ptr->mode & PNG_HAVE_IHDR))
1245 + png_error(png_ptr, "Missing IHDR before acTL");
1247 + else if (png_ptr->mode & PNG_HAVE_IDAT)
1249 + png_warning(png_ptr, "Invalid acTL after IDAT skipped");
1250 + png_crc_finish(png_ptr, length);
1253 + else if (png_ptr->mode & PNG_HAVE_acTL)
1255 + png_warning(png_ptr, "Duplicate acTL skipped");
1256 + png_crc_finish(png_ptr, length);
1259 + else if (length != 8)
1261 + png_warning(png_ptr, "acTL with invalid length skipped");
1262 + png_crc_finish(png_ptr, length);
1266 + png_crc_read(png_ptr, data, 8);
1267 + png_crc_finish(png_ptr, 0);
1269 + num_frames = png_get_uint_31(png_ptr, data);
1270 + num_plays = png_get_uint_31(png_ptr, data + 4);
1272 + /* the set function will do error checking on num_frames */
1273 + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
1275 + png_ptr->mode |= PNG_HAVE_acTL;
1279 +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1281 + png_byte data[22];
1282 + png_uint_32 width;
1283 + png_uint_32 height;
1284 + png_uint_32 x_offset;
1285 + png_uint_32 y_offset;
1286 + png_uint_16 delay_num;
1287 + png_uint_16 delay_den;
1288 + png_byte dispose_op;
1289 + png_byte blend_op;
1291 + png_debug(1, "in png_handle_fcTL\n");
1293 + if (!(png_ptr->mode & PNG_HAVE_IHDR))
1295 + png_error(png_ptr, "Missing IHDR before fcTL");
1297 + else if (png_ptr->mode & PNG_HAVE_IDAT)
1299 + /* for any frames other then the first this message may be misleading,
1300 + * but correct. PNG_HAVE_IDAT is unset before the frame head is read
1301 + * i can't think of a better message */
1302 + png_warning(png_ptr, "Invalid fcTL after IDAT skipped");
1303 + png_crc_finish(png_ptr, length);
1306 + else if (png_ptr->mode & PNG_HAVE_fcTL)
1308 + png_warning(png_ptr, "Duplicate fcTL within one frame skipped");
1309 + png_crc_finish(png_ptr, length);
1312 + else if (length != 26)
1314 + png_warning(png_ptr, "fcTL with invalid length skipped");
1315 + png_crc_finish(png_ptr, length);
1319 + png_ensure_sequence_number(png_ptr, length);
1321 + png_crc_read(png_ptr, data, 22);
1322 + png_crc_finish(png_ptr, 0);
1324 + width = png_get_uint_31(png_ptr, data);
1325 + height = png_get_uint_31(png_ptr, data + 4);
1326 + x_offset = png_get_uint_31(png_ptr, data + 8);
1327 + y_offset = png_get_uint_31(png_ptr, data + 12);
1328 + delay_num = png_get_uint_16(data + 16);
1329 + delay_den = png_get_uint_16(data + 18);
1330 + dispose_op = data[20];
1331 + blend_op = data[21];
1333 + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
1334 + png_error(png_ptr, "fcTL for the first frame must have zero offset");
1335 + if (png_ptr->num_frames_read == 0 &&
1336 + (width != info_ptr->width || height != info_ptr->height))
1337 + png_error(png_ptr, "size in first frame's fcTL must match "
1338 + "the size in IHDR");
1340 + /* the set function will do more error checking */
1341 + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
1342 + x_offset, y_offset, delay_num, delay_den,
1343 + dispose_op, blend_op);
1345 + png_read_reinit(png_ptr, info_ptr);
1347 + png_ptr->mode |= PNG_HAVE_fcTL;
1351 +png_have_info(png_structp png_ptr, png_infop info_ptr)
1353 + if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL))
1355 + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1356 + info_ptr->num_frames++;
1361 +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1363 + png_ensure_sequence_number(png_ptr, length);
1365 + /* This function is only called from png_read_end(), png_read_info(),
1366 + * and png_push_read_chunk() which means that:
1367 + * - the user doesn't want to read this frame
1368 + * - or this is an out-of-place fdAT
1369 + * in either case it is safe to ignore the chunk with a warning */
1370 + png_warning(png_ptr, "ignoring fdAT chunk");
1371 + png_crc_finish(png_ptr, length - 4);
1375 +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
1378 + png_uint_32 sequence_number;
1381 + png_error(png_ptr, "invalid fcTL or fdAT chunk found");
1383 + png_crc_read(png_ptr, data, 4);
1384 + sequence_number = png_get_uint_31(png_ptr, data);
1386 + if (sequence_number != png_ptr->next_seq_num)
1387 + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
1390 + png_ptr->next_seq_num++;
1392 +#endif /* PNG_READ_APNG_SUPPORTED */
1394 /* This function is called when we haven't found a handler for a
1395 chunk. If there isn't a problem with the chunk itself (ie bad
1396 chunk name, CRC, or a critical chunk), the chunk is silently ignored
1397 @@ -3318,8 +3318,10 @@
1398 if(row_bytes + 64 > png_ptr->old_big_row_buf_size)
1400 png_free(png_ptr,png_ptr->big_row_buf);
1401 - png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
1402 - png_ptr->row_buf = png_ptr->big_row_buf+32;
1403 + if (png_ptr->big_row_buf == NULL)
1404 + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
1405 + if (png_ptr->row_buf == NULL)
1406 + png_ptr->row_buf = png_ptr->big_row_buf+32;
1407 png_ptr->old_big_row_buf_size = row_bytes+64;
1410 @@ -3161,4 +3330,82 @@
1412 png_ptr->flags |= PNG_FLAG_ROW_INIT;
1415 +#if defined(PNG_READ_APNG_SUPPORTED)
1416 +/* This function is to be called after the main IDAT set has been read and
1417 + * before a new IDAT is read. It resets some parts of png_ptr
1418 + * to make them usable by the read functions again */
1420 +png_read_reset(png_structp png_ptr)
1422 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1423 + png_ptr->mode &= ~PNG_AFTER_IDAT;
1424 + png_ptr->row_number = 0;
1425 + png_ptr->pass = 0;
1426 + png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
1430 +png_read_reinit(png_structp png_ptr, png_infop info_ptr)
1432 + png_ptr->width = info_ptr->next_frame_width;
1433 + png_ptr->height = info_ptr->next_frame_height;
1434 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
1437 +/* same as png_read_reset() but for the progressive reader */
1439 +png_progressive_read_reset(png_structp png_ptr)
1441 +#ifdef PNG_USE_LOCAL_ARRAYS
1442 + /* start of interlace block */
1443 + const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1445 + /* offset to next interlace block */
1446 + const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1448 + /* start of interlace block in the y direction */
1449 + const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1451 + /* offset to next interlace block in the y direction */
1452 + const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1454 + png_uint_32 row_bytes;
1456 + if (png_ptr->interlaced)
1458 + if (!(png_ptr->transformations & PNG_INTERLACE))
1459 + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1460 + png_pass_ystart[0]) / png_pass_yinc[0];
1462 + png_ptr->num_rows = png_ptr->height;
1464 + png_ptr->iwidth = (png_ptr->width +
1465 + png_pass_inc[png_ptr->pass] - 1 -
1466 + png_pass_start[png_ptr->pass]) /
1467 + png_pass_inc[png_ptr->pass];
1469 + row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
1471 + png_ptr->irowbytes = (png_size_t)row_bytes;
1472 + if((png_uint_32)png_ptr->irowbytes != row_bytes)
1473 + png_error(png_ptr, "png_progressive_read_reset(): Rowbytes "
1478 + png_ptr->num_rows = png_ptr->height;
1479 + png_ptr->iwidth = png_ptr->width;
1480 + png_ptr->irowbytes = png_ptr->rowbytes + 1;
1483 + png_ptr->flags &= ~PNG_FLAG_ZLIB_FINISHED;
1484 + if (inflateReset(&(png_ptr->zstream)) != Z_OK)
1485 + png_error(png_ptr, "inflateReset failed");
1486 + png_ptr->zstream.avail_in = 0;
1487 + png_ptr->zstream.next_in = 0;
1488 + png_ptr->zstream.next_out = png_ptr->row_buf;
1489 + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
1491 +#endif /* PNG_READ_APNG_SUPPORTED */
1492 #endif /* PNG_READ_SUPPORTED */
1494 ===================================================================
1495 --- pngwutil.c (révision 149)
1496 +++ pngwutil.c (copie de travail)
1497 @@ -496,6 +496,11 @@
1498 /* write the chunk */
1499 png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
1501 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1502 + png_ptr->first_frame_width = width;
1503 + png_ptr->first_frame_height = height;
1506 /* initialize zlib with PNG info */
1507 png_ptr->zstream.zalloc = png_zalloc;
1508 png_ptr->zstream.zfree = png_zfree;
1509 @@ -608,7 +613,10 @@
1511 #ifdef PNG_USE_LOCAL_ARRAYS
1513 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1517 png_debug(1, "in png_write_IDAT\n");
1519 /* Optimize the CMF field in the zlib stream. */
1520 @@ -650,7 +658,28 @@
1521 "Invalid zlib compression method or flags in IDAT");
1524 - png_write_chunk(png_ptr, png_IDAT, data, length);
1525 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1526 + if(png_ptr->num_frames_written == 0)
1528 + png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
1529 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1534 + png_write_chunk_start(png_ptr, (png_bytep)png_fdAT, 4 + length);
1536 + png_save_uint_32(buf, png_ptr->next_seq_num);
1537 + png_write_chunk_data(png_ptr, buf, 4);
1539 + png_write_chunk_data(png_ptr, data, length);
1541 + png_write_chunk_end(png_ptr);
1543 + png_ptr->next_seq_num++;
1547 png_ptr->mode |= PNG_HAVE_IDAT;
1553 png_debug(1, "in png_write_IEND\n");
1554 - png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
1555 + png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
1557 png_ptr->mode |= PNG_HAVE_IEND;
1559 @@ -1722,6 +1751,70 @@
1563 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1565 +png_write_acTL(png_structp png_ptr,
1566 + png_uint_32 num_frames, png_uint_32 num_plays)
1568 +#ifdef PNG_USE_LOCAL_ARRAYS
1571 + png_byte data[16];
1573 + png_debug(1, "in png_write_acTL\n");
1575 + png_ptr->num_frames_to_write = num_frames;
1577 + if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN)
1580 + png_save_uint_32(data, num_frames);
1581 + png_save_uint_32(data + 4, num_plays);
1583 + png_write_chunk(png_ptr, (png_bytep)png_acTL, data, (png_size_t)8);
1587 +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
1588 + png_uint_32 x_offset, png_uint_32 y_offset,
1589 + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
1590 + png_byte blend_op)
1592 +#ifdef PNG_USE_LOCAL_ARRAYS
1595 + png_byte data[26];
1597 + png_debug(1, "in png_write_fcTL\n");
1599 + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0))
1600 + png_error(png_ptr, "x and/or y offset for the first frame aren't 0\n");
1601 + if (png_ptr->num_frames_written == 0 &&
1602 + (width != png_ptr->first_frame_width ||
1603 + height != png_ptr->first_frame_height))
1604 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1605 + "don't match the ones in IHDR\n");
1607 + /* more error checking */
1608 + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1609 + delay_num, delay_den, dispose_op, blend_op);
1611 + png_save_uint_32(data, png_ptr->next_seq_num);
1612 + png_save_uint_32(data + 4, width);
1613 + png_save_uint_32(data + 8, height);
1614 + png_save_uint_32(data + 12, x_offset);
1615 + png_save_uint_32(data + 16, y_offset);
1616 + png_save_uint_16(data + 20, delay_num);
1617 + png_save_uint_16(data + 22, delay_den);
1618 + data[24] = dispose_op;
1619 + data[25] = blend_op;
1621 + png_write_chunk(png_ptr, (png_bytep)png_fcTL, data, (png_size_t)26);
1623 + png_ptr->next_seq_num++;
1625 +#endif /* PNG_WRITE_APNG_SUPPORTED */
1627 /* initializes the row writing capability of libpng */
1629 png_write_start_row(png_structp png_ptr)
1630 @@ -2789,4 +2882,39 @@
1635 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1637 +png_write_reset(png_structp png_ptr)
1639 + png_ptr->row_number = 0;
1640 + png_ptr->pass = 0;
1641 + png_ptr->mode &= ~PNG_HAVE_IDAT;
1645 +png_write_reinit(png_structp png_ptr, png_infop info_ptr,
1646 + png_uint_32 width, png_uint_32 height)
1648 + if (png_ptr->num_frames_written == 0 &&
1649 + (width != png_ptr->first_frame_width ||
1650 + height != png_ptr->first_frame_height))
1651 + png_error(png_ptr, "width and/or height in the first frame's fcTL "
1652 + "don't match the ones in IHDR\n");
1653 + if (width > png_ptr->first_frame_width ||
1654 + height > png_ptr->first_frame_height)
1655 + png_error(png_ptr, "width and/or height for a frame greater than"
1656 + "the ones in IHDR");
1658 + png_set_IHDR(png_ptr, info_ptr, width, height,
1659 + info_ptr->bit_depth, info_ptr->color_type,
1660 + info_ptr->interlace_type, info_ptr->compression_type,
1661 + info_ptr->filter_type);
1663 + png_ptr->width = width;
1664 + png_ptr->height = height;
1665 + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
1666 + png_ptr->usr_width = png_ptr->width;
1669 #endif /* PNG_WRITE_SUPPORTED */
1671 ===================================================================
1672 --- pngrtran.c (révision 149)
1673 +++ pngrtran.c (copie de travail)
1674 @@ -1293,7 +1293,7 @@
1675 * or png_read_update_info() after setting transforms that expand
1676 * pixels. This check added to libpng-1.2.19 */
1677 #if (PNG_WARN_UNINITIALIZED_ROW==1)
1678 - png_error(png_ptr, "Uninitialized row");
1679 + png_warning(png_ptr, "Uninitialized row");
1681 png_warning(png_ptr, "Uninitialized row");