home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !LibU / man / libpng.3 next >
Encoding:
Text File  |  2006-09-20  |  181.2 KB  |  4,036 lines

  1. <!-- manual page source format generated by PolyglotMan v3.0.8+X.Org, -->
  2. <!-- available at http://polyglotman.sourceforge.net/ -->
  3.  
  4. <html>
  5. <head>
  6. <title>LIBPNG(3) manual page</title>
  7. </head>
  8. <body bgcolor='#efefef' text='black' link='blue' vlink='#551A8B' alink='red'>
  9. <a href='#toc'>Table of Contents</a><p>
  10.  
  11. <h2><a name='sect0' href='#toc0'>Name</a></h2>
  12. libpng - Portable Network Graphics (PNG) Reference Library 1.2.8 
  13. <h2><a name='sect1' href='#toc1'>Synopsis</a></h2>
  14. <i><b>
  15. </b></i>
  16. <p> <b>#include <png.h></b> 
  17. <p> <i><b> 
  18. <p></b></i> <b>png_uint_32 png_access_version_number <i>(void</i></b><b>);</b> 
  19. <p> <i><b> 
  20. <p></b></i> <b>int
  21. png_check_sig (png_bytep </b><i>sig</i><b>, int <i>num</i></b><b>);</b> 
  22. <p> <i><b> 
  23. <p></b></i> <b>void png_chunk_error (png_structp
  24. </b><i>png_ptr</i><b>, png_const_charp <i>error</i></b><b>);</b> 
  25. <p> <i><b> 
  26. <p></b></i> <b>void png_chunk_warning (png_structp
  27. </b><i>png_ptr</i><b>, png_const_charp <i>message</i></b><b>);</b> 
  28. <p> <i><b> 
  29. <p></b></i> <b>void png_convert_from_struct_tm (png_timep
  30. </b><i>ptime</i><b>, struct tm FAR * <i>ttime</i></b><b>);</b> 
  31. <p> <i><b> 
  32. <p></b></i> <b>void png_convert_from_time_t (png_timep
  33. </b><i>ptime</i><b>, time_t <i>ttime</i></b><b>);</b> 
  34. <p> <i><b> 
  35. <p></b></i> <b>png_charp png_convert_to_rfc1123 (png_structp
  36. </b><i>png_ptr</i><b>, png_timep <i>ptime</i></b><b>);</b> 
  37. <p> <i><b> 
  38. <p></b></i> <b>png_infop png_create_info_struct (png_structp
  39. <i>png_ptr</i></b><b>);</b> 
  40. <p> <i><b> 
  41. <p></b></i> <b>png_structp png_create_read_struct (png_const_charp </b><i>user_png_ver</i><b>,
  42. png_voidp </b><i>error_ptr</i><b>, png_error_ptr </b><i>error_fn</i><b>, png_error_ptr <i>warn_fn</i></b><b>);</b> 
  43. <p> <i><b>
  44.  
  45. <p></b></i> <b>png_structp png_create_read_struct_2(png_const_charp </b><i>user_png_ver</i><b>, png_voidp
  46. </b><i>error_ptr</i><b>, png_error_ptr </b><i>error_fn</i><b>, png_error_ptr </b><i>warn_fn</i><b>, png_voidp </b><i>mem_ptr</i><b>,
  47. png_malloc_ptr </b><i>malloc_fn</i><b>, png_free_ptr <i>free_fn</i></b><b>);</b> 
  48. <p> <i><b> 
  49. <p></b></i> <b>png_structp png_create_write_struct
  50. (png_const_charp </b><i>user_png_ver</i><b>, png_voidp </b><i>error_ptr</i><b>, png_error_ptr </b><i>error_fn</i><b>,
  51. png_error_ptr <i>warn_fn</i></b><b>);</b> 
  52. <p> <i><b> 
  53. <p></b></i> <b>png_structp png_create_write_struct_2(png_const_charp
  54. </b><i>user_png_ver</i><b>, png_voidp </b><i>error_ptr</i><b>, png_error_ptr </b><i>error_fn</i><b>, png_error_ptr
  55. </b><i>warn_fn</i><b>, png_voidp </b><i>mem_ptr</i><b>, png_malloc_ptr </b><i>malloc_fn</i><b>, png_free_ptr <i>free_fn</i></b><b>);</b>
  56.  
  57. <p> <i><b> 
  58. <p></b></i> <b>int png_debug(int </b><i>level</i><b>, png_const_charp <i>message</i></b><b>);</b> 
  59. <p> <i><b> 
  60. <p></b></i> <b>int png_debug1(int
  61. </b><i>level</i><b>, png_const_charp </b><i>message</i><b>, <i>p1</i></b><b>);</b> 
  62. <p> <i><b> 
  63. <p></b></i> <b>int png_debug2(int </b><i>level</i><b>, png_const_charp
  64. </b><i>message</i><b>, </b><i>p1</i><b>, <i>p2</i></b><b>);</b> 
  65. <p> <i><b> 
  66. <p></b></i> <b>void png_destroy_info_struct (png_structp </b><i>png_ptr</i><b>,
  67. png_infopp <i>info_ptr_ptr</i></b><b>);</b> 
  68. <p> <i><b> 
  69. <p></b></i> <b>void png_destroy_read_struct (png_structpp
  70. </b><i>png_ptr_ptr</i><b>, png_infopp </b><i>info_ptr_ptr</i><b>, png_infopp <i>end_info_ptr_ptr</i></b><b>);</b> 
  71. <p> <i><b> 
  72. <p></b></i>
  73. <b>void png_destroy_write_struct (png_structpp </b><i>png_ptr_ptr</i><b>, png_infopp <i>info_ptr_ptr</i></b><b>);</b>
  74.  
  75. <p> <i><b> 
  76. <p></b></i> <b>void png_error (png_structp </b><i>png_ptr</i><b>, png_const_charp <i>error</i></b><b>);</b> 
  77. <p> <i><b> 
  78. <p></b></i> <b>void
  79. png_free (png_structp </b><i>png_ptr</i><b>, png_voidp <i>ptr</i></b><b>);</b> 
  80. <p> <i><b> 
  81. <p></b></i> <b>void png_free_chunk_list
  82. (png_structp <i>png_ptr</i></b><b>);</b> 
  83. <p> <i><b> 
  84. <p></b></i> <b>void png_free_default(png_structp </b><i>png_ptr</i><b>, png_voidp
  85. <i>ptr</i></b><b>);</b> 
  86. <p> <i><b> 
  87. <p></b></i> <b>void png_free_data (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, int
  88. <i>num</i></b><b>);</b> 
  89. <p> <i><b> 
  90. <p></b></i> <b>png_byte png_get_bit_depth (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b>
  91.  
  92. <p> <i><b> 
  93. <p></b></i> <b>png_uint_32 png_get_bKGD (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_color_16p
  94. <i>*background</i></b><b>);</b> 
  95. <p> <i><b> 
  96. <p></b></i> <b>png_byte png_get_channels (png_structp </b><i>png_ptr</i><b>, png_infop
  97. <i>info_ptr</i></b><b>);</b> 
  98. <p> <i><b> 
  99. <p></b></i> <b>png_uint_32 png_get_cHRM (png_structp </b><i>png_ptr</i><b>, png_infop
  100. </b><i>info_ptr</i><b>, double </b><i>*white_x</i><b>, double </b><i>*white_y</i><b>, double </b><i>*red_x</i><b>, double </b><i>*red_y</i><b>,
  101. double </b><i>*green_x</i><b>, double </b><i>*green_y</i><b>, double </b><i>*blue_x</i><b>, double <i>*blue_y</i></b><b>);</b> 
  102. <p> <i><b> 
  103. <p></b></i> <b>png_uint_32
  104. png_get_cHRM_fixed (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32
  105. </b><i>*white_x</i><b>, png_uint_32 </b><i>*white_y</i><b>, png_uint_32 </b><i>*red_x</i><b>, png_uint_32 </b><i>*red_y</i><b>,
  106. png_uint_32 </b><i>*green_x</i><b>, png_uint_32 </b><i>*green_y</i><b>, png_uint_32 </b><i>*blue_x</i><b>, png_uint_32
  107. <i>*blue_y</i></b><b>);</b> 
  108. <p> <i><b> 
  109. <p></b></i> <b>png_byte png_get_color_type (png_structp </b><i>png_ptr</i><b>, png_infop
  110. <i>info_ptr</i></b><b>);</b> 
  111. <p> <i><b> 
  112. <p></b></i> <b>png_byte png_get_compression_type (png_structp </b><i>png_ptr</i><b>, png_infop
  113. <i>info_ptr</i></b><b>);</b> 
  114. <p> <i><b> 
  115. <p></b></i> <b>png_byte png_get_copyright (png_structp <i>png_ptr</i></b><b>);</b> 
  116. <p> <i><b> 
  117. <p></b></i> <b>png_voidp
  118. png_get_error_ptr (png_structp <i>png_ptr</i></b><b>);</b> 
  119. <p> <i><b> 
  120. <p></b></i> <b>png_byte png_get_filter_type
  121. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  122. <p> <i><b> 
  123. <p></b></i> <b>png_uint_32 png_get_gAMA
  124. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, double <i>*file_gamma</i></b><b>);</b> 
  125. <p> <i><b> 
  126. <p></b></i> <b>png_uint_32
  127. png_get_gAMA_fixed (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32
  128. <i>*int_file_gamma</i></b><b>);</b> 
  129. <p> <i><b> 
  130. <p></b></i> <b>png_byte png_get_header_ver (png_structp <i>png_ptr</i></b><b>);</b>
  131.  
  132. <p> <i><b> 
  133. <p></b></i> <b>png_byte png_get_header_version (png_structp <i>png_ptr</i></b><b>);</b> 
  134. <p> <i><b> 
  135. <p></b></i> <b>png_uint_32
  136. png_get_hIST (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_16p <i>*hist</i></b><b>);</b>
  137.  
  138. <p> <i><b> 
  139. <p></b></i> <b>png_uint_32 png_get_iCCP (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_charpp
  140. </b><i>name</i><b>, int </b><i>*compression_type</i><b>, png_charpp </b><i>profile</i><b>, png_uint_32 <i>*proflen</i></b><b>);</b>
  141.  
  142. <p> <i><b> 
  143. <p></b></i> <b>png_uint_32 png_get_IHDR (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32
  144. </b><i>*width</i><b>, png_uint_32 </b><i>*height</i><b>, int </b><i>*bit_depth</i><b>, int </b><i>*color_type</i><b>, int </b><i>*interlace_type</i><b>,
  145. int </b><i>*compression_type</i><b>, int <i>*filter_type</i></b><b>);</b> 
  146. <p> <i><b> 
  147. <p></b></i> <b>png_uint_32 png_get_image_height
  148. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  149. <p> <i><b> 
  150. <p></b></i> <b>png_uint_32 png_get_image_width
  151. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  152. <p> <i><b> 
  153. <p></b></i> <b>png_byte png_get_interlace_type
  154. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  155. <p> <i><b> 
  156. <p></b></i> <b>png_voidp png_get_io_ptr
  157. (png_structp <i>png_ptr</i></b><b>);</b> 
  158. <p> <i><b> 
  159. <p></b></i> <b>png_byte png_get_libpng_ver (png_structp <i>png_ptr</i></b><b>);</b>
  160.  
  161. <p> <i><b> 
  162. <p></b></i> <b>png_voidp png_get_mem_ptr(png_structp <i>png_ptr</i></b><b>);</b> 
  163. <p> <i><b> 
  164. <p></b></i> <b>png_uint_32 png_get_oFFs
  165. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32 </b><i>*offset_x</i><b>, png_uint_32
  166. </b><i>*offset_y</i><b>, int <i>*unit_type</i></b><b>);</b> 
  167. <p> <i><b> 
  168. <p></b></i> <b>png_uint_32 png_get_pCAL (png_structp </b><i>png_ptr</i><b>,
  169. png_infop </b><i>info_ptr</i><b>, png_charp </b><i>*purpose</i><b>, png_int_32 </b><i>*X0</i><b>, png_int_32 </b><i>*X1</i><b>,
  170. int </b><i>*type</i><b>, int </b><i>*nparams</i><b>, png_charp </b><i>*units</i><b>, png_charpp <i>*params</i></b><b>);</b> 
  171. <p> <i><b> 
  172. <p></b></i> <b>png_uint_32
  173. png_get_pHYs (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32 </b><i>*res_x</i><b>,
  174. png_uint_32 </b><i>*res_y</i><b>, int <i>*unit_type</i></b><b>);</b> 
  175. <p> <i><b> 
  176. <p></b></i> <b>float png_get_pixel_aspect_ratio
  177. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  178. <p> <i><b> 
  179. <p></b></i> <b>png_uint_32 png_get_pixels_per_meter
  180. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  181. <p> <i><b> 
  182. <p></b></i> <b>png_voidp png_get_progressive_ptr
  183. (png_structp <i>png_ptr</i></b><b>);</b> 
  184. <p> <i><b> 
  185. <p></b></i> <b>png_uint_32 png_get_PLTE (png_structp </b><i>png_ptr</i><b>,
  186. png_infop </b><i>info_ptr</i><b>, png_colorp </b><i>*palette</i><b>, int <i>*num_palette</i></b><b>);</b> 
  187. <p> <i><b> 
  188. <p></b></i> <b>png_byte
  189. png_get_rgb_to_gray_status (png_structp <i>png_ptr) 
  190. <p></i></b> <b>png_uint_32 png_get_rowbytes
  191. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  192. <p> <i><b> 
  193. <p></b></i> <b>png_bytepp png_get_rows (png_structp
  194. </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  195. <p> <i><b> 
  196. <p></b></i> <b>png_uint_32 png_get_sBIT (png_structp
  197. </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_color_8p <i>*sig_bit</i></b><b>);</b> 
  198. <p> <i><b> 
  199. <p></b></i> <b>png_bytep png_get_signature
  200. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  201. <p> <i><b> 
  202. <p></b></i> <b>png_uint_32 png_get_sPLT
  203. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_spalette_p <i>*splt_ptr</i></b><b>);</b> 
  204. <p> <i><b>
  205.  
  206. <p></b></i> <b>png_uint_32 png_get_sRGB (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, int
  207. <i>*intent</i></b><b>);</b> 
  208. <p> <i><b> 
  209. <p></b></i> <b>png_uint_32 png_get_text (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>,
  210. png_textp </b><i>*text_ptr</i><b>, int <i>*num_text</i></b><b>);</b> 
  211. <p> <i><b> 
  212. <p></b></i> <b>png_uint_32 png_get_tIME (png_structp
  213. </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_timep <i>*mod_time</i></b><b>);</b> 
  214. <p> <i><b> 
  215. <p></b></i> <b>png_uint_32 png_get_tRNS
  216. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_bytep </b><i>*trans</i><b>, int </b><i>*num_trans</i><b>,
  217. png_color_16p <i>*trans_values</i></b><b>);</b> 
  218. <p> <i><b> 
  219. <p></b></i> <b>png_uint_32 png_get_unknown_chunks (png_structp
  220. </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_unknown_chunkpp <i>unknowns</i></b><b>);</b> 
  221. <p> <i><b> 
  222. <p></b></i> <b>png_voidp
  223. png_get_user_chunk_ptr (png_structp <i>png_ptr</i></b><b>);</b> 
  224. <p> <i><b> 
  225. <p></b></i> <b>png_uint_32 png_get_user_height_max(
  226. png_structp <i>png_ptr</i></b><b>);</b> 
  227. <p> <i><b> 
  228. <p></b></i> <b>png_voidp png_get_user_transform_ptr (png_structp
  229. <i>png_ptr</i></b><b>);</b> 
  230. <p> <i><b> 
  231. <p></b></i> <b>png_uint_32 png_get_user_width_max (png_structp <i>png_ptr</i></b><b>);</b>
  232.  
  233. <p> <i><b> 
  234. <p></b></i> <b>png_uint_32 png_get_valid (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>,
  235. png_uint_32 <i>flag</i></b><b>);</b> 
  236. <p> <i><b> 
  237. <p></b></i> <b>png_int_32 png_get_x_offset_microns (png_structp
  238. </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  239. <p> <i><b> 
  240. <p></b></i> <b>png_int_32 png_get_x_offset_pixels (png_structp
  241. </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  242. <p> <i><b> 
  243. <p></b></i> <b>png_uint_32 png_get_x_pixels_per_meter
  244. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  245. <p> <i><b> 
  246. <p></b></i> <b>png_int_32 png_get_y_offset_microns
  247. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  248. <p> <i><b> 
  249. <p></b></i> <b>png_int_32 png_get_y_offset_pixels
  250. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  251. <p> <i><b> 
  252. <p></b></i> <b>png_uint_32 png_get_y_pixels_per_meter
  253. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  254. <p> <i><b> 
  255. <p></b></i> <b>png_uint_32 png_get_compression_buffer_size
  256. (png_structp <i>png_ptr</i></b><b>);</b> 
  257. <p> <i><b> 
  258. <p></b></i> <b>int png_handle_as_unknown (png_structp </b><i>png_ptr</i><b>,
  259. png_bytep <i>chunk_name</i></b><b>);</b> 
  260. <p> <i><b> 
  261. <p></b></i> <b>void png_init_io (png_structp </b><i>png_ptr</i><b>, FILE <i>*fp</i></b><b>);</b>
  262.  
  263. <p> <i><b> 
  264. <p></b></i> <b>DEPRECATED: void png_info_init (png_infop <i>info_ptr</i></b><b>);</b> 
  265. <p> <i><b> 
  266. <p></b></i> <b>DEPRECATED:
  267. void png_info_init_2 (png_infopp </b><i>ptr_ptr</i><b>, png_size_t <i>png_info_struct_size</i></b><b>);</b>
  268.  
  269. <p> <i><b> 
  270. <p></b></i> <b>png_voidp png_malloc (png_structp </b><i>png_ptr</i><b>, png_uint_32 <i>size</i></b><b>);</b> 
  271. <p> <i><b> 
  272. <p></b></i> <b>png_voidp
  273. png_malloc_default(png_structp </b><i>png_ptr</i><b>, png_uint_32 <i>size</i></b><b>);</b> 
  274. <p> <i><b> 
  275. <p></b></i> <b>voidp png_memcpy
  276. (png_voidp </b><i>s1</i><b>, png_voidp </b><i>s2</i><b>, png_size_t <i>size</i></b><b>);</b> 
  277. <p> <i><b> 
  278. <p></b></i> <b>png_voidp png_memcpy_check
  279. (png_structp </b><i>png_ptr</i><b>, png_voidp </b><i>s1</i><b>, png_voidp </b><i>s2</i><b>, png_uint_32 <i>size</i></b><b>);</b> 
  280. <p> <i><b>
  281.  
  282. <p></b></i> <b>voidp png_memset (png_voidp </b><i>s1</i><b>, int </b><i>value</i><b>, png_size_t <i>size</i></b><b>);</b> 
  283. <p> <i><b> 
  284. <p></b></i> <b>png_voidp
  285. png_memset_check (png_structp </b><i>png_ptr</i><b>, png_voidp </b><i>s1</i><b>, int </b><i>value</i><b>, png_uint_32
  286. <i>size</i></b><b>);</b> 
  287. <p> <i><b> 
  288. <p></b></i> <b>DEPRECATED: void png_permit_empty_plte (png_structp </b><i>png_ptr</i><b>,
  289. int <i>empty_plte_permitted</i></b><b>);</b> 
  290. <p> <i><b> 
  291. <p></b></i> <b>void png_process_data (png_structp </b><i>png_ptr</i><b>,
  292. png_infop </b><i>info_ptr</i><b>, png_bytep </b><i>buffer</i><b>, png_size_t <i>buffer_size</i></b><b>);</b> 
  293. <p> <i><b> 
  294. <p></b></i> <b>void
  295. png_progressive_combine_row (png_structp </b><i>png_ptr</i><b>, png_bytep </b><i>old_row</i><b>, png_bytep
  296. <i>new_row</i></b><b>);</b> 
  297. <p> <i><b> 
  298. <p></b></i> <b>void png_read_destroy (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>,
  299. png_infop <i>end_info_ptr</i></b><b>);</b> 
  300. <p> <i><b> 
  301. <p></b></i> <b>void png_read_end (png_structp </b><i>png_ptr</i><b>, png_infop
  302. <i>info_ptr</i></b><b>);</b> 
  303. <p> <i><b> 
  304. <p></b></i> <b>void png_read_image (png_structp </b><i>png_ptr</i><b>, png_bytepp <i>image</i></b><b>);</b>
  305.  
  306. <p> <i><b> 
  307. <p></b></i> <b>DEPRECATED: void png_read_init (png_structp <i>png_ptr</i></b><b>);</b> 
  308. <p> <i><b> 
  309. <p></b></i> <b>DEPRECATED:
  310. void png_read_init_2 (png_structpp </b><i>ptr_ptr</i><b>, png_const_charp </b><i>user_png_ver</i><b>,
  311. png_size_t </b><i>png_struct_size</i><b>, png_size_t <i>png_info_size</i></b><b>);</b> 
  312. <p> <i><b> 
  313. <p></b></i> <b>void png_read_info
  314. (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  315. <p> <i><b> 
  316. <p></b></i> <b>void png_read_png (png_structp
  317. </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, int </b><i>transforms</i><b>, png_voidp <i>params</i></b><b>);</b> 
  318. <p> <i><b> 
  319. <p></b></i> <b>void
  320. png_read_row (png_structp </b><i>png_ptr</i><b>, png_bytep </b><i>row</i><b>, png_bytep <i>display_row</i></b><b>);</b>
  321.  
  322. <p> <i><b> 
  323. <p></b></i> <b>void png_read_rows (png_structp </b><i>png_ptr</i><b>, png_bytepp </b><i>row</i><b>, png_bytepp
  324. </b><i>display_row</i><b>, png_uint_32 <i>num_rows</i></b><b>);</b> 
  325. <p> <i><b> 
  326. <p></b></i> <b>void png_read_update_info (png_structp
  327. </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  328. <p> <i><b> 
  329. <p></b></i> <b>#if <i>!defined(PNG_1_0_X) 
  330. <p></i></b> <b>void png_set_add_alpha
  331. (png_structp </b><i>png_ptr</i><b>, png_uint_32 </b><i>filler</i><b>, int <i>flags</i></b><b>);</b> 
  332. <p> <i><b>#endif </b></i>
  333. <p> <i><b> 
  334. <p></b></i> <b>void png_set_background
  335. (png_structp </b><i>png_ptr</i><b>, png_color_16p </b><i>background_color</i><b>, int </b><i>background_gamma_code</i><b>,
  336. int </b><i>need_expand</i><b>, double <i>background_gamma</i></b><b>);</b> 
  337. <p> <i><b> 
  338. <p></b></i> <b>void png_set_bgr (png_structp
  339. <i>png_ptr</i></b><b>);</b> 
  340. <p> <i><b> 
  341. <p></b></i> <b>void png_set_bKGD (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>,
  342. png_color_16p <i>background</i></b><b>);</b> 
  343. <p> <i><b> 
  344. <p></b></i> <b>void png_set_cHRM (png_structp </b><i>png_ptr</i><b>, png_infop
  345. </b><i>info_ptr</i><b>, double </b><i>white_x</i><b>, double </b><i>white_y</i><b>, double </b><i>red_x</i><b>, double </b><i>red_y</i><b>, double
  346. </b><i>green_x</i><b>, double </b><i>green_y</i><b>, double </b><i>blue_x</i><b>, double <i>blue_y</i></b><b>);</b> 
  347. <p> <i><b> 
  348. <p></b></i> <b>void png_set_cHRM_fixed
  349. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32 </b><i>white_x</i><b>, png_uint_32
  350. </b><i>white_y</i><b>, png_uint_32 </b><i>red_x</i><b>, png_uint_32 </b><i>red_y</i><b>, png_uint_32 </b><i>green_x</i><b>, png_uint_32
  351. </b><i>green_y</i><b>, png_uint_32 </b><i>blue_x</i><b>, png_uint_32 <i>blue_y</i></b><b>);</b> 
  352. <p> <i><b> 
  353. <p></b></i> <b>void png_set_compression_level
  354. (png_structp </b><i>png_ptr</i><b>, int <i>level</i></b><b>);</b> 
  355. <p> <i><b> 
  356. <p></b></i> <b>void png_set_compression_mem_level
  357. (png_structp </b><i>png_ptr</i><b>, int <i>mem_level</i></b><b>);</b> 
  358. <p> <i><b> 
  359. <p></b></i> <b>void png_set_compression_method
  360. (png_structp </b><i>png_ptr</i><b>, int <i>method</i></b><b>);</b> 
  361. <p> <i><b> 
  362. <p></b></i> <b>void png_set_compression_strategy
  363. (png_structp </b><i>png_ptr</i><b>, int <i>strategy</i></b><b>);</b> 
  364. <p> <i><b> 
  365. <p></b></i> <b>void png_set_compression_window_bits
  366. (png_structp </b><i>png_ptr</i><b>, int <i>window_bits</i></b><b>);</b> 
  367. <p> <i><b> 
  368. <p></b></i> <b>void png_set_crc_action (png_structp
  369. </b><i>png_ptr</i><b>, int </b><i>crit_action</i><b>, int <i>ancil_action</i></b><b>);</b> 
  370. <p> <i><b> 
  371. <p></b></i> <b>void png_set_dither (png_structp
  372. </b><i>png_ptr</i><b>, png_colorp </b><i>palette</i><b>, int </b><i>num_palette</i><b>, int </b><i>maximum_colors</i><b>, png_uint_16p
  373. </b><i>histogram</i><b>, int <i>full_dither</i></b><b>);</b> 
  374. <p> <i><b> 
  375. <p></b></i> <b>void png_set_error_fn (png_structp </b><i>png_ptr</i><b>,
  376. png_voidp </b><i>error_ptr</i><b>, png_error_ptr </b><i>error_fn</i><b>, png_error_ptr <i>warning_fn</i></b><b>);</b>
  377.  
  378. <p> <i><b> 
  379. <p></b></i> <b>void png_set_expand (png_structp <i>png_ptr</i></b><b>);</b> 
  380. <p> <i><b> 
  381. <p></b></i> <b>void png_set_filler (png_structp
  382. </b><i>png_ptr</i><b>, png_uint_32 </b><i>filler</i><b>, int <i>flags</i></b><b>);</b> 
  383. <p> <i><b> 
  384. <p></b></i> <b>void png_set_filter (png_structp
  385. </b><i>png_ptr</i><b>, int </b><i>method</i><b>, int <i>filters</i></b><b>);</b> 
  386. <p> <i><b> 
  387. <p></b></i> <b>void png_set_filter_heuristics (png_structp
  388. </b><i>png_ptr</i><b>, int </b><i>heuristic_method</i><b>, int </b><i>num_weights</i><b>, png_doublep </b><i>filter_weights</i><b>,
  389. png_doublep <i>filter_costs</i></b><b>);</b> 
  390. <p> <i><b> 
  391. <p></b></i> <b>void png_set_flush (png_structp </b><i>png_ptr</i><b>,
  392. int <i>nrows</i></b><b>);</b> 
  393. <p> <i><b> 
  394. <p></b></i> <b>void png_set_gamma (png_structp </b><i>png_ptr</i><b>, double </b><i>screen_gamma</i><b>,
  395. double <i>default_file_gamma</i></b><b>);</b> 
  396. <p> <i><b> 
  397. <p></b></i> <b>void png_set_gAMA (png_structp </b><i>png_ptr</i><b>,
  398. png_infop </b><i>info_ptr</i><b>, double <i>file_gamma</i></b><b>);</b> 
  399. <p> <i><b> 
  400. <p></b></i> <b>void png_set_gAMA_fixed (png_structp
  401. </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32 <i>file_gamma</i></b><b>);</b> 
  402. <p> <i><b> 
  403. <p></b></i> <b>void png_set_gray_1_2_4_to_8(png_structp
  404. <i>png_ptr</i></b><b>);</b> 
  405. <p> <i><b> 
  406. <p></b></i> <b>void png_set_gray_to_rgb (png_structp <i>png_ptr</i></b><b>);</b> 
  407. <p> <i><b> 
  408. <p></b></i> <b>void png_set_hIST
  409. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_16p <i>hist</i></b><b>);</b> 
  410. <p> <i><b> 
  411. <p></b></i> <b>void png_set_iCCP
  412. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_charp </b><i>name</i><b>, int </b><i>compression_type</i><b>,
  413. png_charp </b><i>profile</i><b>, png_uint_32 <i>proflen</i></b><b>);</b> 
  414. <p> <i><b> 
  415. <p></b></i> <b>int png_set_interlace_handling
  416. (png_structp <i>png_ptr</i></b><b>);</b> 
  417. <p> <i><b> 
  418. <p></b></i> <b>void png_set_invalid (png_structp </b><i>png_ptr</i><b>, png_infop
  419. </b><i>info_ptr</i><b>, int <i>mask</i></b><b>);</b> 
  420. <p> <i><b> 
  421. <p></b></i> <b>void png_set_invert_alpha (png_structp <i>png_ptr</i></b><b>);</b>
  422.  
  423. <p> <i><b> 
  424. <p></b></i> <b>void png_set_invert_mono (png_structp <i>png_ptr</i></b><b>);</b> 
  425. <p> <i><b> 
  426. <p></b></i> <b>void png_set_IHDR
  427. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32 </b><i>width</i><b>, png_uint_32
  428. </b><i>height</i><b>, int </b><i>bit_depth</i><b>, int </b><i>color_type</i><b>, int </b><i>interlace_type</i><b>, int </b><i>compression_type</i><b>,
  429. int <i>filter_type</i></b><b>);</b> 
  430. <p> <i><b> 
  431. <p></b></i> <b>void png_set_keep_unknown_chunks (png_structp </b><i>png_ptr</i><b>,
  432. int </b><i>keep</i><b>, png_bytep </b><i>chunk_list</i><b>, int <i>num_chunks</i></b><b>);</b> 
  433. <p> <i><b> 
  434. <p></b></i> <b>void png_set_mem_fn(png_structp
  435. </b><i>png_ptr</i><b>, png_voidp </b><i>mem_ptr</i><b>, png_malloc_ptr </b><i>malloc_fn</i><b>, png_free_ptr <i>free_fn</i></b><b>);</b>
  436.  
  437. <p> <i><b> 
  438. <p></b></i> <b>void png_set_oFFs (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32
  439. </b><i>offset_x</i><b>, png_uint_32 </b><i>offset_y</i><b>, int <i>unit_type</i></b><b>);</b> 
  440. <p> <i><b> 
  441. <p></b></i> <b>void png_set_packing
  442. (png_structp <i>png_ptr</i></b><b>);</b> 
  443. <p> <i><b> 
  444. <p></b></i> <b>void png_set_packswap (png_structp <i>png_ptr</i></b><b>);</b>
  445.  
  446. <p> <i><b> 
  447. <p></b></i> <b>void png_set_palette_to_rgb(png_structp <i>png_ptr</i></b><b>);</b> 
  448. <p> <i><b> 
  449. <p></b></i> <b>void png_set_pCAL
  450. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_charp </b><i>purpose</i><b>, png_int_32
  451. </b><i>X0</i><b>, png_int_32 </b><i>X1</i><b>, int </b><i>type</i><b>, int </b><i>nparams</i><b>, png_charp </b><i>units</i><b>, png_charpp <i>params</i></b><b>);</b>
  452.  
  453. <p> <i><b> 
  454. <p></b></i> <b>void png_set_pHYs (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_uint_32
  455. </b><i>res_x</i><b>, png_uint_32 </b><i>res_y</i><b>, int <i>unit_type</i></b><b>);</b> 
  456. <p> <i><b> 
  457. <p></b></i> <b>void png_set_progressive_read_fn
  458. (png_structp </b><i>png_ptr</i><b>, png_voidp </b><i>progressive_ptr</i><b>, png_progressive_info_ptr
  459. </b><i>info_fn</i><b>, png_progressive_row_ptr </b><i>row_fn</i><b>, png_progressive_end_ptr <i>end_fn</i></b><b>);</b>
  460.  
  461. <p> <i><b> 
  462. <p></b></i> <b>void png_set_PLTE (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_colorp
  463. </b><i>palette</i><b>, int <i>num_palette</i></b><b>);</b> 
  464. <p> <i><b> 
  465. <p></b></i> <b>void png_set_read_fn (png_structp </b><i>png_ptr</i><b>,
  466. png_voidp </b><i>io_ptr</i><b>, png_rw_ptr <i>read_data_fn</i></b><b>);</b> 
  467. <p> <i><b> 
  468. <p></b></i> <b>void png_set_read_status_fn
  469. (png_structp </b><i>png_ptr</i><b>, png_read_status_ptr <i>read_row_fn</i></b><b>);</b> 
  470. <p> <i><b> 
  471. <p></b></i> <b>void png_set_read_user_transform_fn
  472. (png_structp </b><i>png_ptr</i><b>, png_user_transform_ptr <i>read_user_transform_fn</i></b><b>);</b> 
  473. <p>
  474. <i><b> 
  475. <p></b></i> <b>void png_set_rgb_to_gray (png_structp </b><i>png_ptr</i><b>, int </b><i>error_action</i><b>, double
  476. </b><i>red</i><b>, double <i>green</i></b><b>);</b> 
  477. <p> <i><b> 
  478. <p></b></i> <b>void png_set_rgb_to_gray_fixed (png_structp </b><i>png_ptr</i><b>,
  479. int error_action png_fixed_point </b><i>red</i><b>, png_fixed_point <i>green</i></b><b>);</b> 
  480. <p> <i><b> 
  481. <p></b></i> <b>void png_set_rows
  482. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_bytepp <i>row_pointers</i></b><b>);</b> 
  483. <p> <i><b> 
  484. <p></b></i>
  485. <b>void png_set_sBIT (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_color_8p
  486. <i>sig_bit</i></b><b>);</b> 
  487. <p> <i><b> 
  488. <p></b></i> <b>void png_set_sCAL (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>,
  489. png_charp </b><i>unit</i><b>, double </b><i>width</i><b>, double <i>height</i></b><b>);</b> 
  490. <p> <i><b> 
  491. <p></b></i> <b>void png_set_shift (png_structp
  492. </b><i>png_ptr</i><b>, png_color_8p <i>true_bits</i></b><b>);</b> 
  493. <p> <i><b> 
  494. <p></b></i> <b>void png_set_sig_bytes (png_structp
  495. </b><i>png_ptr</i><b>, int <i>num_bytes</i></b><b>);</b> 
  496. <p> <i><b> 
  497. <p></b></i> <b>void png_set_sPLT (png_structp </b><i>png_ptr</i><b>, png_infop
  498. </b><i>info_ptr</i><b>, png_spalette_p </b><i>splt_ptr</i><b>, int <i>num_spalettes</i></b><b>);</b> 
  499. <p> <i><b> 
  500. <p></b></i> <b>void png_set_sRGB
  501. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, int <i>intent</i></b><b>);</b> 
  502. <p> <i><b> 
  503. <p></b></i> <b>void png_set_sRGB_gAMA_and_cHRM
  504. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, int <i>intent</i></b><b>);</b> 
  505. <p> <i><b> 
  506. <p></b></i> <b>void png_set_strip_16
  507. (png_structp <i>png_ptr</i></b><b>);</b> 
  508. <p> <i><b> 
  509. <p></b></i> <b>void png_set_strip_alpha (png_structp <i>png_ptr</i></b><b>);</b>
  510.  
  511. <p> <i><b> 
  512. <p></b></i> <b>void png_set_swap (png_structp <i>png_ptr</i></b><b>);</b> 
  513. <p> <i><b> 
  514. <p></b></i> <b>void png_set_swap_alpha
  515. (png_structp <i>png_ptr</i></b><b>);</b> 
  516. <p> <i><b> 
  517. <p></b></i> <b>void png_set_text (png_structp </b><i>png_ptr</i><b>, png_infop
  518. </b><i>info_ptr</i><b>, png_textp </b><i>text_ptr</i><b>, int <i>num_text</i></b><b>);</b> 
  519. <p> <i><b> 
  520. <p></b></i> <b>void png_set_tIME (png_structp
  521. </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_timep <i>mod_time</i></b><b>);</b> 
  522. <p> <i><b> 
  523. <p></b></i> <b>void png_set_tRNS
  524. (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, png_bytep </b><i>trans</i><b>, int </b><i>num_trans</i><b>,
  525. png_color_16p <i>trans_values</i></b><b>);</b> 
  526. <p> <i><b> 
  527. <p></b></i> <b>void png_set_tRNS_to_alpha(png_structp
  528. <i>png_ptr</i></b><b>);</b> 
  529. <p> <i><b> 
  530. <p></b></i> <b>png_uint_32 png_set_unknown_chunks (png_structp </b><i>png_ptr</i><b>, png_infop
  531. </b><i>info_ptr</i><b>, png_unknown_chunkp </b><i>unknowns</i><b>, int </b><i>num</i><b>, int <i>location</i></b><b>);</b> 
  532. <p> <i><b> 
  533. <p></b></i> <b>void
  534. png_set_unknown_chunk_location(png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>,
  535. int </b><i>chunk</i><b>, int <i>location</i></b><b>);</b> 
  536. <p> <i><b> 
  537. <p></b></i> <b>void png_set_read_user_chunk_fn (png_structp
  538. </b><i>png_ptr</i><b>, png_voidp </b><i>user_chunk_ptr</i><b>, png_user_chunk_ptr <i>read_user_chunk_fn</i></b><b>);</b>
  539.  
  540. <p> <i><b> 
  541. <p></b></i> <b>void png_set_user_limits (png_structp </b><i>png_ptr</i><b>, png_uint_32 </b><i>user_width_max</i><b>,
  542. png_uint_32 <i>user_height_max</i></b><b>);</b> 
  543. <p> <i><b> 
  544. <p></b></i> <b>void png_set_user_transform_info (png_structp
  545. </b><i>png_ptr</i><b>, png_voidp </b><i>user_transform_ptr</i><b>, int </b><i>user_transform_depth</i><b>, int <i>user_transform_channels</i></b><b>);</b>
  546.  
  547. <p> <i><b> 
  548. <p></b></i> <b>void png_set_write_fn (png_structp </b><i>png_ptr</i><b>, png_voidp </b><i>io_ptr</i><b>, png_rw_ptr
  549. </b><i>write_data_fn</i><b>, png_flush_ptr <i>output_flush_fn</i></b><b>);</b> 
  550. <p> <i><b> 
  551. <p></b></i> <b>void png_set_write_status_fn
  552. (png_structp </b><i>png_ptr</i><b>, png_write_status_ptr <i>write_row_fn</i></b><b>);</b> 
  553. <p> <i><b> 
  554. <p></b></i> <b>void png_set_write_user_transform_fn
  555. (png_structp </b><i>png_ptr</i><b>, png_user_transform_ptr <i>write_user_transform_fn</i></b><b>);</b>
  556.  
  557. <p> <i><b> 
  558. <p></b></i> <b>void png_set_compression_buffer_size(png_structp </b><i>png_ptr</i><b>, png_uint_32
  559. <i>size</i></b><b>);</b> 
  560. <p> <i><b> 
  561. <p></b></i> <b>int png_sig_cmp (png_bytep </b><i>sig</i><b>, png_size_t </b><i>start</i><b>, png_size_t
  562. <i>num_to_check</i></b><b>);</b> 
  563. <p> <i><b> 
  564. <p></b></i> <b>void png_start_read_image (png_structp <i>png_ptr</i></b><b>);</b> 
  565. <p> <i><b> 
  566. <p></b></i> <b>void
  567. png_warning (png_structp </b><i>png_ptr</i><b>, png_const_charp <i>message</i></b><b>);</b> 
  568. <p> <i><b> 
  569. <p></b></i> <b>void png_write_chunk
  570. (png_structp </b><i>png_ptr</i><b>, png_bytep </b><i>chunk_name</i><b>, png_bytep </b><i>data</i><b>, png_size_t
  571. <i>length</i></b><b>);</b> 
  572. <p> <i><b> 
  573. <p></b></i> <b>void png_write_chunk_data (png_structp </b><i>png_ptr</i><b>, png_bytep </b><i>data</i><b>,
  574. png_size_t <i>length</i></b><b>);</b> 
  575. <p> <i><b> 
  576. <p></b></i> <b>void png_write_chunk_end (png_structp <i>png_ptr</i></b><b>);</b>
  577.  
  578. <p> <i><b> 
  579. <p></b></i> <b>void png_write_chunk_start (png_structp </b><i>png_ptr</i><b>, png_bytep </b><i>chunk_name</i><b>,
  580. png_uint_32 <i>length</i></b><b>);</b> 
  581. <p> <i><b> 
  582. <p></b></i> <b>void png_write_destroy (png_structp <i>png_ptr</i></b><b>);</b> 
  583. <p>
  584. <i><b> 
  585. <p></b></i> <b>void png_write_end (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  586. <p> <i><b> 
  587. <p></b></i> <b>void
  588. png_write_flush (png_structp <i>png_ptr</i></b><b>);</b> 
  589. <p> <i><b> 
  590. <p></b></i> <b>void png_write_image (png_structp
  591. </b><i>png_ptr</i><b>, png_bytepp <i>image</i></b><b>);</b> 
  592. <p> <i><b> 
  593. <p></b></i> <b>DEPRECATED: void png_write_init (png_structp
  594. <i>png_ptr</i></b><b>);</b> 
  595. <p> <i><b> 
  596. <p></b></i> <b>DEPRECATED: void png_write_init_2 (png_structpp </b><i>ptr_ptr</i><b>, png_const_charp
  597. </b><i>user_png_ver</i><b>, png_size_t </b><i>png_struct_size</i><b>, png_size_t <i>png_info_size</i></b><b>);</b> 
  598. <p> <i><b>
  599.  
  600. <p></b></i> <b>void png_write_info (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  601. <p> <i><b> 
  602. <p></b></i> <b>void
  603. png_write_info_before_PLTE (png_structp </b><i>png_ptr</i><b>, png_infop <i>info_ptr</i></b><b>);</b> 
  604. <p>
  605. <i><b> 
  606. <p></b></i> <b>void png_write_png (png_structp </b><i>png_ptr</i><b>, png_infop </b><i>info_ptr</i><b>, int </b><i>transforms</i><b>,
  607. png_voidp <i>params</i></b><b>);</b> 
  608. <p> <i><b> 
  609. <p></b></i> <b>void png_write_row (png_structp </b><i>png_ptr</i><b>, png_bytep
  610. <i>row</i></b><b>);</b> 
  611. <p> <i><b> 
  612. <p></b></i> <b>void png_write_rows (png_structp </b><i>png_ptr</i><b>, png_bytepp </b><i>row</i><b>, png_uint_32
  613. <i>num_rows</i></b><b>);</b> 
  614. <p> <i><b> 
  615. <p></b></i> <b>voidpf png_zalloc (voidpf </b><i>png_ptr</i><b>, uInt </b><i>items</i><b>, uInt <i>size</i></b><b>);</b>
  616.  
  617. <p> <i><b> 
  618. <p></b></i> <b>void png_zfree (voidpf </b><i>png_ptr</i><b>, voidpf <i>ptr</i></b><b>);</b> 
  619. <p> <i><b> 
  620. <p></b></i> 
  621. <h2><a name='sect2' href='#toc2'>Description</a></h2>
  622. The <i>libpng</i>
  623. library supports encoding, decoding, and various manipulations of the Portable
  624. Network Graphics (PNG) format image files.  It uses the <a href='zlib.3.html'><i>zlib(3)</i></a>
  625.  compression
  626. library. Following is a copy of the libpng.txt file that accompanies libpng.
  627.  
  628. <h2><a name='sect3' href='#toc3'>Libpng.txt</a></h2>
  629. libpng.txt - A description on how to use and modify libpng 
  630. <p>  libpng
  631. version 1.2.8 - December 3, 2004<br>
  632.   Updated and distributed by Glenn Randers-Pehrson<br>
  633.   <glennrp at users.sourceforge.net><br>
  634.   Copyright (c) 1998-2004 Glenn Randers-Pehrson<br>
  635.   For conditions of distribution and use, see copyright<br>
  636.   notice in png.h.<br>
  637.  
  638. <p> 
  639. <p>  based on:<br>
  640.  
  641. <p> 
  642. <p>  libpng 1.0 beta 6  version 0.96 May 28, 1997<br>
  643.   Updated and distributed by Andreas Dilger<br>
  644.   Copyright (c) 1996, 1997 Andreas Dilger<br>
  645.  
  646. <p> 
  647. <p>  libpng 1.0 beta 2 - version 0.88  January 26, 1996<br>
  648.   For conditions of distribution and use, see copyright<br>
  649.   notice in png.h. Copyright (c) 1995, 1996 Guy Eric<br>
  650.   Schalnat, Group 42, Inc.<br>
  651.  
  652. <p> 
  653. <p>  Updated/rewritten per request in the libpng FAQ<br>
  654.   Copyright (c) 1995, 1996 Frank J. T. Wojcik<br>
  655.   December 18, 1995 & January 20, 1996<br>
  656.  
  657. <p> 
  658. <p> 
  659. <h2><a name='sect4' href='#toc4'>I. Introduction</a></h2>
  660.  
  661. <p> This file describes how to use and modify the PNG reference
  662. library (known as libpng) for your own use.  There are five sections to
  663. this file: introduction, structures, reading, writing, and modification
  664. and configuration notes for various special platforms.  In addition to this
  665. file, example.c is a good starting point for using the library, as it is
  666. heavily commented and should include everything most people will need. 
  667. We assume that libpng is already installed; see the INSTALL file for instructions
  668. on how to install libpng. 
  669. <p> Libpng was written as a companion to the PNG
  670. specification, as a way of reducing the amount of time and effort it takes
  671. to support the PNG file format in application programs. 
  672. <p> The PNG specification
  673. (second edition), November 2003, is available as a W3C Recommendation and
  674. as an ISO Standard (ISO/IEC 15948:2003 (E)) at <<a href='http://www.w3.org/TR/2003/REC-PNG-20031110/'>http://www.w3.org/TR/2003/REC-PNG-20031110/</a>
  675.  
  676. The W3C and ISO documents have identical technical content. 
  677. <p> The PNG-1.2 specification
  678. is available at <<a href='http://www.libpng.org/pub/png/documents/'>http://www.libpng.org/pub/png/documents/</a>
  679. <p> The PNG-1.0 specification
  680. is available as RFC 2083 <<a href='http://www.libpng.org/pub/png/documents/'>http://www.libpng.org/pub/png/documents/</a>
  681. > and as
  682. a W3C Recommendation <<a href='http://www.w3.org/TR/REC.png.html'>http://www.w3.org/TR/REC.png.html</a>
  683. >. Some additional chunks
  684. are described in the special-purpose public chunks documents at <<a href='http://www.libpng.org/pub/png/documents/'>http://www.libpng.org/pub/png/documents/</a>
  685. >.
  686.  
  687. <p> Other information about PNG, and the latest version of libpng, can be
  688. found at the PNG home page, <<a href='http://www.libpng.org/pub/png/'>http://www.libpng.org/pub/png/</a>
  689. >. 
  690. <p> Most users will
  691. not have to modify the library significantly; advanced users may want to
  692. modify it more.  All attempts were made to make it as complete as possible,
  693. while keeping the code easy to understand. Currently, this library only
  694. supports C.  Support for other languages is being considered. 
  695. <p> Libpng has
  696. been designed to handle multiple sessions at one time, to be easily modifiable,
  697. to be portable to the vast majority of machines (ANSI, K&R, 16-, 32-, and
  698. 64-bit) available, and to be easy to use.  The ultimate goal of libpng is
  699. to promote the acceptance of the PNG file format in whatever way possible.
  700.  While there is still work to be done (see the TODO file), libpng should
  701. cover the majority of the needs of its users. 
  702. <p> Libpng uses zlib for its
  703. compression and decompression of PNG files. Further information about zlib,
  704. and the latest version of zlib, can be found at the zlib home page, <<a href='http://www.info-zip.org/pub/infozip/zlib/'>http://www.info-zip.org/pub/infozip/zlib/</a>
  705. >.
  706. The zlib compression utility is a general purpose utility that is useful
  707. for more than PNG files, and can be used without libpng. See the documentation
  708. delivered with zlib for more details. You can usually find the source files
  709. for the zlib utility wherever you find the libpng source files. 
  710. <p> Libpng
  711. is thread safe, provided the threads are using different instances of the
  712. structures.  Each thread should have its own png_struct and png_info instances,
  713. and thus its own image. Libpng does not protect itself against two threads
  714. using the same instance of a structure.  Note: thread safety may be defeated
  715. by use of some of the MMX assembler code in pnggccrd.c, which is only compiled
  716. when the user defines PNG_THREAD_UNSAFE_OK. 
  717. <p> 
  718. <h2><a name='sect5' href='#toc5'>II. Structures</a></h2>
  719.  
  720. <p> There are two
  721. main structures that are important to libpng, png_struct and png_info. 
  722. The first, png_struct, is an internal structure that will not, for the
  723. most part, be used by a user except as the first variable passed to every
  724. libpng function call. 
  725. <p> The png_info structure is designed to provide information
  726. about the PNG file.  At one time, the fields of png_info were intended to
  727. be directly accessible to the user.  However, this tended to cause problems
  728. with applications using dynamically loaded libraries, and as a result a
  729. set of interface functions for png_info (the png_get_*() and png_set_*()
  730. functions) was developed.  The fields of png_info are still available for
  731. older applications, but it is suggested that applications use the new interfaces
  732. if at all possible. 
  733. <p> Applications that do make direct access to the members
  734. of png_struct (except for png_ptr->jmpbuf) must be recompiled whenever the
  735. library is updated, and applications that make direct access to the members
  736. of png_info must be recompiled if they were compiled or loaded with libpng
  737. version 1.0.6, in which the members were in a different order.  In version
  738. 1.0.7, the members of the png_info structure reverted to the old order, as
  739. they were in versions 0.97c through 1.0.5.  Starting with version 2.0.0, both
  740. structures are going to be hidden, and the contents of the structures will
  741. only be accessible through the png_get/png_set functions. 
  742. <p> The png.h header
  743. file is an invaluable reference for programming with libpng. And while I'm
  744. on the topic, make sure you include the libpng header file: 
  745. <p> #include <png.h>
  746.  
  747. <p> 
  748. <h2><a name='sect6' href='#toc6'>III. Reading</a></h2>
  749.  
  750. <p> We'll now walk you through the possible functions to call when
  751. reading in a PNG file sequentially, briefly explaining the syntax and purpose
  752. of each one.  See example.c and png.h for more detail.  While progressive reading
  753. is covered in the next section, you will still need some of the functions
  754. discussed in this section to read a PNG file. 
  755. <p> 
  756. <h3><a name='sect7' href='#toc7'>Setup</a></h3>
  757.  
  758. <p> You will want to do
  759. the I/O initialization(*) before you get into libpng, so if it doesn't work,
  760. you don't have much to undo.  Of course, you will also want to insure that
  761. you are, in fact, dealing with a PNG file.  Libpng provides a simple check
  762. to see if a file is a PNG file. To use it, pass in the first 1 to 8 bytes
  763. of the file to the function png_sig_cmp(), and it will return 0 if the
  764. bytes match the corresponding bytes of the PNG signature, or nonzero otherwise.
  765.  Of course, the more bytes you pass in, the greater the accuracy of the
  766. prediction. 
  767. <p> If you are intending to keep the file pointer open for use
  768. in libpng, you must ensure you don't read more than 8 bytes from the beginning
  769. of the file, and you also have to make a call to png_set_sig_bytes_read()
  770. with the number of bytes you read from the beginning.  Libpng will then
  771. only check the bytes (if any) that your program didn't read. 
  772. <p> (*): If you
  773. are not using the standard I/O functions, you will need to replace them
  774. with custom functions.  See the discussion under Customizing libpng. 
  775. <p> 
  776. <p>  
  777.   FILE *fp = fopen(file_name, "rb");<br>
  778.      if (!fp)<br>
  779.      {<br>
  780.          return (ERROR);<br>
  781.      }<br>
  782.      fread(header, 1, number, fp);<br>
  783.      is_png = !png_sig_cmp(header, 0, number);<br>
  784.      if (!is_png)<br>
  785.      {<br>
  786.          return (NOT_PNG);<br>
  787.      }<br>
  788.  
  789. <p> 
  790. <p> 
  791. <p> Next, png_struct and png_info need to be allocated and initialized. 
  792. In order to ensure that the size of these structures is correct even with
  793. a dynamically linked libpng, there are functions to initialize and allocate
  794. the structures.  We also pass the library version, optional pointers to
  795. error handling functions, and a pointer to a data struct for use by the
  796. error functions, if necessary (the pointer and functions can be NULL if
  797. the default error handlers are to be used).  See the section on Changes
  798. to Libpng below regarding the old initialization functions. The structure
  799. allocation functions quietly return NULL if they fail to create the structure,
  800. so your application should check for that. 
  801. <p>     png_structp png_ptr = png_create_read_struct<br>
  802.         (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,<br>
  803.          user_error_fn, user_warning_fn);<br>
  804.      if (!png_ptr)<br>
  805.          return (ERROR);<br>
  806.  
  807. <p> 
  808. <p>     png_infop info_ptr = png_create_info_struct(png_ptr);<br>
  809.      if (!info_ptr)<br>
  810.      {<br>
  811.          png_destroy_read_struct(&png_ptr,<br>
  812.             (png_infopp)NULL, (png_infopp)NULL);<br>
  813.          return (ERROR);<br>
  814.      }<br>
  815.  
  816. <p> 
  817. <p>     png_infop end_info = png_create_info_struct(png_ptr);<br>
  818.      if (!end_info)<br>
  819.      {<br>
  820.          png_destroy_read_struct(&png_ptr, &info_ptr,<br>
  821.            (png_infopp)NULL);<br>
  822.          return (ERROR);<br>
  823.      }<br>
  824.  
  825. <p> 
  826. <p> If you want to use your own memory allocation routines, define PNG_USER_MEM_SUPPORTED
  827. and use png_create_read_struct_2() instead of png_create_read_struct():
  828.  
  829. <p>     png_structp png_ptr = png_create_read_struct_2<br>
  830.         (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,<br>
  831.          user_error_fn, user_warning_fn, (png_voidp)<br>
  832.          user_mem_ptr, user_malloc_fn, user_free_fn);<br>
  833.  
  834. <p> 
  835. <p> The error handling routines passed to png_create_read_struct() and the
  836. memory alloc/free routines passed to png_create_struct_2() are only necessary
  837. if you are not using the libpng supplied error handling and memory alloc/free
  838. functions. 
  839. <p> When libpng encounters an error, it expects to longjmp back
  840. to your routine.  Therefore, you will need to call setjmp and pass your
  841. png_jmpbuf(png_ptr).  If you read the file from different routines, you
  842. will need to update the jmpbuf field every time you enter a new routine
  843. that will call a png_*() function. 
  844. <p> See your documentation of setjmp/longjmp
  845. for your compiler for more information on setjmp/longjmp.  See the discussion
  846. on libpng error handling in the Customizing Libpng section below for more
  847. information on the libpng error handling.  If an error occurs, and libpng
  848. longjmp's back to your setjmp, you will want to call png_destroy_read_struct()
  849. to free any memory. 
  850. <p>     if (setjmp(png_jmpbuf(png_ptr)))<br>
  851.      {<br>
  852.          png_destroy_read_struct(&png_ptr, &info_ptr,<br>
  853.             &end_info);<br>
  854.          fclose(fp);<br>
  855.          return (ERROR);<br>
  856.      }<br>
  857.  
  858. <p> 
  859. <p> If you would rather avoid the complexity of setjmp/longjmp issues, you
  860. can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case errors
  861. will result in a call to PNG_ABORT() which defaults to abort(). 
  862. <p> Now you
  863. need to set up the input code.  The default for libpng is to use the C function
  864. fread().  If you use this, you will need to pass a valid FILE * in the function
  865. png_init_io().  Be sure that the file is opened in binary mode.  If you wish
  866. to handle reading data in another way, you need not call the png_init_io()
  867. function, but you must then implement the libpng I/O methods discussed
  868. in the Customizing Libpng section below. 
  869. <p>     png_init_io(png_ptr, fp);<br>
  870.  
  871. <p> 
  872. <p> If you had previously opened the file and read any of the signature from
  873. the beginning in order to see if this was a PNG file, you need to let libpng
  874. know that there are some bytes missing from the start of the file. 
  875. <p>    
  876. png_set_sig_bytes(png_ptr, number);<br>
  877.  
  878. <p> 
  879. <p> 
  880. <h3><a name='sect8' href='#toc8'>Setting up callback code</a></h3>
  881.  
  882. <p> You can set up a callback function to handle
  883. any unknown chunks in the input stream. You must supply the function 
  884. <p>  
  885.   read_chunk_callback(png_ptr ptr,<br>
  886.           png_unknown_chunkp chunk);<br>
  887.      {<br>
  888.         /* The unknown chunk structure contains your<br>
  889.            chunk data: */<br>
  890.             png_byte name[5];<br>
  891.             png_byte *data;<br>
  892.             png_size_t size;<br>
  893.         /* Note that libpng has already taken care of<br>
  894.            the CRC handling */<br>
  895.  
  896. <p> 
  897. <p>        /* put your code here.  Return one of the<br>
  898.            following: */<br>
  899.  
  900. <p> 
  901. <p>        return (-n); /* chunk had an error */<br>
  902.         return (0); /* did not recognize */<br>
  903.         <a href='return.n.html'>return (n)</a>
  904. ; /* success */<br>
  905.      }<br>
  906.  
  907. <p> 
  908. <p> (You can give your function another name that you like instead of "read_chunk_callback")
  909.  
  910. <p> To inform libpng about your function, use 
  911. <p>     png_set_read_user_chunk_fn(png_ptr,
  912. user_chunk_ptr,<br>
  913.          read_chunk_callback);<br>
  914.  
  915. <p> 
  916. <p> This names not only the callback function, but also a user pointer that
  917.  
  918. <p>you can retrieve with 
  919. <p>     png_get_user_chunk_ptr(png_ptr);<br>
  920.  
  921. <p> 
  922. <p> At this point, you can set up a callback function that will be called
  923. after each row has been read, which you can use to control a progress meter
  924. or the like.  It's demonstrated in pngtest.c. You must supply a function 
  925. <p> 
  926.    void read_row_callback(png_ptr ptr, png_uint_32 row,<br>
  927.         int pass);<br>
  928.      {<br>
  929.        /* put your code here */<br>
  930.      }<br>
  931.  
  932. <p> 
  933. <p> (You can give it another name that you like instead of "read_row_callback")
  934.  
  935. <p> To inform libpng about your function, use 
  936. <p>     png_set_read_status_fn(png_ptr,
  937. read_row_callback);<br>
  938.  
  939. <p> 
  940. <p> 
  941. <h3><a name='sect9' href='#toc9'>Width and height limits</a></h3>
  942.  
  943. <p> The PNG specification allows the width and height
  944. of an image to be as large as 2^31-1 (0x7fffffff), or about 2.147 billion
  945. rows and columns. Since very few applications really need to process such
  946. large images, we have imposed an arbitrary 1-million limit on rows and columns.
  947. Larger images will be rejected immediately with a png_error() call. If you
  948. wish to override this limit, you can use 
  949. <p>    png_set_user_limits(png_ptr,
  950. width_max, height_max);<br>
  951.  
  952. <p> 
  953. <p> to set your own limits, or use width_max = height_max = 0x7fffffffL to
  954. allow all valid dimensions (libpng may reject some very large images anyway
  955. because of potential buffer overflow conditions). 
  956. <p> You should put this statement
  957. after you create the PNG structure and before calling png_read_info(),
  958. png_read_png(), or png_process_data(). If you need to retrieve the limits
  959. that are being applied, use 
  960. <p>    width_max = png_get_user_width_max(png_ptr);<br>
  961.     height_max = png_get_user_height_max(png_ptr);<br>
  962.  
  963. <p> 
  964. <p> 
  965. <h3><a name='sect10' href='#toc10'>Unknown-chunk handling</a></h3>
  966.  
  967. <p> Now you get to set the way the library processes
  968. unknown chunks in the input PNG stream. Both known and unknown chunks will
  969. be read.  Normal behavior is that known chunks will be parsed into information
  970. in various info_ptr members; unknown chunks will be discarded. To change
  971. this, you can call: 
  972. <p>     png_set_keep_unknown_chunks(png_ptr, keep,<br>
  973.          chunk_list, num_chunks);<br>
  974.      keep       - 0: do not handle as unknown<br>
  975.                   1: do not keep<br>
  976.                   2: keep only if safe-to-copy<br>
  977.                   3: keep even if unsafe-to-copy<br>
  978.                 You can use these definitions:<br>
  979.                   PNG_HANDLE_CHUNK_AS_DEFAULT   0<br>
  980.                   PNG_HANDLE_CHUNK_NEVER        1<br>
  981.                   PNG_HANDLE_CHUNK_IF_SAFE      2<br>
  982.                   PNG_HANDLE_CHUNK_ALWAYS       3<br>
  983.      chunk_list - list of chunks affected (a byte string,<br>
  984.                   five bytes per chunk, NULL or ' ' if<br>
  985.                   num_chunks is 0)<br>
  986.      num_chunks - number of chunks affected; if 0, all<br>
  987.                   unknown chunks are affected.  If nonzero,<br>
  988.                   only the chunks in the list are affected<br>
  989.  
  990. <p> 
  991. <p> Unknown chunks declared in this way will be saved as raw data onto a
  992. list of png_unknown_chunk structures.  If a chunk that is normally known
  993. to libpng is named in the list, it will be handled as unknown, according
  994. to the "keep" directive.  If a chunk is named in successive instances of
  995. png_set_keep_unknown_chunks(), the final instance will take precedence.
  996.  The IHDR and IEND chunks should not be named in chunk_list; if they are,
  997. libpng will process them normally anyway. 
  998. <p> 
  999. <h3><a name='sect11' href='#toc11'>The high-level read interface</a></h3>
  1000.  
  1001. <p>
  1002. At this point there are two ways to proceed; through the high-level read
  1003. interface, or through a sequence of low-level read operations. You can use
  1004. the high-level interface if (a) you are willing to read the entire image
  1005. into memory, and (b) the input transformations you want to do are limited
  1006. to the following set: 
  1007. <p>     PNG_TRANSFORM_IDENTITY      No transformation<br>
  1008.      PNG_TRANSFORM_STRIP_16      Strip 16-bit samples to<br>
  1009.                                  8 bits<br>
  1010.      PNG_TRANSFORM_STRIP_ALPHA   Discard the alpha channel<br>
  1011.      PNG_TRANSFORM_PACKING       Expand 1, 2 and 4-bit<br>
  1012.                                  samples to bytes<br>
  1013.      PNG_TRANSFORM_PACKSWAP      Change order of packed<br>
  1014.                                  pixels to LSB first<br>
  1015.      PNG_TRANSFORM_EXPAND        Perform set_expand()<br>
  1016.      PNG_TRANSFORM_INVERT_MONO   Invert monochrome images<br>
  1017.      PNG_TRANSFORM_SHIFT         Normalize pixels to the<br>
  1018.                                  sBIT depth<br>
  1019.      PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA<br>
  1020.                                  to BGRA<br>
  1021.      PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA<br>
  1022.                                  to AG<br>
  1023.      PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity<br>
  1024.                                  to transparency<br>
  1025.      PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples<br>
  1026.  
  1027. <p> 
  1028. <p> (This excludes setting a background color, doing gamma transformation,
  1029. dithering, and setting filler.)  If this is the case, simply do this: 
  1030. <p> 
  1031.    png_read_png(png_ptr, info_ptr, png_transforms, NULL)<br>
  1032.  
  1033. <p> 
  1034. <p> where png_transforms is an integer containing the logical OR of some
  1035. set of transformation flags.  This call is equivalent to png_read_info(),
  1036. followed the set of transformations indicated by the transform mask, then
  1037. png_read_image(), and finally png_read_end(). 
  1038. <p> (The final parameter of this
  1039. call is not yet used.  Someday it might point to transformation parameters
  1040. required by some future input transform.) 
  1041. <p> You must use png_transforms and
  1042. not call any png_set_transform() functions when you use png_read_png().
  1043.  
  1044. <p> After you have called png_read_png(), you can retrieve the image data
  1045.  
  1046. <p>with 
  1047. <p>    row_pointers = png_get_rows(png_ptr, info_ptr);<br>
  1048.  
  1049. <p> 
  1050. <p> where row_pointers is an array of pointers to the pixel data for each
  1051. row: 
  1052. <p>    png_bytep row_pointers[height];<br>
  1053.  
  1054. <p> 
  1055. <p> If you know your image size and pixel size ahead of time, you can allocate
  1056. row_pointers prior to calling png_read_png() with 
  1057. <p>    if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))<br>
  1058.        png_error (png_ptr,<br>
  1059.           "Image is too tall to process in memory");<br>
  1060.     if (width > PNG_UINT_32_MAX/pixel_size)<br>
  1061.        png_error (png_ptr,<br>
  1062.           "Image is too wide to process in memory");<br>
  1063.     row_pointers = png_malloc(png_ptr,<br>
  1064.        height*png_sizeof(png_bytep));<br>
  1065.     for (int i=0; i<height, i++)<br>
  1066.        row_pointers[i]=png_malloc(png_ptr,<br>
  1067.           width*pixel_size);<br>
  1068.     png_set_rows(png_ptr, info_ptr, &row_pointers);<br>
  1069.  
  1070. <p> 
  1071. <p> Alternatively you could allocate your image in one big block and define
  1072. row_pointers[i] to point into the proper places in your block. 
  1073. <p> If you use
  1074. png_set_rows(), the application is responsible for freeing row_pointers
  1075. (and row_pointers[i], if they were separately allocated). 
  1076. <p> If you don't allocate
  1077. row_pointers ahead of time, png_read_png() will do it, and it'll be free'ed
  1078. when you call png_destroy_*(). 
  1079. <p> 
  1080. <h3><a name='sect12' href='#toc12'>The low-level read interface</a></h3>
  1081.  
  1082. <p> If you are going
  1083. the low-level route, you are now ready to read all the file information
  1084. up to the actual image data.  You do this with a call to png_read_info().
  1085.  
  1086. <p>     png_read_info(png_ptr, info_ptr);<br>
  1087.  
  1088. <p> 
  1089. <p> This will process all chunks up to but not including the image data. 
  1090. <p>
  1091.  
  1092. <h3><a name='sect13' href='#toc13'>Querying the info structure</a></h3>
  1093.  
  1094. <p> Functions are used to get the information from
  1095. the info_ptr once it has been read.  Note that these fields may not be completely
  1096. filled in until png_read_end() has read the chunk data following the image.
  1097.  
  1098. <p>     png_get_IHDR(png_ptr, info_ptr, &width, &height,<br>
  1099.         &bit_depth, &color_type, &interlace_type,<br>
  1100.         &compression_type, &filter_method);<br>
  1101.  
  1102. <p> 
  1103. <p>     width          - holds the width of the image<br>
  1104.                       in pixels (up to 2^31).<br>
  1105.      height         - holds the height of the image<br>
  1106.                       in pixels (up to 2^31).<br>
  1107.      bit_depth      - holds the bit depth of one of the<br>
  1108.                       image channels.  (valid values are<br>
  1109.                       1, 2, 4, 8, 16 and depend also on<br>
  1110.                       the color_type.  See also<br>
  1111.                       significant bits (sBIT) below).<br>
  1112.      color_type     - describes which color/alpha channels<br>
  1113.                           are present.<br>
  1114.                       PNG_COLOR_TYPE_GRAY<br>
  1115.                          (bit depths 1, 2, 4, 8, 16)<br>
  1116.                       PNG_COLOR_TYPE_GRAY_ALPHA<br>
  1117.                          (bit depths 8, 16)<br>
  1118.                       PNG_COLOR_TYPE_PALETTE<br>
  1119.                          (bit depths 1, 2, 4, 8)<br>
  1120.                       PNG_COLOR_TYPE_RGB<br>
  1121.                          (bit_depths 8, 16)<br>
  1122.                       PNG_COLOR_TYPE_RGB_ALPHA<br>
  1123.                          (bit_depths 8, 16)<br>
  1124.  
  1125. <p> 
  1126. <p>                      PNG_COLOR_MASK_PALETTE<br>
  1127.                       PNG_COLOR_MASK_COLOR<br>
  1128.                       PNG_COLOR_MASK_ALPHA<br>
  1129.  
  1130. <p> 
  1131. <p>     filter_method  - (must be PNG_FILTER_TYPE_BASE<br>
  1132.                       for PNG 1.0, and can also be<br>
  1133.                       PNG_INTRAPIXEL_DIFFERENCING if<br>
  1134.                       the PNG datastream is embedded in<br>
  1135.                       a MNG-1.0 datastream)<br>
  1136.      compression_type - (must be PNG_COMPRESSION_TYPE_BASE<br>
  1137.                       for PNG 1.0)<br>
  1138.      interlace_type - (PNG_INTERLACE_NONE or<br>
  1139.                       PNG_INTERLACE_ADAM7)<br>
  1140.      Any or all of interlace_type, compression_type, of<br>
  1141.      filter_method can be NULL if you are<br>
  1142.      not interested in their values.<br>
  1143.  
  1144. <p> 
  1145. <p>     channels = png_get_channels(png_ptr, info_ptr);<br>
  1146.      channels       - number of channels of info for the<br>
  1147.                       color type (valid values are 1 (GRAY,<br>
  1148.                       PALETTE), 2 (GRAY_ALPHA), 3 (RGB),<br>
  1149.                       4 (RGB_ALPHA or RGB + filler byte))<br>
  1150.      rowbytes = png_get_rowbytes(png_ptr, info_ptr);<br>
  1151.      rowbytes       - number of bytes needed to hold a row<br>
  1152.  
  1153. <p> 
  1154. <p>     signature = png_get_signature(png_ptr, info_ptr);<br>
  1155.      signature      - holds the signature read from the<br>
  1156.                       file (if any).  The data is kept in<br>
  1157.                       the same offset it would be if the<br>
  1158.                       whole signature were read (i.e. if an<br>
  1159.                       application had already read in 4<br>
  1160.                       bytes of signature before starting<br>
  1161.                       libpng, the remaining 4 bytes would<br>
  1162.                       be in signature[4] through signature[7]<br>
  1163.                       (see png_set_sig_bytes())).<br>
  1164.  
  1165. <p> 
  1166. <p> 
  1167. <p>     width            = png_get_image_width(png_ptr,<br>
  1168.                           info_ptr);<br>
  1169.      height           = png_get_image_height(png_ptr,<br>
  1170.                           info_ptr);<br>
  1171.      bit_depth        = png_get_bit_depth(png_ptr,<br>
  1172.                           info_ptr);<br>
  1173.      color_type       = png_get_color_type(png_ptr,<br>
  1174.                           info_ptr);<br>
  1175.      filter_method    = png_get_filter_type(png_ptr,<br>
  1176.                           info_ptr);<br>
  1177.      compression_type = png_get_compression_type(png_ptr,<br>
  1178.                           info_ptr);<br>
  1179.      interlace_type   = png_get_interlace_type(png_ptr,<br>
  1180.                           info_ptr);<br>
  1181.  
  1182. <p> 
  1183. <p> 
  1184. <p> These are also important, but their validity depends on whether the
  1185. chunk has been read.  The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>)
  1186. and png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
  1187. data has been read, or zero if it is missing.  The parameters to the png_get_<chunk>
  1188. are set directly if they are simple data types, or a pointer into the info_ptr
  1189. is returned for any complex types. 
  1190. <p>     png_get_PLTE(png_ptr, info_ptr,
  1191. &palette,<br>
  1192.                       &num_palette);<br>
  1193.      palette        - the palette for the file<br>
  1194.                       (array of png_color)<br>
  1195.      num_palette    - number of entries in the palette<br>
  1196.  
  1197. <p> 
  1198. <p>     png_get_gAMA(png_ptr, info_ptr, &gamma);<br>
  1199.      gamma          - the gamma the file is written<br>
  1200.                       at (PNG_INFO_gAMA)<br>
  1201.  
  1202. <p> 
  1203. <p>     png_get_sRGB(png_ptr, info_ptr, &srgb_intent);<br>
  1204.      srgb_intent    - the rendering intent (PNG_INFO_sRGB)<br>
  1205.                       The presence of the sRGB chunk<br>
  1206.                       means that the pixel data is in the<br>
  1207.                       sRGB color space.  This chunk also<br>
  1208.                       implies specific values of gAMA and<br>
  1209.                       cHRM.<br>
  1210.  
  1211. <p> 
  1212. <p>     png_get_iCCP(png_ptr, info_ptr, &name,<br>
  1213.         &compression_type, &profile, &proflen);<br>
  1214.      name            - The profile name.<br>
  1215.      compression     - The compression type; always<br>
  1216.                        PNG_COMPRESSION_TYPE_BASE for PNG 1.0.<br>
  1217.                        You may give NULL to this argument to<br>
  1218.                        ignore it.<br>
  1219.      profile         - International Color Consortium color<br>
  1220.                        profile data. May contain NULs.<br>
  1221.      proflen         - length of profile data in bytes.<br>
  1222.  
  1223. <p> 
  1224. <p>     png_get_sBIT(png_ptr, info_ptr, &sig_bit);<br>
  1225.      sig_bit        - the number of significant bits for<br>
  1226.                       (PNG_INFO_sBIT) each of the gray,<br>
  1227.                       red, green, and blue channels,<br>
  1228.                       whichever are appropriate for the<br>
  1229.                       given color type (png_color_16)<br>
  1230.  
  1231. <p> 
  1232. <p>     png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,<br>
  1233.                       &trans_values);<br>
  1234.      trans          - array of transparent entries for<br>
  1235.                       palette (PNG_INFO_tRNS)<br>
  1236.      trans_values   - graylevel or color sample values of<br>
  1237.                       the single transparent color for<br>
  1238.                       non-paletted images (PNG_INFO_tRNS)<br>
  1239.      num_trans      - number of transparent entries<br>
  1240.                       (PNG_INFO_tRNS)<br>
  1241.  
  1242. <p> 
  1243. <p>     png_get_hIST(png_ptr, info_ptr, &hist);<br>
  1244.                       (PNG_INFO_hIST)<br>
  1245.      hist           - histogram of palette (array of<br>
  1246.                       png_uint_16)<br>
  1247.  
  1248. <p> 
  1249. <p>     png_get_tIME(png_ptr, info_ptr, &mod_time);<br>
  1250.      mod_time       - time image was last modified<br>
  1251.                      (PNG_VALID_tIME)<br>
  1252.  
  1253. <p> 
  1254. <p>     png_get_bKGD(png_ptr, info_ptr, &background);<br>
  1255.      background     - background color (PNG_VALID_bKGD)<br>
  1256.                       valid 16-bit red, green and blue<br>
  1257.                       values, regardless of color_type<br>
  1258.  
  1259. <p> 
  1260. <p>     num_comments   = png_get_text(png_ptr, info_ptr,<br>
  1261.                       &text_ptr, &num_text);<br>
  1262.      num_comments   - number of comments<br>
  1263.      text_ptr       - array of png_text holding image<br>
  1264.                       comments<br>
  1265.      text_ptr[i].compression - type of compression used<br>
  1266.                   on "text" PNG_TEXT_COMPRESSION_NONE<br>
  1267.                             PNG_TEXT_COMPRESSION_zTXt<br>
  1268.                             PNG_ITXT_COMPRESSION_NONE<br>
  1269.                             PNG_ITXT_COMPRESSION_zTXt<br>
  1270.      text_ptr[i].key   - keyword for comment.  Must contain<br>
  1271.                           1-79 characters.<br>
  1272.      text_ptr[i].text  - text comments for current<br>
  1273.                           keyword.  Can be empty.<br>
  1274.      text_ptr[i].text_length - length of text string,<br>
  1275.                   after decompression, 0 for iTXt<br>
  1276.      text_ptr[i].itxt_length - length of itxt string,<br>
  1277.                   after decompression, 0 for tEXt/zTXt<br>
  1278.      text_ptr[i].lang  - language of comment (empty<br>
  1279.                           string for unknown).<br>
  1280.      text_ptr[i].lang_key  - keyword in UTF-8<br>
  1281.                           (empty string for unknown).<br>
  1282.      num_text       - number of comments (same as<br>
  1283.                       num_comments; you can put NULL here<br>
  1284.                       to avoid the duplication)<br>
  1285.      Note while png_set_text() will accept text, language,<br>
  1286.      and translated keywords that can be NULL pointers, the<br>
  1287.      structure returned by png_get_text will always contain<br>
  1288.      regular zero-terminated C strings.  They might be<br>
  1289.      empty strings but they will never be NULL pointers.<br>
  1290.  
  1291. <p> 
  1292. <p>     num_spalettes = png_get_sPLT(png_ptr, info_ptr,<br>
  1293.         &palette_ptr);<br>
  1294.      palette_ptr    - array of palette structures holding<br>
  1295.                       contents of one or more sPLT chunks<br>
  1296.                       read.<br>
  1297.      num_spalettes  - number of sPLT chunks read.<br>
  1298.  
  1299. <p> 
  1300. <p>     png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,<br>
  1301.         &unit_type);<br>
  1302.      offset_x       - positive offset from the left edge<br>
  1303.                       of the screen<br>
  1304.      offset_y       - positive offset from the top edge<br>
  1305.                       of the screen<br>
  1306.      unit_type      - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER<br>
  1307.  
  1308. <p> 
  1309. <p>     png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,<br>
  1310.         &unit_type);<br>
  1311.      res_x          - pixels/unit physical resolution in<br>
  1312.                       x direction<br>
  1313.      res_y          - pixels/unit physical resolution in<br>
  1314.                       x direction<br>
  1315.      unit_type      - PNG_RESOLUTION_UNKNOWN,<br>
  1316.                       PNG_RESOLUTION_METER<br>
  1317.  
  1318. <p> 
  1319. <p>     png_get_sCAL(png_ptr, info_ptr, &unit, &width,<br>
  1320.         &height)<br>
  1321.      unit        - physical scale units (an integer)<br>
  1322.      width       - width of a pixel in physical scale units<br>
  1323.      height      - height of a pixel in physical scale units<br>
  1324.                   (width and height are doubles)<br>
  1325.  
  1326. <p> 
  1327. <p>     png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,<br>
  1328.         &height)<br>
  1329.      unit        - physical scale units (an integer)<br>
  1330.      width       - width of a pixel in physical scale units<br>
  1331.      height      - height of a pixel in physical scale units<br>
  1332.                   (width and height are strings like "2.54")<br>
  1333.  
  1334. <p> 
  1335. <p>     num_unknown_chunks = png_get_unknown_chunks(png_ptr,<br>
  1336.         info_ptr, &unknowns)<br>
  1337.      unknowns          - array of png_unknown_chunk<br>
  1338.                          structures holding unknown chunks<br>
  1339.      unknowns[i].name  - name of unknown chunk<br>
  1340.      unknowns[i].data  - data of unknown chunk<br>
  1341.      unknowns[i].size  - size of unknown chunk's data<br>
  1342.      unknowns[i].location - position of chunk in file<br>
  1343.  
  1344. <p> 
  1345. <p>     The value of "i" corresponds to the order in which the<br>
  1346.      chunks were read from the PNG file or inserted with the<br>
  1347.      png_set_unknown_chunks() function.<br>
  1348.  
  1349. <p> 
  1350. <p> The data from the pHYs chunk can be retrieved in several convenient forms:
  1351.  
  1352. <p>     res_x = png_get_x_pixels_per_meter(png_ptr,<br>
  1353.         info_ptr)<br>
  1354.      res_y = png_get_y_pixels_per_meter(png_ptr,<br>
  1355.         info_ptr)<br>
  1356.      res_x_and_y = png_get_pixels_per_meter(png_ptr,<br>
  1357.         info_ptr)<br>
  1358.      res_x = png_get_x_pixels_per_inch(png_ptr,<br>
  1359.         info_ptr)<br>
  1360.      res_y = png_get_y_pixels_per_inch(png_ptr,<br>
  1361.         info_ptr)<br>
  1362.      res_x_and_y = png_get_pixels_per_inch(png_ptr,<br>
  1363.         info_ptr)<br>
  1364.      aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,<br>
  1365.         info_ptr)<br>
  1366.  
  1367. <p> 
  1368. <p>    (Each of these returns 0 [signifying "unknown"] if<br>
  1369.         the data is not present or if res_x is 0;<br>
  1370.         res_x_and_y is 0 if res_x != res_y)<br>
  1371.  
  1372. <p> 
  1373. <p> The data from the oFFs chunk can be retrieved in several convenient forms:
  1374.  
  1375. <p>     x_offset = png_get_x_offset_microns(png_ptr, info_ptr);<br>
  1376.      y_offset = png_get_y_offset_microns(png_ptr, info_ptr);<br>
  1377.      x_offset = png_get_x_offset_inches(png_ptr, info_ptr);<br>
  1378.      y_offset = png_get_y_offset_inches(png_ptr, info_ptr);<br>
  1379.  
  1380. <p> 
  1381. <p>    (Each of these returns 0 [signifying "unknown" if both<br>
  1382.         x and y are 0] if the data is not present or if the<br>
  1383.         chunk is present but the unit is the pixel)<br>
  1384.  
  1385. <p> 
  1386. <p> For more information, see the png_info definition in png.h and the PNG
  1387. specification for chunk contents.  Be careful with trusting rowbytes, as
  1388. some of the transformations could increase the space needed to hold a row
  1389. (expand, filler, gray_to_rgb, etc.). See png_read_update_info(), below. 
  1390. <p> A
  1391. quick word about text_ptr and num_text.  PNG stores comments in keyword/text
  1392. pairs, one pair per chunk, with no limit on the number of text chunks,
  1393. and a 2^31 byte limit on their size.  While there are suggested keywords,
  1394. there is no requirement to restrict the use to these strings.  It is strongly
  1395. suggested that keywords and text be sensible to humans (that's the point),
  1396. so don't use abbreviations.  Non-printing symbols are not allowed.  See the
  1397. PNG specification for more details. There is also no requirement to have
  1398. text after the keyword. 
  1399. <p> Keywords should be limited to 79 Latin-1 characters
  1400. without leading or trailing spaces, but non-consecutive spaces are allowed
  1401. within the keyword.  It is possible to have the same keyword any number
  1402. of times. The text_ptr is an array of png_text structures, each holding
  1403. a pointer to a language string, a pointer to a keyword and a pointer to
  1404. a text string.  The text string, language code, and translated keyword may
  1405. be empty or NULL pointers.  The keyword/text pairs are put into the array
  1406. in the order that they are received. However, some or all of the text chunks
  1407. may be after the image, so, to make sure you have read all the text chunks,
  1408. don't mess with these until after you read the stuff after the image.  This
  1409. will be mentioned again below in the discussion that goes with png_read_end().
  1410.  
  1411. <p> 
  1412. <h3><a name='sect14' href='#toc14'>Input transformations</a></h3>
  1413.  
  1414. <p> After you've read the header information, you can
  1415. set up the library to handle any special transformations of the image data.
  1416.  The various ways to transform the data will be described in the order
  1417. that they should occur.  This is important, as some of these change the
  1418. color type and/or bit depth of the data, and some others only work on certain
  1419. color types and bit depths.  Even though each transformation checks to see
  1420. if it has data that it can do something with, you should make sure to only
  1421. enable a transformation if it will be valid for the data.  For example,
  1422. don't swap red and blue on grayscale data. 
  1423. <p> The colors used for the background
  1424. and transparency values should be supplied in the same format/depth as
  1425. the current image data.  They are stored in the same format/depth as the
  1426. image data in a bKGD or tRNS chunk, so this is what libpng expects for
  1427. this data.  The colors are transformed to keep in sync with the image data
  1428. when an application calls the png_read_update_info() routine (see below).
  1429.  
  1430. <p> Data will be decoded into the supplied row buffers packed into bytes unless
  1431. the library has been told to transform it into another format. For example,
  1432. 4 bit/pixel paletted or grayscale data will be returned 2 pixels/byte with
  1433. the leftmost pixel in the high-order bits of the byte, unless png_set_packing()
  1434. is called.  8-bit RGB data will be stored in RGB RGB RGB format unless png_set_filler()
  1435. or png_set_add_alpha() is called to insert filler bytes, either before
  1436. or after each RGB triplet. 16-bit RGB data will be returned RRGGBB RRGGBB,
  1437. with the most significant byte of the color value first, unless png_set_strip_16()
  1438. is called to transform it to regular RGB RGB triplets, or png_set_filler()
  1439. or png_set_add alpha() is called to insert filler bytes, either before
  1440. or after each RRGGBB triplet.  Similarly, 8-bit or 16-bit grayscale data can
  1441. be modified with png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
  1442.  
  1443. <p> The following code transforms grayscale images of less than 8 to 8 bits,
  1444. changes paletted images to RGB, and adds a full alpha channel if there
  1445. is transparency information in a tRNS chunk.  This is most useful on grayscale
  1446. images with bit depths of 2 or 4 or if there is a multiple-image viewing
  1447. application that wishes to treat all images in the same way. 
  1448. <p>     if (color_type
  1449. == PNG_COLOR_TYPE_PALETTE)<br>
  1450.          png_set_palette_to_rgb(png_ptr);<br>
  1451.  
  1452. <p> 
  1453. <p>     if (color_type == PNG_COLOR_TYPE_GRAY &&<br>
  1454.          bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);<br>
  1455.  
  1456. <p> 
  1457. <p>     if (png_get_valid(png_ptr, info_ptr,<br>
  1458.          PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);<br>
  1459.  
  1460. <p> 
  1461. <p> These three functions are actually aliases for png_set_expand(), added
  1462. in libpng version 1.0.4, with the function names expanded to improve code
  1463. readability.  In some future version they may actually do different things.
  1464.  
  1465. <p> PNG can have files with 16 bits per channel.  If you only can handle 8
  1466. bits per channel, this will strip the pixels down to 8 bit. 
  1467. <p>     if (bit_depth
  1468. == 16)<br>
  1469.          png_set_strip_16(png_ptr);<br>
  1470.  
  1471. <p> 
  1472. <p> If, for some reason, you don't need the alpha channel on an image, and
  1473. you want to remove it rather than combining it with the background (but
  1474. the image author certainly had in mind that you *would* combine it with
  1475. the background, so that's what you should probably do): 
  1476. <p>     if (color_type
  1477. & PNG_COLOR_MASK_ALPHA)<br>
  1478.          png_set_strip_alpha(png_ptr);<br>
  1479.  
  1480. <p> 
  1481. <p> In PNG files, the alpha channel in an image is the level of opacity. 
  1482. If you need the alpha channel in an image to be the level of transparency
  1483. instead of opacity, you can invert the alpha channel (or the tRNS chunk
  1484. data) after it's read, so that 0 is fully opaque and 255 (in 8-bit or paletted
  1485. images) or 65535 (in 16-bit images) is fully transparent, with 
  1486. <p>     png_set_invert_alpha(png_ptr);<br>
  1487.  
  1488. <p> 
  1489. <p> PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
  1490. they can, resulting in, for example, 8 pixels per byte for 1 bit files.
  1491.  This code expands to 1 pixel per byte without changing the values of the
  1492. pixels: 
  1493. <p>     if (bit_depth < 8)<br>
  1494.          png_set_packing(png_ptr);<br>
  1495.  
  1496. <p> 
  1497. <p> PNG files have possible bit depths of 1, 2, 4, 8, and 16.  All pixels
  1498. stored in a PNG image have been "scaled" or "shifted" up to the next higher
  1499. possible bit depth (e.g. from 5 bits/sample in the range [0,31] to 8 bits/sample
  1500. in the range [0, 255]).  However, it is also possible to convert the PNG
  1501. pixel data back to the original bit depth of the image. This call reduces
  1502. the pixels back down to the original bit depth: 
  1503. <p>     png_color_8p sig_bit;<br>
  1504.  
  1505. <p> 
  1506. <p>     if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))<br>
  1507.          png_set_shift(png_ptr, sig_bit);<br>
  1508.  
  1509. <p> 
  1510. <p> PNG files store 3-color pixels in red, green, blue order.  This code changes
  1511. the storage of the pixels to blue, green, red: 
  1512. <p>     if (color_type == PNG_COLOR_TYPE_RGB
  1513. ||<br>
  1514.          color_type == PNG_COLOR_TYPE_RGB_ALPHA)<br>
  1515.          png_set_bgr(png_ptr);<br>
  1516.  
  1517. <p> 
  1518. <p> PNG files store RGB pixels packed into 3 or 6 bytes. This code expands
  1519. them into 4 or 8 bytes for windowing systems that need them in this format:
  1520.  
  1521. <p>     if (color_type == PNG_COLOR_TYPE_RGB)<br>
  1522.          png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);<br>
  1523.  
  1524. <p> 
  1525. <p> where "filler" is the 8 or 16-bit number to fill with, and the location
  1526. is either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
  1527. you want the filler before the RGB or after.  This transformation does not
  1528. affect images that already have full alpha channels.  To add an opaque alpha
  1529. channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which will generate
  1530. RGBA pixels. 
  1531. <p> Note that png_set_filler() does not change the color type.
  1532.  If you want to do that, you can add a true alpha channel with 
  1533. <p>     if
  1534. (color_type == PNG_COLOR_TYPE_RGB ||<br>
  1535.             color_type == PNG_COLOR_TYPE_GRAY)<br>
  1536.      png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);<br>
  1537.  
  1538. <p> 
  1539. <p> where "filler" contains the alpha value to assign to each pixel. This
  1540. function was added in libpng-1.2.7. 
  1541. <p> If you are reading an image with an alpha
  1542. channel, and you need the data as ARGB instead of the normal PNG format
  1543. RGBA: 
  1544. <p>     if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)<br>
  1545.          png_set_swap_alpha(png_ptr);<br>
  1546.  
  1547. <p> 
  1548. <p> For some uses, you may want a grayscale image to be represented as RGB.
  1549.  This code will do that conversion: 
  1550. <p>     if (color_type == PNG_COLOR_TYPE_GRAY
  1551. ||<br>
  1552.          color_type == PNG_COLOR_TYPE_GRAY_ALPHA)<br>
  1553.            png_set_gray_to_rgb(png_ptr);<br>
  1554.  
  1555. <p> 
  1556. <p> Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
  1557. with alpha. 
  1558. <p>     if (color_type == PNG_COLOR_TYPE_RGB ||<br>
  1559.          color_type == PNG_COLOR_TYPE_RGB_ALPHA)<br>
  1560.            png_set_rgb_to_gray_fixed(png_ptr, error_action,<br>
  1561.               int red_weight, int green_weight);<br>
  1562.  
  1563. <p> 
  1564. <p>     error_action = 1: silently do the conversion<br>
  1565.      error_action = 2: issue a warning if the original<br>
  1566.                        image has any pixel where<br>
  1567.                        red != green or red != blue<br>
  1568.      error_action = 3: issue an error and abort the<br>
  1569.                        conversion if the original<br>
  1570.                        image has any pixel where<br>
  1571.                        red != green or red != blue<br>
  1572.  
  1573. <p> 
  1574. <p>     red_weight:       weight of red component times 100000<br>
  1575.      green_weight:     weight of green component times 100000<br>
  1576.                        If either weight is negative, default<br>
  1577.                        weights (21268, 71514) are used.<br>
  1578.  
  1579. <p> 
  1580. <p> If you have set error_action = 1 or 2, you can later check whether the
  1581. image really was gray, after processing the image rows, with the png_get_rgb_to_gray_status(png_ptr)
  1582. function. It will return a png_byte that is zero if the image was gray or
  1583. 1 if there were any non-gray pixels.  bKGD and sBIT data will be silently
  1584. converted to grayscale, using the green channel data, regardless of the
  1585. error_action setting. 
  1586. <p> With red_weight+green_weight<=100000, the normalized
  1587. graylevel is computed: 
  1588. <p>     int rw = red_weight * 65536;<br>
  1589.      int gw = green_weight * 65536;<br>
  1590.      int bw = 65536 - (rw + gw);<br>
  1591.      gray = (rw*red + gw*green + bw*blue)/65536;<br>
  1592.  
  1593. <p> 
  1594. <p> The default values approximate those recommended in the Charles Poynton's
  1595. Color FAQ, <<a href='http://www.inforamp.net/~poynton/'>http://www.inforamp.net/~poynton/</a>
  1596. > Copyright (c) 1998-01-04 Charles
  1597. Poynton <poynton at inforamp.net> 
  1598. <p>     Y = 0.212671 * R + 0.715160 * G + 0.072169
  1599. * B<br>
  1600.  
  1601. <p> 
  1602. <p> Libpng approximates this with 
  1603. <p>     Y = 0.21268 * R    + 0.7151 * G    +
  1604. 0.07217 * B<br>
  1605.  
  1606. <p> 
  1607. <p> which can be expressed with integers as 
  1608. <p>     Y = (6969 * R + 23434 *
  1609. G + 2365 * B)/32768<br>
  1610.  
  1611. <p> 
  1612. <p> The calculation is done in a linear colorspace, if the image gamma is
  1613. known. 
  1614. <p> If you have a grayscale and you are using png_set_expand_depth(),
  1615. png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to a
  1616. higher bit-depth, you must either supply the background color as a gray
  1617. value at the original file bit-depth (need_expand = 1) or else supply the
  1618. background color as an RGB triplet at the final, expanded bit depth (need_expand
  1619. = 0).  Similarly, if you are reading a paletted image, you must either supply
  1620. the background color as a palette index (need_expand = 1) or as an RGB
  1621. triplet that may or may not be in the palette (need_expand = 0). 
  1622. <p>     png_color_16
  1623. my_background;<br>
  1624.      png_color_16p image_background;<br>
  1625.  
  1626. <p> 
  1627. <p>     if (png_get_bKGD(png_ptr, info_ptr, &image_background))<br>
  1628.          png_set_background(png_ptr, image_background,<br>
  1629.            PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);<br>
  1630.      else<br>
  1631.          png_set_background(png_ptr, &my_background,<br>
  1632.            PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);<br>
  1633.  
  1634. <p> 
  1635. <p> The png_set_background() function tells libpng to composite images with
  1636. alpha or simple transparency against the supplied background color.  If
  1637. the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), you may use this
  1638. color, or supply another color more suitable for the current display (e.g.,
  1639. the background color from a web page).  You need to tell libpng whether
  1640. the color is in the gamma space of the display (PNG_BACKGROUND_GAMMA_SCREEN
  1641. for colors you supply), the file (PNG_BACKGROUND_GAMMA_FILE for colors
  1642. from the bKGD chunk), or one that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE
  1643. - I don't know why anyone would use this, but it's here). 
  1644. <p> To properly display
  1645. PNG images on any kind of system, the application needs to know what the
  1646. display gamma is.  Ideally, the user will know this, and the application
  1647. will allow them to set it.  One method of allowing the user to set the display
  1648. gamma separately for each system is to check for a SCREEN_GAMMA or DISPLAY_GAMMA
  1649. environment variable, which will hopefully be correctly set. 
  1650. <p> Note that
  1651. display_gamma is the overall gamma correction required to produce pleasing
  1652. results, which depends on the lighting conditions in the surrounding environment.
  1653.  In a dim or brightly lit room, no compensation other than the physical
  1654. gamma exponent of the monitor is needed, while in a dark room a slightly
  1655. smaller exponent is better. 
  1656. <p>    double gamma, screen_gamma;<br>
  1657.  
  1658. <p> 
  1659. <p>    if (/* We have a user-defined screen<br>
  1660.         gamma value */)<br>
  1661.     {<br>
  1662.        screen_gamma = user_defined_screen_gamma;<br>
  1663.     }<br>
  1664.     /* One way that applications can share the same<br>
  1665.        screen gamma value */<br>
  1666.     else if ((gamma_str = getenv("SCREEN_GAMMA"))<br>
  1667.        != NULL)<br>
  1668.     {<br>
  1669.        screen_gamma = (double)atof(gamma_str);<br>
  1670.     }<br>
  1671.     /* If we don't have another value */<br>
  1672.     else<br>
  1673.     {<br>
  1674.        screen_gamma = 2.2; /* A good guess for a<br>
  1675.             PC monitor in a bright office or a dim room */<br>
  1676.        screen_gamma = 2.0; /* A good guess for a<br>
  1677.             PC monitor in a dark room */<br>
  1678.        screen_gamma = 1.7 or 1.0;  /* A good<br>
  1679.             guess for Mac systems */<br>
  1680.     }<br>
  1681.  
  1682. <p> 
  1683. <p> The png_set_gamma() function handles gamma transformations of the data.
  1684. Pass both the file gamma and the current screen_gamma.  If the file does
  1685. not have a gamma value, you can pass one anyway if you have an idea what
  1686. it is (usually 0.45455 is a good guess for GIF images on PCs).  Note that
  1687. file gammas are inverted from screen gammas.  See the discussions on gamma
  1688. in the PNG specification for an excellent description of what gamma is,
  1689. and why all applications should support it.  It is strongly recommended
  1690. that PNG viewers support gamma correction. 
  1691. <p>    if (png_get_gAMA(png_ptr,
  1692. info_ptr, &gamma))<br>
  1693.        png_set_gamma(png_ptr, screen_gamma, gamma);<br>
  1694.     else<br>
  1695.        png_set_gamma(png_ptr, screen_gamma, 0.45455);<br>
  1696.  
  1697. <p> 
  1698. <p> If you need to reduce an RGB file to a paletted file, or if a paletted
  1699. file has more entries then will fit on your screen, png_set_dither() will
  1700. do that.  Note that this is a simple match dither that merely finds the
  1701. closest color available.  This should work fairly well with optimized palettes,
  1702. and fairly badly with linear color cubes.  If you pass a palette that is
  1703. larger then maximum_colors, the file will reduce the number of colors in
  1704. the palette so it will fit into maximum_colors.  If there is a histogram,
  1705. it will use it to make more intelligent choices when reducing the palette.
  1706.  If there is no histogram, it may not do as good a job. 
  1707. <p>    if (color_type
  1708. & PNG_COLOR_MASK_COLOR)<br>
  1709.     {<br>
  1710.        if (png_get_valid(png_ptr, info_ptr,<br>
  1711.           PNG_INFO_PLTE))<br>
  1712.        {<br>
  1713.           png_uint_16p histogram = NULL;<br>
  1714.  
  1715. <p> 
  1716. <p>          png_get_hIST(png_ptr, info_ptr,<br>
  1717.              &histogram);<br>
  1718.           png_set_dither(png_ptr, palette, num_palette,<br>
  1719.              max_screen_colors, histogram, 1);<br>
  1720.        }<br>
  1721.        else<br>
  1722.        {<br>
  1723.           png_color std_color_cube[MAX_SCREEN_COLORS] =<br>
  1724.              { ... colors ... };<br>
  1725.  
  1726. <p> 
  1727. <p>          png_set_dither(png_ptr, std_color_cube,<br>
  1728.              MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,<br>
  1729.              NULL,0);<br>
  1730.        }<br>
  1731.     }<br>
  1732.  
  1733. <p> 
  1734. <p> PNG files describe monochrome as black being zero and white being one.
  1735. The following code will reverse this (make black be one and white be zero):
  1736.  
  1737. <p>    if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)<br>
  1738.        png_set_invert_mono(png_ptr);<br>
  1739.  
  1740. <p> 
  1741. <p> This function can also be used to invert grayscale and gray-alpha images:
  1742.  
  1743. <p>    if (color_type == PNG_COLOR_TYPE_GRAY ||<br>
  1744.          color_type == PNG_COLOR_TYPE_GRAY_ALPHA)<br>
  1745.        png_set_invert_mono(png_ptr);<br>
  1746.  
  1747. <p> 
  1748. <p> PNG files store 16 bit pixels in network byte order (big-endian, ie. most
  1749. significant bits first).  This code changes the storage to the other way
  1750. (little-endian, i.e. least significant bits first, the way PCs store them):
  1751.  
  1752. <p>     if (bit_depth == 16)<br>
  1753.          png_set_swap(png_ptr);<br>
  1754.  
  1755. <p> 
  1756. <p> If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
  1757. need to change the order the pixels are packed into bytes, you can use:
  1758.  
  1759. <p>     if (bit_depth < 8)<br>
  1760.         png_set_packswap(png_ptr);<br>
  1761.  
  1762. <p> 
  1763. <p> Finally, you can write your own transformation function if none of the
  1764. existing ones meets your needs.  This is done by setting a callback with
  1765.  
  1766. <p>     png_set_read_user_transform_fn(png_ptr,<br>
  1767.         read_transform_fn);<br>
  1768.  
  1769. <p> 
  1770. <p> You must supply the function 
  1771. <p>     void read_transform_fn(png_ptr ptr,
  1772. row_info_ptr<br>
  1773.         row_info, png_bytep data)<br>
  1774.  
  1775. <p> 
  1776. <p> See pngtest.c for a working example.  Your function will be called after
  1777. all of the other transformations have been processed. 
  1778. <p> You can also set
  1779. up a pointer to a user structure for use by your callback function, and
  1780.  
  1781. <p>you can inform libpng that your transform function will change the number
  1782.  
  1783. <p>of channels or bit depth with the function 
  1784. <p>     png_set_user_transform_info(png_ptr,
  1785. user_ptr,<br>
  1786.         user_depth, user_channels);<br>
  1787.  
  1788. <p> 
  1789. <p> The user's application, not libpng, is responsible for allocating and
  1790. freeing any memory required for the user structure. 
  1791. <p> You can retrieve the
  1792. pointer via the function png_get_user_transform_ptr().  For example: 
  1793. <p>  
  1794.   voidp read_user_transform_ptr =<br>
  1795.         png_get_user_transform_ptr(png_ptr);<br>
  1796.  
  1797. <p> 
  1798. <p> The last thing to handle is interlacing; this is covered in detail below,
  1799. but you must call the function here if you want libpng to handle expansion
  1800. of the interlaced image. 
  1801. <p>     number_of_passes = png_set_interlace_handling(png_ptr);<br>
  1802.  
  1803. <p> 
  1804. <p> After setting the transformations, libpng can update your png_info structure
  1805. to reflect any transformations you've requested with this call.  This is
  1806. most useful to update the info structure's rowbytes field so you can use
  1807. it to allocate your image memory.  This function will also update your palette
  1808. with the correct screen_gamma and background if these have been given with
  1809. the calls above. 
  1810. <p>     png_read_update_info(png_ptr, info_ptr);<br>
  1811.  
  1812. <p> 
  1813. <p> After you call png_read_update_info(), you can allocate any memory you
  1814. need to hold the image.  The row data is simply raw byte data for all forms
  1815. of images.  As the actual allocation varies among applications, no example
  1816. will be given.  If you are allocating one large chunk, you will need to
  1817. build an array of pointers to each row, as it will be needed for some of
  1818. the functions below. 
  1819. <p> 
  1820. <h3><a name='sect15' href='#toc15'>Reading image data</a></h3>
  1821.  
  1822. <p> After you've allocated memory, you
  1823. can read the image data. The simplest way to do this is in one function
  1824. call.  If you are allocating enough memory to hold the whole image, you
  1825. can just call png_read_image() and libpng will read in all the image data
  1826. and put it in the memory area supplied.  You will need to pass in an array
  1827. of pointers to each row. 
  1828. <p> This function automatically handles interlacing,
  1829. so you don't need to call png_set_interlace_handling() or call this function
  1830. multiple times, or any of that other stuff necessary with png_read_rows().
  1831.  
  1832. <p>    png_read_image(png_ptr, row_pointers);<br>
  1833.  
  1834. <p> 
  1835. <p> where row_pointers is: 
  1836. <p>    png_bytep row_pointers[height];<br>
  1837.  
  1838. <p> 
  1839. <p> You can point to void or char or whatever you use for pixels. 
  1840. <p> If you
  1841. don't want to read in the whole image at once, you can use png_read_rows()
  1842. instead.  If there is no interlacing (check interlace_type == PNG_INTERLACE_NONE),
  1843. this is simple: 
  1844. <p>     png_read_rows(png_ptr, row_pointers, NULL,<br>
  1845.         number_of_rows);<br>
  1846.  
  1847. <p> 
  1848. <p> where row_pointers is the same as in the png_read_image() call. 
  1849. <p> If you
  1850. are doing this just one row at a time, you can do this with a single row_pointer
  1851. instead of an array of row_pointers: 
  1852. <p>     png_bytep row_pointer = row;<br>
  1853.      png_read_row(png_ptr, row_pointer, NULL);<br>
  1854.  
  1855. <p> 
  1856. <p> If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
  1857. get somewhat harder.  The only current (PNG Specification version 1.2) interlacing
  1858. type for PNG is (interlace_type == PNG_INTERLACE_ADAM7) is a somewhat complicated
  1859. 2D interlace scheme, known as Adam7, that breaks down an image into seven
  1860. smaller images of varying size, based on an 8x8 grid. 
  1861. <p> libpng can fill out
  1862. those images or it can give them to you "as is". If you want them filled
  1863. out, there are two ways to do that.  The one mentioned in the PNG specification
  1864. is to expand each pixel to cover those pixels that have not been read yet
  1865. (the "rectangle" method). This results in a blocky image for the first pass,
  1866. which gradually smooths out as more pixels are read.  The other method is
  1867. the "sparkle" method, where pixels are drawn only in their final locations,
  1868. with the rest of the image remaining whatever colors they were initialized
  1869. to before the start of the read.  The first method usually looks better,
  1870. but tends to be slower, as there are more pixels to put in the rows. 
  1871. <p> If
  1872. you don't want libpng to handle the interlacing details, just call png_read_rows()
  1873. seven times to read in all seven images.  Each of the images is a valid
  1874. image by itself, or they can all be combined on an 8x8 grid to form a single
  1875. image (although if you intend to combine them you would be far better off
  1876. using the libpng interlace handling). 
  1877. <p> The first pass will return an image
  1878. 1/8 as wide as the entire image (every 8th column starting in column 0)
  1879. and 1/8 as high as the original (every 8th row starting in row 0), the
  1880. second will be 1/8 as wide (starting in column 4) and 1/8 as high (also
  1881. starting in row 0).  The third pass will be 1/4 as wide (every 4th pixel
  1882. starting in column 0) and 1/8 as high (every 8th row starting in row 4),
  1883. and the fourth pass will be 1/4 as wide and 1/4 as high (every 4th column
  1884. starting in column 2, and every 4th row starting in row 0).  The fifth pass
  1885. will return an image 1/2 as wide, and 1/4 as high (starting at column 0
  1886. and row 2), while the sixth pass will be 1/2 as wide and 1/2 as high as
  1887. the original (starting in column 1 and row 0).  The seventh and final pass
  1888. will be as wide as the original, and 1/2 as high, containing all of the
  1889. odd numbered scanlines.  Phew! 
  1890. <p> If you want libpng to expand the images,
  1891. call this before calling png_start_read_image() or png_read_update_info():
  1892.  
  1893. <p>     if (interlace_type == PNG_INTERLACE_ADAM7)<br>
  1894.          number_of_passes<br>
  1895.             = png_set_interlace_handling(png_ptr);<br>
  1896.  
  1897. <p> 
  1898. <p> This will return the number of passes needed.  Currently, this is seven,
  1899. but may change if another interlace type is added. This function can be
  1900. called even if the file is not interlaced, where it will return one pass.
  1901.  
  1902. <p> If you are not going to display the image after each pass, but are going
  1903. to wait until the entire image is read in, use the sparkle effect.  This
  1904. effect is faster and the end result of either method is exactly the same.
  1905.  If you are planning on displaying the image after each pass, the "rectangle"
  1906. effect is generally considered the better looking one. 
  1907. <p> If you only want
  1908. the "sparkle" effect, just call png_read_rows() as normal, with the third
  1909. parameter NULL.  Make sure you make pass over the image number_of_passes
  1910. times, and you don't change the data in the rows between calls.  You can
  1911. change the locations of the data, just not the data.  Each pass only writes
  1912. the pixels appropriate for that pass, and assumes the data from previous
  1913. passes is still valid. 
  1914. <p>     png_read_rows(png_ptr, row_pointers, NULL,<br>
  1915.         number_of_rows);<br>
  1916.  
  1917. <p> 
  1918. <p> If you only want the first effect (the rectangles), do the same as before
  1919. except pass the row buffer in the third parameter, and leave the second
  1920. parameter NULL. 
  1921. <p>     png_read_rows(png_ptr, NULL, row_pointers,<br>
  1922.         number_of_rows);<br>
  1923.  
  1924. <p> 
  1925. <p> 
  1926. <h3><a name='sect16' href='#toc16'>Finishing a sequential read</a></h3>
  1927.  
  1928. <p> After you are finished reading the image
  1929. through either the high- or low-level interfaces, you can finish reading
  1930. the file.  If you are interested in comments or time, which may be stored
  1931. either before or after the image data, you should pass the separate png_info
  1932. struct if you want to keep the comments from before and after the image
  1933. separate.  If you are not interested, you can pass NULL. 
  1934. <p>    png_read_end(png_ptr,
  1935. end_info);<br>
  1936.  
  1937. <p> 
  1938. <p> When you are done, you can free all memory allocated by libpng like this:
  1939.  
  1940. <p>    png_destroy_read_struct(&png_ptr, &info_ptr,<br>
  1941.         &end_info);<br>
  1942.  
  1943. <p> 
  1944. <p> It is also possible to individually free the info_ptr members that point
  1945. to libpng-allocated storage with the following function: 
  1946. <p>     png_free_data(png_ptr,
  1947. info_ptr, mask, seq)<br>
  1948.      mask - identifies data to be freed, a mask<br>
  1949.             containing the logical OR of one or<br>
  1950.             more of<br>
  1951.               PNG_FREE_PLTE, PNG_FREE_TRNS,<br>
  1952.               PNG_FREE_HIST, PNG_FREE_ICCP,<br>
  1953.               PNG_FREE_PCAL, PNG_FREE_ROWS,<br>
  1954.               PNG_FREE_SCAL, PNG_FREE_SPLT,<br>
  1955.               PNG_FREE_TEXT, PNG_FREE_UNKN,<br>
  1956.             or simply PNG_FREE_ALL<br>
  1957.      seq  - sequence number of item to be freed<br>
  1958.             (-1 for all items)<br>
  1959.  
  1960. <p> 
  1961. <p> This function may be safely called when the relevant storage has already
  1962. been freed, or has not yet been allocated, or was allocated by the user
  1963. and not by libpng,  and will in those cases do nothing.  The "seq" parameter
  1964. is ignored if only one item of the selected data type, such as PLTE, is
  1965. allowed.  If "seq" is not -1, and multiple items are allowed for the data
  1966. type identified in the mask, such as text or sPLT, only the n'th item in
  1967. the structure is freed, where n is "seq". 
  1968. <p> The default behavior is only
  1969. to free data that was allocated internally by libpng.  This can be changed,
  1970. so that libpng will not free the data, or so that it will free data that
  1971. was allocated by the user with png_malloc() or png_zalloc() and passed
  1972. in via a png_set_*() function, with 
  1973. <p>     png_data_freer(png_ptr, info_ptr,
  1974. freer, mask)<br>
  1975.      mask   - which data elements are affected<br>
  1976.               same choices as in png_free_data()<br>
  1977.      freer  - one of<br>
  1978.                 PNG_DESTROY_WILL_FREE_DATA<br>
  1979.                 PNG_SET_WILL_FREE_DATA<br>
  1980.                 PNG_USER_WILL_FREE_DATA<br>
  1981.  
  1982. <p> 
  1983. <p> This function only affects data that has already been allocated. You can
  1984. call this function after reading the PNG data but before calling any png_set_*()
  1985. functions, to control whether the user or the png_set_*() function is responsible
  1986. for freeing any existing data that might be present, and again after the
  1987. png_set_*() functions to control whether the user or png_destroy_*() is
  1988. supposed to free the data.  When the user assumes responsibility for libpng-allocated
  1989. data, the application must use png_free() to free it, and when the user
  1990. transfers responsibility to libpng for data that the user has allocated,
  1991. the user must have used png_malloc() or png_zalloc() to allocate it. 
  1992. <p> If
  1993. you allocated your row_pointers in a single block, as suggested above in
  1994. the description of the high level read interface, you must not transfer
  1995. responsibility for freeing it to the png_set_rows or png_read_destroy function,
  1996. because they would also try to free the individual row_pointers[i]. 
  1997. <p> If
  1998. you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
  1999. separately, do not transfer responsibility for freeing text_ptr to libpng,
  2000. because when libpng fills a png_text structure it combines these members
  2001. with the key member, and png_free_data() will free only text_ptr.key.  Similarly,
  2002. if you transfer responsibility for free'ing text_ptr from libpng to your
  2003. application, your application must not separately free those members. 
  2004. <p> The
  2005. png_free_data() function will turn off the "valid" flag for anything it
  2006. frees.  If you need to turn the flag off for a chunk that was freed by your
  2007. application instead of by libpng, you can use 
  2008. <p>     png_set_invalid(png_ptr,
  2009. info_ptr, mask);<br>
  2010.      mask - identifies the chunks to be made invalid,<br>
  2011.             containing the logical OR of one or<br>
  2012.             more of<br>
  2013.               PNG_INFO_gAMA, PNG_INFO_sBIT,<br>
  2014.               PNG_INFO_cHRM, PNG_INFO_PLTE,<br>
  2015.               PNG_INFO_tRNS, PNG_INFO_bKGD,<br>
  2016.               PNG_INFO_hIST, PNG_INFO_pHYs,<br>
  2017.               PNG_INFO_oFFs, PNG_INFO_tIME,<br>
  2018.               PNG_INFO_pCAL, PNG_INFO_sRGB,<br>
  2019.               PNG_INFO_iCCP, PNG_INFO_sPLT,<br>
  2020.               PNG_INFO_sCAL, PNG_INFO_IDAT<br>
  2021.  
  2022. <p> 
  2023. <p> For a more compact example of reading a PNG image, see the file example.c.
  2024.  
  2025. <p> 
  2026. <h3><a name='sect17' href='#toc17'>Reading PNG files progressively</a></h3>
  2027.  
  2028. <p> The progressive reader is slightly different
  2029. then the non-progressive reader.  Instead of calling png_read_info(), png_read_rows(),
  2030. and png_read_end(), you make one call to png_process_data(), which calls
  2031. callbacks when it has the info, a row, or the end of the image.  You set
  2032. up these callbacks with png_set_progressive_read_fn().  You don't have to
  2033. worry about the input/output functions of libpng, as you are giving the
  2034. library the data directly in png_process_data().  I will assume that you
  2035. have read the section on reading PNG files above, so I will only highlight
  2036. the differences (although I will show all of the code). 
  2037. <p> png_structp png_ptr;
  2038. png_infop info_ptr; 
  2039. <p>  /*  An example code fragment of how you would<br>
  2040.       initialize the progressive reader in your<br>
  2041.       application. */<br>
  2042.   int<br>
  2043.   initialize_png_reader()<br>
  2044.   {<br>
  2045.      png_ptr = png_create_read_struct<br>
  2046.          (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,<br>
  2047.           user_error_fn, user_warning_fn);<br>
  2048.      if (!png_ptr)<br>
  2049.          return (ERROR);<br>
  2050.      info_ptr = png_create_info_struct(png_ptr);<br>
  2051.      if (!info_ptr)<br>
  2052.      {<br>
  2053.          png_destroy_read_struct(&png_ptr, (png_infopp)NULL,<br>
  2054.             (png_infopp)NULL);<br>
  2055.          return (ERROR);<br>
  2056.      }<br>
  2057.  
  2058. <p> 
  2059. <p>     if (setjmp(png_jmpbuf(png_ptr)))<br>
  2060.      {<br>
  2061.          png_destroy_read_struct(&png_ptr, &info_ptr,<br>
  2062.             (png_infopp)NULL);<br>
  2063.          return (ERROR);<br>
  2064.      }<br>
  2065.  
  2066. <p> 
  2067. <p>     /* This one's new.  You can provide functions<br>
  2068.         to be called when the header info is valid,<br>
  2069.         when each row is completed, and when the image<br>
  2070.         is finished.  If you aren't using all functions,<br>
  2071.         you can specify NULL parameters.  Even when all<br>
  2072.         three functions are NULL, you need to call<br>
  2073.         png_set_progressive_read_fn().  You can use<br>
  2074.         any struct as the user_ptr (cast to a void pointer<br>
  2075.         for the function call), and retrieve the pointer<br>
  2076.         from inside the callbacks using the function<br>
  2077.  
  2078. <p> 
  2079. <p>           png_get_progressive_ptr(png_ptr);<br>
  2080.  
  2081. <p> 
  2082. <p>        which will return a void pointer, which you have<br>
  2083.         to cast appropriately.<br>
  2084.       */<br>
  2085.      png_set_progressive_read_fn(png_ptr, (void *)user_ptr,<br>
  2086.          info_callback, row_callback, end_callback);<br>
  2087.  
  2088. <p> 
  2089. <p>     return 0;<br>
  2090.   }<br>
  2091.  
  2092. <p> 
  2093. <p>  /* A code fragment that you call as you receive blocks<br>
  2094.     of data */<br>
  2095.   int<br>
  2096.   process_data(png_bytep buffer, png_uint_32 length)<br>
  2097.   {<br>
  2098.      if (setjmp(png_jmpbuf(png_ptr)))<br>
  2099.      {<br>
  2100.          png_destroy_read_struct(&png_ptr, &info_ptr,<br>
  2101.             (png_infopp)NULL);<br>
  2102.          return (ERROR);<br>
  2103.      }<br>
  2104.  
  2105. <p> 
  2106. <p>     /* This one's new also.  Simply give it a chunk<br>
  2107.         of data from the file stream (in order, of<br>
  2108.         course).  On machines with segmented memory<br>
  2109.         models machines, don't give it any more than<br>
  2110.         64K.  The library seems to run fine with sizes<br>
  2111.         of 4K. Although you can give it much less if<br>
  2112.         necessary (I assume you can give it chunks of<br>
  2113.         1 byte, I haven't tried less then 256 bytes<br>
  2114.         yet).  When this function returns, you may<br>
  2115.         want to display any rows that were generated<br>
  2116.         in the row callback if you don't already do<br>
  2117.         so there.<br>
  2118.       */<br>
  2119.      png_process_data(png_ptr, info_ptr, buffer, length);<br>
  2120.      return 0;<br>
  2121.   }<br>
  2122.  
  2123. <p> 
  2124. <p>  /* This function is called (as set by<br>
  2125.      png_set_progressive_read_fn() above) when enough data<br>
  2126.      has been supplied so all of the header has been<br>
  2127.      read.<br>
  2128.   */<br>
  2129.   void<br>
  2130.   info_callback(png_structp png_ptr, png_infop info)<br>
  2131.   {<br>
  2132.      /* Do any setup here, including setting any of<br>
  2133.         the transformations mentioned in the Reading<br>
  2134.         PNG files section.  For now, you _must_ call<br>
  2135.         either png_start_read_image() or<br>
  2136.         png_read_update_info() after all the<br>
  2137.         transformations are set (even if you don't set<br>
  2138.         any).  You may start getting rows before<br>
  2139.         png_process_data() returns, so this is your<br>
  2140.         last chance to prepare for that.<br>
  2141.       */<br>
  2142.   }<br>
  2143.  
  2144. <p> 
  2145. <p>  /* This function is called when each row of image<br>
  2146.      data is complete */<br>
  2147.   void<br>
  2148.   row_callback(png_structp png_ptr, png_bytep new_row,<br>
  2149.      png_uint_32 row_num, int pass)<br>
  2150.   {<br>
  2151.      /* If the image is interlaced, and you turned<br>
  2152.         on the interlace handler, this function will<br>
  2153.         be called for every row in every pass.  Some<br>
  2154.         of these rows will not be changed from the<br>
  2155.         previous pass.  When the row is not changed,<br>
  2156.         the new_row variable will be NULL.  The rows<br>
  2157.         and passes are called in order, so you don't<br>
  2158.         really need the row_num and pass, but I'm<br>
  2159.         supplying them because it may make your life<br>
  2160.         easier.<br>
  2161.  
  2162. <p> 
  2163. <p>        For the non-NULL rows of interlaced images,<br>
  2164.         you must call png_progressive_combine_row()<br>
  2165.         passing in the row and the old row.  You can<br>
  2166.         call this function for NULL rows (it will just<br>
  2167.         return) and for non-interlaced images (it just<br>
  2168.         does the memcpy for you) if it will make the<br>
  2169.         code easier.  Thus, you can just do this for<br>
  2170.         all cases:<br>
  2171.       */<br>
  2172.  
  2173. <p> 
  2174. <p>         png_progressive_combine_row(png_ptr, old_row,<br>
  2175.            new_row);<br>
  2176.  
  2177. <p> 
  2178. <p>     /* where old_row is what was displayed for<br>
  2179.         previously for the row.  Note that the first<br>
  2180.         pass (pass == 0, really) will completely cover<br>
  2181.         the old row, so the rows do not have to be<br>
  2182.         initialized.  After the first pass (and only<br>
  2183.         for interlaced images), you will have to pass<br>
  2184.         the current row, and the function will combine<br>
  2185.         the old row and the new row.<br>
  2186.      */<br>
  2187.   }<br>
  2188.  
  2189. <p> 
  2190. <p>  void<br>
  2191.   end_callback(png_structp png_ptr, png_infop info)<br>
  2192.   {<br>
  2193.      /* This function is called after the whole image<br>
  2194.         has been read, including any chunks after the<br>
  2195.         image (up to and including the IEND).  You<br>
  2196.         will usually have the same info chunk as you<br>
  2197.         had in the header, although some data may have<br>
  2198.         been added to the comments and time fields.<br>
  2199.  
  2200. <p> 
  2201. <p>        Most people won't do much here, perhaps setting<br>
  2202.         a flag that marks the image as finished.<br>
  2203.       */<br>
  2204.   }<br>
  2205.  
  2206. <p> 
  2207. <p> 
  2208. <p> 
  2209. <p> 
  2210. <h2><a name='sect18' href='#toc18'>IV. Writing</a></h2>
  2211.  
  2212. <p> Much of this is very similar to reading.  However, everything
  2213. of importance is repeated here, so you won't have to constantly look back
  2214. up in the reading section to understand writing. 
  2215. <p> 
  2216. <h3><a name='sect19' href='#toc19'>Setup</a></h3>
  2217.  
  2218. <p> You will want to
  2219. do the I/O initialization before you get into libpng, so if it doesn't work,
  2220. you don't have anything to undo. If you are not using the standard I/O functions,
  2221. you will need to replace them with custom writing functions.  See the discussion
  2222. under Customizing libpng. 
  2223. <p>     FILE *fp = fopen(file_name, "wb");<br>
  2224.      if (!fp)<br>
  2225.      {<br>
  2226.         return (ERROR);<br>
  2227.      }<br>
  2228.  
  2229. <p> 
  2230. <p> Next, png_struct and png_info need to be allocated and initialized. As
  2231. these can be both relatively large, you may not want to store these on
  2232. the stack, unless you have stack space to spare.  Of course, you will want
  2233. to check if they return NULL.  If you are also reading, you won't want to
  2234. name your read structure and your write structure both "png_ptr"; you can
  2235. call them anything you like, such as "read_ptr" and "write_ptr".  Look at
  2236. pngtest.c, for example. 
  2237. <p>     png_structp png_ptr = png_create_write_struct<br>
  2238.         (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,<br>
  2239.          user_error_fn, user_warning_fn);<br>
  2240.      if (!png_ptr)<br>
  2241.         return (ERROR);<br>
  2242.  
  2243. <p> 
  2244. <p>     png_infop info_ptr = png_create_info_struct(png_ptr);<br>
  2245.      if (!info_ptr)<br>
  2246.      {<br>
  2247.         png_destroy_write_struct(&png_ptr,<br>
  2248.           (png_infopp)NULL);<br>
  2249.         return (ERROR);<br>
  2250.      }<br>
  2251.  
  2252. <p> 
  2253. <p> If you want to use your own memory allocation routines, define PNG_USER_MEM_SUPPORTED
  2254. and use png_create_write_struct_2() instead of png_create_write_struct():
  2255.  
  2256. <p>     png_structp png_ptr = png_create_write_struct_2<br>
  2257.         (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,<br>
  2258.          user_error_fn, user_warning_fn, (png_voidp)<br>
  2259.          user_mem_ptr, user_malloc_fn, user_free_fn);<br>
  2260.  
  2261. <p> 
  2262. <p> After you have these structures, you will need to set up the error handling.
  2263.  When libpng encounters an error, it expects to longjmp() back to your
  2264. routine.  Therefore, you will need to call setjmp() and pass the png_jmpbuf(png_ptr).
  2265.  If you write the file from different routines, you will need to update
  2266. the png_jmpbuf(png_ptr) every time you enter a new routine that will call
  2267. a png_*() function.  See your documentation of setjmp/longjmp for your compiler
  2268. for more information on setjmp/longjmp.  See the discussion on libpng error
  2269. handling in the Customizing Libpng section below for more information on
  2270. the libpng error handling. 
  2271. <p>     if (setjmp(png_jmpbuf(png_ptr)))<br>
  2272.      {<br>
  2273.         png_destroy_write_struct(&png_ptr, &info_ptr);<br>
  2274.         fclose(fp);<br>
  2275.         return (ERROR);<br>
  2276.      }<br>
  2277.      ...<br>
  2278.      return;<br>
  2279.  
  2280. <p> 
  2281. <p> If you would rather avoid the complexity of setjmp/longjmp issues, you
  2282. can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case errors
  2283. will result in a call to PNG_ABORT() which defaults to abort(). 
  2284. <p> Now you
  2285. need to set up the output code.  The default for libpng is to use the C
  2286. function fwrite().  If you use this, you will need to pass a valid FILE
  2287. * in the function png_init_io().  Be sure that the file is opened in binary
  2288. mode.  Again, if you wish to handle writing data in another way, see the
  2289. discussion on libpng I/O handling in the Customizing Libpng section below.
  2290.  
  2291. <p>     png_init_io(png_ptr, fp);<br>
  2292.  
  2293. <p> 
  2294. <p> 
  2295. <h3><a name='sect20' href='#toc20'>Write callbacks</a></h3>
  2296.  
  2297. <p> At this point, you can set up a callback function that
  2298. will be called after each row has been written, which you can use to control
  2299. a progress meter or the like.  It's demonstrated in pngtest.c. You must supply
  2300.  
  2301. <p>a function 
  2302. <p>     void write_row_callback(png_ptr, png_uint_32 row,<br>
  2303.         int pass);<br>
  2304.      {<br>
  2305.        /* put your code here */<br>
  2306.      }<br>
  2307.  
  2308. <p> 
  2309. <p> (You can give it another name that you like instead of "write_row_callback")
  2310.  
  2311. <p> To inform libpng about your function, use 
  2312. <p>     png_set_write_status_fn(png_ptr,
  2313. write_row_callback);<br>
  2314.  
  2315. <p> 
  2316. <p> You now have the option of modifying how the compression library will
  2317. run.  The following functions are mainly for testing, but may be useful
  2318. in some cases, like if you need to write PNG files extremely fast and are
  2319. willing to give up some compression, or if you want to get the maximum
  2320. possible compression at the expense of slower writing.  If you have no special
  2321. needs in this area, let the library do what it wants by not calling this
  2322. function at all, as it has been tuned to deliver a good speed/compression
  2323. ratio. The second parameter to png_set_filter() is the filter method, for
  2324. which the only valid values are 0 (as of the July 1999 PNG specification,
  2325. version 1.2) or 64 (if you are writing a PNG datastream that is to be embedded
  2326. in a MNG datastream).  The third parameter is a flag that indicates which
  2327. filter type(s) are to be tested for each scanline.  See the PNG specification
  2328. for details on the specific filter types. 
  2329. <p> 
  2330. <p>     /* turn on or off filtering,
  2331. and/or choose<br>
  2332.         specific filters.  You can use either a single<br>
  2333.         PNG_FILTER_VALUE_NAME or the logical OR of one<br>
  2334.         or more PNG_FILTER_NAME masks. */<br>
  2335.      png_set_filter(png_ptr, 0,<br>
  2336.         PNG_FILTER_NONE  | PNG_FILTER_VALUE_NONE |<br>
  2337.         PNG_FILTER_SUB   | PNG_FILTER_VALUE_SUB  |<br>
  2338.         PNG_FILTER_UP    | PNG_FILTER_VALUE_UP   |<br>
  2339.         PNG_FILTER_AVE   | PNG_FILTER_VALUE_AVE  |<br>
  2340.         PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|<br>
  2341.         PNG_ALL_FILTERS);<br>
  2342.  
  2343. <p> 
  2344. <p> If an application wants to start and stop using particular filters during
  2345. compression, it should start out with all of the filters (to ensure that
  2346. the previous row of pixels will be stored in case it's needed later), and
  2347. then add and remove them after the start of compression. 
  2348. <p> If you are writing
  2349. a PNG datastream that is to be embedded in a MNG datastream, the second
  2350. parameter can be either 0 or 64. 
  2351. <p> The png_set_compression_*() functions
  2352. interface to the zlib compression library, and should mostly be ignored
  2353. unless you really know what you are doing.  The only generally useful call
  2354. is png_set_compression_level() which changes how much time zlib spends
  2355. on trying to compress the image data.  See the Compression Library (zlib.h
  2356. and algorithm.txt, distributed with zlib) for details on the compression
  2357. levels. 
  2358. <p>     /* set the zlib compression level */<br>
  2359.      png_set_compression_level(png_ptr,<br>
  2360.          Z_BEST_COMPRESSION);<br>
  2361.  
  2362. <p> 
  2363. <p>     /* set other zlib parameters */<br>
  2364.      png_set_compression_mem_level(png_ptr, 8);<br>
  2365.      png_set_compression_strategy(png_ptr,<br>
  2366.          Z_DEFAULT_STRATEGY);<br>
  2367.      png_set_compression_window_bits(png_ptr, 15);<br>
  2368.      png_set_compression_method(png_ptr, 8);<br>
  2369.      png_set_compression_buffer_size(png_ptr, 8192)<br>
  2370.  
  2371. <p> 
  2372. <p> extern PNG_EXPORT(void,png_set_zbuf_size) 
  2373. <p> 
  2374. <h3><a name='sect21' href='#toc21'>Setting the contents of info
  2375. for output</a></h3>
  2376.  
  2377. <p> You now need to fill in the png_info structure with all the
  2378. data you wish to write before the actual image.  Note that the only thing
  2379. you are allowed to write after the image is the text chunks and the time
  2380. chunk (as of PNG Specification 1.2, anyway).  See png_write_end() and the
  2381. latest PNG specification for more information on that.  If you wish to write
  2382. them before the image, fill them in now, and flag that data as being valid.
  2383.  If you want to wait until after the data, don't fill them until png_write_end().
  2384.  For all the fields in png_info and their data types, see png.h.  For explanations
  2385. of what the fields contain, see the PNG specification. 
  2386. <p> Some of the more
  2387. important parts of the png_info are: 
  2388. <p>     png_set_IHDR(png_ptr, info_ptr,
  2389. width, height,<br>
  2390.         bit_depth, color_type, interlace_type,<br>
  2391.         compression_type, filter_method)<br>
  2392.      width          - holds the width of the image<br>
  2393.                       in pixels (up to 2^31).<br>
  2394.      height         - holds the height of the image<br>
  2395.                       in pixels (up to 2^31).<br>
  2396.      bit_depth      - holds the bit depth of one of the<br>
  2397.                       image channels.<br>
  2398.                       (valid values are 1, 2, 4, 8, 16<br>
  2399.                       and depend also on the<br>
  2400.                       color_type.  See also significant<br>
  2401.                       bits (sBIT) below).<br>
  2402.      color_type     - describes which color/alpha<br>
  2403.                       channels are present.<br>
  2404.                       PNG_COLOR_TYPE_GRAY<br>
  2405.                          (bit depths 1, 2, 4, 8, 16)<br>
  2406.                       PNG_COLOR_TYPE_GRAY_ALPHA<br>
  2407.                          (bit depths 8, 16)<br>
  2408.                       PNG_COLOR_TYPE_PALETTE<br>
  2409.                          (bit depths 1, 2, 4, 8)<br>
  2410.                       PNG_COLOR_TYPE_RGB<br>
  2411.                          (bit_depths 8, 16)<br>
  2412.                       PNG_COLOR_TYPE_RGB_ALPHA<br>
  2413.                          (bit_depths 8, 16)<br>
  2414.  
  2415. <p> 
  2416. <p>                      PNG_COLOR_MASK_PALETTE<br>
  2417.                       PNG_COLOR_MASK_COLOR<br>
  2418.                       PNG_COLOR_MASK_ALPHA<br>
  2419.  
  2420. <p> 
  2421. <p>     interlace_type - PNG_INTERLACE_NONE or<br>
  2422.                       PNG_INTERLACE_ADAM7<br>
  2423.      compression_type - (must be<br>
  2424.                       PNG_COMPRESSION_TYPE_DEFAULT)<br>
  2425.      filter_method  - (must be PNG_FILTER_TYPE_DEFAULT<br>
  2426.                       or, if you are writing a PNG to<br>
  2427.                       be embedded in a MNG datastream,<br>
  2428.                       can also be<br>
  2429.                       PNG_INTRAPIXEL_DIFFERENCING)<br>
  2430.  
  2431. <p> 
  2432. <p>     png_set_PLTE(png_ptr, info_ptr, palette,<br>
  2433.         num_palette);<br>
  2434.      palette        - the palette for the file<br>
  2435.                       (array of png_color)<br>
  2436.      num_palette    - number of entries in the palette<br>
  2437.  
  2438. <p> 
  2439. <p>     png_set_gAMA(png_ptr, info_ptr, gamma);<br>
  2440.      gamma          - the gamma the image was created<br>
  2441.                       at (PNG_INFO_gAMA)<br>
  2442.  
  2443. <p> 
  2444. <p>     png_set_sRGB(png_ptr, info_ptr, srgb_intent);<br>
  2445.      srgb_intent    - the rendering intent<br>
  2446.                       (PNG_INFO_sRGB) The presence of<br>
  2447.                       the sRGB chunk means that the pixel<br>
  2448.                       data is in the sRGB color space.<br>
  2449.                       This chunk also implies specific<br>
  2450.                       values of gAMA and cHRM.  Rendering<br>
  2451.                       intent is the CSS-1 property that<br>
  2452.                       has been defined by the International<br>
  2453.                       Color Consortium<br>
  2454.                       (http://www.color.org).<br>
  2455.                       It can be one of<br>
  2456.                       PNG_sRGB_INTENT_SATURATION,<br>
  2457.                       PNG_sRGB_INTENT_PERCEPTUAL,<br>
  2458.                       PNG_sRGB_INTENT_ABSOLUTE, or<br>
  2459.                       PNG_sRGB_INTENT_RELATIVE.<br>
  2460.  
  2461. <p> 
  2462. <p> 
  2463. <p>     png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,<br>
  2464.         srgb_intent);<br>
  2465.      srgb_intent    - the rendering intent<br>
  2466.                       (PNG_INFO_sRGB) The presence of the<br>
  2467.                       sRGB chunk means that the pixel<br>
  2468.                       data is in the sRGB color space.<br>
  2469.                       This function also causes gAMA and<br>
  2470.                       cHRM chunks with the specific values<br>
  2471.                       that are consistent with sRGB to be<br>
  2472.                       written.<br>
  2473.  
  2474. <p> 
  2475. <p>     png_set_iCCP(png_ptr, info_ptr, name, compression_type,<br>
  2476.                        profile, proflen);<br>
  2477.      name            - The profile name.<br>
  2478.      compression     - The compression type; always<br>
  2479.                        PNG_COMPRESSION_TYPE_BASE for PNG 1.0.<br>
  2480.                        You may give NULL to this argument to<br>
  2481.                        ignore it.<br>
  2482.      profile         - International Color Consortium color<br>
  2483.                        profile data. May contain NULs.<br>
  2484.      proflen         - length of profile data in bytes.<br>
  2485.  
  2486. <p> 
  2487. <p>     png_set_sBIT(png_ptr, info_ptr, sig_bit);<br>
  2488.      sig_bit        - the number of significant bits for<br>
  2489.                       (PNG_INFO_sBIT) each of the gray, red,<br>
  2490.                       green, and blue channels, whichever are<br>
  2491.                       appropriate for the given color type<br>
  2492.                       (png_color_16)<br>
  2493.  
  2494. <p> 
  2495. <p>     png_set_tRNS(png_ptr, info_ptr, trans, num_trans,<br>
  2496.         trans_values);<br>
  2497.      trans          - array of transparent entries for<br>
  2498.                       palette (PNG_INFO_tRNS)<br>
  2499.      trans_values   - graylevel or color sample values of<br>
  2500.                       the single transparent color for<br>
  2501.                       non-paletted images (PNG_INFO_tRNS)<br>
  2502.      num_trans      - number of transparent entries<br>
  2503.                       (PNG_INFO_tRNS)<br>
  2504.  
  2505. <p> 
  2506. <p>     png_set_hIST(png_ptr, info_ptr, hist);<br>
  2507.                      (PNG_INFO_hIST)<br>
  2508.      hist           - histogram of palette (array of<br>
  2509.                       png_uint_16)<br>
  2510.  
  2511. <p> 
  2512. <p>     png_set_tIME(png_ptr, info_ptr, mod_time);<br>
  2513.      mod_time       - time image was last modified<br>
  2514.                       (PNG_VALID_tIME)<br>
  2515.  
  2516. <p> 
  2517. <p>     png_set_bKGD(png_ptr, info_ptr, background);<br>
  2518.      background     - background color (PNG_VALID_bKGD)<br>
  2519.  
  2520. <p> 
  2521. <p>     png_set_text(png_ptr, info_ptr, text_ptr, num_text);<br>
  2522.      text_ptr       - array of png_text holding image<br>
  2523.                       comments<br>
  2524.      text_ptr[i].compression - type of compression used<br>
  2525.                   on "text" PNG_TEXT_COMPRESSION_NONE<br>
  2526.                             PNG_TEXT_COMPRESSION_zTXt<br>
  2527.                             PNG_ITXT_COMPRESSION_NONE<br>
  2528.                             PNG_ITXT_COMPRESSION_zTXt<br>
  2529.      text_ptr[i].key   - keyword for comment.  Must contain<br>
  2530.                   1-79 characters.<br>
  2531.      text_ptr[i].text  - text comments for current<br>
  2532.                           keyword.  Can be NULL or empty.<br>
  2533.      text_ptr[i].text_length - length of text string,<br>
  2534.                   after decompression, 0 for iTXt<br>
  2535.      text_ptr[i].itxt_length - length of itxt string,<br>
  2536.                   after decompression, 0 for tEXt/zTXt<br>
  2537.      text_ptr[i].lang  - language of comment (NULL or<br>
  2538.                           empty for unknown).<br>
  2539.      text_ptr[i].translated_keyword  - keyword in UTF-8 (NULL<br>
  2540.                           or empty for unknown).<br>
  2541.      num_text       - number of comments<br>
  2542.  
  2543. <p> 
  2544. <p>     png_set_sPLT(png_ptr, info_ptr, &palette_ptr,<br>
  2545.         num_spalettes);<br>
  2546.      palette_ptr    - array of png_sPLT_struct structures<br>
  2547.                       to be added to the list of palettes<br>
  2548.                       in the info structure.<br>
  2549.      num_spalettes  - number of palette structures to be<br>
  2550.                       added.<br>
  2551.  
  2552. <p> 
  2553. <p>     png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,<br>
  2554.          unit_type);<br>
  2555.      offset_x  - positive offset from the left<br>
  2556.                       edge of the screen<br>
  2557.      offset_y  - positive offset from the top<br>
  2558.                       edge of the screen<br>
  2559.      unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER<br>
  2560.  
  2561. <p> 
  2562. <p>     png_set_pHYs(png_ptr, info_ptr, res_x, res_y,<br>
  2563.          unit_type);<br>
  2564.      res_x       - pixels/unit physical resolution<br>
  2565.                    in x direction<br>
  2566.      res_y       - pixels/unit physical resolution<br>
  2567.                    in y direction<br>
  2568.      unit_type   - PNG_RESOLUTION_UNKNOWN,<br>
  2569.                    PNG_RESOLUTION_METER<br>
  2570.  
  2571. <p> 
  2572. <p>     png_set_sCAL(png_ptr, info_ptr, unit, width, height)<br>
  2573.      unit        - physical scale units (an integer)<br>
  2574.      width       - width of a pixel in physical scale units<br>
  2575.      height      - height of a pixel in physical scale units<br>
  2576.                    (width and height are doubles)<br>
  2577.  
  2578. <p> 
  2579. <p>     png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)<br>
  2580.      unit        - physical scale units (an integer)<br>
  2581.      width       - width of a pixel in physical scale units<br>
  2582.      height      - height of a pixel in physical scale units<br>
  2583.                   (width and height are strings like "2.54")<br>
  2584.  
  2585. <p> 
  2586. <p>     png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,<br>
  2587.         num_unknowns)<br>
  2588.      unknowns          - array of png_unknown_chunk<br>
  2589.                          structures holding unknown chunks<br>
  2590.      unknowns[i].name  - name of unknown chunk<br>
  2591.      unknowns[i].data  - data of unknown chunk<br>
  2592.      unknowns[i].size  - size of unknown chunk's data<br>
  2593.      unknowns[i].location - position to write chunk in file<br>
  2594.                             0: do not write chunk<br>
  2595.                             PNG_HAVE_IHDR: before PLTE<br>
  2596.                             PNG_HAVE_PLTE: before IDAT<br>
  2597.                             PNG_AFTER_IDAT: after IDAT<br>
  2598.  
  2599. <p> 
  2600. <p> The "location" member is set automatically according to what part of
  2601. the output file has already been written. You can change its value after
  2602. calling png_set_unknown_chunks() as demonstrated in pngtest.c.  Within each
  2603. of the "locations", the chunks are sequenced according to their position
  2604. in the structure (that is, the value of "i", which is the order in which
  2605. the chunk was either read from the input file or defined with png_set_unknown_chunks).
  2606.  
  2607. <p> A quick word about text and num_text.  text is an array of png_text structures.
  2608.  num_text is the number of valid structures in the array. Each png_text
  2609. structure holds a language code, a keyword, a text value, and a compression
  2610. type. 
  2611. <p> The compression types have the same valid numbers as the compression
  2612. types of the image data.  Currently, the only valid number is zero. However,
  2613. you can store text either compressed or uncompressed, unlike images, which
  2614. always have to be compressed.  So if you don't want the text compressed,
  2615. set the compression type to PNG_TEXT_COMPRESSION_NONE. Because tEXt and
  2616. zTXt chunks don't have a language field, if you specify PNG_TEXT_COMPRESSION_NONE
  2617. or PNG_TEXT_COMPRESSION_zTXt any language code or translated keyword will
  2618. not be written out. 
  2619. <p> Until text gets around 1000 bytes, it is not worth
  2620. compressing it. After the text has been written out to the file, the compression
  2621. type is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
  2622. so that it isn't written out again at the end (in case you are calling png_write_end()
  2623. with the same struct. 
  2624. <p> The keywords that are given in the PNG Specification
  2625. are: 
  2626. <p>     Title            Short (one line) title or<br>
  2627.                       caption for image<br>
  2628.      Author           Name of image's creator<br>
  2629.      Description      Description of image (possibly long)<br>
  2630.      Copyright        Copyright notice<br>
  2631.      Creation Time    Time of original image creation<br>
  2632.                       (usually RFC 1123 format, see below)<br>
  2633.      Software         Software used to create the image<br>
  2634.      Disclaimer       Legal disclaimer<br>
  2635.      Warning          Warning of nature of content<br>
  2636.      Source           Device used to create the image<br>
  2637.      Comment          Miscellaneous comment; conversion<br>
  2638.                       from other image format<br>
  2639.  
  2640. <p> 
  2641. <p> The keyword-text pairs work like this.  Keywords should be short simple
  2642. descriptions of what the comment is about.  Some typical keywords are found
  2643. in the PNG specification, as is some recommendations on keywords.  You can
  2644. repeat keywords in a file.  You can even write some text before the image
  2645. and some after.  For example, you may want to put a description of the image
  2646. before the image, but leave the disclaimer until after, so viewers working
  2647. over modem connections don't have to wait for the disclaimer to go over
  2648. the modem before they start seeing the image.  Finally, keywords should
  2649. be full words, not abbreviations.  Keywords and text are in the ISO 8859-1
  2650. (Latin-1) character set (a superset of regular ASCII) and can not contain
  2651. NUL characters, and should not contain control or other unprintable characters.
  2652.  To make the comments widely readable, stick with basic ASCII, and avoid
  2653. machine specific character set extensions like the IBM-PC character set.
  2654.  The keyword must be present, but you can leave off the text string on
  2655. non-compressed pairs. Compressed pairs must have a text string, as only the
  2656. text string is compressed anyway, so the compression would be meaningless.
  2657.  
  2658. <p> PNG supports modification time via the png_time structure.  Two conversion
  2659. routines are provided, png_convert_from_time_t() for time_t and png_convert_from_struct_tm()
  2660. for struct tm.  The time_t routine uses gmtime().  You don't have to use either
  2661. of these, but if you wish to fill in the png_time structure directly, you
  2662. should provide the time in universal time (GMT) if possible instead of
  2663. your local time.  Note that the year number is the full year (e.g. 1998, rather
  2664. than 98 - PNG is year 2000 compliant!), and that months start with 1. 
  2665. <p> If
  2666. you want to store the time of the original image creation, you should use
  2667. a plain tEXt chunk with the "Creation Time" keyword.  This is necessary
  2668. because the "creation time" of a PNG image is somewhat vague, depending
  2669. on whether you mean the PNG file, the time the image was created in a non-PNG
  2670. format, a still photo from which the image was scanned, or possibly the
  2671. subject matter itself.  In order to facilitate machine-readable dates, it
  2672. is recommended that the "Creation Time" tEXt chunk use RFC 1123 format
  2673. dates (e.g. "22 May 1997 18:07:10 GMT"), although this isn't a requirement.
  2674.  Unlike the tIME chunk, the "Creation Time" tEXt chunk is not expected
  2675. to be automatically changed by the software.  To facilitate the use of RFC
  2676. 1123 dates, a function png_convert_to_rfc1123(png_timep) is provided to
  2677. convert from PNG time to an RFC 1123 format string. 
  2678. <p> 
  2679. <h3><a name='sect22' href='#toc22'>Writing unknown chunks</a></h3>
  2680.  
  2681. <p>
  2682. You can use the png_set_unknown_chunks function to queue up chunks for
  2683. writing.  You give it a chunk name, raw data, and a size; that's all there
  2684. is to it.  The chunks will be written by the next following png_write_info_before_PLTE,
  2685. png_write_info, or png_write_end function. Any chunks previously read into
  2686. the info structure's unknown-chunk list will also be written out in a sequence
  2687. that satisfies the PNG specification's ordering rules. 
  2688. <p> 
  2689. <h3><a name='sect23' href='#toc23'>The high-level write
  2690. interface</a></h3>
  2691.  
  2692. <p> At this point there are two ways to proceed; through the high-level
  2693. write interface, or through a sequence of low-level write operations. You
  2694. can use the high-level interface if your image data is present in the info
  2695. structure.  All defined output transformations are permitted, enabled by
  2696. the following masks. 
  2697. <p>     PNG_TRANSFORM_IDENTITY      No transformation<br>
  2698.      PNG_TRANSFORM_PACKING       Pack 1, 2 and 4-bit samples<br>
  2699.      PNG_TRANSFORM_PACKSWAP      Change order of packed<br>
  2700.                                  pixels to LSB first<br>
  2701.      PNG_TRANSFORM_INVERT_MONO   Invert monochrome images<br>
  2702.      PNG_TRANSFORM_SHIFT         Normalize pixels to the<br>
  2703.                                  sBIT depth<br>
  2704.      PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA<br>
  2705.                                  to BGRA<br>
  2706.      PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA<br>
  2707.                                  to AG<br>
  2708.      PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity<br>
  2709.                                  to transparency<br>
  2710.      PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples<br>
  2711.      PNG_TRANSFORM_STRIP_FILLER  Strip out filler bytes.<br>
  2712.  
  2713. <p> 
  2714. <p> If you have valid image data in the info structure (you can use png_set_rows()
  2715. to put image data in the info structure), simply do this: 
  2716. <p>     png_write_png(png_ptr,
  2717. info_ptr, png_transforms, NULL)<br>
  2718.  
  2719. <p> 
  2720. <p> where png_transforms is an integer containing the logical OR of some
  2721. set of transformation flags.  This call is equivalent to png_write_info(),
  2722. followed the set of transformations indicated by the transform mask, then
  2723. png_write_image(), and finally png_write_end(). 
  2724. <p> (The final parameter of
  2725. this call is not yet used.  Someday it might point to transformation parameters
  2726. required by some future output transform.) 
  2727. <p> You must use png_transforms
  2728. and not call any png_set_transform() functions when you use png_write_png().
  2729.  
  2730. <p> 
  2731. <h3><a name='sect24' href='#toc24'>The low-level write interface</a></h3>
  2732.  
  2733. <p> If you are going the low-level route instead,
  2734. you are now ready to write all the file information up to the actual image
  2735. data.  You do this with a call to png_write_info(). 
  2736. <p>     png_write_info(png_ptr,
  2737. info_ptr);<br>
  2738.  
  2739. <p> 
  2740. <p> Note that there is one transformation you may need to do before png_write_info().
  2741.  In PNG files, the alpha channel in an image is the level of opacity.  If
  2742. your data is supplied as a level of transparency, you can invert the alpha
  2743. channel before you write it, so that 0 is fully transparent and 255 (in
  2744. 8-bit or paletted images) or 65535 (in 16-bit images) is fully opaque, with
  2745.  
  2746. <p>     png_set_invert_alpha(png_ptr);<br>
  2747.  
  2748. <p> 
  2749. <p> This must appear before png_write_info() instead of later with the other
  2750. transformations because in the case of paletted images the tRNS chunk data
  2751. has to be inverted before the tRNS chunk is written.  If your image is not
  2752. a paletted image, the tRNS data (which in such cases represents a single
  2753. color to be rendered as transparent) won't need to be changed, and you can
  2754. safely do this transformation after your png_write_info() call. 
  2755. <p> If you
  2756. need to write a private chunk that you want to appear before the PLTE chunk
  2757. when PLTE is present, you can write the PNG info in two steps, and insert
  2758. code to write your own chunk between them: 
  2759. <p>     png_write_info_before_PLTE(png_ptr,
  2760. info_ptr);<br>
  2761.      png_set_unknown_chunks(png_ptr, info_ptr, ...);<br>
  2762.      png_write_info(png_ptr, info_ptr);<br>
  2763.  
  2764. <p> 
  2765. <p> After you've written the file information, you can set up the library
  2766. to handle any special transformations of the image data.  The various ways
  2767. to transform the data will be described in the order that they should occur.
  2768.  This is important, as some of these change the color type and/or bit depth
  2769. of the data, and some others only work on certain color types and bit depths.
  2770.  Even though each transformation checks to see if it has data that it can
  2771. do something with, you should make sure to only enable a transformation
  2772. if it will be valid for the data.  For example, don't swap red and blue on
  2773. grayscale data. 
  2774. <p> PNG files store RGB pixels packed into 3 or 6 bytes.  This
  2775. code tells the library to strip input data that has 4 or 8 bytes per pixel
  2776. down to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or
  2777. 2 bytes per pixel). 
  2778. <p>     png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);<br>
  2779.  
  2780. <p> 
  2781. <p> where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
  2782. PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel is
  2783. stored XRGB or RGBX. 
  2784. <p> PNG files pack pixels of bit depths 1, 2, and 4 into
  2785. bytes as small as they can, resulting in, for example, 8 pixels per byte
  2786. for 1 bit files. If the data is supplied at 1 pixel per byte, use this code,
  2787. which will correctly pack the pixels into a single byte: 
  2788. <p>     png_set_packing(png_ptr);<br>
  2789.  
  2790. <p> 
  2791. <p> PNG files reduce possible bit depths to 1, 2, 4, 8, and 16.  If your data
  2792. is of another bit depth, you can write an sBIT chunk into the file so that
  2793. decoders can recover the original data if desired. 
  2794. <p>     /* Set the true
  2795. bit depth of the image data */<br>
  2796.      if (color_type & PNG_COLOR_MASK_COLOR)<br>
  2797.      {<br>
  2798.          sig_bit.red = true_bit_depth;<br>
  2799.          sig_bit.green = true_bit_depth;<br>
  2800.          sig_bit.blue = true_bit_depth;<br>
  2801.      }<br>
  2802.      else<br>
  2803.      {<br>
  2804.          sig_bit.gray = true_bit_depth;<br>
  2805.      }<br>
  2806.      if (color_type & PNG_COLOR_MASK_ALPHA)<br>
  2807.      {<br>
  2808.          sig_bit.alpha = true_bit_depth;<br>
  2809.      }<br>
  2810.  
  2811. <p> 
  2812. <p>     png_set_sBIT(png_ptr, info_ptr, &sig_bit);<br>
  2813.  
  2814. <p> 
  2815. <p> If the data is stored in the row buffer in a bit depth other than one
  2816. supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), this will
  2817. scale the values to appear to be the correct bit depth as is required by
  2818. PNG. 
  2819. <p>     png_set_shift(png_ptr, &sig_bit);<br>
  2820.  
  2821. <p> 
  2822. <p> PNG files store 16 bit pixels in network byte order (big-endian, ie. most
  2823. significant bits first).  This code would be used if they are supplied the
  2824. other way (little-endian, i.e. least significant bits first, the way PCs store
  2825. them): 
  2826. <p>     if (bit_depth > 8)<br>
  2827.         png_set_swap(png_ptr);<br>
  2828.  
  2829. <p> 
  2830. <p> If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
  2831. need to change the order the pixels are packed into bytes, you can use:
  2832.  
  2833. <p>     if (bit_depth < 8)<br>
  2834.         png_set_packswap(png_ptr);<br>
  2835.  
  2836. <p> 
  2837. <p> PNG files store 3 color pixels in red, green, blue order.  This code would
  2838. be used if they are supplied as blue, green, red: 
  2839. <p>     png_set_bgr(png_ptr);<br>
  2840.  
  2841. <p> 
  2842. <p> PNG files describe monochrome as black being zero and white being one.
  2843. This code would be used if the pixels are supplied with this reversed (black
  2844. being one and white being zero): 
  2845. <p>     png_set_invert_mono(png_ptr);<br>
  2846.  
  2847. <p> 
  2848. <p> Finally, you can write your own transformation function if none of the
  2849. existing ones meets your needs.  This is done by setting a callback with
  2850.  
  2851. <p>     png_set_write_user_transform_fn(png_ptr,<br>
  2852.         write_transform_fn);<br>
  2853.  
  2854. <p> 
  2855. <p> You must supply the function 
  2856. <p>     void write_transform_fn(png_ptr ptr,
  2857. row_info_ptr<br>
  2858.         row_info, png_bytep data)<br>
  2859.  
  2860. <p> 
  2861. <p> See pngtest.c for a working example.  Your function will be called before
  2862. any of the other transformations are processed. 
  2863. <p> You can also set up a pointer
  2864. to a user structure for use by your callback function. 
  2865. <p>     png_set_user_transform_info(png_ptr,
  2866. user_ptr, 0, 0);<br>
  2867.  
  2868. <p> 
  2869. <p> The user_channels and user_depth parameters of this function are ignored
  2870. when writing; you can set them to zero as shown. 
  2871. <p> You can retrieve the pointer
  2872. via the function png_get_user_transform_ptr(). For example: 
  2873. <p>     voidp write_user_transform_ptr
  2874. =<br>
  2875.         png_get_user_transform_ptr(png_ptr);<br>
  2876.  
  2877. <p> 
  2878. <p> It is possible to have libpng flush any pending output, either manually,
  2879. or automatically after a certain number of lines have been written.  To
  2880. flush the output stream a single time call: 
  2881. <p>     png_write_flush(png_ptr);<br>
  2882.  
  2883. <p> 
  2884. <p> and to have libpng flush the output stream periodically after a certain
  2885. number of scanlines have been written, call: 
  2886. <p>     png_set_flush(png_ptr,
  2887. nrows);<br>
  2888.  
  2889. <p> 
  2890. <p> Note that the distance between rows is from the last time png_write_flush()
  2891. was called, or the first row of the image if it has never been called. So
  2892. if you write 50 lines, and then png_set_flush 25, it will flush the output
  2893. on the next scanline, and every 25 lines thereafter, unless png_write_flush()
  2894. is called before 25 more lines have been written. If nrows is too small
  2895. (less than about 10 lines for a 640 pixel wide RGB image) the image compression
  2896. may decrease noticeably (although this may be acceptable for real-time applications).
  2897.  Infrequent flushing will only degrade the compression performance by a
  2898. few percent over images that do not use flushing. 
  2899. <p> 
  2900. <h3><a name='sect25' href='#toc25'>Writing the image data</a></h3>
  2901.  
  2902. <p>
  2903. That's it for the transformations.  Now you can write the image data. The
  2904. simplest way to do this is in one function call.  If you have the whole
  2905. image in memory, you can just call png_write_image() and libpng will write
  2906. the image.  You will need to pass in an array of pointers to each row.  This
  2907. function automatically handles interlacing, so you don't need to call png_set_interlace_handling()
  2908. or call this function multiple times, or any of that other stuff necessary
  2909. with png_write_rows(). 
  2910. <p>     png_write_image(png_ptr, row_pointers);<br>
  2911.  
  2912. <p> 
  2913. <p> where row_pointers is: 
  2914. <p>     png_byte *row_pointers[height];<br>
  2915.  
  2916. <p> 
  2917. <p> You can point to void or char or whatever you use for pixels. 
  2918. <p> If you
  2919. don't want to write the whole image at once, you can use png_write_rows()
  2920. instead.  If the file is not interlaced, this is simple: 
  2921. <p>     png_write_rows(png_ptr,
  2922. row_pointers,<br>
  2923.         number_of_rows);<br>
  2924.  
  2925. <p> 
  2926. <p> row_pointers is the same as in the png_write_image() call. 
  2927. <p> If you are
  2928. just writing one row at a time, you can do this with a single row_pointer
  2929. instead of an array of row_pointers: 
  2930. <p>     png_bytep row_pointer = row;<br>
  2931.  
  2932. <p> 
  2933. <p>     png_write_row(png_ptr, row_pointer);<br>
  2934.  
  2935. <p> 
  2936. <p> When the file is interlaced, things can get a good deal more complicated.
  2937.  The only currently (as of the PNG Specification version 1.2, dated July
  2938. 1999) defined interlacing scheme for PNG files is the "Adam7" interlace
  2939. scheme, that breaks down an image into seven smaller images of varying
  2940. size.  libpng will build these images for you, or you can do them yourself.
  2941.  If you want to build them yourself, see the PNG specification for details
  2942. of which pixels to write when. 
  2943. <p> If you don't want libpng to handle the interlacing
  2944. details, just use png_set_interlace_handling() and call png_write_rows()
  2945. the correct number of times to write all seven sub-images. 
  2946. <p> If you want libpng
  2947. to build the sub-images, call this before you start writing any rows: 
  2948. <p> 
  2949.    number_of_passes =<br>
  2950.         png_set_interlace_handling(png_ptr);<br>
  2951.  
  2952. <p> 
  2953. <p> This will return the number of passes needed.  Currently, this is seven,
  2954. but may change if another interlace type is added. 
  2955. <p> Then write the complete
  2956. image number_of_passes times. 
  2957. <p>     png_write_rows(png_ptr, row_pointers,<br>
  2958.         number_of_rows);<br>
  2959.  
  2960. <p> 
  2961. <p> As some of these rows are not used, and thus return immediately, you
  2962. may want to read about interlacing in the PNG specification, and only update
  2963. the rows that are actually used. 
  2964. <p> 
  2965. <h3><a name='sect26' href='#toc26'>Finishing a sequential write</a></h3>
  2966.  
  2967. <p> After you
  2968. are finished writing the image, you should finish writing the file.  If
  2969. you are interested in writing comments or time, you should pass an appropriately
  2970. filled png_info pointer.  If you are not interested, you can pass NULL. 
  2971. <p>
  2972.     png_write_end(png_ptr, info_ptr);<br>
  2973.  
  2974. <p> 
  2975. <p> When you are done, you can free all memory used by libpng like this:
  2976.  
  2977. <p>     png_destroy_write_struct(&png_ptr, &info_ptr);<br>
  2978.  
  2979. <p> 
  2980. <p> It is also possible to individually free the info_ptr members that point
  2981. to libpng-allocated storage with the following function: 
  2982. <p>     png_free_data(png_ptr,
  2983. info_ptr, mask, seq)<br>
  2984.      mask  - identifies data to be freed, a mask<br>
  2985.              containing the logical OR of one or<br>
  2986.              more of<br>
  2987.                PNG_FREE_PLTE, PNG_FREE_TRNS,<br>
  2988.                PNG_FREE_HIST, PNG_FREE_ICCP,<br>
  2989.                PNG_FREE_PCAL, PNG_FREE_ROWS,<br>
  2990.                PNG_FREE_SCAL, PNG_FREE_SPLT,<br>
  2991.                PNG_FREE_TEXT, PNG_FREE_UNKN,<br>
  2992.              or simply PNG_FREE_ALL<br>
  2993.      seq   - sequence number of item to be freed<br>
  2994.              (-1 for all items)<br>
  2995.  
  2996. <p> 
  2997. <p> This function may be safely called when the relevant storage has already
  2998. been freed, or has not yet been allocated, or was allocated by the user
  2999.  and not by libpng,  and will in those cases do nothing.  The "seq" parameter
  3000. is ignored if only one item of the selected data type, such as PLTE, is
  3001. allowed.  If "seq" is not -1, and multiple items are allowed for the data
  3002. type identified in the mask, such as text or sPLT, only the n'th item in
  3003. the structure is freed, where n is "seq". 
  3004. <p> If you allocated data such as
  3005. a palette that you passed in to libpng with png_set_*, you must not free
  3006. it until just before the call to png_destroy_write_struct(). 
  3007. <p> The default
  3008. behavior is only to free data that was allocated internally by libpng. 
  3009. This can be changed, so that libpng will not free the data, or so that
  3010. it will free data that was allocated by the user with png_malloc() or png_zalloc()
  3011. and passed in via a png_set_*() function, with 
  3012. <p>     png_data_freer(png_ptr,
  3013. info_ptr, freer, mask)<br>
  3014.      mask   - which data elements are affected<br>
  3015.               same choices as in png_free_data()<br>
  3016.      freer  - one of<br>
  3017.                 PNG_DESTROY_WILL_FREE_DATA<br>
  3018.                 PNG_SET_WILL_FREE_DATA<br>
  3019.                 PNG_USER_WILL_FREE_DATA<br>
  3020.  
  3021. <p> 
  3022. <p> For example, to transfer responsibility for some data from a read structure
  3023. to a write structure, you could use 
  3024. <p>     png_data_freer(read_ptr, read_info_ptr,<br>
  3025.         PNG_USER_WILL_FREE_DATA,<br>
  3026.         PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)<br>
  3027.      png_data_freer(write_ptr, write_info_ptr,<br>
  3028.         PNG_DESTROY_WILL_FREE_DATA,<br>
  3029.         PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)<br>
  3030.  
  3031. <p> 
  3032. <p> thereby briefly reassigning responsibility for freeing to the user but
  3033. immediately afterwards reassigning it once more to the write_destroy function.
  3034.  Having done this, it would then be safe to destroy the read structure
  3035. and continue to use the PLTE, tRNS, and hIST data in the write structure.
  3036.  
  3037. <p> This function only affects data that has already been allocated. You can
  3038. call this function before calling after the png_set_*() functions to control
  3039. whether the user or png_destroy_*() is supposed to free the data. When the
  3040. user assumes responsibility for libpng-allocated data, the application must
  3041. use png_free() to free it, and when the user transfers responsibility to
  3042. libpng for data that the user has allocated, the user must have used png_malloc()
  3043. or png_zalloc() to allocate it. 
  3044. <p> If you allocated text_ptr.text, text_ptr.lang,
  3045. and text_ptr.translated_keyword separately, do not transfer responsibility
  3046. for freeing text_ptr to libpng, because when libpng fills a png_text structure
  3047. it combines these members with the key member, and png_free_data() will
  3048. free only text_ptr.key.  Similarly, if you transfer responsibility for free'ing
  3049. text_ptr from libpng to your application, your application must not separately
  3050. free those members. For a more compact example of writing a PNG image, see
  3051. the file example.c. 
  3052. <p> 
  3053. <h2><a name='sect27' href='#toc27'>V. Modifying/Customizing libpng:</a></h2>
  3054.  
  3055. <p> There are three issues
  3056. here.  The first is changing how libpng does standard things like memory
  3057. allocation, input/output, and error handling. The second deals with more
  3058. complicated things like adding new chunks, adding new transformations,
  3059. and generally changing how libpng works. Both of those are compile-time issues;
  3060. that is, they are generally determined at the time the code is written,
  3061. and there is rarely a need to provide the user with a means of changing
  3062. them.  The third is a run-time issue:  choosing between and/or tuning one
  3063. or more alternate versions of computationally intensive routines; specifically,
  3064. optimized assembly-language (and therefore compiler- and platform-dependent)
  3065. versions. 
  3066. <p> Memory allocation, input/output, and error handling 
  3067. <p> All of the
  3068. memory allocation, input/output, and error handling in libpng goes through
  3069. callbacks that are user-settable.  The default routines are in pngmem.c, pngrio.c,
  3070. pngwio.c, and pngerror.c, respectively.  To change these functions, call the
  3071. appropriate png_set_*_fn() function. 
  3072. <p> Memory allocation is done through
  3073. the functions png_malloc() and png_free().  These currently just call the
  3074. standard C functions.  If your pointers can't access more then 64K at a time,
  3075. you will want to set MAXSEG_64K in zlib.h.  Since it is unlikely that the
  3076. method of handling memory allocation on a platform will change between
  3077. applications, these functions must be modified in the library at compile
  3078. time.  If you prefer to use a different method of allocating and freeing
  3079. data, you can use png_create_read_struct_2() or png_create_write_struct_2()
  3080. to register your own functions as described above. These functions also
  3081.  
  3082. <p>provide a void pointer that can be retrieved via 
  3083. <p>     mem_ptr=png_get_mem_ptr(png_ptr);<br>
  3084.  
  3085. <p> 
  3086. <p> Your replacement memory functions must have prototypes as follows: 
  3087. <p> 
  3088.    png_voidp malloc_fn(png_structp png_ptr,<br>
  3089.         png_size_t size);<br>
  3090.      void free_fn(png_structp png_ptr, png_voidp ptr);<br>
  3091.  
  3092. <p> 
  3093. <p> Your malloc_fn() must return NULL in case of failure.  The png_malloc()
  3094. function will normally call png_error() if it receives a NULL from the
  3095. system memory allocator or from your replacement malloc_fn(). 
  3096. <p> Input/Output
  3097. in libpng is done through png_read() and png_write(), which currently just
  3098. call fread() and fwrite().  The FILE * is stored in png_struct and is initialized
  3099. via png_init_io().  If you wish to change the method of I/O, the library
  3100. supplies callbacks that you can set through the function png_set_read_fn()
  3101. and png_set_write_fn() at run time, instead of calling the png_init_io()
  3102. function.  These functions also provide a void pointer that can be retrieved
  3103. via the function png_get_io_ptr().  For example: 
  3104. <p>     png_set_read_fn(png_structp
  3105. read_ptr,<br>
  3106.          voidp read_io_ptr, png_rw_ptr read_data_fn)<br>
  3107.  
  3108. <p> 
  3109. <p>     png_set_write_fn(png_structp write_ptr,<br>
  3110.          voidp write_io_ptr, png_rw_ptr write_data_fn,<br>
  3111.          png_flush_ptr output_flush_fn);<br>
  3112.  
  3113. <p> 
  3114. <p>     voidp read_io_ptr = png_get_io_ptr(read_ptr);<br>
  3115.      voidp write_io_ptr = png_get_io_ptr(write_ptr);<br>
  3116.  
  3117. <p> 
  3118. <p> The replacement I/O functions must have prototypes as follows: 
  3119. <p>     void
  3120. user_read_data(png_structp png_ptr,<br>
  3121.          png_bytep data, png_size_t length);<br>
  3122.      void user_write_data(png_structp png_ptr,<br>
  3123.          png_bytep data, png_size_t length);<br>
  3124.      void user_flush_data(png_structp png_ptr);<br>
  3125.  
  3126. <p> 
  3127. <p> Supplying NULL for the read, write, or flush functions sets them back
  3128. to using the default C stream functions.  It is an error to read from a
  3129. write stream, and vice versa. 
  3130. <p> Error handling in libpng is done through
  3131. png_error() and png_warning(). Errors handled through png_error() are fatal,
  3132. meaning that png_error() should never return to its caller.  Currently,
  3133. this is handled via setjmp() and longjmp() (unless you have compiled libpng
  3134. with PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
  3135. but you could change this to do things like exit() if you should wish. 
  3136. <p>
  3137. On non-fatal errors, png_warning() is called to print a warning message,
  3138. and then control returns to the calling code. By default png_error() and
  3139. png_warning() print a message on stderr via fprintf() unless the library
  3140. is compiled with PNG_NO_CONSOLE_IO defined (because you don't want the messages)
  3141. or PNG_NO_STDIO defined (because fprintf() isn't available).  If you wish
  3142. to change the behavior of the error functions, you will need to set up
  3143. your own message callbacks.  These functions are normally supplied at the
  3144. time that the png_struct is created. It is also possible to redirect errors
  3145. and warnings to your own replacement functions after png_create_*_struct()
  3146. has been called by calling: 
  3147. <p>     png_set_error_fn(png_structp png_ptr,<br>
  3148.          png_voidp error_ptr, png_error_ptr error_fn,<br>
  3149.          png_error_ptr warning_fn);<br>
  3150.  
  3151. <p> 
  3152. <p>     png_voidp error_ptr = png_get_error_ptr(png_ptr);<br>
  3153.  
  3154. <p> 
  3155. <p> If NULL is supplied for either error_fn or warning_fn, then the libpng
  3156. default function will be used, calling fprintf() and/or longjmp() if a
  3157. problem is encountered.  The replacement error functions should have parameters
  3158. as follows: 
  3159. <p>     void user_error_fn(png_structp png_ptr,<br>
  3160.          png_const_charp error_msg);<br>
  3161.      void user_warning_fn(png_structp png_ptr,<br>
  3162.          png_const_charp warning_msg);<br>
  3163.  
  3164. <p> 
  3165. <p> The motivation behind using setjmp() and longjmp() is the C++ throw and
  3166. catch exception handling methods.  This makes the code much easier to write,
  3167. as there is no need to check every return code of every function call. However,
  3168. there are some uncertainties about the status of local variables after
  3169. a longjmp, so the user may want to be careful about doing anything after
  3170. setjmp returns non-zero besides returning itself.  Consult your compiler
  3171. documentation for more details.  For an alternative approach, you may wish
  3172. to use the "cexcept" facility (see http://cexcept.sourceforge.net). 
  3173. <p> 
  3174. <h3><a name='sect28' href='#toc28'>Custom
  3175. chunks</a></h3>
  3176.  
  3177. <p> If you need to read or write custom chunks, you may need to get
  3178. deeper into the libpng code.  The library now has mechanisms for storing
  3179. and writing chunks of unknown type; you can even declare callbacks for
  3180. custom chunks.  Hoewver, this may not be good enough if the library code
  3181. itself needs to know about interactions between your chunk and existing
  3182. `intrinsic' chunks. 
  3183. <p> If you need to write a new intrinsic chunk, first read
  3184. the PNG specification. Acquire a first level of understanding of how it
  3185. works.  Pay particular attention to the sections that describe chunk names,
  3186. and look at how other chunks were designed, so you can do things similarly.
  3187.  Second, check out the sections of libpng that read and write chunks.  Try
  3188. to find a chunk that is similar to yours and use it as a template.  More
  3189. details can be found in the comments inside the code.  It is best to handle
  3190. unknown chunks in a generic method, via callback functions, instead of
  3191. by modifying libpng functions. 
  3192. <p> If you wish to write your own transformation
  3193. for the data, look through the part of the code that does the transformations,
  3194. and check out some of the simpler ones to get an idea of how they work.
  3195.  Try to find a similar transformation to the one you want to add and copy
  3196. off of it.  More details can be found in the comments inside the code itself.
  3197.  
  3198. <p> 
  3199. <h3><a name='sect29' href='#toc29'>Configuring for 16 bit platforms</a></h3>
  3200.  
  3201. <p> You will want to look into zconf.h to
  3202. tell zlib (and thus libpng) that it cannot allocate more then 64K at a
  3203. time.  Even if you can, the memory won't be accessible.  So limit zlib and
  3204. libpng to 64K by defining MAXSEG_64K. 
  3205. <p> 
  3206. <h3><a name='sect30' href='#toc30'>Configuring for DOS</a></h3>
  3207.  
  3208. <p> For DOS users
  3209. who only have access to the lower 640K, you will have to limit zlib's memory
  3210. usage via a png_set_compression_mem_level() call.  See zlib.h or zconf.h in
  3211. the zlib library for more information. 
  3212. <p> 
  3213. <h3><a name='sect31' href='#toc31'>Configuring for Medium Model</a></h3>
  3214.  
  3215. <p> Libpng's
  3216. support for medium model has been tested on most of the popular compilers.
  3217.  Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets defined, and FAR
  3218. gets defined to far in pngconf.h, and you should be all set.  Everything
  3219. in the library (except for zlib's structure) is expecting far data.  You
  3220. must use the typedefs with the p or pp on the end for pointers (or at least
  3221. look at them and be careful).  Make note that the rows of data are defined
  3222. as png_bytepp, which is an unsigned char far * far *. 
  3223. <p> 
  3224. <h3><a name='sect32' href='#toc32'>Configuring for gui/windowing
  3225. platforms:</a></h3>
  3226.  
  3227. <p> You will need to write new error and warning functions that
  3228. use the GUI interface, as described previously, and set them to be the
  3229. error and warning functions at the time that png_create_*_struct() is called,
  3230. in order to have them available during the structure initialization. They
  3231. can be changed later via png_set_error_fn().  On some compilers, you may
  3232. also have to change the memory allocators (png_malloc, etc.). 
  3233. <p> 
  3234. <h3><a name='sect33' href='#toc33'>Configuring
  3235. for compiler xxx:</a></h3>
  3236.  
  3237. <p> All includes for libpng are in pngconf.h.  If you need
  3238. to add/change/delete an include, this is the place to do it.  The includes
  3239. that are not needed outside libpng are protected by the PNG_INTERNAL definition,
  3240. which is only defined for those routines inside libpng itself.  The files
  3241. in libpng proper only include png.h, which includes pngconf.h. 
  3242. <p> 
  3243. <h3><a name='sect34' href='#toc34'>Configuring
  3244. zlib:</a></h3>
  3245.  
  3246. <p> There are special functions to configure the compression.  Perhaps
  3247. the most useful one changes the compression level, which currently uses
  3248. input compression values in the range 0 - 9.  The library normally uses the
  3249. default compression level (Z_DEFAULT_COMPRESSION = 6).  Tests have shown
  3250. that for a large majority of images, compression values in the range 3-6
  3251. compress nearly as well as higher levels, and do so much faster.  For online
  3252. applications it may be desirable to have maximum speed (Z_BEST_SPEED =
  3253. 1).  With versions of zlib after v0.99, you can also specify no compression
  3254. (Z_NO_COMPRESSION = 0), but this would create files larger than just storing
  3255. the raw bitmap.  You can specify the compression level by calling: 
  3256. <p>    
  3257. png_set_compression_level(png_ptr, level);<br>
  3258.  
  3259. <p> 
  3260. <p> Another useful one is to reduce the memory level used by the library.
  3261. The memory level defaults to 8, but it can be lowered if you are short
  3262. on memory (running DOS, for example, where you only have 640K). Note that
  3263. the memory level does have an effect on compression; among other things,
  3264. lower levels will result in sections of incompressible data being emitted
  3265. in smaller stored blocks, with a correspondingly larger relative overhead
  3266. of up to 15% in the worst case. 
  3267. <p>     png_set_compression_mem_level(png_ptr,
  3268. level);<br>
  3269.  
  3270. <p> 
  3271. <p> The other functions are for configuring zlib.  They are not recommended
  3272. for normal use and may result in writing an invalid PNG file.  See zlib.h
  3273. for more information on what these mean. 
  3274. <p>     png_set_compression_strategy(png_ptr,<br>
  3275.          strategy);<br>
  3276.      png_set_compression_window_bits(png_ptr,<br>
  3277.          window_bits);<br>
  3278.      png_set_compression_method(png_ptr, method);<br>
  3279.      png_set_compression_buffer_size(png_ptr, size);<br>
  3280.  
  3281. <p> 
  3282. <p> 
  3283. <h3><a name='sect35' href='#toc35'>Controlling row filtering</a></h3>
  3284.  
  3285. <p> If you want to control whether libpng uses
  3286. filtering or not, which filters are used, and how it goes about picking
  3287. row filters, you can call one of these functions.  The selection and configuration
  3288. of row filters can have a significant impact on the size and encoding speed
  3289. and a somewhat lesser impact on the decoding speed of an image.  Filtering
  3290. is enabled by default for RGB and grayscale images (with and without alpha),
  3291. but not for paletted images nor for any images with bit depths less than
  3292. 8 bits/pixel. 
  3293. <p> The 'method' parameter sets the main filtering method, which
  3294. is currently only '0' in the PNG 1.2 specification.  The 'filters' parameter
  3295. sets which filter(s), if any, should be used for each scanline.  Possible
  3296. values are PNG_ALL_FILTERS and PNG_NO_FILTERS to turn filtering on and
  3297. off, respectively. 
  3298. <p> Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
  3299. PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise ORed
  3300. together with '|' to specify one or more filters to use. These filters are
  3301. described in more detail in the PNG specification. If you intend to change
  3302. the filter type during the course of writing the image, you should start
  3303. with flags set for all of the filters you intend to use so that libpng
  3304. can initialize its internal structures appropriately for all of the filter
  3305. types.  (Note that this means the first row must always be adaptively filtered,
  3306. because libpng currently does not allocate the filter buffers until png_write_row()
  3307. is called for the first time.) 
  3308. <p>     filters = PNG_FILTER_NONE | PNG_FILTER_SUB<br>
  3309.                PNG_FILTER_UP | PNG_FILTER_AVE |<br>
  3310.                PNG_FILTER_PAETH | PNG_ALL_FILTERS;<br>
  3311.  
  3312. <p> 
  3313. <p>     png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,<br>
  3314.         filters);<br>
  3315.                The second parameter can also be<br>
  3316.                PNG_INTRAPIXEL_DIFFERENCING if you are<br>
  3317.                writing a PNG to be embedded in a MNG<br>
  3318.                datastream.  This parameter must be the<br>
  3319.                same as the value of filter_method used<br>
  3320.                in png_set_IHDR().<br>
  3321.  
  3322. <p> 
  3323. <p> It is also possible to influence how libpng chooses from among the available
  3324. filters.  This is done in one or both of two ways - by telling it how important
  3325. it is to keep the same filter for successive rows, and by telling it the
  3326. relative computational costs of the filters. 
  3327. <p>     double weights[3] = {1.5,
  3328. 1.3, 1.1},<br>
  3329.         costs[PNG_FILTER_VALUE_LAST] =<br>
  3330.         {1.0, 1.3, 1.3, 1.5, 1.7};<br>
  3331.  
  3332. <p> 
  3333. <p>     png_set_filter_heuristics(png_ptr,<br>
  3334.         PNG_FILTER_HEURISTIC_WEIGHTED, 3,<br>
  3335.         weights, costs);<br>
  3336.  
  3337. <p> 
  3338. <p> The weights are multiplying factors that indicate to libpng that the
  3339. row filter should be the same for successive rows unless another row filter
  3340. is that many times better than the previous filter.  In the above example,
  3341. if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have
  3342. a "sum of absolute differences" 1.5 x 1.3 times higher than other filters
  3343. and still be chosen, while the NONE filter could have a sum 1.1 times higher
  3344. than other filters and still be chosen.  Unspecified weights are taken to
  3345. be 1.0, and the specified weights should probably be declining like those
  3346. above in order to emphasize recent filters over older filters. 
  3347. <p> The filter
  3348. costs specify for each filter type a relative decoding cost to be considered
  3349. when selecting row filters.  This means that filters with higher costs are
  3350. less likely to be chosen over filters with lower costs, unless their "sum
  3351. of absolute differences" is that much smaller. The costs do not necessarily
  3352. reflect the exact computational speeds of the various filters, since this
  3353. would unduly influence the final image size. 
  3354. <p> Note that the numbers above
  3355. were invented purely for this example and are given only to help explain
  3356. the function usage.  Little testing has been done to find optimum values
  3357. for either the costs or the weights. 
  3358. <p> 
  3359. <h3><a name='sect36' href='#toc36'>Removing unwanted object code</a></h3>
  3360.  
  3361. <p> There
  3362. are a bunch of #define's in pngconf.h that control what parts of libpng are
  3363. compiled.  All the defines end in _SUPPORTED.  If you are never going to
  3364. use a capability, you can change the #define to #undef before recompiling
  3365. libpng and save yourself code and data space, or you can turn off individual
  3366. capabilities with defines that begin with PNG_NO_. 
  3367. <p> You can also turn all
  3368. of the transforms and ancillary chunk capabilities off en masse with compiler
  3369. directives that define PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or
  3370. WRITE]_ANCILLARY_CHUNKS, or all four, along with directives to turn on
  3371. any of the capabilities that you do want.  The PNG_NO_READ[or WRITE]_TRANSFORMS
  3372. directives disable the extra transformations but still leave the library
  3373. fully capable of reading and writing PNG files with all known public chunks
  3374. Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a
  3375. library that is incapable of reading or writing ancillary chunks. If you
  3376. are not using the progressive reading capability, you can turn that off
  3377. with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING capability,
  3378. which you'll still have). 
  3379. <p> All the reading and writing specific code are
  3380. in separate files, so the linker should only grab the files it needs.  However,
  3381. if you want to make sure, or if you are building a stand alone library,
  3382. all the reading files start with pngr and all the writing files start with
  3383. pngw.  The files that don't match either (like png.c, pngtrans.c, etc.) are
  3384. used for both reading and writing, and always need to be included. The progressive
  3385.  
  3386. <p>reader is in pngpread.c 
  3387. <p> If you are creating or distributing a dynamically
  3388. linked library (a .so or DLL file), you should not remove or disable any
  3389. parts of the library, as this will cause applications linked with different
  3390. versions of the library to fail if they call functions not available in
  3391. your library. The size of the library itself should not be an issue, because
  3392. only those sections that are actually used will be loaded into memory. 
  3393. <p>
  3394.  
  3395. <h3><a name='sect37' href='#toc37'>Requesting debug printout</a></h3>
  3396.  
  3397. <p> The macro definition PNG_DEBUG can be used to
  3398. request debugging printout.  Set it to an integer value in the range 0 to
  3399. 3.  Higher numbers result in increasing amounts of debugging information.
  3400.  The information is printed to the "stderr" file, unless another file name
  3401. is specified in the PNG_DEBUG_FILE macro definition. 
  3402. <p> When PNG_DEBUG > 0,
  3403. the following functions (macros) become available: 
  3404. <p>    png_debug(level,
  3405. message)<br>
  3406.     png_debug1(level, message, p1)<br>
  3407.     png_debug2(level, message, p1, p2)<br>
  3408.  
  3409. <p> 
  3410. <p> in which "level" is compared to PNG_DEBUG to decide whether to print
  3411. the message, "message" is the formatted string to be printed, and p1 and
  3412. p2 are parameters that are to be embedded in the string according to printf-style
  3413. formatting directives.  For example, 
  3414. <p>    png_debug1(2, "foo=%d0, foo);<br>
  3415.  
  3416. <p> 
  3417. <p> is expanded to 
  3418. <p>    if(PNG_DEBUG > 2)<br>
  3419.       fprintf(PNG_DEBUG_FILE, "foo=%d0, foo);<br>
  3420.  
  3421. <p> 
  3422. <p> When PNG_DEBUG is defined but is zero, the macros aren't defined, but
  3423. you can still use PNG_DEBUG to control your own debugging: 
  3424. <p>    #ifdef PNG_DEBUG<br>
  3425.         fprintf(stderr, ...<br>
  3426.     #endif<br>
  3427.  
  3428. <p> 
  3429. <p> When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
  3430. having level = 0 will be printed.  There aren't any such statements in this
  3431. version of libpng, but if you insert some they will be printed. 
  3432. <p> 
  3433. <h2><a name='sect38' href='#toc38'>VI.  Runtime
  3434. optimization</a></h2>
  3435.  
  3436. <p> A new feature in libpng 1.2.0 is the ability to dynamically
  3437. switch between standard and optimized versions of some routines.  Currently
  3438. these are limited to three computationally intensive tasks when reading
  3439. PNG files: decoding row filters, expanding interlacing, and combining interlaced
  3440. or transparent row data with previous row data.  Currently the optimized
  3441. versions are available only for x86 (Intel, AMD, etc.) platforms with MMX
  3442. support, though this may change in future versions.  (For example, the non-MMX
  3443. assembler optimizations for zlib might become similarly runtime-selectable
  3444. in future releases, in which case libpng could be extended to support them.
  3445.  Alternatively, the compile-time choice of floating-point versus integer
  3446. routines for gamma correction might become runtime-selectable.) 
  3447. <p> Because
  3448. such optimizations tend to be very platform- and compiler-dependent, both
  3449. in how they are written and in how they perform, the new runtime code in
  3450. libpng has been written to allow programs to query, enable, and disable
  3451. either specific optimizations or all such optimizations.  For example, to
  3452. enable all possible optimizations (bearing in mind that some "optimizations"
  3453. may actually run more slowly in rare cases): 
  3454. <p>     #if defined(PNG_LIBPNG_VER)
  3455. && (PNG_LIBPNG_VER >= 10200)<br>
  3456.         png_uint_32 mask, flags;<br>
  3457.  
  3458. <p> 
  3459. <p>        flags = png_get_asm_flags(png_ptr);<br>
  3460.         mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);<br>
  3461.         png_set_asm_flags(png_ptr, flags | mask);<br>
  3462.      #endif<br>
  3463.  
  3464. <p> 
  3465. <p> To enable only optimizations relevant to reading PNGs, use PNG_SELECT_READ
  3466. by itself when calling png_get_asm_flagmask(); similarly for optimizing
  3467. only writing.  To disable all optimizations: 
  3468. <p>     #if defined(PNG_LIBPNG_VER)
  3469. && (PNG_LIBPNG_VER >= 10200)<br>
  3470.         flags = png_get_asm_flags(png_ptr);<br>
  3471.         mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);<br>
  3472.         png_set_asm_flags(png_ptr, flags & ~mask);<br>
  3473.      #endif<br>
  3474.  
  3475. <p> 
  3476. <p> To enable or disable only MMX-related features, use png_get_mmx_flagmask()
  3477. in place of png_get_asm_flagmask().  The mmx version takes one additional
  3478. parameter: 
  3479. <p>     #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)<br>
  3480.         int selection = PNG_SELECT_READ | PNG_SELECT_WRITE;<br>
  3481.         int compilerID;<br>
  3482.  
  3483. <p> 
  3484. <p>        mask = png_get_mmx_flagmask(selection, &compilerID);<br>
  3485.      #endif<br>
  3486.  
  3487. <p> 
  3488. <p> On return, compilerID will indicate which version of the MMX assembler
  3489. optimizations was compiled.  Currently two flavors exist:  Microsoft Visual
  3490. C++ (compilerID == 1) and GNU C (a.k.a. gcc/gas, compilerID == 2). On non-x86
  3491. platforms or on systems compiled without MMX optimizations, a value of
  3492. -1 is used. 
  3493. <p> Note that both png_get_asm_flagmask() and png_get_mmx_flagmask()
  3494. return all valid, settable optimization bits for the version of the library
  3495. that's currently in use.  In the case of shared (dynamically linked) libraries,
  3496. this may include optimizations that did not exist at the time the code
  3497. was written and compiled.  It is also possible, of course, to enable only
  3498. known, specific optimizations; for example: 
  3499. <p>     #if defined(PNG_LIBPNG_VER)
  3500. && (PNG_LIBPNG_VER >= 10200)<br>
  3501.         flags = PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  <br>
  3502.               | PNG_ASM_FLAG_MMX_READ_INTERLACE    <br>
  3503.               | PNG_ASM_FLAG_MMX_READ_FILTER_SUB   <br>
  3504.               | PNG_ASM_FLAG_MMX_READ_FILTER_UP    <br>
  3505.               | PNG_ASM_FLAG_MMX_READ_FILTER_AVG   <br>
  3506.               | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;<br>
  3507.         png_set_asm_flags(png_ptr, flags);<br>
  3508.      #endif<br>
  3509.  
  3510. <p> 
  3511. <p> This method would enable only the MMX read-optimizations available at
  3512. the time of libpng 1.2.0's release, regardless of whether a later version
  3513. of the DLL were actually being used.  (Also note that these functions did
  3514. not exist in versions older than 1.2.0, so any attempt to run a dynamically
  3515. linked app on such an older version would fail.) 
  3516. <p> To determine whether the
  3517. processor supports MMX instructions at all, use the png_mmx_support() function:
  3518.  
  3519. <p>     #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)<br>
  3520.         mmxsupport = png_mmx_support();<br>
  3521.      #endif<br>
  3522.  
  3523. <p> 
  3524. <p> It returns -1 if MMX support is not compiled into libpng, 0 if MMX code
  3525. is compiled but MMX is not supported by the processor, or 1 if MMX support
  3526. is fully available.  Note that png_mmx_support(), png_get_mmx_flagmask(),
  3527. and png_get_asm_flagmask() all may be called without allocating and ini-
  3528. tializing any PNG structures (for example, as part of a usage screen or
  3529. "about" box). 
  3530. <p> The following code can be used to prevent an application
  3531. from using the thread_unsafe features, even if libpng was built with PNG_THREAD_UNSAFE_OK
  3532. defined: 
  3533. <p> #if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  3534.    && defined(PNG_THREAD_UNSAFE_OK)<br>
  3535.      /* Disable thread-unsafe features of pnggccrd */<br>
  3536.      if (png_access_version() >= 10200)<br>
  3537.      {<br>
  3538.        png_uint_32 mmx_disable_mask = 0;<br>
  3539.        png_uint_32 asm_flags;<br>
  3540.  
  3541. <p> 
  3542. <p>       mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  <br>
  3543.                            | PNG_ASM_FLAG_MMX_READ_FILTER_SUB   <br>
  3544.                            | PNG_ASM_FLAG_MMX_READ_FILTER_AVG   <br>
  3545.                            | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );<br>
  3546.        asm_flags = png_get_asm_flags(png_ptr);<br>
  3547.        png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);<br>
  3548.      }<br>
  3549.  
  3550. <p> #endif 
  3551. <p> For more extensive examples of runtime querying, enabling and
  3552. disabling of optimized features, see contrib/gregbook/readpng2.c in the
  3553. libpng source-code distribution. 
  3554. <p> 
  3555. <h2><a name='sect39' href='#toc39'>VII.  MNG support</a></h2>
  3556.  
  3557. <p> The MNG specification
  3558. (available at http://www.libpng.org/pub/mng) allows certain extensions to
  3559. PNG for PNG images that are embedded in MNG datastreams. Libpng can support
  3560. some of these extensions.  To enable them, use the png_permit_mng_features()
  3561. function: 
  3562. <p>    feature_set = png_permit_mng_features(png_ptr, mask)<br>
  3563.     mask is a png_uint_32 containing the logical OR of the<br>
  3564.          features you want to enable.  These include<br>
  3565.          PNG_FLAG_MNG_EMPTY_PLTE<br>
  3566.          PNG_FLAG_MNG_FILTER_64<br>
  3567.          PNG_ALL_MNG_FEATURES<br>
  3568.     feature_set is a png_uint_32 that is the logical AND of<br>
  3569.        your mask with the set of MNG features that is<br>
  3570.        supported by the version of libpng that you are using.<br>
  3571.  
  3572. <p> 
  3573. <p> It is an error to use this function when reading or writing a standalone
  3574. PNG file with the PNG 8-byte signature.  The PNG datastream must be wrapped
  3575. in a MNG datastream.  As a minimum, it must have the MNG 8-byte signature
  3576. and the MHDR and MEND chunks.  Libpng does not provide support for these
  3577. or any other MNG chunks; your application must provide its own support
  3578. for them.  You may wish to consider using libmng (available at http://www.libmng.com)
  3579. instead. 
  3580. <p> 
  3581. <h2><a name='sect40' href='#toc40'>VIII.  Changes to Libpng from version 0.88</a></h2>
  3582.  
  3583. <p> It should be noted that
  3584. versions of libpng later than 0.96 are not distributed by the original libpng
  3585. author, Guy Schalnat, nor by Andreas Dilger, who had taken over from Guy
  3586. during 1996 and 1997, and distributed versions 0.89 through 0.96, but rather
  3587. by another member of the original PNG Group, Glenn Randers-Pehrson.  Guy
  3588. and Andreas are still alive and well, but they have moved on to other things.
  3589.  
  3590. <p> The old libpng functions png_read_init(), png_write_init(), png_info_init(),
  3591. png_read_destroy(), and png_write_destroy() have been moved to PNG_INTERNAL
  3592. in version 0.95 to discourage their use.  These functions will be removed
  3593. from libpng version 2.0.0. 
  3594. <p> The preferred method of creating and initializing
  3595. the libpng structures is via the png_create_read_struct(), png_create_write_struct(),
  3596. and png_create_info_struct() because they isolate the size of the structures
  3597. from the application, allow version error checking, and also allow the
  3598. use of custom error handling routines during the initialization, which
  3599. the old functions do not.  The functions png_read_destroy() and png_write_destroy()
  3600. do not actually free the memory that libpng allocated for these structs,
  3601. but just reset the data structures, so they can be used instead of png_destroy_read_struct()
  3602. and png_destroy_write_struct() if you feel there is too much system overhead
  3603. allocating and freeing the png_struct for each image read. 
  3604. <p> Setting the
  3605. error callbacks via png_set_message_fn() before png_read_init() as was
  3606. suggested in libpng-0.88 is no longer supported because this caused applications
  3607. that do not use custom error functions to fail if the png_ptr was not initialized
  3608. to zero.  It is still possible to set the error callbacks AFTER png_read_init(),
  3609. or to change them with png_set_error_fn(), which is essentially the same
  3610. function, but with a new name to force compilation errors with applications
  3611. that try to use the old method. 
  3612. <p> Starting with version 1.0.7, you can find
  3613. out which version of the library you are using at run-time: 
  3614. <p>    png_uint_32
  3615. libpng_vn = png_access_version_number();<br>
  3616.  
  3617. <p> 
  3618. <p> The number libpng_vn is constructed from the major version, minor version
  3619. with leading zero, and release number with leading zero, (e.g., libpng_vn
  3620. for version 1.0.7 is 10007). 
  3621. <p> You can also check which version of png.h you
  3622. used when compiling your application: 
  3623. <p>    png_uint_32 application_vn =
  3624. PNG_LIBPNG_VER;<br>
  3625.  
  3626. <p> 
  3627. <p> 
  3628. <h2><a name='sect41' href='#toc41'>IX. Y2K Compliance in libpng</a></h2>
  3629.  
  3630. <p> December 3, 2004 
  3631. <p> Since the PNG Development
  3632. group is an ad-hoc body, we can't make an official declaration. 
  3633. <p> This is your
  3634. unofficial assurance that libpng from version 0.71 and upward through 1.2.8
  3635. are Y2K compliant.  It is my belief that earlier versions were also Y2K
  3636. compliant. 
  3637. <p> Libpng only has three year fields.  One is a 2-byte unsigned integer
  3638. that will hold years up to 65535.  The other two hold the date in text format,
  3639. and will hold years up to 9999. 
  3640. <p> The integer is     "png_uint_16 year" in
  3641. png_time_struct.<br>
  3642.  
  3643. <p> 
  3644. <p> The strings are     "png_charp time_buffer" in png_struct and<br>
  3645.      "near_time_buffer", which is a local character string in png.c.<br>
  3646.  
  3647. <p> 
  3648. <p> There are seven time-related functions: 
  3649. <p>     png_convert_to_rfc_1123()
  3650. in png.c<br>
  3651.        (formerly png_convert_to_rfc_1152() in error)<br>
  3652.      png_convert_from_struct_tm() in pngwrite.c, called<br>
  3653.        in pngwrite.c<br>
  3654.      png_convert_from_time_t() in pngwrite.c<br>
  3655.      png_get_tIME() in pngget.c<br>
  3656.      png_handle_tIME() in pngrutil.c, called in pngread.c<br>
  3657.      png_set_tIME() in pngset.c<br>
  3658.      png_write_tIME() in pngwutil.c, called in pngwrite.c<br>
  3659.  
  3660. <p> 
  3661. <p> All appear to handle dates properly in a Y2K environment.  The png_convert_from_time_t()
  3662. function calls gmtime() to convert from system clock time, which returns
  3663. (year - 1900), which we properly convert to the full 4-digit year.  There
  3664. is a possibility that applications using libpng are not passing 4-digit
  3665. years into the png_convert_to_rfc_1123() function, or that they are incorrectly
  3666. passing only a 2-digit year instead of "year - 1900" into the png_convert_from_struct_tm()
  3667. function, but this is not under our control.  The libpng documentation has
  3668. always stated that it works with 4-digit years, and the APIs have been documented
  3669. as such. 
  3670. <p> The tIME chunk itself is also Y2K compliant.  It uses a 2-byte unsigned
  3671. integer to hold the year, and can hold years as large as 65535. 
  3672. <p> zlib, upon
  3673. which libpng depends, is also Y2K compliant.  It contains no date-related
  3674. code. 
  3675. <p> 
  3676. <p>    Glenn Randers-Pehrson<br>
  3677.     libpng maintainer<br>
  3678.     PNG Development Group<br>
  3679.  
  3680. <p> 
  3681. <p> 
  3682. <h2><a name='sect42' href='#toc42'>Note</a></h2>
  3683.  
  3684. <p> Note about libpng version numbers: 
  3685. <p> Due to various miscommunications,
  3686. unforeseen code incompatibilities and occasional factors outside the authors'
  3687. control, version numbering on the library has not always been consistent
  3688. and straightforward. The following table summarizes matters since version
  3689. 0.89c, which was the first widely used release: 
  3690. <p>  source             png.h
  3691.  png.h  shared-lib<br>
  3692.   version            string   int  version<br>
  3693.   -------            ------  ----- ----------<br>
  3694.   0.89c ("beta 3")  0.89       89  1.0.89<br>
  3695.   0.90  ("beta 4")  0.90       90  0.90<br>
  3696.   0.95  ("beta 5")  0.95       95  0.95<br>
  3697.   0.96  ("beta 6")  0.96       96  0.96<br>
  3698.   0.97b ("beta 7")  1.00.97    97  1.0.1<br>
  3699.   0.97c             0.97       97  2.0.97<br>
  3700.   0.98              0.98       98  2.0.98<br>
  3701.   0.99              0.99       98  2.0.99<br>
  3702.   0.99a-m           0.99       99  2.0.99<br>
  3703.   1.00              1.00      100  2.1.0<br>
  3704.   1.0.0             1.0.0     100  2.1.0<br>
  3705.   1.0.0   (from here on, the  100  2.1.0<br>
  3706.   1.0.1    png.h string is  10001  2.1.0<br>
  3707.   1.0.1a-e identical to the 10002  from here on, the<br>
  3708.   1.0.2    source version)  10002  shared library is 2.V<br>
  3709.   1.0.2a-b                  10003  where V is the source<br>
  3710.   1.0.1                     10001  code version except as<br>
  3711.   1.0.1a-e                  10002  2.1.0.1a-e   noted.<br>
  3712.   1.0.2                     10002  2.1.0.2<br>
  3713.   1.0.2a-b                  10003  2.1.0.2a-b<br>
  3714.   1.0.3                     10003  2.1.0.3<br>
  3715.   1.0.3a-d                  10004  2.1.0.3a-d<br>
  3716.   1.0.4                     10004  2.1.0.4<br>
  3717.   1.0.4a-f                  10005  2.1.0.4a-f<br>
  3718.   1.0.5 (+ 2 patches)       10005  2.1.0.5<br>
  3719.   1.0.5a-d                  10006  2.1.0.5a-d<br>
  3720.   1.0.5e-r                  10100  2.1.0.5e-r<br>
  3721.   1.0.5s-v                  10006  2.1.0.5s-v<br>
  3722.   1.0.6 (+ 3 patches)       10006  2.1.0.6<br>
  3723.   1.0.6d-g                  10007  2.1.0.6d-g<br>
  3724.   1.0.6h                    10007  10.6h<br>
  3725.   1.0.6i                    10007  10.6i<br>
  3726.   1.0.6j                    10007  2.1.0.6j<br>
  3727.   1.0.7beta11-14    DLLNUM  10007  2.1.0.7beta11-14<br>
  3728.   1.0.7beta15-18       1    10007  2.1.0.7beta15-18<br>
  3729.   1.0.7rc1-2           1    10007  2.1.0.7rc1-2<br>
  3730.   1.0.7                1    10007  2.1.0.7<br>
  3731.   1.0.8beta1-4         1    10008  2.1.0.8beta1-4<br>
  3732.   1.0.8rc1             1    10008  2.1.0.8rc1<br>
  3733.   1.0.8                1    10008  2.1.0.8<br>
  3734.   1.0.9beta1-6         1    10009  2.1.0.9beta1-6<br>
  3735.   1.0.9rc1             1    10009  2.1.0.9rc1<br>
  3736.   1.0.9beta7-10        1    10009  2.1.0.9beta7-10<br>
  3737.   1.0.9rc2             1    10009  2.1.0.9rc2<br>
  3738.   1.0.9                1    10009  2.1.0.9<br>
  3739.   1.0.10beta1          1    10010  2.1.0.10beta1<br>
  3740.   1.0.10rc1            1    10010  2.1.0.10rc1<br>
  3741.   1.0.10               1    10010  2.1.0.10<br>
  3742.   1.0.11beta1-3        1    10011  2.1.0.11beta1-3<br>
  3743.   1.0.11rc1            1    10011  2.1.0.11rc1<br>
  3744.   1.0.11               1    10011  2.1.0.11<br>
  3745.   1.0.12beta1-2        2    10012  2.1.0.12beta1-2<br>
  3746.   1.0.12rc1            2    10012  2.1.0.12rc1<br>
  3747.   1.0.12               2    10012  2.1.0.12<br>
  3748.   1.1.0a-f             -    10100  2.1.1.0a-f abandoned<br>
  3749.   1.2.0beta1-2         2    10200  2.1.2.0beta1-2<br>
  3750.   1.2.0beta3-5         3    10200  3.1.2.0beta3-5<br>
  3751.   1.2.0rc1             3    10200  3.1.2.0rc1<br>
  3752.   1.2.0                3    10200  3.1.2.0<br>
  3753.   1.2.1beta-4          3    10201  3.1.2.1beta1-4<br>
  3754.   1.2.1rc1-2           3    10201  3.1.2.1rc1-2<br>
  3755.   1.2.1                3    10201  3.1.2.1<br>
  3756.   1.2.2beta1-6        12    10202  12.so.0.1.2.2beta1-6<br>
  3757.   1.0.13beta1         10    10013  10.so.0.1.0.13beta1<br>
  3758.   1.0.13rc1           10    10013  10.so.0.1.0.13rc1<br>
  3759.   1.2.2rc1            12    10202  12.so.0.1.2.2rc1<br>
  3760.   1.0.13              10    10013  10.so.0.1.0.13<br>
  3761.   1.2.2               12    10202  12.so.0.1.2.2<br>
  3762.   1.2.3rc1-6          12    10203  12.so.0.1.2.3rc1-6<br>
  3763.   1.2.3               12    10203  12.so.0.1.2.3<br>
  3764.   1.2.4beta1-3        13    10204  12.so.0.1.2.4beta1-3<br>
  3765.   1.2.4rc1            13    10204  12.so.0.1.2.4rc1<br>
  3766.   1.0.14              10    10014  10.so.0.1.0.14<br>
  3767.   1.2.4               13    10204  12.so.0.1.2.4<br>
  3768.   1.2.5beta1-2        13    10205  12.so.0.1.2.5beta1-2<br>
  3769.   1.0.15rc1           10    10015  10.so.0.1.0.15rc1<br>
  3770.   1.0.15              10    10015  10.so.0.1.0.15<br>
  3771.   1.2.5               13    10205  12.so.0.1.2.5<br>
  3772.   1.2.6beta1-4        13    10206  12.so.0.1.2.6beta1-4<br>
  3773.   1.2.6rc1-5          13    10206  12.so.0.1.2.6rc1-5<br>
  3774.   1.0.16              10    10016  10.so.0.1.0.16<br>
  3775.   1.2.6               13    10206  12.so.0.1.2.6<br>
  3776.   1.2.7beta1-2        13    10207  12.so.0.1.2.7beta1-2<br>
  3777.   1.0.17rc1           10    10017  12.so.0.1.0.17rc1<br>
  3778.   1.2.7rc1            13    10207  12.so.0.1.2.7rc1<br>
  3779.   1.0.17              10    10017  12.so.0.1.0.17<br>
  3780.   1.2.7               13    10207  12.so.0.1.2.7<br>
  3781.   1.2.8beta1-5        13    10208  12.so.0.1.2.8beta1-5<br>
  3782.   1.0.18rc1-5         10    10018  12.so.0.1.0.18rc1-5<br>
  3783.   1.2.8rc1-5          13    10208  12.so.0.1.2.8rc1-5<br>
  3784.   1.0.18              10    10018  12.so.0.1.0.18<br>
  3785.   1.2.8               13    10208  12.so.0.1.2.8<br>
  3786.  
  3787. <p> 
  3788. <p> Henceforth the source version will match the shared-library minor and
  3789. patch numbers; the shared-library major version number will be used for
  3790. changes in backward compatibility, as it is intended.  The PNG_PNGLIB_VER
  3791. macro, which is not used within libpng but is available for applications,
  3792. is an unsigned integer of the form xyyzz corresponding to the source version
  3793. x.y.z (leading zeros in y and z).  Beta versions were given the previous public
  3794. release number plus a letter, until version 1.0.6j; from then on they were
  3795. given the upcoming public release number plus "betaNN" or "rcN". 
  3796. <p> 
  3797. <h2><a name='sect43' href='#toc43'>See Also</a></h2>
  3798. <a href='libpngpf.3.html'>libpngpf(3)</a>
  3799. ,
  3800. <a href='png.5.html'>png(5)</a>
  3801.  <p>
  3802. <i>libpng</i>: 
  3803. <dl>
  3804.  
  3805. <dt><a href='http://libpng.sourceforge.net'>http://libpng.sourceforge.net</a>
  3806.  (follow the [DOWNLOAD] link)
  3807. </dt>
  3808. <dd>
  3809. <p><a href='http://www.libpng.org/pub/png'>http://www.libpng.org/pub/png</a>
  3810.  
  3811. <p> </dd>
  3812. </dl>
  3813. <p>
  3814. <i>zlib</i>: 
  3815. <dl>
  3816.  
  3817. <dt>(generally) at the same location as
  3818. </dt>
  3819. <dd><i>libpng</i> or at <br>
  3820.  
  3821. <p>ftp://ftp.info-zip.org/pub/infozip/zlib 
  3822. <p> </dd>
  3823. </dl>
  3824. <p>
  3825. <i>PNG</i>specification:<i>RFC</i>2083 
  3826. <dl>
  3827.  
  3828. <dt>(generally)
  3829. at the same location as </dt>
  3830. <dd><i>libpng</i> or at <br>
  3831. ftp://ds.internic.net/rfc/rfc2083.txt <br>
  3832. or (as a W3C Recommendation) at <br>
  3833.  
  3834. <p><a href='http://www.w3.org/TR/REC-png.html'>http://www.w3.org/TR/REC-png.html</a>
  3835.  
  3836. <p> </dd>
  3837. </dl>
  3838. <p>
  3839. In the case of any inconsistency between
  3840. the PNG specification and this library, the specification takes precedence.
  3841.  
  3842. <p> 
  3843. <h2><a name='sect44' href='#toc44'>Authors</a></h2>
  3844. This man page: Glenn Randers-Pehrson <glennrp at users.sourceforge.net>
  3845.  
  3846. <p> The contributing authors would like to thank all those who helped with
  3847. testing, bug fixes, and patience.  This wouldn't have been possible without
  3848. all of you. 
  3849. <p> Thanks to Frank J. T. Wojcik for helping with the documentation.
  3850.  
  3851. <p> Libpng version 1.2.8 - December 3, 2004: Initially created in 1995 by Guy
  3852. Eric Schalnat, then of Group 42, Inc. Currently maintained by Glenn Randers-Pehrson
  3853. (glennrp at users.sourceforge.net). 
  3854. <p> Supported by the PNG development group
  3855. <br>
  3856. png-implement at ccrc.wustl.edu (subscription required; write to majordomo
  3857. at ccrc.wustl.edu with "subscribe png-implement" in the message). 
  3858. <p> 
  3859. <h2><a name='sect45' href='#toc45'>COPYRIGHT
  3860. NOTICE, DISCLAIMER, and LICENSE:</a></h2>
  3861.  
  3862. <p> (This copy of the libpng notices is provided
  3863. for your convenience.  In case of any discrepancy between this copy and
  3864. the notices in the file png.h that is included in the libpng distribution,
  3865. the latter shall prevail.) 
  3866. <p> If you modify libpng you may insert additional
  3867. notices immediately following this sentence. 
  3868. <p> libpng version 1.2.6, December
  3869. 3, 2004, is Copyright (c) 2004 Glenn Randers-Pehrson, and is distributed
  3870.  
  3871. <p>according to the same disclaimer and license as libpng-1.2.5 with the following
  3872.  
  3873. <p>individual added to the list of Contributing Authors 
  3874. <p>    Cosmin Truta<br>
  3875.  
  3876. <p> 
  3877. <p> libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
  3878. Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are distributed according
  3879.  
  3880. <p>to the same disclaimer and license as libpng-1.0.6 with the following individuals
  3881.  
  3882. <p>added to the list of Contributing Authors 
  3883. <p>    Simon-Pierre Cadieux<br>
  3884.     Eric S. Raymond<br>
  3885.     Gilles Vollant<br>
  3886.  
  3887. <p> 
  3888. <p> and with the following additions to the disclaimer: 
  3889. <p>    There is no warranty
  3890. against interference with your<br>
  3891.     enjoyment of the library or against infringement.<br>
  3892.     There is no warranty that our efforts or the library<br>
  3893.     will fulfill any of your particular purposes or needs.<br>
  3894.     This library is provided with all faults, and the entire<br>
  3895.     risk of satisfactory quality, performance, accuracy, and<br>
  3896.     effort is with the user.<br>
  3897.  
  3898. <p> 
  3899. <p> libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are Copyright
  3900. (c) 1998, 1999 Glenn Randers-Pehrson Distributed according to the same disclaimer
  3901. and license as libpng-0.96, with the following individuals added to the list
  3902. of Contributing Authors: 
  3903. <p>    Tom Lane<br>
  3904.     Glenn Randers-Pehrson<br>
  3905.     Willem van Schaik<br>
  3906.  
  3907. <p> 
  3908. <p> libpng versions 0.89, June 1996, through 0.96, May 1997, are Copyright
  3909. (c) 1996, 1997 Andreas Dilger Distributed according to the same disclaimer
  3910. and license as libpng-0.88, with the following individuals added to the list
  3911. of Contributing Authors: 
  3912. <p>    John Bowler<br>
  3913.     Kevin Bracey<br>
  3914.     Sam Bushell<br>
  3915.     Magnus Holmgren<br>
  3916.     Greg Roelofs<br>
  3917.     Tom Tanner<br>
  3918.  
  3919. <p> 
  3920. <p> libpng versions 0.5, May 1995, through 0.88, January 1996, are Copyright
  3921. (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. 
  3922. <p> For the purposes of this
  3923. copyright and license, "Contributing Authors" is defined as the following
  3924. set of individuals: 
  3925. <p>    Andreas Dilger<br>
  3926.     Dave Martindale<br>
  3927.     Guy Eric Schalnat<br>
  3928.     Paul Schmidt<br>
  3929.     Tim Wegner<br>
  3930.  
  3931. <p> 
  3932. <p> The PNG Reference Library is supplied "AS IS".  The Contributing Authors
  3933. and Group 42, Inc. disclaim all warranties, expressed or implied, including,
  3934. without limitation, the warranties of merchantability and of fitness for
  3935. any purpose.  The Contributing Authors and Group 42, Inc. assume no liability
  3936. for direct, indirect, incidental, special, exemplary, or consequential
  3937. damages, which may result from the use of the PNG Reference Library, even
  3938. if advised of the possibility of such damage. 
  3939. <p> Permission is hereby granted
  3940. to use, copy, modify, and distribute this source code, or portions hereof,
  3941. for any purpose, without fee, subject to the following restrictions: 
  3942. <p> 1.
  3943. The origin of this source code must not be misrepresented. 
  3944. <p> 2. Altered versions
  3945. must be plainly marked as such and    must not be misrepresented as being
  3946. the original source.<br>
  3947.  
  3948. <p> 
  3949. <p> 3. This Copyright notice may not be removed or altered from    any source
  3950. or altered source distribution.<br>
  3951.  
  3952. <p> 
  3953. <p> The Contributing Authors and Group 42, Inc. specifically permit, without
  3954. fee, and encourage the use of this source code as a component to supporting
  3955. the PNG file format in commercial products.  If you use this source code
  3956. in a product, acknowledgment is not required but would be appreciated. 
  3957. <p>
  3958.  
  3959. <p> A "png_get_copyright" function is available, for convenient use in "about"
  3960. boxes and the like: 
  3961. <p>    printf("%s",png_get_copyright(NULL));<br>
  3962.  
  3963. <p> 
  3964. <p> Also, the PNG logo (in PNG format, of course) is supplied in the files
  3965. "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). 
  3966. <p> Libpng is OSI
  3967. Certified Open Source Software.  OSI Certified Open Source is a certification
  3968. mark of the Open Source Initiative. 
  3969. <p> Glenn Randers-Pehrson glennrp at users.sourceforge.net
  3970. December 3, 2004 
  3971. <p> 
  3972. <!--
  3973.   end of man page
  3974.  
  3975. <p> <p>
  3976.  
  3977. <hr><p>
  3978. <a name='toc'><b>Table of Contents</b></a><p>
  3979. <ul>
  3980. <li><a name='toc0' href='#sect0'>Name</a></li>
  3981. <li><a name='toc1' href='#sect1'>Synopsis</a></li>
  3982. <li><a name='toc2' href='#sect2'>Description</a></li>
  3983. <li><a name='toc3' href='#sect3'>Libpng.txt</a></li>
  3984. <li><a name='toc4' href='#sect4'>I. Introduction</a></li>
  3985. <li><a name='toc5' href='#sect5'>II. Structures</a></li>
  3986. <li><a name='toc6' href='#sect6'>III. Reading</a></li>
  3987. <ul>
  3988. <li><a name='toc7' href='#sect7'>Setup</a></li>
  3989. <li><a name='toc8' href='#sect8'>Setting up callback code</a></li>
  3990. <li><a name='toc9' href='#sect9'>Width and height limits</a></li>
  3991. <li><a name='toc10' href='#sect10'>Unknown-chunk handling</a></li>
  3992. <li><a name='toc11' href='#sect11'>The high-level read interface</a></li>
  3993. <li><a name='toc12' href='#sect12'>The low-level read interface</a></li>
  3994. <li><a name='toc13' href='#sect13'>Querying the info structure</a></li>
  3995. <li><a name='toc14' href='#sect14'>Input transformations</a></li>
  3996. <li><a name='toc15' href='#sect15'>Reading image data</a></li>
  3997. <li><a name='toc16' href='#sect16'>Finishing a sequential read</a></li>
  3998. <li><a name='toc17' href='#sect17'>Reading PNG files progressively</a></li>
  3999. </ul>
  4000. <li><a name='toc18' href='#sect18'>IV. Writing</a></li>
  4001. <ul>
  4002. <li><a name='toc19' href='#sect19'>Setup</a></li>
  4003. <li><a name='toc20' href='#sect20'>Write callbacks</a></li>
  4004. <li><a name='toc21' href='#sect21'>Setting the contents of info for output</a></li>
  4005. <li><a name='toc22' href='#sect22'>Writing unknown chunks</a></li>
  4006. <li><a name='toc23' href='#sect23'>The high-level write interface</a></li>
  4007. <li><a name='toc24' href='#sect24'>The low-level write interface</a></li>
  4008. <li><a name='toc25' href='#sect25'>Writing the image data</a></li>
  4009. <li><a name='toc26' href='#sect26'>Finishing a sequential write</a></li>
  4010. </ul>
  4011. <li><a name='toc27' href='#sect27'>V. Modifying/Customizing libpng:</a></li>
  4012. <ul>
  4013. <li><a name='toc28' href='#sect28'>Custom chunks</a></li>
  4014. <li><a name='toc29' href='#sect29'>Configuring for 16 bit platforms</a></li>
  4015. <li><a name='toc30' href='#sect30'>Configuring for DOS</a></li>
  4016. <li><a name='toc31' href='#sect31'>Configuring for Medium Model</a></li>
  4017. <li><a name='toc32' href='#sect32'>Configuring for gui/windowing platforms:</a></li>
  4018. <li><a name='toc33' href='#sect33'>Configuring for compiler xxx:</a></li>
  4019. <li><a name='toc34' href='#sect34'>Configuring zlib:</a></li>
  4020. <li><a name='toc35' href='#sect35'>Controlling row filtering</a></li>
  4021. <li><a name='toc36' href='#sect36'>Removing unwanted object code</a></li>
  4022. <li><a name='toc37' href='#sect37'>Requesting debug printout</a></li>
  4023. </ul>
  4024. <li><a name='toc38' href='#sect38'>VI.  Runtime optimization</a></li>
  4025. <li><a name='toc39' href='#sect39'>VII.  MNG support</a></li>
  4026. <li><a name='toc40' href='#sect40'>VIII.  Changes to Libpng from version 0.88</a></li>
  4027. <li><a name='toc41' href='#sect41'>IX. Y2K Compliance in libpng</a></li>
  4028. <li><a name='toc42' href='#sect42'>Note</a></li>
  4029. <li><a name='toc43' href='#sect43'>See Also</a></li>
  4030. <li><a name='toc44' href='#sect44'>Authors</a></li>
  4031. <li><a name='toc45' href='#sect45'>COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:</a></li>
  4032. </ul>
  4033. </body>
  4034. </html>
  4035.