apng.patch 52 KB

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