]> git.pld-linux.org Git - packages/libpng.git/blob - libpng-apng.patch
- from http://littlesvr.ca/apng/diff/libpng-1.2.24-apng.patch
[packages/libpng.git] / libpng-apng.patch
1 Index: pngread.c
2 ===================================================================
3 --- pngread.c   (révision 144)
4 +++ pngread.c   (copie de travail)
5 @@ -399,6 +399,11 @@
6  #if defined(PNG_READ_zTXt_SUPPORTED)
7        PNG_CONST PNG_zTXt;
8  #endif
9 +#if defined(PNG_READ_APNG_SUPPORTED)
10 +      PNG_CONST PNG_acTL;
11 +      PNG_CONST PNG_fcTL;
12 +      PNG_CONST PNG_fdAT;
13 +#endif
14  #endif /* PNG_USE_LOCAL_ARRAYS */
15        png_byte chunk_length[4];
16        png_uint_32 length;
17 @@ -452,6 +457,9 @@
18                    !(png_ptr->mode & PNG_HAVE_PLTE))
19              png_error(png_ptr, "Missing PLTE before IDAT");
20  
21 +#if defined(PNG_READ_APNG_SUPPORTED)
22 +         png_have_info(png_ptr, info_ptr);
23 +#endif
24           png_ptr->idat_size = length;
25           png_ptr->mode |= PNG_HAVE_IDAT;
26           break;
27 @@ -524,12 +532,97 @@
28        else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
29           png_handle_iTXt(png_ptr, info_ptr, length);
30  #endif
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);
38 +#endif
39        else
40           png_handle_unknown(png_ptr, info_ptr, length);
41     }
42  }
43  #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
44  
45 +#if defined(PNG_READ_APNG_SUPPORTED)
46 +void PNGAPI
47 +png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
48 +{
49 +    png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
50 +    
51 +    png_debug(0, "Reading frame head\n");
52 +    
53 +    if (!(png_ptr->mode & PNG_HAVE_acTL))
54 +        png_error(png_ptr, "attempt to png_read_frame_head() but "
55 +                           "no acTL present");
56 +    
57 +    /* do nothing for the main IDAT */
58 +    if (png_ptr->num_frames_read == 0)
59 +        return;
60 +    
61 +    png_crc_finish(png_ptr, 0); /* CRC from last IDAT or fdAT chunk */
62 +    
63 +    png_read_reset(png_ptr);
64 +    png_ptr->mode &= ~PNG_HAVE_fcTL;
65 +    
66 +    have_chunk_after_DAT = 0;
67 +    for (;;)
68 +    {
69 +#ifdef PNG_USE_LOCAL_ARRAYS
70 +        PNG_IDAT;
71 +        PNG_fdAT;
72 +        PNG_fcTL;
73 +#endif
74 +        png_byte chunk_length[4];
75 +        png_uint_32 length;
76 +        
77 +        png_read_data(png_ptr, chunk_length, 4);
78 +        length = png_get_uint_31(png_ptr, chunk_length);
79 +        
80 +        png_reset_crc(png_ptr);
81 +        png_crc_read(png_ptr, png_ptr->chunk_name, 4);
82 +        
83 +        if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
84 +        {
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);
89 +        }
90 +        else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
91 +        {
92 +            png_handle_fcTL(png_ptr, info_ptr, length);
93 +            have_chunk_after_DAT = 1;
94 +        }
95 +        else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
96 +        {
97 +            png_ensure_sequence_number(png_ptr, length);
98 +            
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)
103 +            {
104 +                png_ptr->idat_size = length - 4;
105 +                png_ptr->mode |= PNG_HAVE_IDAT;
106 +                
107 +                break;
108 +            }
109 +            else
110 +                png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
111 +        }
112 +        else
113 +        {
114 +            png_warning(png_ptr, "Skipped (ignored) a chunk "
115 +                                 "between APNG chunks");
116 +            png_crc_finish(png_ptr, length);
117 +        }
118 +    }
119 +}
120 +#endif /* PNG_READ_APNG_SUPPORTED */
121 +
122  /* optional call to update the users info_ptr structure */
123  void PNGAPI
124  png_read_update_info(png_structp png_ptr, png_infop info_ptr)
125 @@ -566,6 +659,10 @@
126  {
127  #ifdef PNG_USE_LOCAL_ARRAYS
128     PNG_CONST PNG_IDAT;
129 +#if defined(PNG_READ_APNG_SUPPORTED)
130 +   PNG_CONST PNG_fdAT;
131 +   PNG_CONST PNG_IEND;
132 +#endif
133     PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
134       0xff};
135     PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
136 @@ -695,19 +792,46 @@
137     {
138        if (!(png_ptr->zstream.avail_in))
139        {
140 -         while (!png_ptr->idat_size)
141 +         png_uint_32 bytes_to_skip = 0;
142 +         
143 +         while (!png_ptr->idat_size || bytes_to_skip != 0)
144           {
145              png_byte chunk_length[4];
146  
147 -            png_crc_finish(png_ptr, 0);
148 -
149 +            png_crc_finish(png_ptr, bytes_to_skip);
150 +            bytes_to_skip = 0;
151 +            
152              png_read_data(png_ptr, chunk_length, 4);
153              png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
154 -
155 +            
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");
160 +            
161 +#if defined(PNG_READ_APNG_SUPPORTED)
162 +            if (png_ptr->num_frames_read == 0)
163 +            {
164 +#endif
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)
168 +            }
169 +            else
170 +            {
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))
174 +               {
175 +                  png_warning(png_ptr, "Skipped (ignored) a chunk "
176 +                                       "between APNG chunks");
177 +                  bytes_to_skip = png_ptr->idat_size;
178 +                  continue;
179 +               }
180 +               
181 +               png_ensure_sequence_number(png_ptr, png_ptr->idat_size);
182 +               
183 +               png_ptr->idat_size -= 4;
184 +            }
185 +#endif
186           }
187           png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
188           png_ptr->zstream.next_in = png_ptr->zbuf;
189 @@ -725,6 +849,9 @@
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++;
195 +#endif
196           break;
197        }
198        if (ret != Z_OK)
199 @@ -979,6 +1106,11 @@
200  #if defined(PNG_READ_zTXt_SUPPORTED)
201        PNG_CONST PNG_zTXt;
202  #endif
203 +#if defined(PNG_READ_APNG_SUPPORTED)
204 +      PNG_CONST PNG_acTL;
205 +      PNG_CONST PNG_fcTL;
206 +      PNG_CONST PNG_fdAT;
207 +#endif
208  #endif /* PNG_USE_LOCAL_ARRAYS */
209  
210        png_read_data(png_ptr, chunk_length, 4);
211 @@ -1085,6 +1217,14 @@
212        else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
213           png_handle_iTXt(png_ptr, info_ptr, length);
214  #endif
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);
222 +#endif
223        else
224           png_handle_unknown(png_ptr, info_ptr, length);
225     } while (!(png_ptr->mode & PNG_HAVE_IEND));
226 Index: png.c
227 ===================================================================
228 --- png.c       (révision 144)
229 +++ png.c       (copie de travail)
230 @@ -51,6 +51,9 @@
231  PNG_tIME;
232  PNG_tRNS;
233  PNG_zTXt;
234 +PNG_acTL;
235 +PNG_fcTL;
236 +PNG_fdAT;
237  
238  #ifdef PNG_READ_SUPPORTED
239  /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
240 Index: pngget.c
241 ===================================================================
242 --- pngget.c    (révision 144)
243 +++ pngget.c    (copie de travail)
244 @@ -797,6 +797,167 @@
245  }
246  #endif
247  
248 +#if defined(PNG_APNG_SUPPORTED)
249 +png_uint_32 PNGAPI
250 +png_get_acTL(png_structp png_ptr, png_infop info_ptr,
251 +             png_uint_32 *num_frames, png_uint_32 *num_plays)
252 +{
253 +    png_debug1(1, "in %s retrieval function\n", "acTL");
254 +    
255 +    if (png_ptr != NULL && info_ptr != NULL &&
256 +        (info_ptr->valid & PNG_INFO_acTL) &&
257 +        num_frames != NULL && num_plays != NULL)
258 +    {
259 +        *num_frames = info_ptr->num_frames;
260 +        *num_plays = info_ptr->num_plays;
261 +        return (1);
262 +    }
263 +    
264 +    return (0);
265 +}
266 +
267 +png_uint_32 PNGAPI
268 +png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
269 +{
270 +    png_debug(1, "in png_get_num_frames()\n");
271 +    
272 +    if (png_ptr != NULL && info_ptr != NULL)
273 +        return (info_ptr->num_frames);
274 +    return (0);
275 +}
276 +
277 +png_uint_32 PNGAPI
278 +png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
279 +{
280 +    png_debug(1, "in png_get_num_plays()\n");
281 +    
282 +    if (png_ptr != NULL && info_ptr != NULL)
283 +        return (info_ptr->num_plays);
284 +    return (0);
285 +}
286 +
287 +png_uint_32 PNGAPI
288 +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
289 +             png_uint_32 *width, png_uint_32 *height,
290 +             png_uint_32 *x_offset, png_uint_32 *y_offset,
291 +             png_uint_16 *delay_num, png_uint_16 *delay_den,
292 +             png_byte *dispose_op, png_byte *blend_op)
293 +{
294 +    png_debug1(1, "in %s retrieval function\n", "fcTL");
295 +    
296 +    if (png_ptr != NULL && info_ptr != NULL &&
297 +        (info_ptr->valid & PNG_INFO_fcTL) &&
298 +        width != NULL && height != NULL && 
299 +        x_offset != NULL && x_offset != NULL && 
300 +        delay_num != NULL && delay_den != NULL &&
301 +       dispose_op != NULL && blend_op != NULL)
302 +    {
303 +        *width = info_ptr->next_frame_width;
304 +        *height = info_ptr->next_frame_height;
305 +        *x_offset = info_ptr->next_frame_x_offset;
306 +        *y_offset = info_ptr->next_frame_y_offset;
307 +        *delay_num = info_ptr->next_frame_delay_num;
308 +        *delay_den = info_ptr->next_frame_delay_den;
309 +        *dispose_op = info_ptr->next_frame_dispose_op;
310 +        *blend_op = info_ptr->next_frame_blend_op;
311 +        return (1);
312 +    }
313 +    
314 +    return (0);
315 +}
316 +
317 +png_uint_32 PNGAPI
318 +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
319 +{
320 +    png_debug(1, "in png_get_next_frame_width()\n");
321 +    
322 +    if (png_ptr != NULL && info_ptr != NULL)
323 +        return (info_ptr->next_frame_width);
324 +    return (0);
325 +}
326 +
327 +png_uint_32 PNGAPI
328 +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
329 +{
330 +    png_debug(1, "in png_get_next_frame_height()\n");
331 +    
332 +    if (png_ptr != NULL && info_ptr != NULL)
333 +        return (info_ptr->next_frame_height);
334 +    return (0);
335 +}
336 +
337 +png_uint_32 PNGAPI
338 +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
339 +{
340 +    png_debug(1, "in png_get_next_frame_x_offset()\n");
341 +    
342 +    if (png_ptr != NULL && info_ptr != NULL)
343 +        return (info_ptr->next_frame_x_offset);
344 +    return (0);
345 +}
346 +
347 +png_uint_32 PNGAPI
348 +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
349 +{
350 +    png_debug(1, "in png_get_next_frame_y_offset()\n");
351 +    
352 +    if (png_ptr != NULL && info_ptr != NULL)
353 +        return (info_ptr->next_frame_y_offset);
354 +    return (0);
355 +}
356 +
357 +png_uint_16 PNGAPI
358 +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
359 +{
360 +    png_debug(1, "in png_get_next_frame_delay_num()\n");
361 +    
362 +    if (png_ptr != NULL && info_ptr != NULL)
363 +        return (info_ptr->next_frame_delay_num);
364 +    return (0);
365 +}
366 +
367 +png_uint_16 PNGAPI
368 +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
369 +{
370 +    png_debug(1, "in png_get_next_frame_delay_den()\n");
371 +    
372 +    if (png_ptr != NULL && info_ptr != NULL)
373 +        return (info_ptr->next_frame_delay_den);
374 +    return (0);
375 +}
376 +
377 +png_byte PNGAPI
378 +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
379 +{
380 +    png_debug(1, "in png_get_next_frame_dispose_op()\n");
381 +    
382 +    if (png_ptr != NULL && info_ptr != NULL)
383 +        return (info_ptr->next_frame_dispose_op);
384 +    return (0);
385 +}
386 +
387 +png_byte PNGAPI
388 +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
389 +{
390 +    png_debug(1, "in png_get_next_frame_blend_op()\n");
391 +    
392 +    if (png_ptr != NULL && info_ptr != NULL)
393 +        return (info_ptr->next_frame_blend_op);
394 +    return (0);
395 +}
396 +
397 +png_byte PNGAPI
398 +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
399 +{
400 +    png_debug(1, "in png_first_frame_is_hidden()\n");
401 +    
402 +    if (png_ptr != NULL)
403 +       return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
404 +    
405 +    return 0;
406 +}
407 +#endif /* PNG_APNG_SUPPORTED */
408 +
409  #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
410  png_uint_32 PNGAPI
411  png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
412 Index: png.h
413 ===================================================================
414 --- png.h       (révision 144)
415 +++ png.h       (copie de travail)
416 @@ -947,6 +947,19 @@
417     png_fixed_point int_y_blue;
418  #endif
419  
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;
431 +#endif
432 +
433  } png_info;
434  
435  typedef png_info FAR * png_infop;
436 @@ -1048,6 +1061,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
442  
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 @@ -1088,7 +1103,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,
448     png_uint_32, int));
449 +#if defined(PNG_APNG_SUPPORTED)
450 +typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp, 
451 +   png_uint_32));
452  #endif
453 +#endif
454  
455  #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
456      defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
457 @@ -1419,6 +1438,39 @@
458     png_uint_32 user_height_max;
459  #endif
460  
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;
466 +
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 */
473 +#endif
474 +#endif
475 +
476 +#if defined(PNG_WRITE_APNG_SUPPORTED)
477 +   png_uint_32 num_frames_to_write;
478 +   png_uint_32 num_frames_written;
479 +#endif
480 +#endif
481 +
482 +/* For png_struct.apng_flags: */
483 +#define PNG_FIRST_FRAME_HIDDEN       0x0001
484 +
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
489 +
490 +/* blend_op flags from inside fcTL */
491 +#define PNG_BLEND_OP_SOURCE        0x00
492 +#define PNG_BLEND_OP_OVER          0x01
493 +
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 @@ -1745,6 +1797,18 @@
498  extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
499     png_bytepp image));
500  
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));
508 +
509 +extern PNG_EXPORT (void,png_write_frame_tail) PNGARG((png_structp png_ptr,
510 +   png_infop png_info));
511 +#endif
512 +   
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 @@ -1993,6 +2057,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));
524 +#endif
525  
526  /* returns the user pointer associated with the push read functions */
527  extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
528 @@ -2430,6 +2499,59 @@
529  #endif
530  #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
531  
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));
541 +
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 */
579 +
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));
583 +#endif
584 +
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 @@ -2736,6 +2858,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
594  
595  /* flags for the transformations the PNG library does on the image data */
596  #define PNG_BGR                0x0001
597 @@ -2876,6 +3000,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'}
604  
605  #ifdef PNG_USE_GLOBAL_ARRAYS
606  PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
607 @@ -2899,6 +3026,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 */
615  
616  #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
617 @@ -3173,6 +3303,17 @@
618  #endif
619  #endif
620  
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));
624 +
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));
630 +#endif
631 +
632  /* Called when finished processing a row of data */
633  PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
634  
635 @@ -3224,6 +3365,20 @@
636  PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
637     png_infop info_ptr));
638  
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));
645 +#endif
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));
651 +#endif
652 +
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 @@ -3439,6 +3594,18 @@
657     png_uint_32 length));
658  #endif
659  
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));
670 +#endif
671 +
672  PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
673     png_infop info_ptr, png_uint_32 length));
674  
675 Index: pngtrans.c
676 ===================================================================
677 --- pngtrans.c  (révision 144)
678 +++ pngtrans.c  (copie de travail)
679 @@ -652,11 +652,10 @@
680  png_voidp PNGAPI
681  png_get_user_transform_ptr(png_structp png_ptr)
682  {
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);
687 -#else
688 -   return (NULL);
689  #endif
690 +   return (NULL);
691  }
692  #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
693 Index: pngconf.h
694 ===================================================================
695 --- pngconf.h   (révision 144)
696 +++ pngconf.h   (copie de travail)
697 @@ -925,6 +925,10 @@
698  #  define PNG_READ_zTXt_SUPPORTED
699  #  define PNG_zTXt_SUPPORTED
700  #endif
701 +#ifndef PNG_NO_READ_APNG
702 +#  define PNG_READ_APNG_SUPPORTED
703 +#  define PNG_APNG_SUPPORTED
704 +#endif
705  #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
706  #  define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
707  #  ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
708 @@ -1067,6 +1071,12 @@
709  #    define PNG_zTXt_SUPPORTED
710  #  endif
711  #endif
712 +#ifndef PNG_NO_WRITE_APNG
713 +#  define PNG_WRITE_APNG_SUPPORTED
714 +#  ifndef PNG_APNG_SUPPORTED
715 +#    define PNG_APNG_SUPPORTED
716 +#  endif
717 +#endif
718  #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
719  #  define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
720  #  ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
721 Index: pngwrite.c
722 ===================================================================
723 --- pngwrite.c  (révision 144)
724 +++ pngwrite.c  (copie de travail)
725 @@ -261,6 +261,10 @@
726        }
727     }
728  #endif
729 +#if defined(PNG_WRITE_APNG_SUPPORTED)
730 +   if (info_ptr->valid & PNG_INFO_acTL)
731 +      png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
732 +#endif
733  #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
734     if (info_ptr->unknown_chunks_num)
735     {
736 @@ -299,6 +303,10 @@
737        return;
738     if (!(png_ptr->mode & PNG_HAVE_IDAT))
739        png_error(png_ptr, "No IDATs written into file");
740 +#if defined(PNG_WRITE_APNG_SUPPORTED)
741 +   if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
742 +      png_error(png_ptr, "Not enough frames written");
743 +#endif
744  
745     /* see if user wants us to write information chunks */
746     if (info_ptr != NULL)
747 @@ -1513,4 +1521,39 @@
748     params = params;
749  }
750  #endif
751 +
752 +#if defined(PNG_WRITE_APNG_SUPPORTED)
753 +void PNGAPI
754 +png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
755 +    png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, 
756 +    png_uint_32 x_offset, png_uint_32 y_offset, 
757 +    png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
758 +    png_byte blend_op)
759 +{
760 +    png_debug(1, "in png_write_frame_head\n");
761 +    
762 +    /* there is a chance this has been set after png_write_info was called,
763 +    * so it would be set but not written. is there a way to be sure? */
764 +    if (!(info_ptr->valid & PNG_INFO_acTL))
765 +        png_error(png_ptr, "png_write_frame_head(): acTL not set");
766 +    
767 +    png_write_reset(png_ptr);
768 +    
769 +    png_write_reinit(png_ptr, info_ptr, width, height);
770 +    
771 +    if ( !(png_ptr->num_frames_written == 0 && 
772 +           (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) )
773 +        png_write_fcTL(png_ptr, width, height, x_offset, y_offset, 
774 +                       delay_num, delay_den, dispose_op, blend_op);
775 +}
776 +
777 +void PNGAPI
778 +png_write_frame_tail(png_structp png_ptr, png_infop png_info)
779 +{
780 +    png_debug(1, "in png_write_frame_tail\n");
781 +    
782 +    png_ptr->num_frames_written++;
783 +}
784 +#endif /* PNG_WRITE_APNG_SUPPORTED */
785 +
786  #endif /* PNG_WRITE_SUPPORTED */
787 Index: pngset.c
788 ===================================================================
789 --- pngset.c    (révision 144)
790 +++ pngset.c    (copie de travail)
791 @@ -364,6 +364,11 @@
792        info_ptr->rowbytes = (png_size_t)0;
793     else
794        info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
795 +   
796 +#if defined(PNG_APNG_SUPPORTED)
797 +   /* for non-animated png. this may be overritten from an acTL chunk later */
798 +   info_ptr->num_frames = 1;
799 +#endif
800  }
801  
802  #if defined(PNG_oFFs_SUPPORTED)
803 @@ -1009,6 +1014,141 @@
804  }
805  #endif /* PNG_sPLT_SUPPORTED */
806  
807 +#if defined(PNG_APNG_SUPPORTED)
808 +png_uint_32 PNGAPI
809 +png_set_acTL(png_structp png_ptr, png_infop info_ptr, 
810 +    png_uint_32 num_frames, png_uint_32 num_plays)
811 +{
812 +    png_debug1(1, "in %s storage function\n", "acTL");
813 +
814 +    if (png_ptr == NULL || info_ptr == NULL)
815 +    {
816 +        png_warning(png_ptr, 
817 +                    "Call to png_set_acTL() with NULL png_ptr "
818 +                    "or info_ptr ignored");
819 +        return (0);
820 +    }
821 +    if (num_frames == 0)
822 +    {
823 +        png_warning(png_ptr, 
824 +                    "Ignoring attempt to set acTL with num_frames zero");
825 +        return (0);
826 +    }
827 +    if (num_frames > PNG_UINT_31_MAX)
828 +    {
829 +        png_warning(png_ptr, 
830 +                    "Ignoring attempt to set acTL with num_frames > 2^31-1");
831 +        return (0);
832 +    }
833 +    if (num_plays > PNG_UINT_31_MAX)
834 +    {
835 +        png_warning(png_ptr, 
836 +                    "Ignoring attempt to set acTL with num_plays "
837 +                    "> 2^31-1");
838 +        return (0);
839 +    }
840 +    
841 +    info_ptr->num_frames = num_frames;
842 +    info_ptr->num_plays = num_plays;
843 +    
844 +    info_ptr->valid |= PNG_INFO_acTL;
845 +    
846 +    return (1);
847 +}
848 +
849 +/* delay_num and delay_den can hold any 16-bit values including zero */
850 +png_uint_32 PNGAPI
851 +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, 
852 +    png_uint_32 width, png_uint_32 height,
853 +    png_uint_32 x_offset, png_uint_32 y_offset,
854 +    png_uint_16 delay_num, png_uint_16 delay_den,
855 +    png_byte dispose_op, png_byte blend_op)
856 +{
857 +    png_debug1(1, "in %s storage function\n", "fcTL");
858 +
859 +    if (png_ptr == NULL || info_ptr == NULL)
860 +    {
861 +        png_warning(png_ptr, 
862 +                    "Call to png_set_fcTL() with NULL png_ptr or info_ptr "
863 +                    "ignored");
864 +        return (0);
865 +    }
866 +    
867 +    png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, 
868 +                             delay_num, delay_den, dispose_op, blend_op);
869 +    
870 +    info_ptr->next_frame_width = width;
871 +    info_ptr->next_frame_height = height;
872 +    info_ptr->next_frame_x_offset = x_offset;
873 +    info_ptr->next_frame_y_offset = y_offset;
874 +    info_ptr->next_frame_delay_num = delay_num;
875 +    info_ptr->next_frame_delay_den = delay_den;
876 +    info_ptr->next_frame_dispose_op = dispose_op;
877 +    info_ptr->next_frame_blend_op = blend_op;
878 +    
879 +    info_ptr->valid |= PNG_INFO_fcTL;
880 +    
881 +    return (1);
882 +}
883 +
884 +void /* PRIVATE */
885 +png_ensure_fcTL_is_valid(png_structp png_ptr, 
886 +    png_uint_32 width, png_uint_32 height,
887 +    png_uint_32 x_offset, png_uint_32 y_offset,
888 +    png_uint_16 delay_num, png_uint_16 delay_den,
889 +    png_byte dispose_op, png_byte blend_op)
890 +{
891 +    if (width + x_offset > png_ptr->first_frame_width || 
892 +        height + y_offset > png_ptr->first_frame_height)
893 +        png_error(png_ptr, "dimensions of a frame are greater than"
894 +                           "the ones in IHDR");
895 +    if (width > PNG_UINT_31_MAX)
896 +        png_error(png_ptr, "invalid width in fcTL (> 2^31-1)");
897 +    if (height > PNG_UINT_31_MAX)
898 +        png_error(png_ptr, "invalid height in fcTL (> 2^31-1)");
899 +    if (x_offset > PNG_UINT_31_MAX)
900 +        png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)");
901 +    if (y_offset > PNG_UINT_31_MAX)
902 +        png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)");
903 +
904 +    if (dispose_op != PNG_DISPOSE_OP_NONE &&
905 +       dispose_op != PNG_DISPOSE_OP_BACKGROUND &&
906 +       dispose_op != PNG_DISPOSE_OP_PREVIOUS)
907 +        png_error(png_ptr, "invalid dispose_op in fcTL");
908 +
909 +    if (blend_op != PNG_BLEND_OP_SOURCE &&
910 +       blend_op != PNG_BLEND_OP_OVER)
911 +        png_error(png_ptr, "invalid blend_op in fcTL");
912 +
913 +    if (blend_op == PNG_BLEND_OP_OVER) {
914 +        if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
915 +            png_error(png_ptr, "PNG_BLEND_OP_OVER is not valid for "
916 +                               "color type 'greyscale without alpha'");
917 +        else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) &&
918 +                !(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))
919 +            png_error(png_ptr, "PNG_BLEND_OP_OVER is not valid for "
920 +                               "color type 'truecolor without alpha'");
921 +    }
922 +}
923 +
924 +png_uint_32 PNGAPI
925 +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
926 +                              png_byte is_hidden)
927 +{
928 +    png_debug(1, "in png_first_frame_is_hidden()\n");
929 +    
930 +    if (png_ptr == NULL)
931 +        return 0;
932 +    
933 +    if(is_hidden)
934 +        png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
935 +    else
936 +        png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN;
937 +    
938 +    return 1;
939 +}
940 +#endif /* PNG_APNG_SUPPORTED */
941 +
942  #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
943  void PNGAPI
944  png_set_unknown_chunks(png_structp png_ptr,
945 Index: pngpread.c
946 ===================================================================
947 --- pngpread.c  (révision 144)
948 +++ pngpread.c  (copie de travail)
949 @@ -192,6 +192,11 @@
950  #if defined(PNG_READ_zTXt_SUPPORTED)
951        PNG_CONST PNG_zTXt;
952  #endif
953 +#if defined(PNG_READ_APNG_SUPPORTED)
954 +      PNG_CONST PNG_acTL;
955 +      PNG_CONST PNG_fcTL;
956 +      PNG_CONST PNG_fdAT;
957 +#endif
958  #endif /* PNG_USE_LOCAL_ARRAYS */
959     /* First we make sure we have enough data for the 4 byte chunk name
960      * and the 4 byte chunk length before proceeding with decoding the
961 @@ -215,7 +220,104 @@
962        png_crc_read(png_ptr, png_ptr->chunk_name, 4);
963        png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
964     }
965 -
966 +   
967 +#if defined(PNG_READ_APNG_SUPPORTED)
968 +   if (png_ptr->num_frames_read > 0 && 
969 +       png_ptr->num_frames_read < info_ptr->num_frames)
970 +   {
971 +      if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
972 +      {
973 +         /* discard trailing IDATs for the first frame */
974 +         if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1)
975 +            png_error(png_ptr, "out of place IDAT");
976 +         
977 +         if (png_ptr->push_length + 4 > png_ptr->buffer_size)
978 +         {
979 +            png_push_save_buffer(png_ptr);
980 +            return;
981 +         }
982 +         png_push_crc_skip(png_ptr, png_ptr->push_length);
983 +         png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
984 +         return;
985 +      }
986 +      else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
987 +      {
988 +         if (png_ptr->buffer_size < 4)
989 +         {
990 +            png_push_save_buffer(png_ptr);
991 +            return;
992 +         }
993 +         png_ensure_sequence_number(png_ptr, 4);
994 +         
995 +         if (!(png_ptr->mode & PNG_HAVE_fcTL))
996 +         {
997 +            /* discard trailing fdATs for frames other than the first */
998 +            if (png_ptr->num_frames_read < 2)
999 +               png_error(png_ptr, "out of place fdAT");
1000 +            
1001 +            if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1002 +            {
1003 +               png_push_save_buffer(png_ptr);
1004 +               return;
1005 +            }
1006 +            png_push_crc_skip(png_ptr, png_ptr->push_length);
1007 +            png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
1008 +            return;
1009 +         }
1010 +         else
1011 +         {
1012 +            /* frame data follows */
1013 +            png_ptr->idat_size = png_ptr->push_length - 4;
1014 +            png_ptr->mode |= PNG_HAVE_IDAT;
1015 +            png_ptr->process_mode = PNG_READ_IDAT_MODE;
1016 +            
1017 +            return;
1018 +         }
1019 +      }
1020 +      else if(!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
1021 +      {
1022 +         if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1023 +         {
1024 +            png_push_save_buffer(png_ptr);
1025 +            return;
1026 +         }
1027 +         
1028 +         png_read_reset(png_ptr);
1029 +         png_ptr->mode &= ~PNG_HAVE_fcTL;
1030 +         
1031 +         png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
1032 +         
1033 +         if (!(png_ptr->mode & PNG_HAVE_fcTL))
1034 +            png_error(png_ptr, "missing required fcTL chunk");
1035 +         
1036 +         png_read_reinit(png_ptr, info_ptr);
1037 +         png_progressive_read_reset(png_ptr);
1038 +         
1039 +         if (png_ptr->frame_info_fn != NULL)
1040 +            (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read);
1041 +         
1042 +         png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
1043 +         
1044 +         return;
1045 +      }
1046 +      else
1047 +      {
1048 +         if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1049 +         {
1050 +            png_push_save_buffer(png_ptr);
1051 +            return;
1052 +         }
1053 +         png_warning(png_ptr, "Skipped (ignored) a chunk "
1054 +                              "between APNG chunks");
1055 +         png_push_crc_skip(png_ptr, png_ptr->push_length);
1056 +         png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
1057 +         return;
1058 +      }
1059 +      
1060 +      return;
1061 +   }
1062 +#endif /* PNG_READ_APNG_SUPPORTED */
1063 +   
1064     if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
1065       if(png_ptr->mode & PNG_AFTER_IDAT)
1066          png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
1067 @@ -295,6 +397,9 @@
1068              png_error(png_ptr, "Too many IDAT's found");
1069        }
1070  
1071 +#if defined(PNG_READ_APNG_SUPPORTED)
1072 +      png_have_info(png_ptr, info_ptr);
1073 +#endif
1074        png_ptr->idat_size = png_ptr->push_length;
1075        png_ptr->mode |= PNG_HAVE_IDAT;
1076        png_ptr->process_mode = PNG_READ_IDAT_MODE;
1077 @@ -490,6 +595,35 @@
1078        png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
1079     }
1080  #endif
1081 +#if defined(PNG_READ_APNG_SUPPORTED)
1082 +   else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4))
1083 +   {
1084 +      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1085 +      {
1086 +         png_push_save_buffer(png_ptr);
1087 +         return;
1088 +      }
1089 +      png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
1090 +   }
1091 +   else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4))
1092 +   {
1093 +      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1094 +      {
1095 +         png_push_save_buffer(png_ptr);
1096 +         return;
1097 +      }
1098 +      png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
1099 +   }
1100 +   else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4))
1101 +   {
1102 +      if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1103 +      {
1104 +         png_push_save_buffer(png_ptr);
1105 +         return;
1106 +      }
1107 +      png_handle_fdAT(png_ptr, info_ptr, png_ptr->push_length);
1108 +   }
1109 +#endif /* PNG_READ_APNG_SUPPORTED */
1110     else
1111     {
1112        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1113 @@ -660,13 +794,17 @@
1114  png_push_read_IDAT(png_structp png_ptr)
1115  {
1116  #ifdef PNG_USE_LOCAL_ARRAYS
1117 -   PNG_CONST PNG_IDAT;
1118 +   PNG_IDAT;
1119 +#if defined(PNG_READ_APNG_SUPPORTED)
1120 +   PNG_fdAT;
1121 +   PNG_IEND;
1122  #endif
1123 +#endif
1124     if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
1125     {
1126        png_byte chunk_length[4];
1127  
1128 -      if (png_ptr->buffer_size < 8)
1129 +      if (png_ptr->buffer_size < 12)
1130        {
1131           png_push_save_buffer(png_ptr);
1132           return;
1133 @@ -678,15 +816,59 @@
1134        png_crc_read(png_ptr, png_ptr->chunk_name, 4);
1135        png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
1136  
1137 -      if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
1138 +#if defined(PNG_READ_APNG_SUPPORTED)
1139 +      if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_fdAT, 4)
1140 +          && png_ptr->num_frames_read > 0)
1141        {
1142 +          if (png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)
1143 +          {
1144 +              png_ptr->process_mode = PNG_READ_CHUNK_MODE;
1145 +              if (png_ptr->frame_end_fn != NULL)
1146 +                 (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
1147 +              png_ptr->num_frames_read++;
1148 +              return;
1149 +          }
1150 +          else
1151 +          {
1152 +              if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
1153 +                  png_error(png_ptr, "Not enough image data");
1154 +              if (png_ptr->push_length + 4 > png_ptr->buffer_size)
1155 +              {
1156 +                 png_push_save_buffer(png_ptr);
1157 +                 return;
1158 +              }
1159 +              png_warning(png_ptr, "Skipping (ignoring) a chunk between "
1160 +                                   "APNG chunks");
1161 +              png_crc_finish(png_ptr, png_ptr->push_length);
1162 +              png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
1163 +              return;
1164 +          }
1165 +      }
1166 +      else 
1167 +#endif
1168 +      if ( png_memcmp(png_ptr->chunk_name, png_IDAT, 4)
1169 +                && (png_ptr->num_frames_read == 0) )
1170 +      {
1171           png_ptr->process_mode = PNG_READ_CHUNK_MODE;
1172           if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
1173              png_error(png_ptr, "Not enough compressed data");
1174 +#if defined(PNG_READ_APNG_SUPPORTED)
1175 +         if (png_ptr->frame_end_fn != NULL)
1176 +            (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
1177 +         png_ptr->num_frames_read++;
1178 +#endif
1179           return;
1180        }
1181  
1182        png_ptr->idat_size = png_ptr->push_length;
1183 +      
1184 +#if defined(PNG_READ_APNG_SUPPORTED)
1185 +      if(png_ptr->num_frames_read > 0)
1186 +      {
1187 +         png_ensure_sequence_number(png_ptr, 4);
1188 +         png_ptr->idat_size -= 4;
1189 +      }
1190 +#endif
1191     }
1192     if (png_ptr->idat_size && png_ptr->save_buffer_size)
1193     {
1194 @@ -1577,6 +1759,17 @@
1195     png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1196  }
1197  
1198 +#if defined(PNG_READ_APNG_SUPPORTED)
1199 +void PNGAPI
1200 +png_set_progressive_frame_fn(png_structp png_ptr,
1201 +   png_progressive_frame_ptr frame_info_fn,
1202 +   png_progressive_frame_ptr frame_end_fn)
1203 +{
1204 +   png_ptr->frame_info_fn = frame_info_fn;
1205 +   png_ptr->frame_end_fn = frame_end_fn;
1206 +}
1207 +#endif
1208 +
1209  png_voidp PNGAPI
1210  png_get_progressive_ptr(png_structp png_ptr)
1211  {
1212 Index: pngrutil.c
1213 ===================================================================
1214 --- pngrutil.c  (révision 144)
1215 +++ pngrutil.c  (copie de travail)
1216 @@ -374,6 +374,11 @@
1217     filter_type = buf[11];
1218     interlace_type = buf[12];
1219  
1220 +#if defined(PNG_READ_APNG_SUPPORTED)
1221 +   png_ptr->first_frame_width = width;
1222 +   png_ptr->first_frame_height = height;
1223 +#endif
1224 +
1225     /* set internal variables */
1226     png_ptr->width = width;
1227     png_ptr->height = height;
1228 @@ -2175,6 +2180,168 @@
1229  }
1230  #endif
1231  
1232 +#if defined(PNG_READ_APNG_SUPPORTED)
1233 +void /* PRIVATE */
1234 +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1235 +{
1236 +    png_byte data[8];
1237 +    png_uint_32 num_frames;
1238 +    png_uint_32 num_plays;
1239 +    png_uint_32 didSet;
1240 +    
1241 +    png_debug(1, "in png_handle_acTL\n");
1242 +
1243 +    if (!(png_ptr->mode & PNG_HAVE_IHDR))
1244 +    {
1245 +        png_error(png_ptr, "Missing IHDR before acTL");
1246 +    }
1247 +    else if (png_ptr->mode & PNG_HAVE_IDAT)
1248 +    {
1249 +        png_warning(png_ptr, "Invalid acTL after IDAT skipped");
1250 +        png_crc_finish(png_ptr, length);
1251 +        return;
1252 +    }
1253 +    else if (png_ptr->mode & PNG_HAVE_acTL)
1254 +    {
1255 +        png_warning(png_ptr, "Duplicate acTL skipped");
1256 +        png_crc_finish(png_ptr, length);
1257 +        return;
1258 +    }
1259 +    else if (length != 8)
1260 +    {
1261 +        png_warning(png_ptr, "acTL with invalid length skipped");
1262 +        png_crc_finish(png_ptr, length);
1263 +        return;
1264 +    }
1265 +    
1266 +    png_crc_read(png_ptr, data, 8);
1267 +    png_crc_finish(png_ptr, 0);
1268 +    
1269 +    num_frames = png_get_uint_31(png_ptr, data);
1270 +    num_plays = png_get_uint_31(png_ptr, data + 4);
1271 +    
1272 +    /* the set function will do error checking on num_frames */
1273 +    didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
1274 +    if(didSet)
1275 +        png_ptr->mode |= PNG_HAVE_acTL;
1276 +}
1277 +
1278 +void /* PRIVATE */
1279 +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1280 +{
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;
1290 +    
1291 +    png_debug(1, "in png_handle_fcTL\n");
1292 +    
1293 +    if (!(png_ptr->mode & PNG_HAVE_IHDR))
1294 +    {
1295 +        png_error(png_ptr, "Missing IHDR before fcTL");
1296 +    }
1297 +    else if (png_ptr->mode & PNG_HAVE_IDAT)
1298 +    {
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);
1304 +        return;
1305 +    }
1306 +    else if (png_ptr->mode & PNG_HAVE_fcTL)
1307 +    {
1308 +        png_warning(png_ptr, "Duplicate fcTL within one frame skipped");
1309 +        png_crc_finish(png_ptr, length);
1310 +        return;
1311 +    }
1312 +    else if (length != 26)
1313 +    {
1314 +        png_warning(png_ptr, "fcTL with invalid length skipped");
1315 +        png_crc_finish(png_ptr, length);
1316 +        return;
1317 +    }
1318 +    
1319 +    png_ensure_sequence_number(png_ptr, length);
1320 +    
1321 +    png_crc_read(png_ptr, data, 22);
1322 +    png_crc_finish(png_ptr, 0);
1323 +    
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];
1332 +    
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");
1339 +    
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);
1344 +    
1345 +    png_read_reinit(png_ptr, info_ptr);
1346 +    
1347 +    png_ptr->mode |= PNG_HAVE_fcTL;
1348 +}
1349 +
1350 +void /* PRIVATE */
1351 +png_have_info(png_structp png_ptr, png_infop info_ptr)
1352 +{
1353 +    if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL))
1354 +    {
1355 +        png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1356 +        info_ptr->num_frames++;
1357 +    }
1358 +}
1359 +
1360 +void /* PRIVATE */
1361 +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1362 +{
1363 +    png_ensure_sequence_number(png_ptr, length);
1364 +    
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);
1372 +}
1373 +
1374 +void /* PRIVATE */
1375 +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
1376 +{
1377 +    png_byte data[4];
1378 +    png_uint_32 sequence_number;
1379 +    
1380 +    if (length < 4)
1381 +        png_error(png_ptr, "invalid fcTL or fdAT chunk found");
1382 +    
1383 +    png_crc_read(png_ptr, data, 4);
1384 +    sequence_number = png_get_uint_31(png_ptr, data);
1385 +    
1386 +    if (sequence_number != png_ptr->next_seq_num)
1387 +        png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
1388 +                           "number found");
1389 +    
1390 +    png_ptr->next_seq_num++;
1391 +}
1392 +#endif /* PNG_READ_APNG_SUPPORTED */
1393 +
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 @@ -3138,8 +3305,10 @@
1398     if (row_bytes > (png_uint_32)65536L)
1399        png_error(png_ptr, "This image requires a row greater than 64KB");
1400  #endif
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  
1408  #ifdef PNG_MAX_MALLOC_64K
1409     if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
1410 @@ -3161,4 +3330,82 @@
1411  
1412     png_ptr->flags |= PNG_FLAG_ROW_INIT;
1413  }
1414 +
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 */
1419 +void /* PRIVATE */
1420 +png_read_reset(png_structp png_ptr)
1421 +{
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;
1427 +}
1428 +
1429 +void /* PRIVATE */
1430 +png_read_reinit(png_structp png_ptr, png_infop info_ptr)
1431 +{
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);
1435 +}
1436 +
1437 +/* same as png_read_reset() but for the progressive reader */
1438 +void /* PRIVATE */
1439 +png_progressive_read_reset(png_structp png_ptr)
1440 +{
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};
1444 +
1445 +    /* offset to next interlace block */
1446 +    const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1447 +
1448 +    /* start of interlace block in the y direction */
1449 +    const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1450 +
1451 +    /* offset to next interlace block in the y direction */
1452 +    const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1453 +#endif
1454 +    png_uint_32 row_bytes;
1455 +    
1456 +    if (png_ptr->interlaced)
1457 +    {
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];
1461 +        else
1462 +           png_ptr->num_rows = png_ptr->height;
1463 +
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];
1468 +
1469 +        row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
1470 +
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 "
1474 +                               "overflow");
1475 +    }
1476 +    else
1477 +    {
1478 +        png_ptr->num_rows = png_ptr->height;
1479 +        png_ptr->iwidth = png_ptr->width;
1480 +        png_ptr->irowbytes = png_ptr->rowbytes + 1;
1481 +    }
1482 +    
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;
1490 +}
1491 +#endif /* PNG_READ_APNG_SUPPORTED */
1492  #endif /* PNG_READ_SUPPORTED */
1493 Index: pngwutil.c
1494 ===================================================================
1495 --- pngwutil.c  (révision 144)
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);
1500  
1501 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1502 +   png_ptr->first_frame_width = width;
1503 +   png_ptr->first_frame_height = height;
1504 +#endif
1505 +
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 @@
1510  {
1511  #ifdef PNG_USE_LOCAL_ARRAYS
1512     PNG_IDAT;
1513 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1514 +   PNG_fdAT;
1515  #endif
1516 +#endif
1517     png_debug(1, "in png_write_IDAT\n");
1518  
1519     /* Optimize the CMF field in the zlib stream. */
1520 @@ -650,7 +658,28 @@
1521              "Invalid zlib compression method or flags in IDAT");
1522     }
1523  
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)
1527 +#endif
1528 +      png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
1529 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1530 +   else
1531 +   {
1532 +      png_byte buf[4];
1533 +      
1534 +      png_write_chunk_start(png_ptr, (png_bytep)png_fdAT, 4 + length);
1535 +      
1536 +      png_save_uint_32(buf, png_ptr->next_seq_num);
1537 +      png_write_chunk_data(png_ptr, buf, 4);
1538 +      
1539 +      png_write_chunk_data(png_ptr, data, length);
1540 +      
1541 +      png_write_chunk_end(png_ptr);
1542 +      
1543 +      png_ptr->next_seq_num++;
1544 +   }
1545 +#endif
1546 +
1547     png_ptr->mode |= PNG_HAVE_IDAT;
1548  }
1549  
1550 @@ -662,7 +691,7 @@
1551     PNG_IEND;
1552  #endif
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,
1556       (png_size_t)0);
1557     png_ptr->mode |= PNG_HAVE_IEND;
1558  }
1559 @@ -1722,6 +1751,70 @@
1560  }
1561  #endif
1562  
1563 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1564 +void /* PRIVATE */
1565 +png_write_acTL(png_structp png_ptr,
1566 +   png_uint_32 num_frames, png_uint_32 num_plays)
1567 +{
1568 +#ifdef PNG_USE_LOCAL_ARRAYS
1569 +    PNG_acTL;
1570 +#endif
1571 +    png_byte data[16];
1572 +    
1573 +    png_debug(1, "in png_write_acTL\n");
1574 +    
1575 +    png_ptr->num_frames_to_write = num_frames;
1576 +    
1577 +    if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN)
1578 +        num_frames--;
1579 +    
1580 +    png_save_uint_32(data, num_frames);
1581 +    png_save_uint_32(data + 4, num_plays);
1582 +    
1583 +    png_write_chunk(png_ptr, (png_bytep)png_acTL, data, (png_size_t)8);
1584 +}
1585 +
1586 +void /* PRIVATE */
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)
1591 +{
1592 +#ifdef PNG_USE_LOCAL_ARRAYS
1593 +    PNG_fcTL;
1594 +#endif
1595 +    png_byte data[26];
1596 +    
1597 +    png_debug(1, "in png_write_fcTL\n");
1598 +    
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");
1606 +    
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);
1610 +    
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;
1620 +    
1621 +    png_write_chunk(png_ptr, (png_bytep)png_fcTL, data, (png_size_t)26);
1622 +    
1623 +    png_ptr->next_seq_num++;
1624 +}
1625 +#endif /* PNG_WRITE_APNG_SUPPORTED */
1626 +
1627  /* initializes the row writing capability of libpng */
1628  void /* PRIVATE */
1629  png_write_start_row(png_structp png_ptr)
1630 @@ -2789,4 +2882,39 @@
1631     }
1632  #endif
1633  }
1634 +
1635 +#if defined(PNG_WRITE_APNG_SUPPORTED)
1636 +void /* PRIVATE */
1637 +png_write_reset(png_structp png_ptr)
1638 +{
1639 +    png_ptr->row_number = 0;
1640 +    png_ptr->pass = 0;
1641 +    png_ptr->mode &= ~PNG_HAVE_IDAT;
1642 +}
1643 +
1644 +void /* PRIVATE */
1645 +png_write_reinit(png_structp png_ptr, png_infop info_ptr, 
1646 +                 png_uint_32 width, png_uint_32 height)
1647 +{
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");
1657 +    
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);
1662 +   
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;
1667 +}
1668 +#endif
1669  #endif /* PNG_WRITE_SUPPORTED */
1670 Index: pngrtran.c
1671 ===================================================================
1672 --- pngrtran.c  (révision 144)
1673 +++ pngrtran.c  (copie de travail)
1674 @@ -1278,7 +1278,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");
1680  #else
1681        png_warning(png_ptr, "Uninitialized row");
1682  #endif
This page took 0.348112 seconds and 4 git commands to generate.