libpng-1.5.15-apng.patch 54 KB

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