media/libpng/apng.patch

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial