001-apng.patch 53 KB

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