libpng-1.6.12-apng.patch 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. diff -Naru libpng-1.6.12.org/png.h libpng-1.6.12/png.h
  2. --- libpng-1.6.12.org/png.h 2014-06-12 20:50:55.236436493 +0900
  3. +++ libpng-1.6.12/png.h 2014-06-12 20:50:55.301438712 +0900
  4. @@ -464,6 +464,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. /* Machine specific configuration. */
  13. # include "pngconf.h"
  14. @@ -554,6 +558,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. @@ -874,6 +889,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. @@ -911,6 +930,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. @@ -3246,6 +3269,74 @@
  52. /*******************************************************************************
  53. * END OF HARDWARE AND SOFTWARE OPTIONS
  54. ******************************************************************************/
  55. +#ifdef PNG_APNG_SUPPORTED
  56. +PNG_EXPORT(245, 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(246, 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(247, png_uint_32, png_get_num_frames, (png_structp png_ptr,
  63. + png_infop info_ptr));
  64. +
  65. +PNG_EXPORT(248, png_uint_32, png_get_num_plays, (png_structp png_ptr,
  66. + png_infop info_ptr));
  67. +
  68. +PNG_EXPORT(249, 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(250, 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(251, png_uint_32, png_get_next_frame_width,
  81. + (png_structp png_ptr, png_infop info_ptr));
  82. +PNG_EXPORT(252, png_uint_32, png_get_next_frame_height,
  83. + (png_structp png_ptr, png_infop info_ptr));
  84. +PNG_EXPORT(253, png_uint_32, png_get_next_frame_x_offset,
  85. + (png_structp png_ptr, png_infop info_ptr));
  86. +PNG_EXPORT(254, png_uint_32, png_get_next_frame_y_offset,
  87. + (png_structp png_ptr, png_infop info_ptr));
  88. +PNG_EXPORT(255, png_uint_16, png_get_next_frame_delay_num,
  89. + (png_structp png_ptr, png_infop info_ptr));
  90. +PNG_EXPORT(256, png_uint_16, png_get_next_frame_delay_den,
  91. + (png_structp png_ptr, png_infop info_ptr));
  92. +PNG_EXPORT(257, png_byte, png_get_next_frame_dispose_op,
  93. + (png_structp png_ptr, png_infop info_ptr));
  94. +PNG_EXPORT(258, png_byte, png_get_next_frame_blend_op,
  95. + (png_structp png_ptr, png_infop info_ptr));
  96. +PNG_EXPORT(259, png_byte, png_get_first_frame_is_hidden,
  97. + (png_structp png_ptr, png_infop info_ptr));
  98. +PNG_EXPORT(260, 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(261, void, png_read_frame_head, (png_structp png_ptr,
  103. + png_infop info_ptr));
  104. +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  105. +PNG_EXPORT(262, 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(263, 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(264, 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, scripts/pnglibconf.h, and scripts/pnglibconf.h.prebuilt
  125. @@ -3256,7 +3347,11 @@
  126. * scripts/symbols.def as well.
  127. */
  128. #ifdef PNG_EXPORT_LAST_ORDINAL
  129. +#ifdef PNG_APNG_SUPPORTED
  130. + PNG_EXPORT_LAST_ORDINAL(264);
  131. +#else
  132. PNG_EXPORT_LAST_ORDINAL(244);
  133. +#endif /* PNG_APNG_SUPPORTED */
  134. #endif
  135. #ifdef __cplusplus
  136. diff -Naru libpng-1.6.12.org/pngget.c libpng-1.6.12/pngget.c
  137. --- libpng-1.6.12.org/pngget.c 2014-06-12 20:50:55.237436527 +0900
  138. +++ libpng-1.6.12/pngget.c 2014-06-12 20:50:55.302438746 +0900
  139. @@ -1195,4 +1195,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.6.12.org/pnginfo.h libpng-1.6.12/pnginfo.h
  306. --- libpng-1.6.12.org/pnginfo.h 2014-06-12 20:50:55.237436527 +0900
  307. +++ libpng-1.6.12/pnginfo.h 2014-06-12 20:50:55.302438746 +0900
  308. @@ -256,5 +256,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.6.12.org/pngpread.c libpng-1.6.12/pngpread.c
  327. --- libpng-1.6.12.org/pngpread.c 2014-06-12 20:50:55.237436527 +0900
  328. +++ libpng-1.6.12/pngpread.c 2014-06-12 20:50:55.302438746 +0900
  329. @@ -217,6 +217,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. if (png_ptr->mode & PNG_AFTER_IDAT)
  437. @@ -300,6 +403,9 @@
  438. else if (chunk_name == png_IDAT)
  439. {
  440. +#ifdef PNG_READ_APNG_SUPPORTED
  441. + png_have_info(png_ptr, info_ptr);
  442. +#endif
  443. png_ptr->idat_size = png_ptr->push_length;
  444. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  445. png_push_have_info(png_ptr, info_ptr);
  446. @@ -530,6 +636,30 @@
  447. png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  448. }
  449. #endif
  450. +#ifdef PNG_READ_APNG_SUPPORTED
  451. + else if (chunk_name == png_acTL)
  452. + {
  453. + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  454. + {
  455. + png_push_save_buffer(png_ptr);
  456. + return;
  457. + }
  458. +
  459. + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length);
  460. + }
  461. +
  462. + else if (chunk_name == png_fcTL)
  463. + {
  464. + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  465. + {
  466. + png_push_save_buffer(png_ptr);
  467. + return;
  468. + }
  469. +
  470. + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length);
  471. + }
  472. +
  473. +#endif /* PNG_READ_APNG_SUPPORTED */
  474. else
  475. {
  476. @@ -732,7 +862,11 @@
  477. png_byte chunk_tag[4];
  478. /* TODO: this code can be commoned up with the same code in push_read */
  479. +#ifdef PNG_READ_APNG_SUPPORTED
  480. + if (png_ptr->buffer_size < 12)
  481. +#else
  482. if (png_ptr->buffer_size < 8)
  483. +#endif
  484. {
  485. png_push_save_buffer(png_ptr);
  486. return;
  487. @@ -745,17 +879,64 @@
  488. png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
  489. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  490. +#ifdef PNG_READ_APNG_SUPPORTED
  491. + if (png_ptr->chunk_name != png_fdAT && png_ptr->num_frames_read > 0)
  492. + {
  493. + if (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)
  494. + {
  495. + png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  496. + if (png_ptr->frame_end_fn != NULL)
  497. + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
  498. + png_ptr->num_frames_read++;
  499. + return;
  500. + }
  501. + else
  502. + {
  503. + if (png_ptr->chunk_name == png_IEND)
  504. + png_error(png_ptr, "Not enough image data");
  505. + if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  506. + {
  507. + png_push_save_buffer(png_ptr);
  508. + return;
  509. + }
  510. + png_warning(png_ptr, "Skipping (ignoring) a chunk between "
  511. + "APNG chunks");
  512. + png_crc_finish(png_ptr, png_ptr->push_length);
  513. + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  514. + return;
  515. + }
  516. + }
  517. + else
  518. +#endif
  519. +#ifdef PNG_READ_APNG_SUPPORTED
  520. + if (png_ptr->chunk_name != png_IDAT && png_ptr->num_frames_read == 0)
  521. +#else
  522. if (png_ptr->chunk_name != png_IDAT)
  523. +#endif
  524. {
  525. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  526. if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
  527. png_error(png_ptr, "Not enough compressed data");
  528. +#ifdef PNG_READ_APNG_SUPPORTED
  529. + if (png_ptr->frame_end_fn != NULL)
  530. + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read);
  531. + png_ptr->num_frames_read++;
  532. +#endif
  533. +
  534. return;
  535. }
  536. png_ptr->idat_size = png_ptr->push_length;
  537. +
  538. +#ifdef PNG_READ_APNG_SUPPORTED
  539. + if (png_ptr->num_frames_read > 0)
  540. + {
  541. + png_ensure_sequence_number(png_ptr, 4);
  542. + png_ptr->idat_size -= 4;
  543. + }
  544. +#endif
  545. }
  546. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  547. @@ -833,6 +1014,15 @@
  548. if (!(buffer_length > 0) || buffer == NULL)
  549. png_error(png_ptr, "No IDAT data (internal error)");
  550. +#ifdef PNG_READ_APNG_SUPPORTED
  551. + /* If the app is not APNG-aware, decode only the first frame */
  552. + if (!(png_ptr->apng_flags & PNG_APNG_APP) && png_ptr->num_frames_read > 0)
  553. + {
  554. + png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
  555. + return;
  556. + }
  557. +#endif
  558. +
  559. /* This routine must process all the data it has been given
  560. * before returning, calling the row callback as required to
  561. * handle the uncompressed results.
  562. @@ -1275,6 +1465,18 @@
  563. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  564. }
  565. +#ifdef PNG_READ_APNG_SUPPORTED
  566. +void PNGAPI
  567. +png_set_progressive_frame_fn(png_structp png_ptr,
  568. + png_progressive_frame_ptr frame_info_fn,
  569. + png_progressive_frame_ptr frame_end_fn)
  570. +{
  571. + png_ptr->frame_info_fn = frame_info_fn;
  572. + png_ptr->frame_end_fn = frame_end_fn;
  573. + png_ptr->apng_flags |= PNG_APNG_APP;
  574. +}
  575. +#endif
  576. +
  577. png_voidp PNGAPI
  578. png_get_progressive_ptr(png_const_structrp png_ptr)
  579. {
  580. diff -Naru libpng-1.6.12.org/pngpriv.h libpng-1.6.12/pngpriv.h
  581. --- libpng-1.6.12.org/pngpriv.h 2014-06-12 20:50:55.238436561 +0900
  582. +++ libpng-1.6.12/pngpriv.h 2014-06-12 20:50:55.303438780 +0900
  583. @@ -551,6 +551,10 @@
  584. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  585. /* 0x4000 (unused) */
  586. #define PNG_IS_READ_STRUCT 0x8000 /* Else is a write struct */
  587. +#ifdef PNG_APNG_SUPPORTED
  588. +#define PNG_HAVE_acTL 0x10000
  589. +#define PNG_HAVE_fcTL 0x20000
  590. +#endif
  591. /* Flags for the transformations the PNG library does on the image data */
  592. #define PNG_BGR 0x0001
  593. @@ -772,6 +776,16 @@
  594. #define png_tRNS PNG_U32(116, 82, 78, 83)
  595. #define png_zTXt PNG_U32(122, 84, 88, 116)
  596. +#ifdef PNG_APNG_SUPPORTED
  597. +#define png_acTL PNG_U32( 97, 99, 84, 76)
  598. +#define png_fcTL PNG_U32(102, 99, 84, 76)
  599. +#define png_fdAT PNG_U32(102, 100, 65, 84)
  600. +
  601. +/* For png_struct.apng_flags: */
  602. +#define PNG_FIRST_FRAME_HIDDEN 0x0001
  603. +#define PNG_APNG_APP 0x0002
  604. +#endif
  605. +
  606. /* The following will work on (signed char*) strings, whereas the get_uint_32
  607. * macro will fail on top-bit-set values because of the sign extension.
  608. */
  609. @@ -1472,6 +1486,47 @@
  610. */
  611. #endif
  612. +#ifdef PNG_APNG_SUPPORTED
  613. +PNG_INTERNAL_FUNCTION(void,png_ensure_fcTL_is_valid,(png_structp png_ptr,
  614. + png_uint_32 width, png_uint_32 height,
  615. + png_uint_32 x_offset, png_uint_32 y_offset,
  616. + png_uint_16 delay_num, png_uint_16 delay_den,
  617. + png_byte dispose_op, png_byte blend_op), PNG_EMPTY);
  618. +
  619. +#ifdef PNG_READ_APNG_SUPPORTED
  620. +PNG_INTERNAL_FUNCTION(void,png_handle_acTL,(png_structp png_ptr, png_infop info_ptr,
  621. + png_uint_32 length),PNG_EMPTY);
  622. +PNG_INTERNAL_FUNCTION(void,png_handle_fcTL,(png_structp png_ptr, png_infop info_ptr,
  623. + png_uint_32 length),PNG_EMPTY);
  624. +PNG_INTERNAL_FUNCTION(void,png_handle_fdAT,(png_structp png_ptr, png_infop info_ptr,
  625. + png_uint_32 length),PNG_EMPTY);
  626. +PNG_INTERNAL_FUNCTION(void,png_have_info,(png_structp png_ptr, png_infop info_ptr),PNG_EMPTY);
  627. +PNG_INTERNAL_FUNCTION(void,png_ensure_sequence_number,(png_structp png_ptr,
  628. + png_uint_32 length),PNG_EMPTY);
  629. +PNG_INTERNAL_FUNCTION(void,png_read_reset,(png_structp png_ptr),PNG_EMPTY);
  630. +PNG_INTERNAL_FUNCTION(void,png_read_reinit,(png_structp png_ptr,
  631. + png_infop info_ptr),PNG_EMPTY);
  632. +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  633. +PNG_INTERNAL_FUNCTION(void,png_progressive_read_reset,(png_structp png_ptr),PNG_EMPTY);
  634. +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  635. +#endif /* PNG_READ_APNG_SUPPORTED */
  636. +
  637. +#ifdef PNG_WRITE_APNG_SUPPORTED
  638. +PNG_INTERNAL_FUNCTION(void,png_write_acTL,(png_structp png_ptr,
  639. + png_uint_32 num_frames, png_uint_32 num_plays),PNG_EMPTY);
  640. +PNG_INTERNAL_FUNCTION(void,png_write_fcTL,(png_structp png_ptr,
  641. + png_uint_32 width, png_uint_32 height,
  642. + png_uint_32 x_offset, png_uint_32 y_offset,
  643. + png_uint_16 delay_num, png_uint_16 delay_den,
  644. + png_byte dispose_op, png_byte blend_op),PNG_EMPTY);
  645. +PNG_INTERNAL_FUNCTION(void,png_write_fdAT,(png_structp png_ptr,
  646. + png_const_bytep data, png_size_t length),PNG_EMPTY);
  647. +PNG_INTERNAL_FUNCTION(void,png_write_reset,(png_structp png_ptr),PNG_EMPTY);
  648. +PNG_INTERNAL_FUNCTION(void,png_write_reinit,(png_structp png_ptr,
  649. + png_infop info_ptr, png_uint_32 width, png_uint_32 height),PNG_EMPTY);
  650. +#endif /* PNG_WRITE_APNG_SUPPORTED */
  651. +#endif /* PNG_APNG_SUPPORTED */
  652. +
  653. /* Added at libpng version 1.4.0 */
  654. #ifdef PNG_COLORSPACE_SUPPORTED
  655. /* These internal functions are for maintaining the colorspace structure within
  656. diff -Naru libpng-1.6.12.org/pngread.c libpng-1.6.12/pngread.c
  657. --- libpng-1.6.12.org/pngread.c 2014-06-12 20:50:55.238436561 +0900
  658. +++ libpng-1.6.12/pngread.c 2014-06-12 20:50:55.304438815 +0900
  659. @@ -158,6 +158,9 @@
  660. else if (chunk_name == png_IDAT)
  661. {
  662. +#ifdef PNG_READ_APNG_SUPPORTED
  663. + png_have_info(png_ptr, info_ptr);
  664. +#endif
  665. png_ptr->idat_size = length;
  666. break;
  667. }
  668. @@ -247,6 +250,17 @@
  669. png_handle_iTXt(png_ptr, info_ptr, length);
  670. #endif
  671. +#ifdef PNG_READ_APNG_SUPPORTED
  672. + else if (chunk_name == png_acTL)
  673. + png_handle_acTL(png_ptr, info_ptr, length);
  674. +
  675. + else if (chunk_name == png_fcTL)
  676. + png_handle_fcTL(png_ptr, info_ptr, length);
  677. +
  678. + else if (chunk_name == png_fdAT)
  679. + png_handle_fdAT(png_ptr, info_ptr, length);
  680. +#endif
  681. +
  682. else
  683. png_handle_unknown(png_ptr, info_ptr, length,
  684. PNG_HANDLE_CHUNK_AS_DEFAULT);
  685. @@ -254,6 +268,72 @@
  686. }
  687. #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
  688. +#ifdef PNG_READ_APNG_SUPPORTED
  689. +void PNGAPI
  690. +png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
  691. +{
  692. + png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
  693. +
  694. + png_debug(0, "Reading frame head");
  695. +
  696. + if (!(png_ptr->mode & PNG_HAVE_acTL))
  697. + png_error(png_ptr, "attempt to png_read_frame_head() but "
  698. + "no acTL present");
  699. +
  700. + /* do nothing for the main IDAT */
  701. + if (png_ptr->num_frames_read == 0)
  702. + return;
  703. +
  704. + png_read_reset(png_ptr);
  705. + png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  706. + png_ptr->mode &= ~PNG_HAVE_fcTL;
  707. +
  708. + have_chunk_after_DAT = 0;
  709. + for (;;)
  710. + {
  711. + png_uint_32 length = png_read_chunk_header(png_ptr);
  712. +
  713. + if (png_ptr->chunk_name == png_IDAT)
  714. + {
  715. + /* discard trailing IDATs for the first frame */
  716. + if (have_chunk_after_DAT || png_ptr->num_frames_read > 1)
  717. + png_error(png_ptr, "png_read_frame_head(): out of place IDAT");
  718. + png_crc_finish(png_ptr, length);
  719. + }
  720. +
  721. + else if (png_ptr->chunk_name == png_fcTL)
  722. + {
  723. + png_handle_fcTL(png_ptr, info_ptr, length);
  724. + have_chunk_after_DAT = 1;
  725. + }
  726. +
  727. + else if (png_ptr->chunk_name == png_fdAT)
  728. + {
  729. + png_ensure_sequence_number(png_ptr, length);
  730. +
  731. + /* discard trailing fdATs for frames other than the first */
  732. + if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1)
  733. + png_crc_finish(png_ptr, length - 4);
  734. + else if(png_ptr->mode & PNG_HAVE_fcTL)
  735. + {
  736. + png_ptr->idat_size = length - 4;
  737. + png_ptr->mode |= PNG_HAVE_IDAT;
  738. +
  739. + break;
  740. + }
  741. + else
  742. + png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
  743. + }
  744. + else
  745. + {
  746. + png_warning(png_ptr, "Skipped (ignored) a chunk "
  747. + "between APNG chunks");
  748. + png_crc_finish(png_ptr, length);
  749. + }
  750. + }
  751. +}
  752. +#endif /* PNG_READ_APNG_SUPPORTED */
  753. +
  754. /* Optional call to update the users info_ptr structure */
  755. void PNGAPI
  756. png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
  757. diff -Naru libpng-1.6.12.org/pngrutil.c libpng-1.6.12/pngrutil.c
  758. --- libpng-1.6.12.org/pngrutil.c 2014-06-12 20:50:55.240436630 +0900
  759. +++ libpng-1.6.12/pngrutil.c 2014-06-12 20:50:55.305438849 +0900
  760. @@ -818,6 +818,11 @@
  761. filter_type = buf[11];
  762. interlace_type = buf[12];
  763. +#ifdef PNG_READ_APNG_SUPPORTED
  764. + png_ptr->first_frame_width = width;
  765. + png_ptr->first_frame_height = height;
  766. +#endif
  767. +
  768. /* Set internal variables */
  769. png_ptr->width = width;
  770. png_ptr->height = height;
  771. @@ -2698,6 +2703,179 @@
  772. }
  773. #endif
  774. +#ifdef PNG_READ_APNG_SUPPORTED
  775. +void /* PRIVATE */
  776. +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  777. +{
  778. + png_byte data[8];
  779. + png_uint_32 num_frames;
  780. + png_uint_32 num_plays;
  781. + png_uint_32 didSet;
  782. +
  783. + png_debug(1, "in png_handle_acTL");
  784. +
  785. + if (!(png_ptr->mode & PNG_HAVE_IHDR))
  786. + {
  787. + png_error(png_ptr, "Missing IHDR before acTL");
  788. + }
  789. + else if (png_ptr->mode & PNG_HAVE_IDAT)
  790. + {
  791. + png_warning(png_ptr, "Invalid acTL after IDAT skipped");
  792. + png_crc_finish(png_ptr, length);
  793. + return;
  794. + }
  795. + else if (png_ptr->mode & PNG_HAVE_acTL)
  796. + {
  797. + png_warning(png_ptr, "Duplicate acTL skipped");
  798. + png_crc_finish(png_ptr, length);
  799. + return;
  800. + }
  801. + else if (length != 8)
  802. + {
  803. + png_warning(png_ptr, "acTL with invalid length skipped");
  804. + png_crc_finish(png_ptr, length);
  805. + return;
  806. + }
  807. +
  808. + png_crc_read(png_ptr, data, 8);
  809. + png_crc_finish(png_ptr, 0);
  810. +
  811. + num_frames = png_get_uint_31(png_ptr, data);
  812. + num_plays = png_get_uint_31(png_ptr, data + 4);
  813. +
  814. + /* the set function will do error checking on num_frames */
  815. + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays);
  816. + if(didSet)
  817. + png_ptr->mode |= PNG_HAVE_acTL;
  818. +}
  819. +
  820. +void /* PRIVATE */
  821. +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  822. +{
  823. + png_byte data[22];
  824. + png_uint_32 width;
  825. + png_uint_32 height;
  826. + png_uint_32 x_offset;
  827. + png_uint_32 y_offset;
  828. + png_uint_16 delay_num;
  829. + png_uint_16 delay_den;
  830. + png_byte dispose_op;
  831. + png_byte blend_op;
  832. +
  833. + png_debug(1, "in png_handle_fcTL");
  834. +
  835. + png_ensure_sequence_number(png_ptr, length);
  836. +
  837. + if (!(png_ptr->mode & PNG_HAVE_IHDR))
  838. + {
  839. + png_error(png_ptr, "Missing IHDR before fcTL");
  840. + }
  841. + else if (png_ptr->mode & PNG_HAVE_IDAT)
  842. + {
  843. + /* for any frames other then the first this message may be misleading,
  844. + * but correct. PNG_HAVE_IDAT is unset before the frame head is read
  845. + * i can't think of a better message */
  846. + png_warning(png_ptr, "Invalid fcTL after IDAT skipped");
  847. + png_crc_finish(png_ptr, length-4);
  848. + return;
  849. + }
  850. + else if (png_ptr->mode & PNG_HAVE_fcTL)
  851. + {
  852. + png_warning(png_ptr, "Duplicate fcTL within one frame skipped");
  853. + png_crc_finish(png_ptr, length-4);
  854. + return;
  855. + }
  856. + else if (length != 26)
  857. + {
  858. + png_warning(png_ptr, "fcTL with invalid length skipped");
  859. + png_crc_finish(png_ptr, length-4);
  860. + return;
  861. + }
  862. +
  863. + png_crc_read(png_ptr, data, 22);
  864. + png_crc_finish(png_ptr, 0);
  865. +
  866. + width = png_get_uint_31(png_ptr, data);
  867. + height = png_get_uint_31(png_ptr, data + 4);
  868. + x_offset = png_get_uint_31(png_ptr, data + 8);
  869. + y_offset = png_get_uint_31(png_ptr, data + 12);
  870. + delay_num = png_get_uint_16(data + 16);
  871. + delay_den = png_get_uint_16(data + 18);
  872. + dispose_op = data[20];
  873. + blend_op = data[21];
  874. +
  875. + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0))
  876. + {
  877. + png_warning(png_ptr, "fcTL for the first frame must have zero offset");
  878. + return;
  879. + }
  880. +
  881. + if (info_ptr != NULL)
  882. + {
  883. + if (png_ptr->num_frames_read == 0 &&
  884. + (width != info_ptr->width || height != info_ptr->height))
  885. + {
  886. + png_warning(png_ptr, "size in first frame's fcTL must match "
  887. + "the size in IHDR");
  888. + return;
  889. + }
  890. +
  891. + /* The set function will do more error checking */
  892. + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height,
  893. + x_offset, y_offset, delay_num, delay_den,
  894. + dispose_op, blend_op);
  895. +
  896. + png_read_reinit(png_ptr, info_ptr);
  897. +
  898. + png_ptr->mode |= PNG_HAVE_fcTL;
  899. + }
  900. +}
  901. +
  902. +void /* PRIVATE */
  903. +png_have_info(png_structp png_ptr, png_infop info_ptr)
  904. +{
  905. + if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL))
  906. + {
  907. + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN;
  908. + info_ptr->num_frames++;
  909. + }
  910. +}
  911. +
  912. +void /* PRIVATE */
  913. +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  914. +{
  915. + png_ensure_sequence_number(png_ptr, length);
  916. +
  917. + /* This function is only called from png_read_end(), png_read_info(),
  918. + * and png_push_read_chunk() which means that:
  919. + * - the user doesn't want to read this frame
  920. + * - or this is an out-of-place fdAT
  921. + * in either case it is safe to ignore the chunk with a warning */
  922. + png_warning(png_ptr, "ignoring fdAT chunk");
  923. + png_crc_finish(png_ptr, length - 4);
  924. + PNG_UNUSED(info_ptr)
  925. +}
  926. +
  927. +void /* PRIVATE */
  928. +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length)
  929. +{
  930. + png_byte data[4];
  931. + png_uint_32 sequence_number;
  932. +
  933. + if (length < 4)
  934. + png_error(png_ptr, "invalid fcTL or fdAT chunk found");
  935. +
  936. + png_crc_read(png_ptr, data, 4);
  937. + sequence_number = png_get_uint_31(png_ptr, data);
  938. +
  939. + if (sequence_number != png_ptr->next_seq_num)
  940. + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence "
  941. + "number found");
  942. +
  943. + png_ptr->next_seq_num++;
  944. +}
  945. +#endif /* PNG_READ_APNG_SUPPORTED */
  946. +
  947. #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  948. /* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
  949. static int
  950. @@ -3954,7 +4132,38 @@
  951. {
  952. uInt avail_in;
  953. png_bytep buffer;
  954. +#ifdef PNG_READ_APNG_SUPPORTED
  955. + png_uint_32 bytes_to_skip = 0;
  956. +
  957. + while (png_ptr->idat_size == 0 || bytes_to_skip != 0)
  958. + {
  959. + png_crc_finish(png_ptr, bytes_to_skip);
  960. + bytes_to_skip = 0;
  961. + png_ptr->idat_size = png_read_chunk_header(png_ptr);
  962. + if (png_ptr->num_frames_read == 0)
  963. + {
  964. + if (png_ptr->chunk_name != png_IDAT)
  965. + png_error(png_ptr, "Not enough image data");
  966. + }
  967. + else
  968. + {
  969. + if (png_ptr->chunk_name == png_IEND)
  970. + png_error(png_ptr, "Not enough image data");
  971. + if (png_ptr->chunk_name != png_fdAT)
  972. + {
  973. + png_warning(png_ptr, "Skipped (ignored) a chunk "
  974. + "between APNG chunks");
  975. + bytes_to_skip = png_ptr->idat_size;
  976. + continue;
  977. + }
  978. +
  979. + png_ensure_sequence_number(png_ptr, png_ptr->idat_size);
  980. +
  981. + png_ptr->idat_size -= 4;
  982. + }
  983. + }
  984. +#else
  985. while (png_ptr->idat_size == 0)
  986. {
  987. png_crc_finish(png_ptr, 0);
  988. @@ -3966,7 +4175,7 @@
  989. if (png_ptr->chunk_name != png_IDAT)
  990. png_error(png_ptr, "Not enough image data");
  991. }
  992. -
  993. +#endif /* PNG_READ_APNG_SUPPORTED */
  994. avail_in = png_ptr->IDAT_read_size;
  995. if (avail_in > png_ptr->idat_size)
  996. @@ -4029,6 +4238,9 @@
  997. png_ptr->mode |= PNG_AFTER_IDAT;
  998. png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
  999. +#ifdef PNG_READ_APNG_SUPPORTED
  1000. + png_ptr->num_frames_read++;
  1001. +#endif
  1002. if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
  1003. png_chunk_benign_error(png_ptr, "Extra compressed data");
  1004. @@ -4466,4 +4678,80 @@
  1005. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  1006. }
  1007. +
  1008. +#ifdef PNG_READ_APNG_SUPPORTED
  1009. +/* This function is to be called after the main IDAT set has been read and
  1010. + * before a new IDAT is read. It resets some parts of png_ptr
  1011. + * to make them usable by the read functions again */
  1012. +void /* PRIVATE */
  1013. +png_read_reset(png_structp png_ptr)
  1014. +{
  1015. + png_ptr->mode &= ~PNG_HAVE_IDAT;
  1016. + png_ptr->mode &= ~PNG_AFTER_IDAT;
  1017. + png_ptr->row_number = 0;
  1018. + png_ptr->pass = 0;
  1019. +}
  1020. +
  1021. +void /* PRIVATE */
  1022. +png_read_reinit(png_structp png_ptr, png_infop info_ptr)
  1023. +{
  1024. + png_ptr->width = info_ptr->next_frame_width;
  1025. + png_ptr->height = info_ptr->next_frame_height;
  1026. + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  1027. + png_ptr->info_rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,
  1028. + png_ptr->width);
  1029. + if (png_ptr->prev_row)
  1030. + memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  1031. +}
  1032. +
  1033. +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  1034. +/* same as png_read_reset() but for the progressive reader */
  1035. +void /* PRIVATE */
  1036. +png_progressive_read_reset(png_structp png_ptr)
  1037. +{
  1038. +#ifdef PNG_READ_INTERLACING_SUPPORTED
  1039. + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
  1040. +
  1041. + /* Start of interlace block */
  1042. + const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  1043. +
  1044. + /* Offset to next interlace block */
  1045. + const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  1046. +
  1047. + /* Start of interlace block in the y direction */
  1048. + const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  1049. +
  1050. + /* Offset to next interlace block in the y direction */
  1051. + const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  1052. +
  1053. + if (png_ptr->interlaced)
  1054. + {
  1055. + if (!(png_ptr->transformations & PNG_INTERLACE))
  1056. + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  1057. + png_pass_ystart[0]) / png_pass_yinc[0];
  1058. + else
  1059. + png_ptr->num_rows = png_ptr->height;
  1060. +
  1061. + png_ptr->iwidth = (png_ptr->width +
  1062. + png_pass_inc[png_ptr->pass] - 1 -
  1063. + png_pass_start[png_ptr->pass]) /
  1064. + png_pass_inc[png_ptr->pass];
  1065. + }
  1066. + else
  1067. +#endif /* PNG_READ_INTERLACING_SUPPORTED */
  1068. + {
  1069. + png_ptr->num_rows = png_ptr->height;
  1070. + png_ptr->iwidth = png_ptr->width;
  1071. + }
  1072. + png_ptr->flags &= ~PNG_FLAG_ZSTREAM_ENDED;
  1073. + if (inflateReset(&(png_ptr->zstream)) != Z_OK)
  1074. + png_error(png_ptr, "inflateReset failed");
  1075. + png_ptr->zstream.avail_in = 0;
  1076. + png_ptr->zstream.next_in = 0;
  1077. + png_ptr->zstream.next_out = png_ptr->row_buf;
  1078. + png_ptr->zstream.avail_out = (uInt)PNG_ROWBYTES(png_ptr->pixel_depth,
  1079. + png_ptr->iwidth) + 1;
  1080. +}
  1081. +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  1082. +#endif /* PNG_READ_APNG_SUPPORTED */
  1083. #endif /* PNG_READ_SUPPORTED */
  1084. diff -Naru libpng-1.6.12.org/pngset.c libpng-1.6.12/pngset.c
  1085. --- libpng-1.6.12.org/pngset.c 2014-06-12 20:50:55.240436630 +0900
  1086. +++ libpng-1.6.12/pngset.c 2014-06-12 20:50:55.306438883 +0900
  1087. @@ -239,6 +239,11 @@
  1088. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  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. @@ -1065,6 +1070,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 > PNG_UINT_31_MAX)
  1196. + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)");
  1197. + if (height > PNG_UINT_31_MAX)
  1198. + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)");
  1199. + if (x_offset > PNG_UINT_31_MAX)
  1200. + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)");
  1201. + if (y_offset > PNG_UINT_31_MAX)
  1202. + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)");
  1203. + if (width + x_offset > png_ptr->first_frame_width ||
  1204. + height + y_offset > png_ptr->first_frame_height)
  1205. + png_error(png_ptr, "dimensions of a frame are greater than"
  1206. + "the ones in IHDR");
  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_STORE_UNKNOWN_CHUNKS_SUPPORTED
  1242. static png_byte
  1243. check_location(png_const_structrp png_ptr, int location)
  1244. diff -Naru libpng-1.6.12.org/pngstruct.h libpng-1.6.12/pngstruct.h
  1245. --- libpng-1.6.12.org/pngstruct.h 2014-06-12 20:50:55.240436630 +0900
  1246. +++ libpng-1.6.12/pngstruct.h 2014-06-12 20:50:55.306438883 +0900
  1247. @@ -409,6 +409,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.6.12.org/pngtest.c libpng-1.6.12/pngtest.c
  1274. --- libpng-1.6.12.org/pngtest.c 2014-06-12 20:50:55.241436664 +0900
  1275. +++ libpng-1.6.12/pngtest.c 2014-06-12 20:50:55.306438883 +0900
  1276. @@ -848,6 +848,10 @@
  1277. png_uint_32 width, height;
  1278. int num_pass = 1, 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. @@ -1314,6 +1318,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. @@ -1375,6 +1393,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.6.12.org/pngwrite.c libpng-1.6.12/pngwrite.c
  1398. --- libpng-1.6.12.org/pngwrite.c 2014-06-12 20:50:55.241436664 +0900
  1399. +++ libpng-1.6.12/pngwrite.c 2014-06-12 20:50:55.307438917 +0900
  1400. @@ -127,6 +127,10 @@
  1401. * application continues writing the PNG. So check the 'invalid' flag here
  1402. * too.
  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_GAMMA_SUPPORTED
  1409. # ifdef PNG_WRITE_gAMA_SUPPORTED
  1410. if (!(info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) &&
  1411. @@ -357,6 +361,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. @@ -1662,6 +1671,43 @@
  1423. }
  1424. #endif
  1425. +#ifdef PNG_WRITE_APNG_SUPPORTED
  1426. +void PNGAPI
  1427. +png_write_frame_head(png_structp png_ptr, png_infop info_ptr,
  1428. + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height,
  1429. + png_uint_32 x_offset, png_uint_32 y_offset,
  1430. + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op,
  1431. + png_byte blend_op)
  1432. +{
  1433. + png_debug(1, "in png_write_frame_head");
  1434. +
  1435. + /* there is a chance this has been set after png_write_info was called,
  1436. + * so it would be set but not written. is there a way to be sure? */
  1437. + if (!(info_ptr->valid & PNG_INFO_acTL))
  1438. + png_error(png_ptr, "png_write_frame_head(): acTL not set");
  1439. +
  1440. + png_write_reset(png_ptr);
  1441. +
  1442. + png_write_reinit(png_ptr, info_ptr, width, height);
  1443. +
  1444. + if ( !(png_ptr->num_frames_written == 0 &&
  1445. + (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) )
  1446. + png_write_fcTL(png_ptr, width, height, x_offset, y_offset,
  1447. + delay_num, delay_den, dispose_op, blend_op);
  1448. +
  1449. + PNG_UNUSED(row_pointers)
  1450. +}
  1451. +
  1452. +void PNGAPI
  1453. +png_write_frame_tail(png_structp png_ptr, png_infop info_ptr)
  1454. +{
  1455. + png_debug(1, "in png_write_frame_tail");
  1456. +
  1457. + png_ptr->num_frames_written++;
  1458. +
  1459. + PNG_UNUSED(info_ptr)
  1460. +}
  1461. +#endif /* PNG_WRITE_APNG_SUPPORTED */
  1462. #ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED
  1463. #ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */
  1464. diff -Naru libpng-1.6.12.org/pngwutil.c libpng-1.6.12/pngwutil.c
  1465. --- libpng-1.6.12.org/pngwutil.c 2014-06-12 20:50:55.242436698 +0900
  1466. +++ libpng-1.6.12/pngwutil.c 2014-06-12 20:50:55.307438917 +0900
  1467. @@ -898,6 +898,11 @@
  1468. /* Write the chunk */
  1469. png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  1470. +#ifdef PNG_WRITE_APNG_SUPPORTED
  1471. + png_ptr->first_frame_width = width;
  1472. + png_ptr->first_frame_height = height;
  1473. +#endif
  1474. +
  1475. if ((png_ptr->do_filter) == PNG_NO_FILTERS)
  1476. {
  1477. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  1478. @@ -1076,7 +1081,14 @@
  1479. optimize_cmf(data, png_image_size(png_ptr));
  1480. # endif
  1481. +# ifdef PNG_WRITE_APNG_SUPPORTED
  1482. + if (png_ptr->num_frames_written == 0)
  1483. +# endif
  1484. png_write_complete_chunk(png_ptr, png_IDAT, data, size);
  1485. +# ifdef PNG_WRITE_APNG_SUPPORTED
  1486. + else
  1487. + png_write_fdAT(png_ptr, data, size);
  1488. +# endif /* PNG_WRITE_APNG_SUPPORTED */
  1489. png_ptr->mode |= PNG_HAVE_IDAT;
  1490. png_ptr->zstream.next_out = data;
  1491. @@ -1122,7 +1134,15 @@
  1492. optimize_cmf(data, png_image_size(png_ptr));
  1493. # endif
  1494. +# ifdef PNG_WRITE_APNG_SUPPORTED
  1495. + if (png_ptr->num_frames_written == 0)
  1496. +# endif
  1497. png_write_complete_chunk(png_ptr, png_IDAT, data, size);
  1498. +# ifdef PNG_WRITE_APNG_SUPPORTED
  1499. + else
  1500. + png_write_fdAT(png_ptr, data, size);
  1501. +# endif /* PNG_WRITE_APNG_SUPPORTED */
  1502. +
  1503. png_ptr->zstream.avail_out = 0;
  1504. png_ptr->zstream.next_out = NULL;
  1505. png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT;
  1506. @@ -1936,6 +1956,82 @@
  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. +
  1566. +void /* PRIVATE */
  1567. +png_write_fdAT(png_structp png_ptr,
  1568. + png_const_bytep data, png_size_t length)
  1569. +{
  1570. + png_byte buf[4];
  1571. +
  1572. + png_write_chunk_header(png_ptr, png_fdAT, (png_uint_32)(4 + length));
  1573. +
  1574. + png_save_uint_32(buf, png_ptr->next_seq_num);
  1575. + png_write_chunk_data(png_ptr, buf, 4);
  1576. +
  1577. + png_write_chunk_data(png_ptr, data, length);
  1578. +
  1579. + png_write_chunk_end(png_ptr);
  1580. +
  1581. + png_ptr->next_seq_num++;
  1582. +}
  1583. +#endif /* PNG_WRITE_APNG_SUPPORTED */
  1584. +
  1585. /* Initializes the row writing capability of libpng */
  1586. void /* PRIVATE */
  1587. png_write_start_row(png_structrp png_ptr)
  1588. @@ -3023,4 +3119,39 @@
  1589. }
  1590. #endif
  1591. }
  1592. +
  1593. +#ifdef PNG_WRITE_APNG_SUPPORTED
  1594. +void /* PRIVATE */
  1595. +png_write_reset(png_structp png_ptr)
  1596. +{
  1597. + png_ptr->row_number = 0;
  1598. + png_ptr->pass = 0;
  1599. + png_ptr->mode &= ~PNG_HAVE_IDAT;
  1600. +}
  1601. +
  1602. +void /* PRIVATE */
  1603. +png_write_reinit(png_structp png_ptr, png_infop info_ptr,
  1604. + png_uint_32 width, png_uint_32 height)
  1605. +{
  1606. + if (png_ptr->num_frames_written == 0 &&
  1607. + (width != png_ptr->first_frame_width ||
  1608. + height != png_ptr->first_frame_height))
  1609. + png_error(png_ptr, "width and/or height in the first frame's fcTL "
  1610. + "don't match the ones in IHDR");
  1611. + if (width > png_ptr->first_frame_width ||
  1612. + height > png_ptr->first_frame_height)
  1613. + png_error(png_ptr, "width and/or height for a frame greater than"
  1614. + "the ones in IHDR");
  1615. +
  1616. + png_set_IHDR(png_ptr, info_ptr, width, height,
  1617. + info_ptr->bit_depth, info_ptr->color_type,
  1618. + info_ptr->interlace_type, info_ptr->compression_type,
  1619. + info_ptr->filter_type);
  1620. +
  1621. + png_ptr->width = width;
  1622. + png_ptr->height = height;
  1623. + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  1624. + png_ptr->usr_width = png_ptr->width;
  1625. +}
  1626. +#endif /* PNG_WRITE_APNG_SUPPORTED */
  1627. #endif /* PNG_WRITE_SUPPORTED */
  1628. diff -Naru libpng-1.6.12.org/scripts/symbols.def libpng-1.6.12/scripts/symbols.def
  1629. --- libpng-1.6.12.org/scripts/symbols.def 2014-06-12 20:50:55.248436903 +0900
  1630. +++ libpng-1.6.12/scripts/symbols.def 2014-06-12 20:50:55.314439156 +0900
  1631. @@ -249,3 +249,23 @@
  1632. png_set_check_for_invalid_index @242
  1633. png_get_palette_max @243
  1634. png_set_option @244
  1635. + png_get_acTL @245
  1636. + png_set_acTL @246
  1637. + png_get_num_frames @247
  1638. + png_get_num_plays @248
  1639. + png_get_next_frame_fcTL @249
  1640. + png_set_next_frame_fcTL @250
  1641. + png_get_next_frame_width @251
  1642. + png_get_next_frame_height @252
  1643. + png_get_next_frame_x_offset @253
  1644. + png_get_next_frame_y_offset @254
  1645. + png_get_next_frame_delay_num @255
  1646. + png_get_next_frame_delay_den @256
  1647. + png_get_next_frame_dispose_op @257
  1648. + png_get_next_frame_blend_op @258
  1649. + png_get_first_frame_is_hidden @259
  1650. + png_set_first_frame_is_hidden @260
  1651. + png_read_frame_head @261
  1652. + png_set_progressive_frame_fn @262
  1653. + png_write_frame_head @263
  1654. + png_write_frame_tail @264