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