Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/scripts/deps/libpng-1.6.54-apng.patch
7197 views
1
diff -Naru libpng-1.6.54.org/png.h libpng-1.6.54/png.h
2
--- libpng-1.6.54.org/png.h 2026-01-15 09:54:33.410881877 +0900
3
+++ libpng-1.6.54/png.h 2026-01-15 14:49:49.345302877 +0900
4
@@ -328,6 +328,10 @@
5
# include "pnglibconf.h"
6
#endif
7
8
+#define PNG_APNG_SUPPORTED
9
+#define PNG_READ_APNG_SUPPORTED
10
+#define PNG_WRITE_APNG_SUPPORTED
11
+
12
#ifndef PNG_VERSION_INFO_ONLY
13
/* Machine specific configuration. */
14
# include "pngconf.h"
15
@@ -423,6 +427,17 @@
16
* See pngconf.h for base types that vary by machine/system
17
*/
18
19
+#ifdef PNG_APNG_SUPPORTED
20
+/* dispose_op flags from inside fcTL */
21
+#define PNG_DISPOSE_OP_NONE 0x00U
22
+#define PNG_DISPOSE_OP_BACKGROUND 0x01U
23
+#define PNG_DISPOSE_OP_PREVIOUS 0x02U
24
+
25
+/* blend_op flags from inside fcTL */
26
+#define PNG_BLEND_OP_SOURCE 0x00U
27
+#define PNG_BLEND_OP_OVER 0x01U
28
+#endif /* PNG_APNG_SUPPORTED */
29
+
30
/* This triggers a compiler error in png.c, if png.c and png.h
31
* do not agree upon the version number.
32
*/
33
@@ -801,6 +816,10 @@
34
(png_structp, png_infop));
35
typedef PNG_CALLBACK(void, *png_progressive_end_ptr,
36
(png_structp, png_infop));
37
+#ifdef PNG_APNG_SUPPORTED
38
+typedef PNG_CALLBACK(void, *png_progressive_frame_ptr,
39
+ (png_structp, png_uint_32));
40
+#endif
41
42
/* The following callback receives png_uint_32 row_number, int pass for the
43
* png_bytep data of the row. When transforming an interlaced image the
44
@@ -3506,6 +3525,80 @@
45
* END OF HARDWARE AND SOFTWARE OPTIONS
46
******************************************************************************/
47
48
+#ifdef PNG_APNG_SUPPORTED
49
+PNG_EXPORT(260, png_uint_32, png_get_acTL,
50
+ (png_structp png_ptr, png_infop info_ptr,
51
+ png_uint_32 *num_frames, png_uint_32 *num_plays));
52
+
53
+PNG_EXPORT(261, png_uint_32, png_set_acTL,
54
+ (png_structp png_ptr, png_infop info_ptr,
55
+ png_uint_32 num_frames, png_uint_32 num_plays));
56
+
57
+PNG_EXPORT(262, png_uint_32, png_get_num_frames,
58
+ (png_structp png_ptr, png_infop info_ptr));
59
+
60
+PNG_EXPORT(263, png_uint_32, png_get_num_plays,
61
+ (png_structp png_ptr, png_infop info_ptr));
62
+
63
+PNG_EXPORT(264, png_uint_32, png_get_next_frame_fcTL,
64
+ (png_structp png_ptr, png_infop info_ptr,
65
+ png_uint_32 *width, png_uint_32 *height,
66
+ png_uint_32 *x_offset, png_uint_32 *y_offset,
67
+ png_uint_16 *delay_num, png_uint_16 *delay_den,
68
+ png_byte *dispose_op, png_byte *blend_op));
69
+
70
+PNG_EXPORT(265, png_uint_32, png_set_next_frame_fcTL,
71
+ (png_structp png_ptr, png_infop info_ptr,
72
+ png_uint_32 width, png_uint_32 height,
73
+ png_uint_32 x_offset, png_uint_32 y_offset,
74
+ png_uint_16 delay_num, png_uint_16 delay_den,
75
+ png_byte dispose_op, png_byte blend_op));
76
+
77
+PNG_EXPORT(266, png_uint_32, png_get_next_frame_width,
78
+ (png_structp png_ptr, png_infop info_ptr));
79
+PNG_EXPORT(267, png_uint_32, png_get_next_frame_height,
80
+ (png_structp png_ptr, png_infop info_ptr));
81
+PNG_EXPORT(268, png_uint_32, png_get_next_frame_x_offset,
82
+ (png_structp png_ptr, png_infop info_ptr));
83
+PNG_EXPORT(269, png_uint_32, png_get_next_frame_y_offset,
84
+ (png_structp png_ptr, png_infop info_ptr));
85
+PNG_EXPORT(270, png_uint_16, png_get_next_frame_delay_num,
86
+ (png_structp png_ptr, png_infop info_ptr));
87
+PNG_EXPORT(271, png_uint_16, png_get_next_frame_delay_den,
88
+ (png_structp png_ptr, png_infop info_ptr));
89
+PNG_EXPORT(272, png_byte, png_get_next_frame_dispose_op,
90
+ (png_structp png_ptr, png_infop info_ptr));
91
+PNG_EXPORT(273, png_byte, png_get_next_frame_blend_op,
92
+ (png_structp png_ptr, png_infop info_ptr));
93
+PNG_EXPORT(274, png_byte, png_get_first_frame_is_hidden,
94
+ (png_structp png_ptr, png_infop info_ptr));
95
+PNG_EXPORT(275, png_uint_32, png_set_first_frame_is_hidden,
96
+ (png_structp png_ptr, png_infop info_ptr, png_byte is_hidden));
97
+
98
+#ifdef PNG_READ_APNG_SUPPORTED
99
+PNG_EXPORT(276, void, png_read_frame_head,
100
+ (png_structp png_ptr, png_infop info_ptr));
101
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
102
+PNG_EXPORT(277, void, png_set_progressive_frame_fn,
103
+ (png_structp png_ptr,
104
+ png_progressive_frame_ptr frame_info_fn,
105
+ png_progressive_frame_ptr frame_end_fn));
106
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
107
+#endif /* PNG_READ_APNG_SUPPORTED */
108
+
109
+#ifdef PNG_WRITE_APNG_SUPPORTED
110
+PNG_EXPORT(278, void, png_write_frame_head,
111
+ (png_structp png_ptr, png_infop info_ptr,
112
+ png_uint_32 width, png_uint_32 height,
113
+ png_uint_32 x_offset, png_uint_32 y_offset,
114
+ png_uint_16 delay_num, png_uint_16 delay_den,
115
+ png_byte dispose_op, png_byte blend_op));
116
+
117
+PNG_EXPORT(279, void, png_write_frame_tail,
118
+ (png_structp png_ptr, png_infop info_ptr));
119
+#endif /* PNG_WRITE_APNG_SUPPORTED */
120
+#endif /* PNG_APNG_SUPPORTED */
121
+
122
/* Maintainer: Put new public prototypes here ^, in libpng.3, in project
123
* defs, and in scripts/symbols.def.
124
*/
125
@@ -3514,7 +3608,11 @@
126
* one to use is one more than this.)
127
*/
128
#ifdef PNG_EXPORT_LAST_ORDINAL
129
+#ifdef PNG_APNG_SUPPORTED
130
+ PNG_EXPORT_LAST_ORDINAL(279);
131
+#else
132
PNG_EXPORT_LAST_ORDINAL(259);
133
+#endif /* PNG_APNG_SUPPORTED */
134
#endif
135
136
#ifdef __cplusplus
137
diff -Naru libpng-1.6.54.org/pngget.c libpng-1.6.54/pngget.c
138
--- libpng-1.6.54.org/pngget.c 2026-01-15 09:54:33.410881877 +0900
139
+++ libpng-1.6.54/pngget.c 2026-01-16 15:37:23.199617980 +0900
140
@@ -1366,4 +1366,166 @@
141
# endif
142
#endif
143
144
+#ifdef PNG_APNG_SUPPORTED
145
+png_uint_32 PNGAPI
146
+png_get_acTL(png_structp png_ptr, png_infop info_ptr,
147
+ png_uint_32 *num_frames, png_uint_32 *num_plays)
148
+{
149
+ png_debug1(1, "in %s retrieval function", "acTL");
150
+
151
+ if (png_ptr != NULL && info_ptr != NULL &&
152
+ (info_ptr->valid & PNG_INFO_acTL) &&
153
+ num_frames != NULL && num_plays != NULL)
154
+ {
155
+ *num_frames = info_ptr->num_frames;
156
+ *num_plays = info_ptr->num_plays;
157
+ return 1;
158
+ }
159
+
160
+ return 0;
161
+}
162
+
163
+png_uint_32 PNGAPI
164
+png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
165
+{
166
+ png_debug(1, "in png_get_num_frames");
167
+
168
+ if (png_ptr != NULL && info_ptr != NULL)
169
+ return info_ptr->num_frames;
170
+ return 0;
171
+}
172
+
173
+png_uint_32 PNGAPI
174
+png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
175
+{
176
+ png_debug(1, "in png_get_num_plays");
177
+
178
+ if (png_ptr != NULL && info_ptr != NULL)
179
+ return info_ptr->num_plays;
180
+ return 0;
181
+}
182
+
183
+png_uint_32 PNGAPI
184
+png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
185
+ png_uint_32 *width, png_uint_32 *height,
186
+ png_uint_32 *x_offset, png_uint_32 *y_offset,
187
+ png_uint_16 *delay_num, png_uint_16 *delay_den,
188
+ png_byte *dispose_op, png_byte *blend_op)
189
+{
190
+ png_debug1(1, "in %s retrieval function", "fcTL");
191
+
192
+ if (png_ptr != NULL && info_ptr != NULL &&
193
+ (info_ptr->valid & PNG_INFO_fcTL) &&
194
+ width != NULL && height != NULL &&
195
+ x_offset != NULL && y_offset != NULL &&
196
+ delay_num != NULL && delay_den != NULL &&
197
+ dispose_op != NULL && blend_op != NULL)
198
+ {
199
+ *width = info_ptr->next_frame_width;
200
+ *height = info_ptr->next_frame_height;
201
+ *x_offset = info_ptr->next_frame_x_offset;
202
+ *y_offset = info_ptr->next_frame_y_offset;
203
+ *delay_num = info_ptr->next_frame_delay_num;
204
+ *delay_den = info_ptr->next_frame_delay_den;
205
+ *dispose_op = info_ptr->next_frame_dispose_op;
206
+ *blend_op = info_ptr->next_frame_blend_op;
207
+ return 1;
208
+ }
209
+
210
+ return 0;
211
+}
212
+
213
+png_uint_32 PNGAPI
214
+png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
215
+{
216
+ png_debug(1, "in png_get_next_frame_width");
217
+
218
+ if (png_ptr != NULL && info_ptr != NULL)
219
+ return info_ptr->next_frame_width;
220
+ return 0;
221
+}
222
+
223
+png_uint_32 PNGAPI
224
+png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
225
+{
226
+ png_debug(1, "in png_get_next_frame_height");
227
+
228
+ if (png_ptr != NULL && info_ptr != NULL)
229
+ return info_ptr->next_frame_height;
230
+ return 0;
231
+}
232
+
233
+png_uint_32 PNGAPI
234
+png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
235
+{
236
+ png_debug(1, "in png_get_next_frame_x_offset");
237
+
238
+ if (png_ptr != NULL && info_ptr != NULL)
239
+ return info_ptr->next_frame_x_offset;
240
+ return 0;
241
+}
242
+
243
+png_uint_32 PNGAPI
244
+png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
245
+{
246
+ png_debug(1, "in png_get_next_frame_y_offset");
247
+
248
+ if (png_ptr != NULL && info_ptr != NULL)
249
+ return info_ptr->next_frame_y_offset;
250
+ return 0;
251
+}
252
+
253
+png_uint_16 PNGAPI
254
+png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
255
+{
256
+ png_debug(1, "in png_get_next_frame_delay_num");
257
+
258
+ if (png_ptr != NULL && info_ptr != NULL)
259
+ return info_ptr->next_frame_delay_num;
260
+ return 0;
261
+}
262
+
263
+png_uint_16 PNGAPI
264
+png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
265
+{
266
+ png_debug(1, "in png_get_next_frame_delay_den");
267
+
268
+ if (png_ptr != NULL && info_ptr != NULL)
269
+ return info_ptr->next_frame_delay_den;
270
+ return 0;
271
+}
272
+
273
+png_byte PNGAPI
274
+png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
275
+{
276
+ png_debug(1, "in png_get_next_frame_dispose_op");
277
+
278
+ if (png_ptr != NULL && info_ptr != NULL)
279
+ return info_ptr->next_frame_dispose_op;
280
+ return 0;
281
+}
282
+
283
+png_byte PNGAPI
284
+png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
285
+{
286
+ png_debug(1, "in png_get_next_frame_blend_op");
287
+
288
+ if (png_ptr != NULL && info_ptr != NULL)
289
+ return info_ptr->next_frame_blend_op;
290
+ return 0;
291
+}
292
+
293
+png_byte PNGAPI
294
+png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
295
+{
296
+ png_debug(1, "in png_first_frame_is_hidden");
297
+
298
+ if (png_ptr != NULL)
299
+ return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
300
+
301
+ PNG_UNUSED(info_ptr)
302
+
303
+ return 0;
304
+}
305
+#endif /* PNG_APNG_SUPPORTED */
306
#endif /* READ || WRITE */
307
diff -Naru libpng-1.6.54.org/pnginfo.h libpng-1.6.54/pnginfo.h
308
--- libpng-1.6.54.org/pnginfo.h 2025-05-11 18:44:02.085040902 +0900
309
+++ libpng-1.6.54/pnginfo.h 2026-01-15 13:50:32.228564907 +0900
310
@@ -259,5 +259,18 @@
311
#ifdef PNG_sRGB_SUPPORTED
312
int rendering_intent;
313
#endif
314
+
315
+#ifdef PNG_APNG_SUPPORTED
316
+ png_uint_32 num_frames; /* including default image */
317
+ png_uint_32 num_plays;
318
+ png_uint_32 next_frame_width;
319
+ png_uint_32 next_frame_height;
320
+ png_uint_32 next_frame_x_offset;
321
+ png_uint_32 next_frame_y_offset;
322
+ png_uint_16 next_frame_delay_num;
323
+ png_uint_16 next_frame_delay_den;
324
+ png_byte next_frame_dispose_op;
325
+ png_byte next_frame_blend_op;
326
+#endif
327
};
328
#endif /* PNGINFO_H */
329
diff -Naru libpng-1.6.54.org/pngpread.c libpng-1.6.54/pngpread.c
330
--- libpng-1.6.54.org/pngpread.c 2025-07-06 11:06:43.933735454 +0900
331
+++ libpng-1.6.54/pngpread.c 2026-01-16 16:44:17.565675229 +0900
332
@@ -200,6 +200,105 @@
333
334
chunk_name = png_ptr->chunk_name;
335
336
+#ifdef PNG_READ_APNG_SUPPORTED
337
+ if (png_ptr->num_frames_read > 0 &&
338
+ png_ptr->num_frames_read < info_ptr->num_frames)
339
+ {
340
+ if (chunk_name == png_IDAT)
341
+ {
342
+ /* Discard trailing IDATs for the first frame. */
343
+ if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1)
344
+ png_error(png_ptr, "Misplaced IDAT in APNG stream");
345
+
346
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
347
+ {
348
+ png_push_save_buffer(png_ptr);
349
+ return;
350
+ }
351
+
352
+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
353
+ return;
354
+ }
355
+ else if (chunk_name == png_fdAT)
356
+ {
357
+ if (png_ptr->buffer_size < 4)
358
+ {
359
+ png_push_save_buffer(png_ptr);
360
+ return;
361
+ }
362
+
363
+ png_ensure_sequence_number(png_ptr, 4);
364
+
365
+ if (!(png_ptr->mode & PNG_HAVE_fcTL))
366
+ {
367
+ /* Discard trailing fdATs for frames other than the first. */
368
+ if (png_ptr->num_frames_read < 2)
369
+ png_error(png_ptr, "Misplaced fdAT in APNG stream");
370
+
371
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
372
+ {
373
+ png_push_save_buffer(png_ptr);
374
+ return;
375
+ }
376
+
377
+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
378
+ return;
379
+ }
380
+
381
+ else
382
+ {
383
+ /* Frame data follows. */
384
+ png_ptr->idat_size = png_ptr->push_length - 4;
385
+ png_ptr->mode |= PNG_HAVE_IDAT;
386
+ png_ptr->process_mode = PNG_READ_IDAT_MODE;
387
+
388
+ return;
389
+ }
390
+ }
391
+
392
+ else if (chunk_name == png_fcTL)
393
+ {
394
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
395
+ {
396
+ png_push_save_buffer(png_ptr);
397
+ return;
398
+ }
399
+
400
+ png_read_reset(png_ptr);
401
+ png_ptr->mode &= ~PNG_HAVE_fcTL;
402
+
403
+ png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
404
+
405
+ if (!(png_ptr->mode & PNG_HAVE_fcTL))
406
+ png_error(png_ptr, "Missing required fcTL chunk in APNG stream");
407
+
408
+ png_read_reinit(png_ptr, info_ptr);
409
+ png_progressive_read_reset(png_ptr);
410
+
411
+ if (png_ptr->frame_info_fn != NULL)
412
+ (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read);
413
+
414
+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
415
+
416
+ return;
417
+ }
418
+
419
+ else
420
+ {
421
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
422
+ {
423
+ png_push_save_buffer(png_ptr);
424
+ return;
425
+ }
426
+ png_warning(png_ptr, "Ignoring unexpected chunk in APNG sequence");
427
+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
428
+ return;
429
+ }
430
+
431
+ return;
432
+ }
433
+#endif /* PNG_READ_APNG_SUPPORTED */
434
+
435
if (chunk_name == png_IDAT)
436
{
437
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
438
@@ -268,6 +367,9 @@
439
440
else if (chunk_name == png_IDAT)
441
{
442
+#ifdef PNG_READ_APNG_SUPPORTED
443
+ png_have_info(png_ptr, info_ptr);
444
+#endif
445
png_ptr->idat_size = png_ptr->push_length;
446
png_ptr->process_mode = PNG_READ_IDAT_MODE;
447
png_push_have_info(png_ptr, info_ptr);
448
@@ -278,6 +380,31 @@
449
return;
450
}
451
452
+#ifdef PNG_READ_APNG_SUPPORTED
453
+ else if (chunk_name == png_acTL)
454
+ {
455
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
456
+ {
457
+ png_push_save_buffer(png_ptr);
458
+ return;
459
+ }
460
+
461
+ png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
462
+ }
463
+
464
+ else if (chunk_name == png_fcTL)
465
+ {
466
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
467
+ {
468
+ png_push_save_buffer(png_ptr);
469
+ return;
470
+ }
471
+
472
+ png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
473
+ }
474
+
475
+#endif /* PNG_READ_APNG_SUPPORTED */
476
+
477
else
478
{
479
PNG_PUSH_SAVE_BUFFER_IF_FULL
480
@@ -409,7 +536,11 @@
481
png_byte chunk_tag[4];
482
483
/* TODO: this code can be commoned up with the same code in push_read */
484
+#ifdef PNG_READ_APNG_SUPPORTED
485
+ PNG_PUSH_SAVE_BUFFER_IF_LT(12)
486
+#else
487
PNG_PUSH_SAVE_BUFFER_IF_LT(8)
488
+#endif
489
png_push_fill_buffer(png_ptr, chunk_length, 4);
490
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
491
png_reset_crc(png_ptr);
492
@@ -417,17 +548,63 @@
493
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
494
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
495
496
+#ifdef PNG_READ_APNG_SUPPORTED
497
+ if (png_ptr->chunk_name != png_fdAT && png_ptr->num_frames_read > 0)
498
+ {
499
+ if (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)
500
+ {
501
+ png_ptr->process_mode = PNG_READ_CHUNK_MODE;
502
+ if (png_ptr->frame_end_fn != NULL)
503
+ (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
504
+ png_ptr->num_frames_read++;
505
+ return;
506
+ }
507
+ else
508
+ {
509
+ if (png_ptr->chunk_name == png_IEND)
510
+ png_error(png_ptr, "Not enough image data");
511
+ if (png_ptr->push_length + 4 > png_ptr->buffer_size)
512
+ {
513
+ png_push_save_buffer(png_ptr);
514
+ return;
515
+ }
516
+ png_warning(png_ptr, "Ignoring unexpected chunk in APNG sequence");
517
+ png_crc_finish(png_ptr, png_ptr->push_length);
518
+ png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
519
+ return;
520
+ }
521
+ }
522
+ else
523
+#endif
524
+#ifdef PNG_READ_APNG_SUPPORTED
525
+ if (png_ptr->chunk_name != png_IDAT && png_ptr->num_frames_read == 0)
526
+#else
527
if (png_ptr->chunk_name != png_IDAT)
528
+#endif
529
{
530
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
531
532
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
533
png_error(png_ptr, "Not enough compressed data");
534
535
+#ifdef PNG_READ_APNG_SUPPORTED
536
+ if (png_ptr->frame_end_fn != NULL)
537
+ (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
538
+ png_ptr->num_frames_read++;
539
+#endif
540
+
541
return;
542
}
543
544
png_ptr->idat_size = png_ptr->push_length;
545
+
546
+#ifdef PNG_READ_APNG_SUPPORTED
547
+ if (png_ptr->num_frames_read > 0)
548
+ {
549
+ png_ensure_sequence_number(png_ptr, 4);
550
+ png_ptr->idat_size -= 4;
551
+ }
552
+#endif
553
}
554
555
if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)
556
@@ -501,6 +678,15 @@
557
if (!(buffer_length > 0) || buffer == NULL)
558
png_error(png_ptr, "No IDAT data (internal error)");
559
560
+#ifdef PNG_READ_APNG_SUPPORTED
561
+ /* If the app is not APNG-aware, decode only the first frame. */
562
+ if (!(png_ptr->apng_flags & PNG_APNG_APP) && png_ptr->num_frames_read > 0)
563
+ {
564
+ png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
565
+ return;
566
+ }
567
+#endif
568
+
569
/* This routine must process all the data it has been given
570
* before returning, calling the row callback as required to
571
* handle the uncompressed results.
572
@@ -934,6 +1120,18 @@
573
png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
574
}
575
576
+#ifdef PNG_READ_APNG_SUPPORTED
577
+void PNGAPI
578
+png_set_progressive_frame_fn(png_structp png_ptr,
579
+ png_progressive_frame_ptr frame_info_fn,
580
+ png_progressive_frame_ptr frame_end_fn)
581
+{
582
+ png_ptr->frame_info_fn = frame_info_fn;
583
+ png_ptr->frame_end_fn = frame_end_fn;
584
+ png_ptr->apng_flags |= PNG_APNG_APP;
585
+}
586
+#endif
587
+
588
png_voidp PNGAPI
589
png_get_progressive_ptr(png_const_structrp png_ptr)
590
{
591
diff -Naru libpng-1.6.54.org/pngpriv.h libpng-1.6.54/pngpriv.h
592
--- libpng-1.6.54.org/pngpriv.h 2026-01-15 09:54:33.411881875 +0900
593
+++ libpng-1.6.54/pngpriv.h 2026-01-16 15:15:06.727223750 +0900
594
@@ -653,6 +653,10 @@
595
#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */
596
#define PNG_WROTE_eXIf 0x4000U
597
#define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */
598
+#ifdef PNG_APNG_SUPPORTED
599
+#define PNG_HAVE_acTL 0x10000U
600
+#define PNG_HAVE_fcTL 0x20000U
601
+#endif
602
603
/* Flags for the transformations the PNG library does on the image data */
604
#define PNG_BGR 0x0001U
605
@@ -917,6 +921,13 @@
606
#define png_tRNS PNG_U32(116, 82, 78, 83)
607
#define png_zTXt PNG_U32(122, 84, 88, 116)
608
609
+#ifdef PNG_APNG_SUPPORTED
610
+
611
+/* For png_struct.apng_flags: */
612
+#define PNG_FIRST_FRAME_HIDDEN 0x0001U
613
+#define PNG_APNG_APP 0x0002U
614
+#endif
615
+
616
/* The following will work on (signed char*) strings, whereas the get_uint_32
617
* macro will fail on top-bit-set values because of the sign extension.
618
*/
619
@@ -1880,6 +1891,68 @@
620
PNG_EMPTY);
621
#endif /* PROGRESSIVE_READ */
622
623
+#ifdef PNG_APNG_SUPPORTED
624
+PNG_INTERNAL_FUNCTION(void, png_ensure_fcTL_is_valid,
625
+ (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
+ PNG_EMPTY);
631
+
632
+#ifdef PNG_READ_APNG_SUPPORTED
633
+PNG_INTERNAL_FUNCTION(void, png_handle_acTL,
634
+ (png_structp png_ptr, png_infop info_ptr, png_uint_32 length),
635
+ PNG_EMPTY);
636
+PNG_INTERNAL_FUNCTION(void, png_handle_fcTL,
637
+ (png_structp png_ptr, png_infop info_ptr, png_uint_32 length),
638
+ PNG_EMPTY);
639
+PNG_INTERNAL_FUNCTION(void, png_handle_fdAT,
640
+ (png_structp png_ptr, png_infop info_ptr, png_uint_32 length),
641
+ PNG_EMPTY);
642
+PNG_INTERNAL_FUNCTION(void, png_have_info,
643
+ (png_structp png_ptr, png_infop info_ptr),
644
+ PNG_EMPTY);
645
+PNG_INTERNAL_FUNCTION(void, png_ensure_sequence_number,
646
+ (png_structp png_ptr, png_uint_32 length),
647
+ PNG_EMPTY);
648
+PNG_INTERNAL_FUNCTION(void, png_read_reset,
649
+ (png_structp png_ptr),
650
+ PNG_EMPTY);
651
+PNG_INTERNAL_FUNCTION(void, png_read_reinit,
652
+ (png_structp png_ptr, png_infop info_ptr),
653
+ PNG_EMPTY);
654
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
655
+PNG_INTERNAL_FUNCTION(void, png_progressive_read_reset,
656
+ (png_structp png_ptr),
657
+ PNG_EMPTY);
658
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
659
+#endif /* PNG_READ_APNG_SUPPORTED */
660
+
661
+#ifdef PNG_WRITE_APNG_SUPPORTED
662
+PNG_INTERNAL_FUNCTION(void, png_write_acTL,
663
+ (png_structp png_ptr, png_uint_32 num_frames, png_uint_32 num_plays),
664
+ PNG_EMPTY);
665
+PNG_INTERNAL_FUNCTION(void, png_write_fcTL,
666
+ (png_structp png_ptr,
667
+ png_uint_32 width, png_uint_32 height,
668
+ png_uint_32 x_offset, png_uint_32 y_offset,
669
+ png_uint_16 delay_num, png_uint_16 delay_den,
670
+ png_byte dispose_op, png_byte blend_op),
671
+ PNG_EMPTY);
672
+PNG_INTERNAL_FUNCTION(void, png_write_fdAT,
673
+ (png_structp png_ptr, png_const_bytep data, png_size_t length),
674
+ PNG_EMPTY);
675
+PNG_INTERNAL_FUNCTION(void, png_write_reset,
676
+ (png_structp png_ptr),
677
+ PNG_EMPTY);
678
+PNG_INTERNAL_FUNCTION(void, png_write_reinit,
679
+ (png_structp png_ptr, png_infop info_ptr,
680
+ png_uint_32 width, png_uint_32 height),
681
+ PNG_EMPTY);
682
+#endif /* PNG_WRITE_APNG_SUPPORTED */
683
+#endif /* PNG_APNG_SUPPORTED */
684
+
685
#ifdef PNG_iCCP_SUPPORTED
686
/* Routines for checking parts of an ICC profile. */
687
#ifdef PNG_READ_iCCP_SUPPORTED
688
diff -Naru libpng-1.6.54.org/pngread.c libpng-1.6.54/pngread.c
689
--- libpng-1.6.54.org/pngread.c 2026-01-15 09:54:33.412881873 +0900
690
+++ libpng-1.6.54/pngread.c 2026-01-16 19:10:26.174024695 +0900
691
@@ -157,16 +157,95 @@
692
693
else if (chunk_name == png_IDAT)
694
{
695
+#ifdef PNG_READ_APNG_SUPPORTED
696
+ png_have_info(png_ptr, info_ptr);
697
+#endif
698
png_ptr->idat_size = length;
699
break;
700
}
701
702
+#ifdef PNG_READ_APNG_SUPPORTED
703
+ else if (chunk_name == png_acTL)
704
+ png_handle_acTL(png_ptr, info_ptr, length);
705
+
706
+ else if (chunk_name == png_fcTL)
707
+ png_handle_fcTL(png_ptr, info_ptr, length);
708
+
709
+ else if (chunk_name == png_fdAT)
710
+ png_handle_fdAT(png_ptr, info_ptr, length);
711
+#endif
712
+
713
else
714
png_handle_chunk(png_ptr, info_ptr, length);
715
}
716
}
717
#endif /* SEQUENTIAL_READ */
718
719
+#ifdef PNG_READ_APNG_SUPPORTED
720
+void PNGAPI
721
+png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
722
+{
723
+ png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
724
+
725
+ png_debug(1, "Reading frame head");
726
+
727
+ if (!(png_ptr->mode & PNG_HAVE_acTL))
728
+ png_error(png_ptr, "Cannot read APNG frame: missing acTL");
729
+
730
+ /* Do nothing for the main IDAT. */
731
+ if (png_ptr->num_frames_read == 0)
732
+ return;
733
+
734
+ png_read_reset(png_ptr);
735
+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
736
+ png_ptr->mode &= ~PNG_HAVE_fcTL;
737
+
738
+ have_chunk_after_DAT = 0;
739
+ for (;;)
740
+ {
741
+ png_uint_32 length = png_read_chunk_header(png_ptr);
742
+
743
+ if (png_ptr->chunk_name == png_IDAT)
744
+ {
745
+ /* Discard trailing IDATs for the first frame. */
746
+ if (have_chunk_after_DAT || png_ptr->num_frames_read > 1)
747
+ png_error(png_ptr, "Misplaced IDAT in APNG stream");
748
+ png_crc_finish(png_ptr, length);
749
+ }
750
+ else if (png_ptr->chunk_name == png_fcTL)
751
+ {
752
+ png_handle_fcTL(png_ptr, info_ptr, length);
753
+ have_chunk_after_DAT = 1;
754
+ }
755
+ else if (png_ptr->chunk_name == png_fdAT)
756
+ {
757
+ png_ensure_sequence_number(png_ptr, length);
758
+
759
+ /* Discard trailing fdATs for all frames except the first. */
760
+ if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1)
761
+ {
762
+ png_crc_finish(png_ptr, length - 4);
763
+ }
764
+ else if (png_ptr->mode & PNG_HAVE_fcTL)
765
+ {
766
+ png_ptr->idat_size = length - 4;
767
+ png_ptr->mode |= PNG_HAVE_IDAT;
768
+ break;
769
+ }
770
+ else
771
+ {
772
+ png_error(png_ptr, "Misplaced fdAT in APNG stream");
773
+ }
774
+ }
775
+ else
776
+ {
777
+ png_warning(png_ptr, "Ignoring unexpected chunk in APNG sequence");
778
+ png_crc_finish(png_ptr, length);
779
+ }
780
+ }
781
+}
782
+#endif /* PNG_READ_APNG_SUPPORTED */
783
+
784
/* Optional call to update the users info_ptr structure */
785
void PNGAPI
786
png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
787
diff -Naru libpng-1.6.54.org/pngrutil.c libpng-1.6.54/pngrutil.c
788
--- libpng-1.6.54.org/pngrutil.c 2026-01-15 09:54:33.413881871 +0900
789
+++ libpng-1.6.54/pngrutil.c 2026-01-17 10:41:44.972759729 +0900
790
@@ -922,6 +922,11 @@
791
filter_type = buf[11];
792
interlace_type = buf[12];
793
794
+#ifdef PNG_READ_APNG_SUPPORTED
795
+ png_ptr->first_frame_width = width;
796
+ png_ptr->first_frame_height = height;
797
+#endif
798
+
799
/* Set internal variables */
800
png_ptr->width = width;
801
png_ptr->height = height;
802
@@ -2718,6 +2723,184 @@
803
# define png_handle_iTXt NULL
804
#endif
805
806
+#ifdef PNG_READ_APNG_SUPPORTED
807
+void /* PRIVATE */
808
+png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
809
+{
810
+ png_byte data[8];
811
+ png_uint_32 num_frames;
812
+ png_uint_32 num_plays;
813
+
814
+ png_debug(1, "in png_handle_acTL");
815
+
816
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
817
+ {
818
+ png_error(png_ptr, "Missing IHDR before acTL");
819
+ }
820
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
821
+ {
822
+ png_warning(png_ptr, "Ignoring misplaced acTL after IDAT");
823
+ png_crc_finish(png_ptr, length);
824
+ return;
825
+ }
826
+ else if (png_ptr->mode & PNG_HAVE_acTL)
827
+ {
828
+ png_warning(png_ptr, "Ignoring duplicate acTL");
829
+ png_crc_finish(png_ptr, length);
830
+ return;
831
+ }
832
+ else if (length != 8)
833
+ {
834
+ png_warning(png_ptr, "Ignoring acTL with incorrect length");
835
+ png_crc_finish(png_ptr, length);
836
+ return;
837
+ }
838
+
839
+ png_crc_read(png_ptr, data, 8);
840
+ png_crc_finish(png_ptr, 0);
841
+
842
+ num_frames = png_get_uint_31(png_ptr, data);
843
+ num_plays = png_get_uint_31(png_ptr, data + 4);
844
+
845
+ /* The set function will do error checking on num_frames. */
846
+ if (png_set_acTL(png_ptr, info_ptr, num_frames, num_plays))
847
+ png_ptr->mode |= PNG_HAVE_acTL;
848
+}
849
+
850
+void /* PRIVATE */
851
+png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
852
+{
853
+ png_byte data[22];
854
+ png_uint_32 width;
855
+ png_uint_32 height;
856
+ png_uint_32 x_offset;
857
+ png_uint_32 y_offset;
858
+ png_uint_16 delay_num;
859
+ png_uint_16 delay_den;
860
+ png_byte dispose_op;
861
+ png_byte blend_op;
862
+
863
+ png_debug(1, "in png_handle_fcTL");
864
+
865
+ png_ensure_sequence_number(png_ptr, length);
866
+
867
+ if (!(png_ptr->mode & PNG_HAVE_IHDR))
868
+ {
869
+ png_error(png_ptr, "Missing IHDR before fcTL");
870
+ }
871
+ else if (png_ptr->mode & PNG_HAVE_IDAT)
872
+ {
873
+ /* For any frames other then the first this message may be misleading,
874
+ * but correct. PNG_HAVE_IDAT is unset before the frame head is read.
875
+ * I can't think of a better message.
876
+ */
877
+ png_warning(png_ptr, "Ignoring invalid fcTL after IDAT");
878
+ png_crc_finish(png_ptr, length-4);
879
+ return;
880
+ }
881
+ else if (png_ptr->mode & PNG_HAVE_fcTL)
882
+ {
883
+ png_warning(png_ptr, "Ignoring duplicate fcTL within one frame");
884
+ png_crc_finish(png_ptr, length-4);
885
+ return;
886
+ }
887
+ else if (length != 26)
888
+ {
889
+ png_warning(png_ptr, "Ignoring fcTL with incorrect length");
890
+ png_crc_finish(png_ptr, length-4);
891
+ return;
892
+ }
893
+
894
+ png_crc_read(png_ptr, data, 22);
895
+ png_crc_finish(png_ptr, 0);
896
+
897
+ width = png_get_uint_31(png_ptr, data);
898
+ height = png_get_uint_31(png_ptr, data + 4);
899
+ x_offset = png_get_uint_31(png_ptr, data + 8);
900
+ y_offset = png_get_uint_31(png_ptr, data + 12);
901
+ delay_num = png_get_uint_16(data + 16);
902
+ delay_den = png_get_uint_16(data + 18);
903
+ dispose_op = data[20];
904
+ blend_op = data[21];
905
+
906
+ if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
907
+ {
908
+ png_warning(png_ptr, "Ignoring leading fcTL with non-zero frame offset");
909
+ return;
910
+ }
911
+
912
+ if (info_ptr != NULL)
913
+ {
914
+ if (png_ptr->num_frames_read == 0 &&
915
+ (width != info_ptr->width || height != info_ptr->height))
916
+ {
917
+ png_warning(png_ptr,
918
+ "Ignoring leading fcTL with incorrect frame size");
919
+ return;
920
+ }
921
+
922
+ /* The set function will do more error checking. */
923
+ png_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
924
+ x_offset, y_offset, delay_num, delay_den,
925
+ dispose_op, blend_op);
926
+
927
+ png_read_reinit(png_ptr, info_ptr);
928
+
929
+ png_ptr->mode |= PNG_HAVE_fcTL;
930
+ }
931
+}
932
+
933
+void /* PRIVATE */
934
+png_have_info(png_structp png_ptr, png_infop info_ptr)
935
+{
936
+ if ((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL))
937
+ {
938
+ png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
939
+ info_ptr->num_frames++;
940
+ }
941
+}
942
+
943
+void /* PRIVATE */
944
+png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
945
+{
946
+ png_ensure_sequence_number(png_ptr, length);
947
+
948
+ /* This function is called only from png_read_end(), png_read_info(),
949
+ * and png_push_read_chunk(). This means one of the following:
950
+ * - The user doesn't want to read this frame.
951
+ * - This is an out-of-place fdAT.
952
+ * In either case, it is safe to ignore the chunk with a warning.
953
+ */
954
+ png_warning(png_ptr, "Ignoring fdAT chunk");
955
+ png_crc_finish(png_ptr, length - 4);
956
+ PNG_UNUSED(info_ptr)
957
+}
958
+
959
+void /* PRIVATE */
960
+png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
961
+{
962
+ png_byte data[4];
963
+ png_uint_32 sequence_number;
964
+
965
+ if (length < 4)
966
+ {
967
+ /* TODO: Write a more precise message. */
968
+ png_error(png_ptr, "Invalid fcTL or fdAT chunk");
969
+ }
970
+
971
+ png_crc_read(png_ptr, data, 4);
972
+ sequence_number = png_get_uint_31(png_ptr, data);
973
+
974
+ if (sequence_number != png_ptr->next_seq_num)
975
+ {
976
+ /* TODO: Write a more precise message. */
977
+ png_error(png_ptr, "Out-of-order sequence number in fcTL or fdAT");
978
+ }
979
+
980
+ png_ptr->next_seq_num++;
981
+}
982
+#endif /* PNG_READ_APNG_SUPPORTED */
983
+
984
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
985
/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
986
static int
987
@@ -4200,7 +4383,38 @@
988
{
989
uInt avail_in;
990
png_bytep buffer;
991
+#ifdef PNG_READ_APNG_SUPPORTED
992
+ png_uint_32 bytes_to_skip = 0;
993
+
994
+ while (png_ptr->idat_size == 0 || bytes_to_skip != 0)
995
+ {
996
+ png_crc_finish(png_ptr, bytes_to_skip);
997
+ bytes_to_skip = 0;
998
+
999
+ png_ptr->idat_size = png_read_chunk_header(png_ptr);
1000
+ if (png_ptr->num_frames_read == 0)
1001
+ {
1002
+ if (png_ptr->chunk_name != png_IDAT)
1003
+ png_error(png_ptr, "Not enough image data");
1004
+ }
1005
+ else
1006
+ {
1007
+ if (png_ptr->chunk_name == png_IEND)
1008
+ png_error(png_ptr, "Not enough image data");
1009
+ if (png_ptr->chunk_name != png_fdAT)
1010
+ {
1011
+ png_warning(png_ptr,
1012
+ "Ignoring unexpected chunk in APNG sequence");
1013
+ bytes_to_skip = png_ptr->idat_size;
1014
+ continue;
1015
+ }
1016
+
1017
+ png_ensure_sequence_number(png_ptr, png_ptr->idat_size);
1018
1019
+ png_ptr->idat_size -= 4;
1020
+ }
1021
+ }
1022
+#else
1023
while (png_ptr->idat_size == 0)
1024
{
1025
png_crc_finish(png_ptr, 0);
1026
@@ -4212,7 +4426,7 @@
1027
if (png_ptr->chunk_name != png_IDAT)
1028
png_error(png_ptr, "Not enough image data");
1029
}
1030
-
1031
+#endif /* PNG_READ_APNG_SUPPORTED */
1032
avail_in = png_ptr->IDAT_read_size;
1033
1034
if (avail_in > png_chunk_max(png_ptr))
1035
@@ -4283,6 +4497,9 @@
1036
1037
png_ptr->mode |= PNG_AFTER_IDAT;
1038
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
1039
+#ifdef PNG_READ_APNG_SUPPORTED
1040
+ png_ptr->num_frames_read++;
1041
+#endif
1042
1043
if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
1044
png_chunk_benign_error(png_ptr, "Extra compressed data");
1045
@@ -4692,4 +4909,82 @@
1046
1047
png_ptr->flags |= PNG_FLAG_ROW_INIT;
1048
}
1049
+
1050
+#ifdef PNG_READ_APNG_SUPPORTED
1051
+/* This function should be called after the main IDAT sequence has been read
1052
+ * and before a new fdAT is about to be read. It resets some parts of png_ptr
1053
+ * to make them usable by the read functions again.
1054
+ */
1055
+void /* PRIVATE */
1056
+png_read_reset(png_structp png_ptr)
1057
+{
1058
+ png_ptr->mode &= ~PNG_HAVE_IDAT;
1059
+ png_ptr->mode &= ~PNG_AFTER_IDAT;
1060
+ png_ptr->row_number = 0;
1061
+ png_ptr->pass = 0;
1062
+}
1063
+
1064
+void /* PRIVATE */
1065
+png_read_reinit(png_structp png_ptr, png_infop info_ptr)
1066
+{
1067
+ png_ptr->width = info_ptr->next_frame_width;
1068
+ png_ptr->height = info_ptr->next_frame_height;
1069
+ png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
1070
+ png_ptr->info_rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,
1071
+ png_ptr->width);
1072
+ if (png_ptr->prev_row)
1073
+ memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
1074
+}
1075
+
1076
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1077
+/* Same as png_read_reset(), but for the progressive reader. */
1078
+void /* PRIVATE */
1079
+png_progressive_read_reset(png_structp png_ptr)
1080
+{
1081
+#ifdef PNG_READ_INTERLACING_SUPPORTED
1082
+ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1083
+
1084
+ /* Start of interlace block */
1085
+ const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1086
+
1087
+ /* Offset to next interlace block */
1088
+ const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1089
+
1090
+ /* Start of interlace block in the y direction */
1091
+ const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1092
+
1093
+ /* Offset to next interlace block in the y direction */
1094
+ const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1095
+
1096
+ if (png_ptr->interlaced)
1097
+ {
1098
+ if (!(png_ptr->transformations & PNG_INTERLACE))
1099
+ png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1100
+ png_pass_ystart[0]) /
1101
+ png_pass_yinc[0];
1102
+ else
1103
+ png_ptr->num_rows = png_ptr->height;
1104
+
1105
+ png_ptr->iwidth = (png_ptr->width +
1106
+ png_pass_inc[png_ptr->pass] - 1 -
1107
+ png_pass_start[png_ptr->pass]) /
1108
+ png_pass_inc[png_ptr->pass];
1109
+ }
1110
+ else
1111
+#endif /* PNG_READ_INTERLACING_SUPPORTED */
1112
+ {
1113
+ png_ptr->num_rows = png_ptr->height;
1114
+ png_ptr->iwidth = png_ptr->width;
1115
+ }
1116
+ png_ptr->flags &= ~PNG_FLAG_ZSTREAM_ENDED;
1117
+ if (inflateReset(&(png_ptr->zstream)) != Z_OK)
1118
+ png_error(png_ptr, "inflateReset failed");
1119
+ png_ptr->zstream.avail_in = 0;
1120
+ png_ptr->zstream.next_in = 0;
1121
+ png_ptr->zstream.next_out = png_ptr->row_buf;
1122
+ png_ptr->zstream.avail_out =
1123
+ (uInt)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1;
1124
+}
1125
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1126
+#endif /* PNG_READ_APNG_SUPPORTED */
1127
#endif /* READ */
1128
diff -Naru libpng-1.6.54.org/pngset.c libpng-1.6.54/pngset.c
1129
--- libpng-1.6.54.org/pngset.c 2025-05-11 18:44:02.087040907 +0900
1130
+++ libpng-1.6.54/pngset.c 2026-01-16 19:22:09.948006831 +0900
1131
@@ -460,6 +460,13 @@
1132
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
1133
1134
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
1135
+
1136
+#ifdef PNG_APNG_SUPPORTED
1137
+ /* Assume a non-animated PNG in the beginning. This may be overridden after
1138
+ * seeing an acTL chunk later.
1139
+ */
1140
+ info_ptr->num_frames = 1;
1141
+#endif
1142
}
1143
1144
#ifdef PNG_oFFs_SUPPORTED
1145
@@ -1315,6 +1322,145 @@
1146
}
1147
#endif /* sPLT */
1148
1149
+#ifdef PNG_APNG_SUPPORTED
1150
+png_uint_32 PNGAPI
1151
+png_set_acTL(png_structp png_ptr, png_infop info_ptr,
1152
+ png_uint_32 num_frames, png_uint_32 num_plays)
1153
+{
1154
+ png_debug1(1, "in %s storage function", "acTL");
1155
+
1156
+ if (png_ptr == NULL || info_ptr == NULL)
1157
+ {
1158
+ png_warning(png_ptr,
1159
+ "Ignoring call to png_set_acTL with NULL libpng object args");
1160
+ return 0;
1161
+ }
1162
+ if (num_frames == 0)
1163
+ {
1164
+ png_warning(png_ptr,
1165
+ "Ignoring attempt to set acTL with num_frames zero");
1166
+ return 0;
1167
+ }
1168
+ if (num_frames > PNG_UINT_31_MAX)
1169
+ {
1170
+ png_warning(png_ptr,
1171
+ "Ignoring attempt to set acTL with num_frames > 2^31-1");
1172
+ return 0;
1173
+ }
1174
+ if (num_plays > PNG_UINT_31_MAX)
1175
+ {
1176
+ png_warning(png_ptr,
1177
+ "Ignoring attempt to set acTL with num_plays > 2^31-1");
1178
+ return 0;
1179
+ }
1180
+
1181
+ info_ptr->num_frames = num_frames;
1182
+ info_ptr->num_plays = num_plays;
1183
+
1184
+ info_ptr->valid |= PNG_INFO_acTL;
1185
+
1186
+ return 1;
1187
+}
1188
+
1189
+/* delay_num and delay_den can hold any 16-bit values including zero */
1190
+png_uint_32 PNGAPI
1191
+png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
1192
+ png_uint_32 width, png_uint_32 height,
1193
+ png_uint_32 x_offset, png_uint_32 y_offset,
1194
+ png_uint_16 delay_num, png_uint_16 delay_den,
1195
+ png_byte dispose_op, png_byte blend_op)
1196
+{
1197
+ png_debug1(1, "in %s storage function", "fcTL");
1198
+
1199
+ if (png_ptr == NULL || info_ptr == NULL)
1200
+ {
1201
+ png_warning(png_ptr,
1202
+ "Ignoring call to png_set_fcTL with NULL libpng object args");
1203
+ return 0;
1204
+ }
1205
+
1206
+ png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1207
+ delay_num, delay_den, dispose_op, blend_op);
1208
+
1209
+ /* No checking is required for delay_num and delay_den.
1210
+ * They can hold any 16-bit value, including zero.
1211
+ */
1212
+
1213
+ if (blend_op == PNG_BLEND_OP_OVER)
1214
+ {
1215
+ if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) &&
1216
+ !(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
1217
+ {
1218
+ png_warning(png_ptr,
1219
+ "Ignoring wasteful fcTL BLEND_OP_OVER in opaque images");
1220
+ blend_op = PNG_BLEND_OP_SOURCE;
1221
+ }
1222
+ }
1223
+
1224
+ info_ptr->next_frame_width = width;
1225
+ info_ptr->next_frame_height = height;
1226
+ info_ptr->next_frame_x_offset = x_offset;
1227
+ info_ptr->next_frame_y_offset = y_offset;
1228
+ info_ptr->next_frame_delay_num = delay_num;
1229
+ info_ptr->next_frame_delay_den = delay_den;
1230
+ info_ptr->next_frame_dispose_op = dispose_op;
1231
+ info_ptr->next_frame_blend_op = blend_op;
1232
+
1233
+ info_ptr->valid |= PNG_INFO_fcTL;
1234
+
1235
+ return 1;
1236
+}
1237
+
1238
+void /* PRIVATE */
1239
+png_ensure_fcTL_is_valid(png_structp png_ptr,
1240
+ png_uint_32 width, png_uint_32 height,
1241
+ png_uint_32 x_offset, png_uint_32 y_offset,
1242
+ png_uint_16 delay_num, png_uint_16 delay_den,
1243
+ png_byte dispose_op, png_byte blend_op)
1244
+{
1245
+ if (width == 0 || width > PNG_UINT_31_MAX)
1246
+ png_error(png_ptr, "Invalid frame width in fcTL");
1247
+ if (height == 0 || height > PNG_UINT_31_MAX)
1248
+ png_error(png_ptr, "Invalid frame height in fcTL");
1249
+ if (x_offset > PNG_UINT_31_MAX || y_offset > PNG_UINT_31_MAX)
1250
+ png_error(png_ptr, "Invalid frame offset in fcTL");
1251
+ if (width + x_offset > png_ptr->first_frame_width ||
1252
+ height + y_offset > png_ptr->first_frame_height)
1253
+ png_error(png_ptr, "Oversized frame in fcTL");
1254
+
1255
+ if (dispose_op != PNG_DISPOSE_OP_NONE &&
1256
+ dispose_op != PNG_DISPOSE_OP_BACKGROUND &&
1257
+ dispose_op != PNG_DISPOSE_OP_PREVIOUS)
1258
+ png_error(png_ptr, "Invalid dispose_op in fcTL");
1259
+
1260
+ if (blend_op != PNG_BLEND_OP_SOURCE &&
1261
+ blend_op != PNG_BLEND_OP_OVER)
1262
+ png_error(png_ptr, "Invalid blend_op in fcTL");
1263
+
1264
+ PNG_UNUSED(delay_num)
1265
+ PNG_UNUSED(delay_den)
1266
+}
1267
+
1268
+png_uint_32 PNGAPI
1269
+png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
1270
+ png_byte is_hidden)
1271
+{
1272
+ png_debug(1, "in png_first_frame_is_hidden");
1273
+
1274
+ if (png_ptr == NULL)
1275
+ return 0;
1276
+
1277
+ if (is_hidden)
1278
+ png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
1279
+ else
1280
+ png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN;
1281
+
1282
+ PNG_UNUSED(info_ptr)
1283
+
1284
+ return 1;
1285
+}
1286
+#endif /* PNG_APNG_SUPPORTED */
1287
+
1288
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1289
static png_byte
1290
check_location(png_const_structrp png_ptr, int location)
1291
diff -Naru libpng-1.6.54.org/pngstruct.h libpng-1.6.54/pngstruct.h
1292
--- libpng-1.6.54.org/pngstruct.h 2025-12-06 20:00:54.866030732 +0900
1293
+++ libpng-1.6.54/pngstruct.h 2026-01-15 13:50:32.229564906 +0900
1294
@@ -391,6 +391,27 @@
1295
png_byte filter_type;
1296
#endif
1297
1298
+#ifdef PNG_APNG_SUPPORTED
1299
+ png_uint_32 apng_flags;
1300
+ png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */
1301
+ png_uint_32 first_frame_width;
1302
+ png_uint_32 first_frame_height;
1303
+
1304
+#ifdef PNG_READ_APNG_SUPPORTED
1305
+ png_uint_32 num_frames_read; /* incremented after all image data of */
1306
+ /* a frame is read */
1307
+#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1308
+ png_progressive_frame_ptr frame_info_fn; /* frame info read callback */
1309
+ png_progressive_frame_ptr frame_end_fn; /* frame data read callback */
1310
+#endif
1311
+#endif
1312
+
1313
+#ifdef PNG_WRITE_APNG_SUPPORTED
1314
+ png_uint_32 num_frames_to_write;
1315
+ png_uint_32 num_frames_written;
1316
+#endif
1317
+#endif /* PNG_APNG_SUPPORTED */
1318
+
1319
/* New members added in libpng-1.2.0 */
1320
1321
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
1322
diff -Naru libpng-1.6.54.org/pngtest.c libpng-1.6.54/pngtest.c
1323
--- libpng-1.6.54.org/pngtest.c 2026-01-15 09:54:33.413881871 +0900
1324
+++ libpng-1.6.54/pngtest.c 2026-01-16 15:31:15.016058178 +0900
1325
@@ -877,6 +877,10 @@
1326
int bit_depth, color_type;
1327
user_chunk_info my_user_chunk_data;
1328
int pass, num_passes;
1329
+#ifdef PNG_APNG_SUPPORTED
1330
+ png_uint_32 num_frames;
1331
+ png_uint_32 num_plays;
1332
+#endif
1333
1334
row_buf = NULL;
1335
error_parameters.file_name = inname;
1336
@@ -1437,6 +1441,22 @@
1337
}
1338
}
1339
#endif
1340
+
1341
+#ifdef PNG_APNG_SUPPORTED
1342
+ if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_acTL))
1343
+ {
1344
+ if (png_get_acTL(read_ptr, read_info_ptr, &num_frames, &num_plays))
1345
+ {
1346
+ png_byte is_hidden;
1347
+ pngtest_debug2("Handling acTL chunks (frames %ld, plays %ld)",
1348
+ num_frames, num_plays);
1349
+ png_set_acTL(write_ptr, write_info_ptr, num_frames, num_plays);
1350
+ is_hidden = png_get_first_frame_is_hidden(read_ptr, read_info_ptr);
1351
+ png_set_first_frame_is_hidden(write_ptr, write_info_ptr, is_hidden);
1352
+ }
1353
+ }
1354
+#endif
1355
+
1356
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1357
{
1358
png_unknown_chunkp unknowns;
1359
@@ -1496,6 +1516,111 @@
1360
t_misc += (t_stop - t_start);
1361
t_start = t_stop;
1362
#endif
1363
+#ifdef PNG_APNG_SUPPORTED
1364
+ if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_acTL))
1365
+ {
1366
+ png_uint_32 frame;
1367
+ for (frame = 0; frame < num_frames; frame++)
1368
+ {
1369
+ png_uint_32 frame_width;
1370
+ png_uint_32 frame_height;
1371
+ png_uint_32 x_offset;
1372
+ png_uint_32 y_offset;
1373
+ png_uint_16 delay_num;
1374
+ png_uint_16 delay_den;
1375
+ png_byte dispose_op;
1376
+ png_byte blend_op;
1377
+ png_read_frame_head(read_ptr, read_info_ptr);
1378
+ if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_fcTL))
1379
+ {
1380
+ png_get_next_frame_fcTL(read_ptr, read_info_ptr,
1381
+ &frame_width, &frame_height,
1382
+ &x_offset, &y_offset,
1383
+ &delay_num, &delay_den,
1384
+ &dispose_op, &blend_op);
1385
+ }
1386
+ else
1387
+ {
1388
+ frame_width = width;
1389
+ frame_height = height;
1390
+ x_offset = 0;
1391
+ y_offset = 0;
1392
+ delay_num = 1;
1393
+ delay_den = 1;
1394
+ dispose_op = PNG_DISPOSE_OP_NONE;
1395
+ blend_op = PNG_BLEND_OP_SOURCE;
1396
+ }
1397
+#ifdef PNG_WRITE_APNG_SUPPORTED
1398
+ png_write_frame_head(write_ptr, write_info_ptr,
1399
+ frame_width, frame_height,
1400
+ x_offset, y_offset,
1401
+ delay_num, delay_den,
1402
+ dispose_op, blend_op);
1403
+#endif
1404
+ for (pass = 0; pass < num_passes; pass++)
1405
+ {
1406
+# ifdef calc_pass_height
1407
+ png_uint_32 pass_height;
1408
+
1409
+ if (num_passes == 7) /* interlaced */
1410
+ {
1411
+ if (PNG_PASS_COLS(frame_width, pass) > 0)
1412
+ pass_height = PNG_PASS_ROWS(frame_height, pass);
1413
+
1414
+ else
1415
+ pass_height = 0;
1416
+ }
1417
+
1418
+ else /* not interlaced */
1419
+ pass_height = frame_height;
1420
+# else
1421
+# define pass_height frame_height
1422
+# endif
1423
+
1424
+ pngtest_debug1("Writing row data for pass %d", pass);
1425
+ for (y = 0; y < pass_height; y++)
1426
+ {
1427
+#ifndef SINGLE_ROWBUF_ALLOC
1428
+ pngtest_debug2("Allocating row buffer (pass %d, y = %u)...",
1429
+ pass, y);
1430
+
1431
+ row_buf = (png_bytep)png_malloc(read_ptr,
1432
+ png_get_rowbytes(read_ptr, read_info_ptr));
1433
+
1434
+ pngtest_debug2("\t0x%08lx (%lu bytes)", (unsigned long)row_buf,
1435
+ (unsigned long)png_get_rowbytes(read_ptr, read_info_ptr));
1436
+
1437
+#endif /* !SINGLE_ROWBUF_ALLOC */
1438
+ png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
1439
+
1440
+#ifdef PNG_WRITE_SUPPORTED
1441
+#ifdef PNGTEST_TIMING
1442
+ t_stop = (float)clock();
1443
+ t_decode += (t_stop - t_start);
1444
+ t_start = t_stop;
1445
+#endif
1446
+ png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
1447
+#ifdef PNGTEST_TIMING
1448
+ t_stop = (float)clock();
1449
+ t_encode += (t_stop - t_start);
1450
+ t_start = t_stop;
1451
+#endif
1452
+#endif /* PNG_WRITE_SUPPORTED */
1453
+
1454
+#ifndef SINGLE_ROWBUF_ALLOC
1455
+ pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
1456
+ png_free(read_ptr, row_buf);
1457
+ row_buf = NULL;
1458
+#endif /* !SINGLE_ROWBUF_ALLOC */
1459
+ }
1460
+ }
1461
+#ifdef PNG_WRITE_APNG_SUPPORTED
1462
+ png_write_frame_tail(write_ptr, write_info_ptr);
1463
+#endif
1464
+ }
1465
+ }
1466
+ else
1467
+#endif
1468
for (pass = 0; pass < num_passes; pass++)
1469
{
1470
# ifdef calc_pass_height
1471
diff -Naru libpng-1.6.54.org/pngwrite.c libpng-1.6.54/pngwrite.c
1472
--- libpng-1.6.54.org/pngwrite.c 2026-01-15 09:54:33.413881871 +0900
1473
+++ libpng-1.6.54/pngwrite.c 2026-01-16 16:49:59.704764231 +0900
1474
@@ -127,6 +127,11 @@
1475
* the application continues writing the PNG. So check the 'invalid'
1476
* flag here too.
1477
*/
1478
+#ifdef PNG_WRITE_APNG_SUPPORTED
1479
+ if ((info_ptr->valid & PNG_INFO_acTL) != 0)
1480
+ png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays);
1481
+#endif
1482
+
1483
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1484
/* Write unknown chunks first; PNG v3 establishes a precedence order
1485
* for colourspace chunks. It is certain therefore that new
1486
@@ -405,6 +410,11 @@
1487
png_benign_error(png_ptr, "Wrote palette index exceeding num_palette");
1488
#endif
1489
1490
+#ifdef PNG_WRITE_APNG_SUPPORTED
1491
+ if (png_ptr->num_frames_written != png_ptr->num_frames_to_write)
1492
+ png_error(png_ptr, "Not enough frames written");
1493
+#endif
1494
+
1495
/* See if user wants us to write information chunks */
1496
if (info_ptr != NULL)
1497
{
1498
@@ -1517,6 +1527,42 @@
1499
}
1500
#endif
1501
1502
+#ifdef PNG_WRITE_APNG_SUPPORTED
1503
+void PNGAPI
1504
+png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
1505
+ png_uint_32 width, png_uint_32 height,
1506
+ png_uint_32 x_offset, png_uint_32 y_offset,
1507
+ png_uint_16 delay_num, png_uint_16 delay_den,
1508
+ png_byte dispose_op, png_byte blend_op)
1509
+{
1510
+ png_debug(1, "in png_write_frame_head");
1511
+
1512
+ /* There is a chance this has been set after png_write_info was called,
1513
+ * so it would be set but not written. Is there a way to be sure?
1514
+ */
1515
+ if (!(info_ptr->valid & PNG_INFO_acTL))
1516
+ png_error(png_ptr, "Cannot write APNG frame: missing acTL");
1517
+
1518
+ png_write_reset(png_ptr);
1519
+
1520
+ png_write_reinit(png_ptr, info_ptr, width, height);
1521
+
1522
+ if (!(png_ptr->num_frames_written == 0 &&
1523
+ (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN)))
1524
+ png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
1525
+ delay_num, delay_den, dispose_op, blend_op);
1526
+}
1527
+
1528
+void PNGAPI
1529
+png_write_frame_tail(png_structp png_ptr, png_infop info_ptr)
1530
+{
1531
+ png_debug(1, "in png_write_frame_tail");
1532
+
1533
+ png_ptr->num_frames_written++;
1534
+
1535
+ PNG_UNUSED(info_ptr)
1536
+}
1537
+#endif /* PNG_WRITE_APNG_SUPPORTED */
1538
1539
#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
1540
/* Initialize the write structure - general purpose utility. */
1541
diff -Naru libpng-1.6.54.org/pngwutil.c libpng-1.6.54/pngwutil.c
1542
--- libpng-1.6.54.org/pngwutil.c 2026-01-15 09:54:33.414881869 +0900
1543
+++ libpng-1.6.54/pngwutil.c 2026-01-16 21:11:48.539248758 +0900
1544
@@ -838,6 +838,11 @@
1545
/* Write the chunk */
1546
png_write_complete_chunk(png_ptr, png_IHDR, buf, 13);
1547
1548
+#ifdef PNG_WRITE_APNG_SUPPORTED
1549
+ png_ptr->first_frame_width = width;
1550
+ png_ptr->first_frame_height = height;
1551
+#endif
1552
+
1553
if ((png_ptr->do_filter) == PNG_NO_FILTERS)
1554
{
1555
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
1556
@@ -1020,7 +1025,17 @@
1557
#endif
1558
1559
if (size > 0)
1560
+ {
1561
+#ifdef PNG_WRITE_APNG_SUPPORTED
1562
+ if (png_ptr->num_frames_written == 0)
1563
+ png_write_complete_chunk(png_ptr, png_IDAT, data, size);
1564
+ else
1565
+ png_write_fdAT(png_ptr, data, size);
1566
+#else
1567
png_write_complete_chunk(png_ptr, png_IDAT, data, size);
1568
+#endif /* PNG_WRITE_APNG_SUPPORTED */
1569
+ }
1570
+
1571
png_ptr->mode |= PNG_HAVE_IDAT;
1572
1573
png_ptr->zstream.next_out = data;
1574
@@ -1067,7 +1082,17 @@
1575
#endif
1576
1577
if (size > 0)
1578
+ {
1579
+#ifdef PNG_WRITE_APNG_SUPPORTED
1580
+ if (png_ptr->num_frames_written == 0)
1581
+ png_write_complete_chunk(png_ptr, png_IDAT, data, size);
1582
+ else
1583
+ png_write_fdAT(png_ptr, data, size);
1584
+#else
1585
png_write_complete_chunk(png_ptr, png_IDAT, data, size);
1586
+#endif /* PNG_WRITE_APNG_SUPPORTED */
1587
+ }
1588
+
1589
png_ptr->zstream.avail_out = 0;
1590
png_ptr->zstream.next_out = NULL;
1591
png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT;
1592
@@ -1969,6 +1994,82 @@
1593
}
1594
#endif
1595
1596
+#ifdef PNG_WRITE_APNG_SUPPORTED
1597
+void /* PRIVATE */
1598
+png_write_acTL(png_structp png_ptr,
1599
+ png_uint_32 num_frames, png_uint_32 num_plays)
1600
+{
1601
+ png_byte buf[8];
1602
+
1603
+ png_debug(1, "in png_write_acTL");
1604
+
1605
+ png_ptr->num_frames_to_write = num_frames;
1606
+
1607
+ if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN)
1608
+ num_frames--;
1609
+
1610
+ png_save_uint_32(buf, num_frames);
1611
+ png_save_uint_32(buf + 4, num_plays);
1612
+
1613
+ png_write_complete_chunk(png_ptr, png_acTL, buf, (png_size_t)8);
1614
+}
1615
+
1616
+void /* PRIVATE */
1617
+png_write_fcTL(png_structp png_ptr,
1618
+ png_uint_32 width, png_uint_32 height,
1619
+ png_uint_32 x_offset, png_uint_32 y_offset,
1620
+ png_uint_16 delay_num, png_uint_16 delay_den,
1621
+ png_byte dispose_op, png_byte blend_op)
1622
+{
1623
+ png_byte buf[26];
1624
+
1625
+ png_debug(1, "in png_write_fcTL");
1626
+
1627
+ if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0))
1628
+ png_error(png_ptr, "Non-zero frame offset in leading fcTL");
1629
+ if (png_ptr->num_frames_written == 0 &&
1630
+ (width != png_ptr->first_frame_width ||
1631
+ height != png_ptr->first_frame_height))
1632
+ png_error(png_ptr, "Incorrect frame size in leading fcTL");
1633
+
1634
+ /* More error checking. */
1635
+ png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset,
1636
+ delay_num, delay_den, dispose_op, blend_op);
1637
+
1638
+ png_save_uint_32(buf, png_ptr->next_seq_num);
1639
+ png_save_uint_32(buf + 4, width);
1640
+ png_save_uint_32(buf + 8, height);
1641
+ png_save_uint_32(buf + 12, x_offset);
1642
+ png_save_uint_32(buf + 16, y_offset);
1643
+ png_save_uint_16(buf + 20, delay_num);
1644
+ png_save_uint_16(buf + 22, delay_den);
1645
+ buf[24] = dispose_op;
1646
+ buf[25] = blend_op;
1647
+
1648
+ png_write_complete_chunk(png_ptr, png_fcTL, buf, (png_size_t)26);
1649
+
1650
+ png_ptr->next_seq_num++;
1651
+}
1652
+
1653
+void /* PRIVATE */
1654
+png_write_fdAT(png_structp png_ptr,
1655
+ png_const_bytep data, png_size_t length)
1656
+{
1657
+ png_byte buf[4];
1658
+
1659
+ png_write_chunk_header(png_ptr, png_fdAT, (png_uint_32)(4 + length));
1660
+
1661
+ png_save_uint_32(buf, png_ptr->next_seq_num);
1662
+ png_write_chunk_data(png_ptr, buf, 4);
1663
+
1664
+ png_write_chunk_data(png_ptr, data, length);
1665
+
1666
+ png_write_chunk_end(png_ptr);
1667
+
1668
+ png_ptr->next_seq_num++;
1669
+}
1670
+#endif /* PNG_WRITE_APNG_SUPPORTED */
1671
+
1672
/* Initializes the row writing capability of libpng */
1673
void /* PRIVATE */
1674
png_write_start_row(png_structrp png_ptr)
1675
@@ -2822,4 +2923,37 @@
1676
}
1677
#endif /* WRITE_FLUSH */
1678
}
1679
+
1680
+#ifdef PNG_WRITE_APNG_SUPPORTED
1681
+void /* PRIVATE */
1682
+png_write_reset(png_structp png_ptr)
1683
+{
1684
+ png_ptr->row_number = 0;
1685
+ png_ptr->pass = 0;
1686
+ png_ptr->mode &= ~PNG_HAVE_IDAT;
1687
+}
1688
+
1689
+void /* PRIVATE */
1690
+png_write_reinit(png_structp png_ptr, png_infop info_ptr,
1691
+ png_uint_32 width, png_uint_32 height)
1692
+{
1693
+ if (png_ptr->num_frames_written == 0 &&
1694
+ (width != png_ptr->first_frame_width ||
1695
+ height != png_ptr->first_frame_height))
1696
+ png_error(png_ptr, "Incorrect frame size in leading fcTL");
1697
+ if (width > png_ptr->first_frame_width ||
1698
+ height > png_ptr->first_frame_height)
1699
+ png_error(png_ptr, "Oversized frame in fcTL");
1700
+
1701
+ png_set_IHDR(png_ptr, info_ptr, width, height,
1702
+ info_ptr->bit_depth, info_ptr->color_type,
1703
+ info_ptr->interlace_type, info_ptr->compression_type,
1704
+ info_ptr->filter_type);
1705
+
1706
+ png_ptr->width = width;
1707
+ png_ptr->height = height;
1708
+ png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
1709
+ png_ptr->usr_width = png_ptr->width;
1710
+}
1711
+#endif /* PNG_WRITE_APNG_SUPPORTED */
1712
#endif /* WRITE */
1713
diff -Naru libpng-1.6.54.org/scripts/symbols.def libpng-1.6.54/scripts/symbols.def
1714
--- libpng-1.6.54.org/scripts/symbols.def 2025-01-26 08:07:01.594606745 +0900
1715
+++ libpng-1.6.54/scripts/symbols.def 2026-01-15 13:50:32.230564905 +0900
1716
@@ -263,3 +263,23 @@
1717
png_get_mDCV_fixed @257
1718
png_set_mDCV @258
1719
png_set_mDCV_fixed @259
1720
+ png_get_acTL @260
1721
+ png_set_acTL @261
1722
+ png_get_num_frames @262
1723
+ png_get_num_plays @263
1724
+ png_get_next_frame_fcTL @264
1725
+ png_set_next_frame_fcTL @265
1726
+ png_get_next_frame_width @266
1727
+ png_get_next_frame_height @267
1728
+ png_get_next_frame_x_offset @268
1729
+ png_get_next_frame_y_offset @269
1730
+ png_get_next_frame_delay_num @270
1731
+ png_get_next_frame_delay_den @271
1732
+ png_get_next_frame_dispose_op @272
1733
+ png_get_next_frame_blend_op @273
1734
+ png_get_first_frame_is_hidden @274
1735
+ png_set_first_frame_is_hidden @275
1736
+ png_read_frame_head @276
1737
+ png_set_progressive_frame_fn @277
1738
+ png_write_frame_head @278
1739
+ png_write_frame_tail @279
1740
1741