1 .TH LIBPNG 3 "June 26, 2010"
3 libpng \- Portable Network Graphics (PNG) Reference Library 1.2.44
11 \fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
15 \fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
19 \fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
23 \fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
27 \fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
31 \fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
35 \fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
39 \fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
43 \fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
47 \fBpng_structp png_create_read_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
51 \fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
55 \fBpng_structp png_create_write_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
59 \fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP
63 \fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP
67 \fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP
71 \fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
75 \fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
79 \fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
83 \fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
87 \fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
91 \fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
95 \fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
99 \fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
103 \fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
107 \fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
111 \fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
115 \fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
119 \fBpng_uint_32 png_get_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
123 \fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
127 \fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
131 \fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
135 \fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
139 \fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
143 \fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
147 \fBpng_uint_32 png_get_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
151 \fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
155 \fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
159 \fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
163 \fBpng_uint_32 png_get_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_charpp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
167 \fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP
171 \fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
175 \fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
179 \fB#if \fI!defined(PNG_1_0_X)
181 \fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
187 \fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
191 \fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
195 \fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
199 \fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
203 \fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
207 \fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
211 \fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
215 \fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
219 \fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
223 \fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
227 \fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
231 \fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
233 \fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
237 \fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
241 \fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
245 \fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
249 \fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
253 \fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
257 \fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
261 \fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
265 \fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP
269 \fB#if \fI!defined(PNG_1_0_X)
271 \fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
275 \fBpng_uint_32 png_get_uint_31 (png_bytep \fIbuf\fP\fB);\fP
279 \fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
285 \fBpng_uint_32 png_get_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
289 \fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
293 \fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP
297 \fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
301 \fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP
305 \fBpng_uint_32 png_get_valid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
309 \fBpng_int_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
313 \fBpng_int_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
317 \fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
321 \fBpng_int_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
325 \fBpng_int_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
329 \fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
333 \fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
337 \fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
341 \fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
345 \fBDEPRECATED: void png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP
349 \fBDEPRECATED: void png_info_init_2 (png_infopp \fP\fIptr_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
353 \fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
357 \fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
361 \fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
365 \fBpng_voidp png_memcpy_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
369 \fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
373 \fBpng_voidp png_memset_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
377 \fBDEPRECATED: void png_permit_empty_plte (png_structp \fP\fIpng_ptr\fP\fB, int \fIempty_plte_permitted\fP\fB);\fP
381 \fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP
385 \fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP
389 \fBvoid png_read_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_infop \fIend_info_ptr\fP\fB);\fP
393 \fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
397 \fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
401 \fBDEPRECATED: void png_read_init (png_structp \fIpng_ptr\fP\fB);\fP
405 \fBDEPRECATED: void png_read_init_2 (png_structpp \fP\fIptr_ptr\fP\fB, png_const_charp \fP\fIuser_png_ver\fP\fB, png_size_t \fP\fIpng_struct_size\fP\fB, png_size_t \fIpng_info_size\fP\fB);\fP
409 \fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
413 \fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
417 \fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
421 \fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
425 \fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
429 \fB#if \fI!defined(PNG_1_0_X)
431 \fBpng_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
435 \fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
439 \fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
443 \fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
449 \fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP
453 \fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
457 \fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP
461 \fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
465 \fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
469 \fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
473 \fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
477 \fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
481 \fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
485 \fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
489 \fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
493 \fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP
497 \fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP
501 \fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
505 \fBvoid png_set_expand_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
509 \fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
513 \fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
517 \fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP
521 \fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
525 \fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
529 \fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
533 \fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP
537 \fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
541 \fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
545 \fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP
549 \fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
553 \fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
557 \fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
561 \fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
565 \fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
569 \fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP
573 \fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP
577 \fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
581 \fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP
585 \fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
589 \fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
593 \fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
597 \fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
601 \fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP
605 \fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP
609 \fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
613 \fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP
617 \fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
621 \fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP
625 \fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP
629 \fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_fixed_point \fP\fIred\fP\fB, png_fixed_point \fIgreen\fP\fB);\fP
633 \fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP
637 \fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP
641 \fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
645 \fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
649 \fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
653 \fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP
657 \fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
661 \fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
665 \fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
669 \fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
673 \fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
677 \fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
681 \fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
685 \fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
689 \fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_values\fP\fB);\fP
693 \fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
697 \fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP
701 \fBvoid png_set_unknown_chunk_location(png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP
705 \fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP
709 \fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
713 \fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP
717 \fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP
721 \fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
725 \fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP
729 \fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
733 \fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP
737 \fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
741 \fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
745 \fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
749 \fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
753 \fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
757 \fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
761 \fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
765 \fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
769 \fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
773 \fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
777 \fBDEPRECATED: void png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
781 \fBDEPRECATED: void png_write_init_2 (png_structpp \fP\fIptr_ptr\fP\fB, png_const_charp \fP\fIuser_png_ver\fP\fB, png_size_t \fP\fIpng_struct_size\fP\fB, png_size_t \fIpng_info_size\fP\fB);\fP
785 \fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
789 \fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
793 \fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
797 \fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
801 \fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
805 \fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
809 \fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
816 library supports encoding, decoding, and various manipulations of
817 the Portable Network Graphics (PNG) format image files. It uses the
820 Following is a copy of the libpng.txt file that accompanies libpng.
822 libpng.txt - A description on how to use and modify libpng
824 libpng version 1.2.44 - June 26, 2010
825 Updated and distributed by Glenn Randers-Pehrson
826 <glennrp at users.sourceforge.net>
827 Copyright (c) 1998-2009 Glenn Randers-Pehrson
829 This document is released under the libpng license.
830 For conditions of distribution and use, see the disclaimer
835 libpng versions 0.97, January 1998, through 1.2.44 - June 26, 2010
836 Updated and distributed by Glenn Randers-Pehrson
837 Copyright (c) 1998-2009 Glenn Randers-Pehrson
839 libpng 1.0 beta 6 version 0.96 May 28, 1997
840 Updated and distributed by Andreas Dilger
841 Copyright (c) 1996, 1997 Andreas Dilger
843 libpng 1.0 beta 2 - version 0.88 January 26, 1996
844 For conditions of distribution and use, see copyright
845 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
846 Schalnat, Group 42, Inc.
848 Updated/rewritten per request in the libpng FAQ
849 Copyright (c) 1995, 1996 Frank J. T. Wojcik
850 December 18, 1995 & January 20, 1996
854 This file describes how to use and modify the PNG reference library
855 (known as libpng) for your own use. There are five sections to this
856 file: introduction, structures, reading, writing, and modification and
857 configuration notes for various special platforms. In addition to this
858 file, example.c is a good starting point for using the library, as
859 it is heavily commented and should include everything most people
860 will need. We assume that libpng is already installed; see the
861 INSTALL file for instructions on how to install libpng.
863 For examples of libpng usage, see the files "example.c", "pngtest.c",
864 and the files in the "contrib" directory, all of which are included in
865 the libpng distribution.
867 Libpng was written as a companion to the PNG specification, as a way
868 of reducing the amount of time and effort it takes to support the PNG
869 file format in application programs.
871 The PNG specification (second edition), November 2003, is available as
872 a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
873 <http://www.w3.org/TR/2003/REC-PNG-20031110/
874 The W3C and ISO documents have identical technical content.
876 The PNG-1.2 specification is available at
877 <http://www.libpng.org/pub/png/documents/>. It is technically equivalent
878 to the PNG specification (second edition) but has some additional material.
880 The PNG-1.0 specification is available
881 as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
882 W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
884 Some additional chunks are described in the special-purpose public chunks
885 documents at <http://www.libpng.org/pub/png/documents/>.
888 about PNG, and the latest version of libpng, can be found at the PNG home
889 page, <http://www.libpng.org/pub/png/>.
891 Most users will not have to modify the library significantly; advanced
892 users may want to modify it more. All attempts were made to make it as
893 complete as possible, while keeping the code easy to understand.
894 Currently, this library only supports C. Support for other languages
897 Libpng has been designed to handle multiple sessions at one time,
898 to be easily modifiable, to be portable to the vast majority of
899 machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
900 to use. The ultimate goal of libpng is to promote the acceptance of
901 the PNG file format in whatever way possible. While there is still
902 work to be done (see the TODO file), libpng should cover the
903 majority of the needs of its users.
905 Libpng uses zlib for its compression and decompression of PNG files.
906 Further information about zlib, and the latest version of zlib, can
907 be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
908 The zlib compression utility is a general purpose utility that is
909 useful for more than PNG files, and can be used without libpng.
910 See the documentation delivered with zlib for more details.
911 You can usually find the source files for the zlib utility wherever you
912 find the libpng source files.
914 Libpng is thread safe, provided the threads are using different
915 instances of the structures. Each thread should have its own
916 png_struct and png_info instances, and thus its own image.
917 Libpng does not protect itself against two threads using the
918 same instance of a structure.
922 There are two main structures that are important to libpng, png_struct
923 and png_info. The first, png_struct, is an internal structure that
924 will not, for the most part, be used by a user except as the first
925 variable passed to every libpng function call.
927 The png_info structure is designed to provide information about the
928 PNG file. At one time, the fields of png_info were intended to be
929 directly accessible to the user. However, this tended to cause problems
930 with applications using dynamically loaded libraries, and as a result
931 a set of interface functions for png_info (the png_get_*() and png_set_*()
932 functions) was developed. The fields of png_info are still available for
933 older applications, but it is suggested that applications use the new
934 interfaces if at all possible.
936 Applications that do make direct access to the members of png_struct (except
937 for png_ptr->jmpbuf) must be recompiled whenever the library is updated,
938 and applications that make direct access to the members of png_info must
939 be recompiled if they were compiled or loaded with libpng version 1.0.6,
940 in which the members were in a different order. In version 1.0.7, the
941 members of the png_info structure reverted to the old order, as they were
942 in versions 0.97c through 1.0.5. Starting with version 2.0.0, both
943 structures are going to be hidden, and the contents of the structures will
944 only be accessible through the png_get/png_set functions.
946 The png.h header file is an invaluable reference for programming with libpng.
947 And while I'm on the topic, make sure you include the libpng header file:
953 We'll now walk you through the possible functions to call when reading
954 in a PNG file sequentially, briefly explaining the syntax and purpose
955 of each one. See example.c and png.h for more detail. While
956 progressive reading is covered in the next section, you will still
957 need some of the functions discussed in this section to read a PNG
962 You will want to do the I/O initialization(*) before you get into libpng,
963 so if it doesn't work, you don't have much to undo. Of course, you
964 will also want to insure that you are, in fact, dealing with a PNG
965 file. Libpng provides a simple check to see if a file is a PNG file.
966 To use it, pass in the first 1 to 8 bytes of the file to the function
967 png_sig_cmp(), and it will return 0 (false) if the bytes match the
968 corresponding bytes of the PNG signature, or nonzero (true) otherwise.
969 Of course, the more bytes you pass in, the greater the accuracy of the
972 If you are intending to keep the file pointer open for use in libpng,
973 you must ensure you don't read more than 8 bytes from the beginning
974 of the file, and you also have to make a call to png_set_sig_bytes_read()
975 with the number of bytes you read from the beginning. Libpng will
976 then only check the bytes (if any) that your program didn't read.
978 (*): If you are not using the standard I/O functions, you will need
979 to replace them with custom functions. See the discussion under
983 FILE *fp = fopen(file_name, "rb");
988 fread(header, 1, number, fp);
989 is_png = !png_sig_cmp(header, 0, number);
996 Next, png_struct and png_info need to be allocated and initialized. In
997 order to ensure that the size of these structures is correct even with a
998 dynamically linked libpng, there are functions to initialize and
999 allocate the structures. We also pass the library version, optional
1000 pointers to error handling functions, and a pointer to a data struct for
1001 use by the error functions, if necessary (the pointer and functions can
1002 be NULL if the default error handlers are to be used). See the section
1003 on Changes to Libpng below regarding the old initialization functions.
1004 The structure allocation functions quietly return NULL if they fail to
1005 create the structure, so your application should check for that.
1007 png_structp png_ptr = png_create_read_struct
1008 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1009 user_error_fn, user_warning_fn);
1013 png_infop info_ptr = png_create_info_struct(png_ptr);
1016 png_destroy_read_struct(&png_ptr,
1017 (png_infopp)NULL, (png_infopp)NULL);
1021 png_infop end_info = png_create_info_struct(png_ptr);
1024 png_destroy_read_struct(&png_ptr, &info_ptr,
1029 If you want to use your own memory allocation routines,
1030 define PNG_USER_MEM_SUPPORTED and use
1031 png_create_read_struct_2() instead of png_create_read_struct():
1033 png_structp png_ptr = png_create_read_struct_2
1034 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1035 user_error_fn, user_warning_fn, (png_voidp)
1036 user_mem_ptr, user_malloc_fn, user_free_fn);
1038 The error handling routines passed to png_create_read_struct()
1039 and the memory alloc/free routines passed to png_create_struct_2()
1040 are only necessary if you are not using the libpng supplied error
1041 handling and memory alloc/free functions.
1043 When libpng encounters an error, it expects to longjmp back
1044 to your routine. Therefore, you will need to call setjmp and pass
1045 your png_jmpbuf(png_ptr). If you read the file from different
1046 routines, you will need to update the jmpbuf field every time you enter
1047 a new routine that will call a png_*() function.
1049 See your documentation of setjmp/longjmp for your compiler for more
1050 information on setjmp/longjmp. See the discussion on libpng error
1051 handling in the Customizing Libpng section below for more information
1052 on the libpng error handling. If an error occurs, and libpng longjmp's
1053 back to your setjmp, you will want to call png_destroy_read_struct() to
1056 if (setjmp(png_jmpbuf(png_ptr)))
1058 png_destroy_read_struct(&png_ptr, &info_ptr,
1064 If you would rather avoid the complexity of setjmp/longjmp issues,
1065 you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
1066 errors will result in a call to PNG_ABORT() which defaults to abort().
1068 Now you need to set up the input code. The default for libpng is to
1069 use the C function fread(). If you use this, you will need to pass a
1070 valid FILE * in the function png_init_io(). Be sure that the file is
1071 opened in binary mode. If you wish to handle reading data in another
1072 way, you need not call the png_init_io() function, but you must then
1073 implement the libpng I/O methods discussed in the Customizing Libpng
1076 png_init_io(png_ptr, fp);
1078 If you had previously opened the file and read any of the signature from
1079 the beginning in order to see if this was a PNG file, you need to let
1080 libpng know that there are some bytes missing from the start of the file.
1082 png_set_sig_bytes(png_ptr, number);
1084 .SS Setting up callback code
1086 You can set up a callback function to handle any unknown chunks in the
1087 input stream. You must supply the function
1089 read_chunk_callback(png_ptr ptr,
1090 png_unknown_chunkp chunk);
1092 /* The unknown chunk structure contains your
1093 chunk data, along with similar data for any other
1100 /* Note that libpng has already taken care of
1103 /* put your code here. Search for your chunk in the
1104 unknown chunk structure, process it, and return one
1105 of the following: */
1107 return (-n); /* chunk had an error */
1108 return (0); /* did not recognize */
1109 return (n); /* success */
1112 (You can give your function another name that you like instead of
1113 "read_chunk_callback")
1115 To inform libpng about your function, use
1117 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1118 read_chunk_callback);
1120 This names not only the callback function, but also a user pointer that
1121 you can retrieve with
1123 png_get_user_chunk_ptr(png_ptr);
1125 If you call the png_set_read_user_chunk_fn() function, then all unknown
1126 chunks will be saved when read, in case your callback function will need
1127 one or more of them. This behavior can be changed with the
1128 png_set_keep_unknown_chunks() function, described below.
1130 At this point, you can set up a callback function that will be
1131 called after each row has been read, which you can use to control
1132 a progress meter or the like. It's demonstrated in pngtest.c.
1133 You must supply a function
1135 void read_row_callback(png_ptr ptr, png_uint_32 row,
1138 /* put your code here */
1141 (You can give it another name that you like instead of "read_row_callback")
1143 To inform libpng about your function, use
1145 png_set_read_status_fn(png_ptr, read_row_callback);
1147 .SS Unknown-chunk handling
1149 Now you get to set the way the library processes unknown chunks in the
1150 input PNG stream. Both known and unknown chunks will be read. Normal
1151 behavior is that known chunks will be parsed into information in
1152 various info_ptr members while unknown chunks will be discarded. This
1153 behavior can be wasteful if your application will never use some known
1154 chunk types. To change this, you can call:
1156 png_set_keep_unknown_chunks(png_ptr, keep,
1157 chunk_list, num_chunks);
1158 keep - 0: default unknown chunk handling
1159 1: ignore; do not keep
1160 2: keep only if safe-to-copy
1161 3: keep even if unsafe-to-copy
1162 You can use these definitions:
1163 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1164 PNG_HANDLE_CHUNK_NEVER 1
1165 PNG_HANDLE_CHUNK_IF_SAFE 2
1166 PNG_HANDLE_CHUNK_ALWAYS 3
1167 chunk_list - list of chunks affected (a byte string,
1168 five bytes per chunk, NULL or '\0' if
1170 num_chunks - number of chunks affected; if 0, all
1171 unknown chunks are affected. If nonzero,
1172 only the chunks in the list are affected
1174 Unknown chunks declared in this way will be saved as raw data onto a
1175 list of png_unknown_chunk structures. If a chunk that is normally
1176 known to libpng is named in the list, it will be handled as unknown,
1177 according to the "keep" directive. If a chunk is named in successive
1178 instances of png_set_keep_unknown_chunks(), the final instance will
1179 take precedence. The IHDR and IEND chunks should not be named in
1180 chunk_list; if they are, libpng will process them normally anyway.
1182 Here is an example of the usage of png_set_keep_unknown_chunks(),
1183 where the private "vpAg" chunk will later be processed by a user chunk
1186 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1188 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1189 png_byte unused_chunks[]=
1191 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1192 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1193 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1194 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1195 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1196 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1202 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1203 /* ignore all unknown chunks: */
1204 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
1205 /* except for vpAg: */
1206 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
1207 /* also ignore unused known chunks: */
1208 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1209 (int)sizeof(unused_chunks)/5);
1214 The PNG specification allows the width and height of an image to be as
1215 large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1216 Since very few applications really need to process such large images,
1217 we have imposed an arbitrary 1-million limit on rows and columns.
1218 Larger images will be rejected immediately with a png_error() call. If
1219 you wish to override this limit, you can use
1221 png_set_user_limits(png_ptr, width_max, height_max);
1223 to set your own limits, or use width_max = height_max = 0x7fffffffL
1224 to allow all valid dimensions (libpng may reject some very large images
1225 anyway because of potential buffer overflow conditions).
1227 You should put this statement after you create the PNG structure and
1228 before calling png_read_info(), png_read_png(), or png_process_data().
1229 If you need to retrieve the limits that are being applied, use
1231 width_max = png_get_user_width_max(png_ptr);
1232 height_max = png_get_user_height_max(png_ptr);
1234 The PNG specification sets no limit on the number of ancillary chunks
1235 allowed in a PNG datastream. You can impose a limit on the total number
1236 of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1238 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1240 where 0x7fffffffL means unlimited. You can retrieve this limit with
1242 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1244 This limit also applies to the number of buffers that can be allocated
1245 by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1247 .SS The high-level read interface
1249 At this point there are two ways to proceed; through the high-level
1250 read interface, or through a sequence of low-level read operations.
1251 You can use the high-level interface if (a) you are willing to read
1252 the entire image into memory, and (b) the input transformations
1253 you want to do are limited to the following set:
1255 PNG_TRANSFORM_IDENTITY No transformation
1256 PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
1258 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
1259 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1261 PNG_TRANSFORM_PACKSWAP Change order of packed
1263 PNG_TRANSFORM_EXPAND Perform set_expand()
1264 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
1265 PNG_TRANSFORM_SHIFT Normalize pixels to the
1267 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1269 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1271 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1273 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
1274 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1275 to RGB (or GA to RGBA)
1277 (This excludes setting a background color, doing gamma transformation,
1278 dithering, and setting filler.) If this is the case, simply do this:
1280 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1282 where png_transforms is an integer containing the bitwise OR of some
1283 set of transformation flags. This call is equivalent to png_read_info(),
1284 followed the set of transformations indicated by the transform mask,
1285 then png_read_image(), and finally png_read_end().
1287 (The final parameter of this call is not yet used. Someday it might point
1288 to transformation parameters required by some future input transform.)
1290 You must use png_transforms and not call any png_set_transform() functions
1291 when you use png_read_png().
1293 After you have called png_read_png(), you can retrieve the image data
1296 row_pointers = png_get_rows(png_ptr, info_ptr);
1298 where row_pointers is an array of pointers to the pixel data for each row:
1300 png_bytep row_pointers[height];
1302 If you know your image size and pixel size ahead of time, you can allocate
1303 row_pointers prior to calling png_read_png() with
1305 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
1307 "Image is too tall to process in memory");
1308 if (width > PNG_UINT_32_MAX/pixel_size)
1310 "Image is too wide to process in memory");
1311 row_pointers = png_malloc(png_ptr,
1312 height*png_sizeof(png_bytep));
1313 for (int i=0; i<height, i++)
1314 row_pointers[i]=NULL; /* security precaution */
1315 for (int i=0; i<height, i++)
1316 row_pointers[i]=png_malloc(png_ptr,
1318 png_set_rows(png_ptr, info_ptr, &row_pointers);
1320 Alternatively you could allocate your image in one big block and define
1321 row_pointers[i] to point into the proper places in your block.
1323 If you use png_set_rows(), the application is responsible for freeing
1324 row_pointers (and row_pointers[i], if they were separately allocated).
1326 If you don't allocate row_pointers ahead of time, png_read_png() will
1327 do it, and it'll be free'ed when you call png_destroy_*().
1329 .SS The low-level read interface
1331 If you are going the low-level route, you are now ready to read all
1332 the file information up to the actual image data. You do this with a
1333 call to png_read_info().
1335 png_read_info(png_ptr, info_ptr);
1337 This will process all chunks up to but not including the image data.
1339 .SS Querying the info structure
1341 Functions are used to get the information from the info_ptr once it
1342 has been read. Note that these fields may not be completely filled
1343 in until png_read_end() has read the chunk data following the image.
1345 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1346 &bit_depth, &color_type, &interlace_type,
1347 &compression_type, &filter_method);
1349 width - holds the width of the image
1350 in pixels (up to 2^31).
1351 height - holds the height of the image
1352 in pixels (up to 2^31).
1353 bit_depth - holds the bit depth of one of the
1354 image channels. (valid values are
1355 1, 2, 4, 8, 16 and depend also on
1356 the color_type. See also
1357 significant bits (sBIT) below).
1358 color_type - describes which color/alpha channels
1361 (bit depths 1, 2, 4, 8, 16)
1362 PNG_COLOR_TYPE_GRAY_ALPHA
1364 PNG_COLOR_TYPE_PALETTE
1365 (bit depths 1, 2, 4, 8)
1368 PNG_COLOR_TYPE_RGB_ALPHA
1371 PNG_COLOR_MASK_PALETTE
1372 PNG_COLOR_MASK_COLOR
1373 PNG_COLOR_MASK_ALPHA
1375 filter_method - (must be PNG_FILTER_TYPE_BASE
1376 for PNG 1.0, and can also be
1377 PNG_INTRAPIXEL_DIFFERENCING if
1378 the PNG datastream is embedded in
1379 a MNG-1.0 datastream)
1380 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1382 interlace_type - (PNG_INTERLACE_NONE or
1383 PNG_INTERLACE_ADAM7)
1385 Any or all of interlace_type, compression_type, or
1386 filter_method can be NULL if you are
1387 not interested in their values.
1389 Note that png_get_IHDR() returns 32-bit data into
1390 the application's width and height variables.
1391 This is an unsafe situation if these are 16-bit
1392 variables. In such situations, the
1393 png_get_image_width() and png_get_image_height()
1394 functions described below are safer.
1396 width = png_get_image_width(png_ptr,
1398 height = png_get_image_height(png_ptr,
1400 bit_depth = png_get_bit_depth(png_ptr,
1402 color_type = png_get_color_type(png_ptr,
1404 filter_method = png_get_filter_type(png_ptr,
1406 compression_type = png_get_compression_type(png_ptr,
1408 interlace_type = png_get_interlace_type(png_ptr,
1411 channels = png_get_channels(png_ptr, info_ptr);
1412 channels - number of channels of info for the
1413 color type (valid values are 1 (GRAY,
1414 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1415 4 (RGB_ALPHA or RGB + filler byte))
1416 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1417 rowbytes - number of bytes needed to hold a row
1419 signature = png_get_signature(png_ptr, info_ptr);
1420 signature - holds the signature read from the
1421 file (if any). The data is kept in
1422 the same offset it would be if the
1423 whole signature were read (i.e. if an
1424 application had already read in 4
1425 bytes of signature before starting
1426 libpng, the remaining 4 bytes would
1427 be in signature[4] through signature[7]
1428 (see png_set_sig_bytes())).
1430 These are also important, but their validity depends on whether the chunk
1431 has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1432 png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1433 data has been read, or zero if it is missing. The parameters to the
1434 png_get_<chunk> are set directly if they are simple data types, or a
1435 pointer into the info_ptr is returned for any complex types.
1437 png_get_PLTE(png_ptr, info_ptr, &palette,
1439 palette - the palette for the file
1440 (array of png_color)
1441 num_palette - number of entries in the palette
1443 png_get_gAMA(png_ptr, info_ptr, &gamma);
1444 gamma - the gamma the file is written
1447 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1448 srgb_intent - the rendering intent (PNG_INFO_sRGB)
1449 The presence of the sRGB chunk
1450 means that the pixel data is in the
1451 sRGB color space. This chunk also
1452 implies specific values of gAMA and
1455 png_get_iCCP(png_ptr, info_ptr, &name,
1456 &compression_type, &profile, &proflen);
1457 name - The profile name.
1458 compression - The compression type; always
1459 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1460 You may give NULL to this argument to
1462 profile - International Color Consortium color
1463 profile data. May contain NULs.
1464 proflen - length of profile data in bytes.
1466 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1467 sig_bit - the number of significant bits for
1468 (PNG_INFO_sBIT) each of the gray,
1469 red, green, and blue channels,
1470 whichever are appropriate for the
1471 given color type (png_color_16)
1473 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
1475 trans - array of transparent
1476 entries for palette (PNG_INFO_tRNS)
1477 trans_values - graylevel or color sample values of
1478 the single transparent color for
1479 non-paletted images (PNG_INFO_tRNS)
1480 num_trans - number of transparent entries
1483 png_get_hIST(png_ptr, info_ptr, &hist);
1485 hist - histogram of palette (array of
1488 png_get_tIME(png_ptr, info_ptr, &mod_time);
1489 mod_time - time image was last modified
1492 png_get_bKGD(png_ptr, info_ptr, &background);
1493 background - background color (PNG_VALID_bKGD)
1494 valid 16-bit red, green and blue
1495 values, regardless of color_type
1497 num_comments = png_get_text(png_ptr, info_ptr,
1498 &text_ptr, &num_text);
1499 num_comments - number of comments
1500 text_ptr - array of png_text holding image
1502 text_ptr[i].compression - type of compression used
1503 on "text" PNG_TEXT_COMPRESSION_NONE
1504 PNG_TEXT_COMPRESSION_zTXt
1505 PNG_ITXT_COMPRESSION_NONE
1506 PNG_ITXT_COMPRESSION_zTXt
1507 text_ptr[i].key - keyword for comment. Must contain
1509 text_ptr[i].text - text comments for current
1510 keyword. Can be empty.
1511 text_ptr[i].text_length - length of text string,
1512 after decompression, 0 for iTXt
1513 text_ptr[i].itxt_length - length of itxt string,
1514 after decompression, 0 for tEXt/zTXt
1515 text_ptr[i].lang - language of comment (empty
1516 string for unknown).
1517 text_ptr[i].lang_key - keyword in UTF-8
1518 (empty string for unknown).
1519 Note that the itxt_length, lang, and lang_key
1520 members of the text_ptr structure only exist
1521 when the library is built with iTXt chunk support.
1523 num_text - number of comments (same as
1524 num_comments; you can put NULL here
1525 to avoid the duplication)
1526 Note while png_set_text() will accept text, language,
1527 and translated keywords that can be NULL pointers, the
1528 structure returned by png_get_text will always contain
1529 regular zero-terminated C strings. They might be
1530 empty strings but they will never be NULL pointers.
1532 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1534 palette_ptr - array of palette structures holding
1535 contents of one or more sPLT chunks
1537 num_spalettes - number of sPLT chunks read.
1539 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
1541 offset_x - positive offset from the left edge
1543 offset_y - positive offset from the top edge
1545 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1547 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
1549 res_x - pixels/unit physical resolution in
1551 res_y - pixels/unit physical resolution in
1553 unit_type - PNG_RESOLUTION_UNKNOWN,
1554 PNG_RESOLUTION_METER
1556 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1558 unit - physical scale units (an integer)
1559 width - width of a pixel in physical scale units
1560 height - height of a pixel in physical scale units
1561 (width and height are doubles)
1563 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1565 unit - physical scale units (an integer)
1566 width - width of a pixel in physical scale units
1567 height - height of a pixel in physical scale units
1568 (width and height are strings like "2.54")
1570 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1571 info_ptr, &unknowns)
1572 unknowns - array of png_unknown_chunk
1573 structures holding unknown chunks
1574 unknowns[i].name - name of unknown chunk
1575 unknowns[i].data - data of unknown chunk
1576 unknowns[i].size - size of unknown chunk's data
1577 unknowns[i].location - position of chunk in file
1579 The value of "i" corresponds to the order in which the
1580 chunks were read from the PNG file or inserted with the
1581 png_set_unknown_chunks() function.
1583 The data from the pHYs chunk can be retrieved in several convenient
1586 res_x = png_get_x_pixels_per_meter(png_ptr,
1588 res_y = png_get_y_pixels_per_meter(png_ptr,
1590 res_x_and_y = png_get_pixels_per_meter(png_ptr,
1592 res_x = png_get_x_pixels_per_inch(png_ptr,
1594 res_y = png_get_y_pixels_per_inch(png_ptr,
1596 res_x_and_y = png_get_pixels_per_inch(png_ptr,
1598 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
1601 (Each of these returns 0 [signifying "unknown"] if
1602 the data is not present or if res_x is 0;
1603 res_x_and_y is 0 if res_x != res_y)
1605 The data from the oFFs chunk can be retrieved in several convenient
1608 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1609 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1610 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1611 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1613 (Each of these returns 0 [signifying "unknown" if both
1614 x and y are 0] if the data is not present or if the
1615 chunk is present but the unit is the pixel)
1617 For more information, see the png_info definition in png.h and the
1618 PNG specification for chunk contents. Be careful with trusting
1619 rowbytes, as some of the transformations could increase the space
1620 needed to hold a row (expand, filler, gray_to_rgb, etc.).
1621 See png_read_update_info(), below.
1623 A quick word about text_ptr and num_text. PNG stores comments in
1624 keyword/text pairs, one pair per chunk, with no limit on the number
1625 of text chunks, and a 2^31 byte limit on their size. While there are
1626 suggested keywords, there is no requirement to restrict the use to these
1627 strings. It is strongly suggested that keywords and text be sensible
1628 to humans (that's the point), so don't use abbreviations. Non-printing
1629 symbols are not allowed. See the PNG specification for more details.
1630 There is also no requirement to have text after the keyword.
1632 Keywords should be limited to 79 Latin-1 characters without leading or
1633 trailing spaces, but non-consecutive spaces are allowed within the
1634 keyword. It is possible to have the same keyword any number of times.
1635 The text_ptr is an array of png_text structures, each holding a
1636 pointer to a language string, a pointer to a keyword and a pointer to
1637 a text string. The text string, language code, and translated
1638 keyword may be empty or NULL pointers. The keyword/text
1639 pairs are put into the array in the order that they are received.
1640 However, some or all of the text chunks may be after the image, so, to
1641 make sure you have read all the text chunks, don't mess with these
1642 until after you read the stuff after the image. This will be
1643 mentioned again below in the discussion that goes with png_read_end().
1645 .SS Input transformations
1647 After you've read the header information, you can set up the library
1648 to handle any special transformations of the image data. The various
1649 ways to transform the data will be described in the order that they
1650 should occur. This is important, as some of these change the color
1651 type and/or bit depth of the data, and some others only work on
1652 certain color types and bit depths. Even though each transformation
1653 checks to see if it has data that it can do something with, you should
1654 make sure to only enable a transformation if it will be valid for the
1655 data. For example, don't swap red and blue on grayscale data.
1657 The colors used for the background and transparency values should be
1658 supplied in the same format/depth as the current image data. They
1659 are stored in the same format/depth as the image data in a bKGD or tRNS
1660 chunk, so this is what libpng expects for this data. The colors are
1661 transformed to keep in sync with the image data when an application
1662 calls the png_read_update_info() routine (see below).
1664 Data will be decoded into the supplied row buffers packed into bytes
1665 unless the library has been told to transform it into another format.
1666 For example, 4 bit/pixel paletted or grayscale data will be returned
1667 2 pixels/byte with the leftmost pixel in the high-order bits of the
1668 byte, unless png_set_packing() is called. 8-bit RGB data will be stored
1669 in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
1670 is called to insert filler bytes, either before or after each RGB triplet.
1671 16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
1672 byte of the color value first, unless png_set_strip_16() is called to
1673 transform it to regular RGB RGB triplets, or png_set_filler() or
1674 png_set_add alpha() is called to insert filler bytes, either before or
1675 after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
1677 png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
1679 The following code transforms grayscale images of less than 8 to 8 bits,
1680 changes paletted images to RGB, and adds a full alpha channel if there is
1681 transparency information in a tRNS chunk. This is most useful on
1682 grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1683 viewing application that wishes to treat all images in the same way.
1685 if (color_type == PNG_COLOR_TYPE_PALETTE)
1686 png_set_palette_to_rgb(png_ptr);
1688 if (color_type == PNG_COLOR_TYPE_GRAY &&
1689 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
1691 if (png_get_valid(png_ptr, info_ptr,
1692 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1694 These three functions are actually aliases for png_set_expand(), added
1695 in libpng version 1.0.4, with the function names expanded to improve code
1696 readability. In some future version they may actually do different
1699 As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
1700 added. It expands the sample depth without changing tRNS to alpha.
1702 As of libpng version 1.2.44, not all possible expansions are supported.
1704 In the following table, the 01 means grayscale with depth<8, 31 means
1705 indexed with depth<8, other numerals represent the color type, "T" means
1706 the tRNS chunk is present, A means an alpha channel is present, and O
1707 means tRNS or alpha is present but all pixels in the image are opaque.
1709 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
1728 "-" means the transformation is not supported.
1729 "X" means the transformation is obtained by png_set_expand().
1730 "1" means the transformation is obtained by
1731 png_set_expand_gray_1_2_4_to_8
1732 "G" means the transformation is obtained by
1733 png_set_gray_to_rgb().
1734 "P" means the transformation is obtained by
1735 png_set_expand_palette_to_rgb().
1736 "T" means the transformation is obtained by
1737 png_set_tRNS_to_alpha().
1739 PNG can have files with 16 bits per channel. If you only can handle
1740 8 bits per channel, this will strip the pixels down to 8 bit.
1742 if (bit_depth == 16)
1743 png_set_strip_16(png_ptr);
1745 If, for some reason, you don't need the alpha channel on an image,
1746 and you want to remove it rather than combining it with the background
1747 (but the image author certainly had in mind that you *would* combine
1748 it with the background, so that's what you should probably do):
1750 if (color_type & PNG_COLOR_MASK_ALPHA)
1751 png_set_strip_alpha(png_ptr);
1753 In PNG files, the alpha channel in an image
1754 is the level of opacity. If you need the alpha channel in an image to
1755 be the level of transparency instead of opacity, you can invert the
1756 alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1757 fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1758 images) is fully transparent, with
1760 png_set_invert_alpha(png_ptr);
1762 The PNG format only supports pixels with postmultiplied alpha.
1763 If you want to replace the pixels, after reading them, with pixels
1764 that have premultiplied color samples, you can do this with
1766 png_set_premultiply_alpha(png_ptr);
1768 If you do this, any input with a tRNS chunk will be expanded to
1769 have an alpha channel.
1771 PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1772 they can, resulting in, for example, 8 pixels per byte for 1 bit
1773 files. This code expands to 1 pixel per byte without changing the
1774 values of the pixels:
1777 png_set_packing(png_ptr);
1779 PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1780 stored in a PNG image have been "scaled" or "shifted" up to the next
1781 higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
1782 to 8 bits/sample in the range [0, 255]). However, it is also possible
1783 to convert the PNG pixel data back to the original bit depth of the
1784 image. This call reduces the pixels back down to the original bit depth:
1786 png_color_8p sig_bit;
1788 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1789 png_set_shift(png_ptr, sig_bit);
1791 PNG files store 3-color pixels in red, green, blue order. This code
1792 changes the storage of the pixels to blue, green, red:
1794 if (color_type == PNG_COLOR_TYPE_RGB ||
1795 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1796 png_set_bgr(png_ptr);
1798 PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
1799 into 4 or 8 bytes for windowing systems that need them in this format:
1801 if (color_type == PNG_COLOR_TYPE_RGB)
1802 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
1804 where "filler" is the 8 or 16-bit number to fill with, and the location is
1805 either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1806 you want the filler before the RGB or after. This transformation
1807 does not affect images that already have full alpha channels. To add an
1808 opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
1809 will generate RGBA pixels.
1811 Note that png_set_filler() does not change the color type. If you want
1812 to do that, you can add a true alpha channel with
1814 if (color_type == PNG_COLOR_TYPE_RGB ||
1815 color_type == PNG_COLOR_TYPE_GRAY)
1816 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
1818 where "filler" contains the alpha value to assign to each pixel.
1819 This function was added in libpng-1.2.7.
1821 If you are reading an image with an alpha channel, and you need the
1822 data as ARGB instead of the normal PNG format RGBA:
1824 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1825 png_set_swap_alpha(png_ptr);
1827 For some uses, you may want a grayscale image to be represented as
1828 RGB. This code will do that conversion:
1830 if (color_type == PNG_COLOR_TYPE_GRAY ||
1831 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1832 png_set_gray_to_rgb(png_ptr);
1834 Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
1837 if (color_type == PNG_COLOR_TYPE_RGB ||
1838 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1839 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1840 int red_weight, int green_weight);
1842 error_action = 1: silently do the conversion
1843 error_action = 2: issue a warning if the original
1844 image has any pixel where
1845 red != green or red != blue
1846 error_action = 3: issue an error and abort the
1847 conversion if the original
1848 image has any pixel where
1849 red != green or red != blue
1851 red_weight: weight of red component times 100000
1852 green_weight: weight of green component times 100000
1853 If either weight is negative, default
1854 weights (21268, 71514) are used.
1856 If you have set error_action = 1 or 2, you can
1857 later check whether the image really was gray, after processing
1858 the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1859 It will return a png_byte that is zero if the image was gray or
1860 1 if there were any non-gray pixels. bKGD and sBIT data
1861 will be silently converted to grayscale, using the green channel
1862 data, regardless of the error_action setting.
1864 With red_weight+green_weight<=100000,
1865 the normalized graylevel is computed:
1867 int rw = red_weight * 65536;
1868 int gw = green_weight * 65536;
1869 int bw = 65536 - (rw + gw);
1870 gray = (rw*red + gw*green + bw*blue)/65536;
1872 The default values approximate those recommended in the Charles
1873 Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
1874 Copyright (c) 1998-01-04 Charles Poynton <poynton at inforamp.net>
1876 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1878 Libpng approximates this with
1880 Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
1882 which can be expressed with integers as
1884 Y = (6969 * R + 23434 * G + 2365 * B)/32768
1886 The calculation is done in a linear colorspace, if the image gamma
1889 If you have a grayscale and you are using png_set_expand_depth(),
1890 png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
1891 a higher bit-depth, you must either supply the background color as a gray
1892 value at the original file bit-depth (need_expand = 1) or else supply the
1893 background color as an RGB triplet at the final, expanded bit depth
1894 (need_expand = 0). Similarly, if you are reading a paletted image, you
1895 must either supply the background color as a palette index (need_expand = 1)
1896 or as an RGB triplet that may or may not be in the palette (need_expand = 0).
1898 png_color_16 my_background;
1899 png_color_16p image_background;
1901 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1902 png_set_background(png_ptr, image_background,
1903 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
1905 png_set_background(png_ptr, &my_background,
1906 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1908 The png_set_background() function tells libpng to composite images
1909 with alpha or simple transparency against the supplied background
1910 color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1911 you may use this color, or supply another color more suitable for
1912 the current display (e.g., the background color from a web page). You
1913 need to tell libpng whether the color is in the gamma space of the
1914 display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
1915 (PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
1916 that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
1917 know why anyone would use this, but it's here).
1919 To properly display PNG images on any kind of system, the application needs
1920 to know what the display gamma is. Ideally, the user will know this, and
1921 the application will allow them to set it. One method of allowing the user
1922 to set the display gamma separately for each system is to check for a
1923 SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
1926 Note that display_gamma is the overall gamma correction required to produce
1927 pleasing results, which depends on the lighting conditions in the surrounding
1928 environment. In a dim or brightly lit room, no compensation other than
1929 the physical gamma exponent of the monitor is needed, while in a dark room
1930 a slightly smaller exponent is better.
1932 double gamma, screen_gamma;
1934 if (/* We have a user-defined screen
1937 screen_gamma = user_defined_screen_gamma;
1939 /* One way that applications can share the same
1940 screen gamma value */
1941 else if ((gamma_str = getenv("SCREEN_GAMMA"))
1944 screen_gamma = (double)atof(gamma_str);
1946 /* If we don't have another value */
1949 screen_gamma = 2.2; /* A good guess for a
1950 PC monitor in a bright office or a dim room */
1951 screen_gamma = 2.0; /* A good guess for a
1952 PC monitor in a dark room */
1953 screen_gamma = 1.7 or 1.0; /* A good
1954 guess for Mac systems */
1957 The png_set_gamma() function handles gamma transformations of the data.
1958 Pass both the file gamma and the current screen_gamma. If the file does
1959 not have a gamma value, you can pass one anyway if you have an idea what
1960 it is (usually 0.45455 is a good guess for GIF images on PCs). Note
1961 that file gammas are inverted from screen gammas. See the discussions
1962 on gamma in the PNG specification for an excellent description of what
1963 gamma is, and why all applications should support it. It is strongly
1964 recommended that PNG viewers support gamma correction.
1966 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
1967 png_set_gamma(png_ptr, screen_gamma, gamma);
1969 png_set_gamma(png_ptr, screen_gamma, 0.45455);
1971 If you need to reduce an RGB file to a paletted file, or if a paletted
1972 file has more entries then will fit on your screen, png_set_dither()
1973 will do that. Note that this is a simple match dither that merely
1974 finds the closest color available. This should work fairly well with
1975 optimized palettes, and fairly badly with linear color cubes. If you
1976 pass a palette that is larger then maximum_colors, the file will
1977 reduce the number of colors in the palette so it will fit into
1978 maximum_colors. If there is a histogram, it will use it to make
1979 more intelligent choices when reducing the palette. If there is no
1980 histogram, it may not do as good a job.
1982 if (color_type & PNG_COLOR_MASK_COLOR)
1984 if (png_get_valid(png_ptr, info_ptr,
1987 png_uint_16p histogram = NULL;
1989 png_get_hIST(png_ptr, info_ptr,
1991 png_set_dither(png_ptr, palette, num_palette,
1992 max_screen_colors, histogram, 1);
1996 png_color std_color_cube[MAX_SCREEN_COLORS] =
1999 png_set_dither(png_ptr, std_color_cube,
2000 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2005 PNG files describe monochrome as black being zero and white being one.
2006 The following code will reverse this (make black be one and white be
2009 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2010 png_set_invert_mono(png_ptr);
2012 This function can also be used to invert grayscale and gray-alpha images:
2014 if (color_type == PNG_COLOR_TYPE_GRAY ||
2015 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2016 png_set_invert_mono(png_ptr);
2018 PNG files store 16 bit pixels in network byte order (big-endian,
2019 ie. most significant bits first). This code changes the storage to the
2020 other way (little-endian, i.e. least significant bits first, the
2021 way PCs store them):
2023 if (bit_depth == 16)
2024 png_set_swap(png_ptr);
2026 If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2027 need to change the order the pixels are packed into bytes, you can use:
2030 png_set_packswap(png_ptr);
2032 Finally, you can write your own transformation function if none of
2033 the existing ones meets your needs. This is done by setting a callback
2036 png_set_read_user_transform_fn(png_ptr,
2039 You must supply the function
2041 void read_transform_fn(png_ptr ptr, row_info_ptr
2042 row_info, png_bytep data)
2044 See pngtest.c for a working example. Your function will be called
2045 after all of the other transformations have been processed.
2047 You can also set up a pointer to a user structure for use by your
2048 callback function, and you can inform libpng that your transform
2049 function will change the number of channels or bit depth with the
2052 png_set_user_transform_info(png_ptr, user_ptr,
2053 user_depth, user_channels);
2055 The user's application, not libpng, is responsible for allocating and
2056 freeing any memory required for the user structure.
2058 You can retrieve the pointer via the function
2059 png_get_user_transform_ptr(). For example:
2061 voidp read_user_transform_ptr =
2062 png_get_user_transform_ptr(png_ptr);
2064 The last thing to handle is interlacing; this is covered in detail below,
2065 but you must call the function here if you want libpng to handle expansion
2066 of the interlaced image.
2068 number_of_passes = png_set_interlace_handling(png_ptr);
2070 After setting the transformations, libpng can update your png_info
2071 structure to reflect any transformations you've requested with this
2072 call. This is most useful to update the info structure's rowbytes
2073 field so you can use it to allocate your image memory. This function
2074 will also update your palette with the correct screen_gamma and
2075 background if these have been given with the calls above.
2077 png_read_update_info(png_ptr, info_ptr);
2079 After you call png_read_update_info(), you can allocate any
2080 memory you need to hold the image. The row data is simply
2081 raw byte data for all forms of images. As the actual allocation
2082 varies among applications, no example will be given. If you
2083 are allocating one large chunk, you will need to build an
2084 array of pointers to each row, as it will be needed for some
2085 of the functions below.
2087 .SS Reading image data
2089 After you've allocated memory, you can read the image data.
2090 The simplest way to do this is in one function call. If you are
2091 allocating enough memory to hold the whole image, you can just
2092 call png_read_image() and libpng will read in all the image data
2093 and put it in the memory area supplied. You will need to pass in
2094 an array of pointers to each row.
2096 This function automatically handles interlacing, so you don't need
2097 to call png_set_interlace_handling() or call this function multiple
2098 times, or any of that other stuff necessary with png_read_rows().
2100 png_read_image(png_ptr, row_pointers);
2102 where row_pointers is:
2104 png_bytep row_pointers[height];
2106 You can point to void or char or whatever you use for pixels.
2108 If you don't want to read in the whole image at once, you can
2109 use png_read_rows() instead. If there is no interlacing (check
2110 interlace_type == PNG_INTERLACE_NONE), this is simple:
2112 png_read_rows(png_ptr, row_pointers, NULL,
2115 where row_pointers is the same as in the png_read_image() call.
2117 If you are doing this just one row at a time, you can do this with
2118 a single row_pointer instead of an array of row_pointers:
2120 png_bytep row_pointer = row;
2121 png_read_row(png_ptr, row_pointer, NULL);
2123 If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2124 get somewhat harder. The only current (PNG Specification version 1.2)
2125 interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
2126 is a somewhat complicated 2D interlace scheme, known as Adam7, that
2127 breaks down an image into seven smaller images of varying size, based
2130 libpng can fill out those images or it can give them to you "as is".
2131 If you want them filled out, there are two ways to do that. The one
2132 mentioned in the PNG specification is to expand each pixel to cover
2133 those pixels that have not been read yet (the "rectangle" method).
2134 This results in a blocky image for the first pass, which gradually
2135 smooths out as more pixels are read. The other method is the "sparkle"
2136 method, where pixels are drawn only in their final locations, with the
2137 rest of the image remaining whatever colors they were initialized to
2138 before the start of the read. The first method usually looks better,
2139 but tends to be slower, as there are more pixels to put in the rows.
2141 If you don't want libpng to handle the interlacing details, just call
2142 png_read_rows() seven times to read in all seven images. Each of the
2143 images is a valid image by itself, or they can all be combined on an
2144 8x8 grid to form a single image (although if you intend to combine them
2145 you would be far better off using the libpng interlace handling).
2147 The first pass will return an image 1/8 as wide as the entire image
2148 (every 8th column starting in column 0) and 1/8 as high as the original
2149 (every 8th row starting in row 0), the second will be 1/8 as wide
2150 (starting in column 4) and 1/8 as high (also starting in row 0). The
2151 third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
2152 1/8 as high (every 8th row starting in row 4), and the fourth pass will
2153 be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
2154 and every 4th row starting in row 0). The fifth pass will return an
2155 image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
2156 while the sixth pass will be 1/2 as wide and 1/2 as high as the original
2157 (starting in column 1 and row 0). The seventh and final pass will be as
2158 wide as the original, and 1/2 as high, containing all of the odd
2159 numbered scanlines. Phew!
2161 If you want libpng to expand the images, call this before calling
2162 png_start_read_image() or png_read_update_info():
2164 if (interlace_type == PNG_INTERLACE_ADAM7)
2166 = png_set_interlace_handling(png_ptr);
2168 This will return the number of passes needed. Currently, this
2169 is seven, but may change if another interlace type is added.
2170 This function can be called even if the file is not interlaced,
2171 where it will return one pass.
2173 If you are not going to display the image after each pass, but are
2174 going to wait until the entire image is read in, use the sparkle
2175 effect. This effect is faster and the end result of either method
2176 is exactly the same. If you are planning on displaying the image
2177 after each pass, the "rectangle" effect is generally considered the
2180 If you only want the "sparkle" effect, just call png_read_rows() as
2181 normal, with the third parameter NULL. Make sure you make pass over
2182 the image number_of_passes times, and you don't change the data in the
2183 rows between calls. You can change the locations of the data, just
2184 not the data. Each pass only writes the pixels appropriate for that
2185 pass, and assumes the data from previous passes is still valid.
2187 png_read_rows(png_ptr, row_pointers, NULL,
2190 If you only want the first effect (the rectangles), do the same as
2191 before except pass the row buffer in the third parameter, and leave
2192 the second parameter NULL.
2194 png_read_rows(png_ptr, NULL, row_pointers,
2197 .SS Finishing a sequential read
2199 After you are finished reading the image through the
2200 low-level interface, you can finish reading the file. If you are
2201 interested in comments or time, which may be stored either before or
2202 after the image data, you should pass the separate png_info struct if
2203 you want to keep the comments from before and after the image
2204 separate. If you are not interested, you can pass NULL.
2206 png_read_end(png_ptr, end_info);
2208 When you are done, you can free all memory allocated by libpng like this:
2210 png_destroy_read_struct(&png_ptr, &info_ptr,
2213 It is also possible to individually free the info_ptr members that
2214 point to libpng-allocated storage with the following function:
2216 png_free_data(png_ptr, info_ptr, mask, seq)
2217 mask - identifies data to be freed, a mask
2218 containing the bitwise OR of one or
2220 PNG_FREE_PLTE, PNG_FREE_TRNS,
2221 PNG_FREE_HIST, PNG_FREE_ICCP,
2222 PNG_FREE_PCAL, PNG_FREE_ROWS,
2223 PNG_FREE_SCAL, PNG_FREE_SPLT,
2224 PNG_FREE_TEXT, PNG_FREE_UNKN,
2225 or simply PNG_FREE_ALL
2226 seq - sequence number of item to be freed
2229 This function may be safely called when the relevant storage has
2230 already been freed, or has not yet been allocated, or was allocated
2231 by the user and not by libpng, and will in those cases do nothing.
2232 The "seq" parameter is ignored if only one item of the selected data
2233 type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
2234 are allowed for the data type identified in the mask, such as text or
2235 sPLT, only the n'th item in the structure is freed, where n is "seq".
2237 The default behavior is only to free data that was allocated internally
2238 by libpng. This can be changed, so that libpng will not free the data,
2239 or so that it will free data that was allocated by the user with png_malloc()
2240 or png_zalloc() and passed in via a png_set_*() function, with
2242 png_data_freer(png_ptr, info_ptr, freer, mask)
2243 mask - which data elements are affected
2244 same choices as in png_free_data()
2246 PNG_DESTROY_WILL_FREE_DATA
2247 PNG_SET_WILL_FREE_DATA
2248 PNG_USER_WILL_FREE_DATA
2250 This function only affects data that has already been allocated.
2251 You can call this function after reading the PNG data but before calling
2252 any png_set_*() functions, to control whether the user or the png_set_*()
2253 function is responsible for freeing any existing data that might be present,
2254 and again after the png_set_*() functions to control whether the user
2255 or png_destroy_*() is supposed to free the data. When the user assumes
2256 responsibility for libpng-allocated data, the application must use
2257 png_free() to free it, and when the user transfers responsibility to libpng
2258 for data that the user has allocated, the user must have used png_malloc()
2259 or png_zalloc() to allocate it.
2261 If you allocated your row_pointers in a single block, as suggested above in
2262 the description of the high level read interface, you must not transfer
2263 responsibility for freeing it to the png_set_rows or png_read_destroy function,
2264 because they would also try to free the individual row_pointers[i].
2266 If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2267 separately, do not transfer responsibility for freeing text_ptr to libpng,
2268 because when libpng fills a png_text structure it combines these members with
2269 the key member, and png_free_data() will free only text_ptr.key. Similarly,
2270 if you transfer responsibility for free'ing text_ptr from libpng to your
2271 application, your application must not separately free those members.
2273 The png_free_data() function will turn off the "valid" flag for anything
2274 it frees. If you need to turn the flag off for a chunk that was freed by
2275 your application instead of by libpng, you can use
2277 png_set_invalid(png_ptr, info_ptr, mask);
2278 mask - identifies the chunks to be made invalid,
2279 containing the bitwise OR of one or
2281 PNG_INFO_gAMA, PNG_INFO_sBIT,
2282 PNG_INFO_cHRM, PNG_INFO_PLTE,
2283 PNG_INFO_tRNS, PNG_INFO_bKGD,
2284 PNG_INFO_hIST, PNG_INFO_pHYs,
2285 PNG_INFO_oFFs, PNG_INFO_tIME,
2286 PNG_INFO_pCAL, PNG_INFO_sRGB,
2287 PNG_INFO_iCCP, PNG_INFO_sPLT,
2288 PNG_INFO_sCAL, PNG_INFO_IDAT
2290 For a more compact example of reading a PNG image, see the file example.c.
2292 .SS Reading PNG files progressively
2294 The progressive reader is slightly different then the non-progressive
2295 reader. Instead of calling png_read_info(), png_read_rows(), and
2296 png_read_end(), you make one call to png_process_data(), which calls
2297 callbacks when it has the info, a row, or the end of the image. You
2298 set up these callbacks with png_set_progressive_read_fn(). You don't
2299 have to worry about the input/output functions of libpng, as you are
2300 giving the library the data directly in png_process_data(). I will
2301 assume that you have read the section on reading PNG files above,
2302 so I will only highlight the differences (although I will show
2305 png_structp png_ptr;
2308 /* An example code fragment of how you would
2309 initialize the progressive reader in your
2312 initialize_png_reader()
2314 png_ptr = png_create_read_struct
2315 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2316 user_error_fn, user_warning_fn);
2319 info_ptr = png_create_info_struct(png_ptr);
2322 png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
2327 if (setjmp(png_jmpbuf(png_ptr)))
2329 png_destroy_read_struct(&png_ptr, &info_ptr,
2334 /* This one's new. You can provide functions
2335 to be called when the header info is valid,
2336 when each row is completed, and when the image
2337 is finished. If you aren't using all functions,
2338 you can specify NULL parameters. Even when all
2339 three functions are NULL, you need to call
2340 png_set_progressive_read_fn(). You can use
2341 any struct as the user_ptr (cast to a void pointer
2342 for the function call), and retrieve the pointer
2343 from inside the callbacks using the function
2345 png_get_progressive_ptr(png_ptr);
2347 which will return a void pointer, which you have
2348 to cast appropriately.
2350 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
2351 info_callback, row_callback, end_callback);
2356 /* A code fragment that you call as you receive blocks
2359 process_data(png_bytep buffer, png_uint_32 length)
2361 if (setjmp(png_jmpbuf(png_ptr)))
2363 png_destroy_read_struct(&png_ptr, &info_ptr,
2368 /* This one's new also. Simply give it a chunk
2369 of data from the file stream (in order, of
2370 course). On machines with segmented memory
2371 models machines, don't give it any more than
2372 64K. The library seems to run fine with sizes
2373 of 4K. Although you can give it much less if
2374 necessary (I assume you can give it chunks of
2375 1 byte, I haven't tried less then 256 bytes
2376 yet). When this function returns, you may
2377 want to display any rows that were generated
2378 in the row callback if you don't already do
2381 png_process_data(png_ptr, info_ptr, buffer, length);
2385 /* This function is called (as set by
2386 png_set_progressive_read_fn() above) when enough data
2387 has been supplied so all of the header has been
2391 info_callback(png_structp png_ptr, png_infop info)
2393 /* Do any setup here, including setting any of
2394 the transformations mentioned in the Reading
2395 PNG files section. For now, you _must_ call
2396 either png_start_read_image() or
2397 png_read_update_info() after all the
2398 transformations are set (even if you don't set
2399 any). You may start getting rows before
2400 png_process_data() returns, so this is your
2401 last chance to prepare for that.
2405 /* This function is called when each row of image
2408 row_callback(png_structp png_ptr, png_bytep new_row,
2409 png_uint_32 row_num, int pass)
2411 /* If the image is interlaced, and you turned
2412 on the interlace handler, this function will
2413 be called for every row in every pass. Some
2414 of these rows will not be changed from the
2415 previous pass. When the row is not changed,
2416 the new_row variable will be NULL. The rows
2417 and passes are called in order, so you don't
2418 really need the row_num and pass, but I'm
2419 supplying them because it may make your life
2422 For the non-NULL rows of interlaced images,
2423 you must call png_progressive_combine_row()
2424 passing in the row and the old row. You can
2425 call this function for NULL rows (it will just
2426 return) and for non-interlaced images (it just
2427 does the memcpy for you) if it will make the
2428 code easier. Thus, you can just do this for
2432 png_progressive_combine_row(png_ptr, old_row,
2435 /* where old_row is what was displayed for
2436 previously for the row. Note that the first
2437 pass (pass == 0, really) will completely cover
2438 the old row, so the rows do not have to be
2439 initialized. After the first pass (and only
2440 for interlaced images), you will have to pass
2441 the current row, and the function will combine
2442 the old row and the new row.
2447 end_callback(png_structp png_ptr, png_infop info)
2449 /* This function is called after the whole image
2450 has been read, including any chunks after the
2451 image (up to and including the IEND). You
2452 will usually have the same info chunk as you
2453 had in the header, although some data may have
2454 been added to the comments and time fields.
2456 Most people won't do much here, perhaps setting
2457 a flag that marks the image as finished.
2465 Much of this is very similar to reading. However, everything of
2466 importance is repeated here, so you won't have to constantly look
2467 back up in the reading section to understand writing.
2471 You will want to do the I/O initialization before you get into libpng,
2472 so if it doesn't work, you don't have anything to undo. If you are not
2473 using the standard I/O functions, you will need to replace them with
2474 custom writing functions. See the discussion under Customizing libpng.
2476 FILE *fp = fopen(file_name, "wb");
2482 Next, png_struct and png_info need to be allocated and initialized.
2483 As these can be both relatively large, you may not want to store these
2484 on the stack, unless you have stack space to spare. Of course, you
2485 will want to check if they return NULL. If you are also reading,
2486 you won't want to name your read structure and your write structure
2487 both "png_ptr"; you can call them anything you like, such as
2488 "read_ptr" and "write_ptr". Look at pngtest.c, for example.
2490 png_structp png_ptr = png_create_write_struct
2491 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2492 user_error_fn, user_warning_fn);
2496 png_infop info_ptr = png_create_info_struct(png_ptr);
2499 png_destroy_write_struct(&png_ptr,
2504 If you want to use your own memory allocation routines,
2505 define PNG_USER_MEM_SUPPORTED and use
2506 png_create_write_struct_2() instead of png_create_write_struct():
2508 png_structp png_ptr = png_create_write_struct_2
2509 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2510 user_error_fn, user_warning_fn, (png_voidp)
2511 user_mem_ptr, user_malloc_fn, user_free_fn);
2513 After you have these structures, you will need to set up the
2514 error handling. When libpng encounters an error, it expects to
2515 longjmp() back to your routine. Therefore, you will need to call
2516 setjmp() and pass the png_jmpbuf(png_ptr). If you
2517 write the file from different routines, you will need to update
2518 the png_jmpbuf(png_ptr) every time you enter a new routine that will
2519 call a png_*() function. See your documentation of setjmp/longjmp
2520 for your compiler for more information on setjmp/longjmp. See
2521 the discussion on libpng error handling in the Customizing Libpng
2522 section below for more information on the libpng error handling.
2524 if (setjmp(png_jmpbuf(png_ptr)))
2526 png_destroy_write_struct(&png_ptr, &info_ptr);
2533 If you would rather avoid the complexity of setjmp/longjmp issues,
2534 you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
2535 errors will result in a call to PNG_ABORT() which defaults to abort().
2537 Now you need to set up the output code. The default for libpng is to
2538 use the C function fwrite(). If you use this, you will need to pass a
2539 valid FILE * in the function png_init_io(). Be sure that the file is
2540 opened in binary mode. Again, if you wish to handle writing data in
2541 another way, see the discussion on libpng I/O handling in the Customizing
2542 Libpng section below.
2544 png_init_io(png_ptr, fp);
2546 If you are embedding your PNG into a datastream such as MNG, and don't
2547 want libpng to write the 8-byte signature, or if you have already
2548 written the signature in your application, use
2550 png_set_sig_bytes(png_ptr, 8);
2552 to inform libpng that it should not write a signature.
2556 At this point, you can set up a callback function that will be
2557 called after each row has been written, which you can use to control
2558 a progress meter or the like. It's demonstrated in pngtest.c.
2559 You must supply a function
2561 void write_row_callback(png_ptr, png_uint_32 row,
2564 /* put your code here */
2567 (You can give it another name that you like instead of "write_row_callback")
2569 To inform libpng about your function, use
2571 png_set_write_status_fn(png_ptr, write_row_callback);
2573 You now have the option of modifying how the compression library will
2574 run. The following functions are mainly for testing, but may be useful
2575 in some cases, like if you need to write PNG files extremely fast and
2576 are willing to give up some compression, or if you want to get the
2577 maximum possible compression at the expense of slower writing. If you
2578 have no special needs in this area, let the library do what it wants by
2579 not calling this function at all, as it has been tuned to deliver a good
2580 speed/compression ratio. The second parameter to png_set_filter() is
2581 the filter method, for which the only valid values are 0 (as of the
2582 July 1999 PNG specification, version 1.2) or 64 (if you are writing
2583 a PNG datastream that is to be embedded in a MNG datastream). The third
2584 parameter is a flag that indicates which filter type(s) are to be tested
2585 for each scanline. See the PNG specification for details on the specific
2589 /* turn on or off filtering, and/or choose
2590 specific filters. You can use either a single
2591 PNG_FILTER_VALUE_NAME or the bitwise OR of one
2592 or more PNG_FILTER_NAME masks. */
2593 png_set_filter(png_ptr, 0,
2594 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
2595 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
2596 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
2597 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
2598 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
2602 wants to start and stop using particular filters during compression,
2603 it should start out with all of the filters (to ensure that the previous
2604 row of pixels will be stored in case it's needed later), and then add
2605 and remove them after the start of compression.
2607 If you are writing a PNG datastream that is to be embedded in a MNG
2608 datastream, the second parameter can be either 0 or 64.
2610 The png_set_compression_*() functions interface to the zlib compression
2611 library, and should mostly be ignored unless you really know what you are
2612 doing. The only generally useful call is png_set_compression_level()
2613 which changes how much time zlib spends on trying to compress the image
2614 data. See the Compression Library (zlib.h and algorithm.txt, distributed
2615 with zlib) for details on the compression levels.
2617 /* set the zlib compression level */
2618 png_set_compression_level(png_ptr,
2619 Z_BEST_COMPRESSION);
2621 /* set other zlib parameters */
2622 png_set_compression_mem_level(png_ptr, 8);
2623 png_set_compression_strategy(png_ptr,
2624 Z_DEFAULT_STRATEGY);
2625 png_set_compression_window_bits(png_ptr, 15);
2626 png_set_compression_method(png_ptr, 8);
2627 png_set_compression_buffer_size(png_ptr, 8192)
2629 extern PNG_EXPORT(void,png_set_zbuf_size)
2631 .SS Setting the contents of info for output
2633 You now need to fill in the png_info structure with all the data you
2634 wish to write before the actual image. Note that the only thing you
2635 are allowed to write after the image is the text chunks and the time
2636 chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
2637 the latest PNG specification for more information on that. If you
2638 wish to write them before the image, fill them in now, and flag that
2639 data as being valid. If you want to wait until after the data, don't
2640 fill them until png_write_end(). For all the fields in png_info and
2641 their data types, see png.h. For explanations of what the fields
2642 contain, see the PNG specification.
2644 Some of the more important parts of the png_info are:
2646 png_set_IHDR(png_ptr, info_ptr, width, height,
2647 bit_depth, color_type, interlace_type,
2648 compression_type, filter_method)
2649 width - holds the width of the image
2650 in pixels (up to 2^31).
2651 height - holds the height of the image
2652 in pixels (up to 2^31).
2653 bit_depth - holds the bit depth of one of the
2655 (valid values are 1, 2, 4, 8, 16
2656 and depend also on the
2657 color_type. See also significant
2659 color_type - describes which color/alpha
2660 channels are present.
2662 (bit depths 1, 2, 4, 8, 16)
2663 PNG_COLOR_TYPE_GRAY_ALPHA
2665 PNG_COLOR_TYPE_PALETTE
2666 (bit depths 1, 2, 4, 8)
2669 PNG_COLOR_TYPE_RGB_ALPHA
2672 PNG_COLOR_MASK_PALETTE
2673 PNG_COLOR_MASK_COLOR
2674 PNG_COLOR_MASK_ALPHA
2676 interlace_type - PNG_INTERLACE_NONE or
2678 compression_type - (must be
2679 PNG_COMPRESSION_TYPE_DEFAULT)
2680 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
2681 or, if you are writing a PNG to
2682 be embedded in a MNG datastream,
2684 PNG_INTRAPIXEL_DIFFERENCING)
2686 If you call png_set_IHDR(), the call must appear before any of the
2687 other png_set_*() functions, because they might require access to some of
2688 the IHDR settings. The remaining png_set_*() functions can be called
2691 If you wish, you can reset the compression_type, interlace_type, or
2692 filter_method later by calling png_set_IHDR() again; if you do this, the
2693 width, height, bit_depth, and color_type must be the same in each call.
2695 png_set_PLTE(png_ptr, info_ptr, palette,
2697 palette - the palette for the file
2698 (array of png_color)
2699 num_palette - number of entries in the palette
2701 png_set_gAMA(png_ptr, info_ptr, gamma);
2702 gamma - the gamma the image was created
2705 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2706 srgb_intent - the rendering intent
2707 (PNG_INFO_sRGB) The presence of
2708 the sRGB chunk means that the pixel
2709 data is in the sRGB color space.
2710 This chunk also implies specific
2711 values of gAMA and cHRM. Rendering
2712 intent is the CSS-1 property that
2713 has been defined by the International
2715 (http://www.color.org).
2717 PNG_sRGB_INTENT_SATURATION,
2718 PNG_sRGB_INTENT_PERCEPTUAL,
2719 PNG_sRGB_INTENT_ABSOLUTE, or
2720 PNG_sRGB_INTENT_RELATIVE.
2723 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2725 srgb_intent - the rendering intent
2726 (PNG_INFO_sRGB) The presence of the
2727 sRGB chunk means that the pixel
2728 data is in the sRGB color space.
2729 This function also causes gAMA and
2730 cHRM chunks with the specific values
2731 that are consistent with sRGB to be
2734 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2736 name - The profile name.
2737 compression - The compression type; always
2738 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2739 You may give NULL to this argument to
2741 profile - International Color Consortium color
2742 profile data. May contain NULs.
2743 proflen - length of profile data in bytes.
2745 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2746 sig_bit - the number of significant bits for
2747 (PNG_INFO_sBIT) each of the gray, red,
2748 green, and blue channels, whichever are
2749 appropriate for the given color type
2752 png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
2754 trans - array of transparent
2755 entries for palette (PNG_INFO_tRNS)
2756 trans_values - graylevel or color sample values
2757 (in order red, green, blue) of the
2758 single transparent color for
2759 non-paletted images (PNG_INFO_tRNS)
2760 num_trans - number of transparent entries
2763 png_set_hIST(png_ptr, info_ptr, hist);
2765 hist - histogram of palette (array of
2768 png_set_tIME(png_ptr, info_ptr, mod_time);
2769 mod_time - time image was last modified
2772 png_set_bKGD(png_ptr, info_ptr, background);
2773 background - background color (PNG_VALID_bKGD)
2775 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2776 text_ptr - array of png_text holding image
2778 text_ptr[i].compression - type of compression used
2779 on "text" PNG_TEXT_COMPRESSION_NONE
2780 PNG_TEXT_COMPRESSION_zTXt
2781 PNG_ITXT_COMPRESSION_NONE
2782 PNG_ITXT_COMPRESSION_zTXt
2783 text_ptr[i].key - keyword for comment. Must contain
2785 text_ptr[i].text - text comments for current
2786 keyword. Can be NULL or empty.
2787 text_ptr[i].text_length - length of text string,
2788 after decompression, 0 for iTXt
2789 text_ptr[i].itxt_length - length of itxt string,
2790 after decompression, 0 for tEXt/zTXt
2791 text_ptr[i].lang - language of comment (NULL or
2793 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
2794 or empty for unknown).
2795 Note that the itxt_length, lang, and lang_key
2796 members of the text_ptr structure only exist
2797 when the library is built with iTXt chunk support.
2799 num_text - number of comments
2801 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
2803 palette_ptr - array of png_sPLT_struct structures
2804 to be added to the list of palettes
2805 in the info structure.
2806 num_spalettes - number of palette structures to be
2809 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2811 offset_x - positive offset from the left
2813 offset_y - positive offset from the top
2815 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2817 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2819 res_x - pixels/unit physical resolution
2821 res_y - pixels/unit physical resolution
2823 unit_type - PNG_RESOLUTION_UNKNOWN,
2824 PNG_RESOLUTION_METER
2826 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
2827 unit - physical scale units (an integer)
2828 width - width of a pixel in physical scale units
2829 height - height of a pixel in physical scale units
2830 (width and height are doubles)
2832 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
2833 unit - physical scale units (an integer)
2834 width - width of a pixel in physical scale units
2835 height - height of a pixel in physical scale units
2836 (width and height are strings like "2.54")
2838 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
2840 unknowns - array of png_unknown_chunk
2841 structures holding unknown chunks
2842 unknowns[i].name - name of unknown chunk
2843 unknowns[i].data - data of unknown chunk
2844 unknowns[i].size - size of unknown chunk's data
2845 unknowns[i].location - position to write chunk in file
2846 0: do not write chunk
2847 PNG_HAVE_IHDR: before PLTE
2848 PNG_HAVE_PLTE: before IDAT
2849 PNG_AFTER_IDAT: after IDAT
2851 The "location" member is set automatically according to
2852 what part of the output file has already been written.
2853 You can change its value after calling png_set_unknown_chunks()
2854 as demonstrated in pngtest.c. Within each of the "locations",
2855 the chunks are sequenced according to their position in the
2856 structure (that is, the value of "i", which is the order in which
2857 the chunk was either read from the input file or defined with
2858 png_set_unknown_chunks).
2860 A quick word about text and num_text. text is an array of png_text
2861 structures. num_text is the number of valid structures in the array.
2862 Each png_text structure holds a language code, a keyword, a text value,
2863 and a compression type.
2865 The compression types have the same valid numbers as the compression
2866 types of the image data. Currently, the only valid number is zero.
2867 However, you can store text either compressed or uncompressed, unlike
2868 images, which always have to be compressed. So if you don't want the
2869 text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
2870 Because tEXt and zTXt chunks don't have a language field, if you
2871 specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
2872 any language code or translated keyword will not be written out.
2874 Until text gets around 1000 bytes, it is not worth compressing it.
2875 After the text has been written out to the file, the compression type
2876 is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2877 so that it isn't written out again at the end (in case you are calling
2878 png_write_end() with the same struct.
2880 The keywords that are given in the PNG Specification are:
2882 Title Short (one line) title or
2884 Author Name of image's creator
2885 Description Description of image (possibly long)
2886 Copyright Copyright notice
2887 Creation Time Time of original image creation
2888 (usually RFC 1123 format, see below)
2889 Software Software used to create the image
2890 Disclaimer Legal disclaimer
2891 Warning Warning of nature of content
2892 Source Device used to create the image
2893 Comment Miscellaneous comment; conversion
2894 from other image format
2896 The keyword-text pairs work like this. Keywords should be short
2897 simple descriptions of what the comment is about. Some typical
2898 keywords are found in the PNG specification, as is some recommendations
2899 on keywords. You can repeat keywords in a file. You can even write
2900 some text before the image and some after. For example, you may want
2901 to put a description of the image before the image, but leave the
2902 disclaimer until after, so viewers working over modem connections
2903 don't have to wait for the disclaimer to go over the modem before
2904 they start seeing the image. Finally, keywords should be full
2905 words, not abbreviations. Keywords and text are in the ISO 8859-1
2906 (Latin-1) character set (a superset of regular ASCII) and can not
2907 contain NUL characters, and should not contain control or other
2908 unprintable characters. To make the comments widely readable, stick
2909 with basic ASCII, and avoid machine specific character set extensions
2910 like the IBM-PC character set. The keyword must be present, but
2911 you can leave off the text string on non-compressed pairs.
2912 Compressed pairs must have a text string, as only the text string
2913 is compressed anyway, so the compression would be meaningless.
2915 PNG supports modification time via the png_time structure. Two
2916 conversion routines are provided, png_convert_from_time_t() for
2917 time_t and png_convert_from_struct_tm() for struct tm. The
2918 time_t routine uses gmtime(). You don't have to use either of
2919 these, but if you wish to fill in the png_time structure directly,
2920 you should provide the time in universal time (GMT) if possible
2921 instead of your local time. Note that the year number is the full
2922 year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
2923 that months start with 1.
2925 If you want to store the time of the original image creation, you should
2926 use a plain tEXt chunk with the "Creation Time" keyword. This is
2927 necessary because the "creation time" of a PNG image is somewhat vague,
2928 depending on whether you mean the PNG file, the time the image was
2929 created in a non-PNG format, a still photo from which the image was
2930 scanned, or possibly the subject matter itself. In order to facilitate
2931 machine-readable dates, it is recommended that the "Creation Time"
2932 tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
2933 although this isn't a requirement. Unlike the tIME chunk, the
2934 "Creation Time" tEXt chunk is not expected to be automatically changed
2935 by the software. To facilitate the use of RFC 1123 dates, a function
2936 png_convert_to_rfc1123(png_timep) is provided to convert from PNG
2937 time to an RFC 1123 format string.
2939 .SS Writing unknown chunks
2941 You can use the png_set_unknown_chunks function to queue up chunks
2942 for writing. You give it a chunk name, raw data, and a size; that's
2943 all there is to it. The chunks will be written by the next following
2944 png_write_info_before_PLTE, png_write_info, or png_write_end function.
2945 Any chunks previously read into the info structure's unknown-chunk
2946 list will also be written out in a sequence that satisfies the PNG
2947 specification's ordering rules.
2949 .SS The high-level write interface
2951 At this point there are two ways to proceed; through the high-level
2952 write interface, or through a sequence of low-level write operations.
2953 You can use the high-level interface if your image data is present
2954 in the info structure. All defined output
2955 transformations are permitted, enabled by the following masks.
2957 PNG_TRANSFORM_IDENTITY No transformation
2958 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
2959 PNG_TRANSFORM_PACKSWAP Change order of packed
2961 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
2962 PNG_TRANSFORM_SHIFT Normalize pixels to the
2964 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
2966 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
2968 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
2970 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
2971 PNG_TRANSFORM_STRIP_FILLER Strip out filler
2973 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
2975 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
2978 If you have valid image data in the info structure (you can use
2979 png_set_rows() to put image data in the info structure), simply do this:
2981 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
2983 where png_transforms is an integer containing the bitwise OR of some set of
2984 transformation flags. This call is equivalent to png_write_info(),
2985 followed the set of transformations indicated by the transform mask,
2986 then png_write_image(), and finally png_write_end().
2988 (The final parameter of this call is not yet used. Someday it might point
2989 to transformation parameters required by some future output transform.)
2991 You must use png_transforms and not call any png_set_transform() functions
2992 when you use png_write_png().
2994 .SS The low-level write interface
2996 If you are going the low-level route instead, you are now ready to
2997 write all the file information up to the actual image data. You do
2998 this with a call to png_write_info().
3000 png_write_info(png_ptr, info_ptr);
3002 Note that there is one transformation you may need to do before
3003 png_write_info(). In PNG files, the alpha channel in an image is the
3004 level of opacity. If your data is supplied as a level of transparency,
3005 you can invert the alpha channel before you write it, so that 0 is
3006 fully transparent and 255 (in 8-bit or paletted images) or 65535
3007 (in 16-bit images) is fully opaque, with
3009 png_set_invert_alpha(png_ptr);
3011 This must appear before png_write_info() instead of later with the
3012 other transformations because in the case of paletted images the tRNS
3013 chunk data has to be inverted before the tRNS chunk is written. If
3014 your image is not a paletted image, the tRNS data (which in such cases
3015 represents a single color to be rendered as transparent) won't need to
3016 be changed, and you can safely do this transformation after your
3017 png_write_info() call.
3019 If you need to write a private chunk that you want to appear before
3020 the PLTE chunk when PLTE is present, you can write the PNG info in
3021 two steps, and insert code to write your own chunk between them:
3023 png_write_info_before_PLTE(png_ptr, info_ptr);
3024 png_set_unknown_chunks(png_ptr, info_ptr, ...);
3025 png_write_info(png_ptr, info_ptr);
3027 After you've written the file information, you can set up the library
3028 to handle any special transformations of the image data. The various
3029 ways to transform the data will be described in the order that they
3030 should occur. This is important, as some of these change the color
3031 type and/or bit depth of the data, and some others only work on
3032 certain color types and bit depths. Even though each transformation
3033 checks to see if it has data that it can do something with, you should
3034 make sure to only enable a transformation if it will be valid for the
3035 data. For example, don't swap red and blue on grayscale data.
3037 PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
3038 the library to strip input data that has 4 or 8 bytes per pixel down
3039 to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
3042 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
3044 where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
3045 PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
3046 is stored XRGB or RGBX.
3048 PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
3049 they can, resulting in, for example, 8 pixels per byte for 1 bit files.
3050 If the data is supplied at 1 pixel per byte, use this code, which will
3051 correctly pack the pixels into a single byte:
3053 png_set_packing(png_ptr);
3055 PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
3056 data is of another bit depth, you can write an sBIT chunk into the
3057 file so that decoders can recover the original data if desired.
3059 /* Set the true bit depth of the image data */
3060 if (color_type & PNG_COLOR_MASK_COLOR)
3062 sig_bit.red = true_bit_depth;
3063 sig_bit.green = true_bit_depth;
3064 sig_bit.blue = true_bit_depth;
3068 sig_bit.gray = true_bit_depth;
3070 if (color_type & PNG_COLOR_MASK_ALPHA)
3072 sig_bit.alpha = true_bit_depth;
3075 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
3077 If the data is stored in the row buffer in a bit depth other than
3078 one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
3079 this will scale the values to appear to be the correct bit depth as
3082 png_set_shift(png_ptr, &sig_bit);
3084 PNG files store 16 bit pixels in network byte order (big-endian,
3085 ie. most significant bits first). This code would be used if they are
3086 supplied the other way (little-endian, i.e. least significant bits
3087 first, the way PCs store them):
3090 png_set_swap(png_ptr);
3092 If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
3093 need to change the order the pixels are packed into bytes, you can use:
3096 png_set_packswap(png_ptr);
3098 PNG files store 3 color pixels in red, green, blue order. This code
3099 would be used if they are supplied as blue, green, red:
3101 png_set_bgr(png_ptr);
3103 PNG files describe monochrome as black being zero and white being
3104 one. This code would be used if the pixels are supplied with this reversed
3105 (black being one and white being zero):
3107 png_set_invert_mono(png_ptr);
3109 Finally, you can write your own transformation function if none of
3110 the existing ones meets your needs. This is done by setting a callback
3113 png_set_write_user_transform_fn(png_ptr,
3114 write_transform_fn);
3116 You must supply the function
3118 void write_transform_fn(png_ptr ptr, row_info_ptr
3119 row_info, png_bytep data)
3121 See pngtest.c for a working example. Your function will be called
3122 before any of the other transformations are processed.
3124 You can also set up a pointer to a user structure for use by your
3127 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
3129 The user_channels and user_depth parameters of this function are ignored
3130 when writing; you can set them to zero as shown.
3132 You can retrieve the pointer via the function png_get_user_transform_ptr().
3135 voidp write_user_transform_ptr =
3136 png_get_user_transform_ptr(png_ptr);
3138 It is possible to have libpng flush any pending output, either manually,
3139 or automatically after a certain number of lines have been written. To
3140 flush the output stream a single time call:
3142 png_write_flush(png_ptr);
3144 and to have libpng flush the output stream periodically after a certain
3145 number of scanlines have been written, call:
3147 png_set_flush(png_ptr, nrows);
3149 Note that the distance between rows is from the last time png_write_flush()
3150 was called, or the first row of the image if it has never been called.
3151 So if you write 50 lines, and then png_set_flush 25, it will flush the
3152 output on the next scanline, and every 25 lines thereafter, unless
3153 png_write_flush() is called before 25 more lines have been written.
3154 If nrows is too small (less than about 10 lines for a 640 pixel wide
3155 RGB image) the image compression may decrease noticeably (although this
3156 may be acceptable for real-time applications). Infrequent flushing will
3157 only degrade the compression performance by a few percent over images
3158 that do not use flushing.
3160 .SS Writing the image data
3162 That's it for the transformations. Now you can write the image data.
3163 The simplest way to do this is in one function call. If you have the
3164 whole image in memory, you can just call png_write_image() and libpng
3165 will write the image. You will need to pass in an array of pointers to
3166 each row. This function automatically handles interlacing, so you don't
3167 need to call png_set_interlace_handling() or call this function multiple
3168 times, or any of that other stuff necessary with png_write_rows().
3170 png_write_image(png_ptr, row_pointers);
3172 where row_pointers is:
3174 png_byte *row_pointers[height];
3176 You can point to void or char or whatever you use for pixels.
3178 If you don't want to write the whole image at once, you can
3179 use png_write_rows() instead. If the file is not interlaced,
3182 png_write_rows(png_ptr, row_pointers,
3185 row_pointers is the same as in the png_write_image() call.
3187 If you are just writing one row at a time, you can do this with
3188 a single row_pointer instead of an array of row_pointers:
3190 png_bytep row_pointer = row;
3192 png_write_row(png_ptr, row_pointer);
3194 When the file is interlaced, things can get a good deal more complicated.
3195 The only currently (as of the PNG Specification version 1.2, dated July
3196 1999) defined interlacing scheme for PNG files is the "Adam7" interlace
3197 scheme, that breaks down an image into seven smaller images of varying
3198 size. libpng will build these images for you, or you can do them
3199 yourself. If you want to build them yourself, see the PNG specification
3200 for details of which pixels to write when.
3202 If you don't want libpng to handle the interlacing details, just
3203 use png_set_interlace_handling() and call png_write_rows() the
3204 correct number of times to write all seven sub-images.
3206 If you want libpng to build the sub-images, call this before you start
3210 png_set_interlace_handling(png_ptr);
3212 This will return the number of passes needed. Currently, this is seven,
3213 but may change if another interlace type is added.
3215 Then write the complete image number_of_passes times.
3217 png_write_rows(png_ptr, row_pointers,
3220 As some of these rows are not used, and thus return immediately, you may
3221 want to read about interlacing in the PNG specification, and only update
3222 the rows that are actually used.
3224 .SS Finishing a sequential write
3226 After you are finished writing the image, you should finish writing
3227 the file. If you are interested in writing comments or time, you should
3228 pass an appropriately filled png_info pointer. If you are not interested,
3231 png_write_end(png_ptr, info_ptr);
3233 When you are done, you can free all memory used by libpng like this:
3235 png_destroy_write_struct(&png_ptr, &info_ptr);
3237 It is also possible to individually free the info_ptr members that
3238 point to libpng-allocated storage with the following function:
3240 png_free_data(png_ptr, info_ptr, mask, seq)
3241 mask - identifies data to be freed, a mask
3242 containing the bitwise OR of one or
3244 PNG_FREE_PLTE, PNG_FREE_TRNS,
3245 PNG_FREE_HIST, PNG_FREE_ICCP,
3246 PNG_FREE_PCAL, PNG_FREE_ROWS,
3247 PNG_FREE_SCAL, PNG_FREE_SPLT,
3248 PNG_FREE_TEXT, PNG_FREE_UNKN,
3249 or simply PNG_FREE_ALL
3250 seq - sequence number of item to be freed
3253 This function may be safely called when the relevant storage has
3254 already been freed, or has not yet been allocated, or was allocated
3255 by the user and not by libpng, and will in those cases do nothing.
3256 The "seq" parameter is ignored if only one item of the selected data
3257 type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3258 are allowed for the data type identified in the mask, such as text or
3259 sPLT, only the n'th item in the structure is freed, where n is "seq".
3261 If you allocated data such as a palette that you passed in to libpng
3262 with png_set_*, you must not free it until just before the call to
3263 png_destroy_write_struct().
3265 The default behavior is only to free data that was allocated internally
3266 by libpng. This can be changed, so that libpng will not free the data,
3267 or so that it will free data that was allocated by the user with png_malloc()
3268 or png_zalloc() and passed in via a png_set_*() function, with
3270 png_data_freer(png_ptr, info_ptr, freer, mask)
3271 mask - which data elements are affected
3272 same choices as in png_free_data()
3274 PNG_DESTROY_WILL_FREE_DATA
3275 PNG_SET_WILL_FREE_DATA
3276 PNG_USER_WILL_FREE_DATA
3278 For example, to transfer responsibility for some data from a read structure
3279 to a write structure, you could use
3281 png_data_freer(read_ptr, read_info_ptr,
3282 PNG_USER_WILL_FREE_DATA,
3283 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3284 png_data_freer(write_ptr, write_info_ptr,
3285 PNG_DESTROY_WILL_FREE_DATA,
3286 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3288 thereby briefly reassigning responsibility for freeing to the user but
3289 immediately afterwards reassigning it once more to the write_destroy
3290 function. Having done this, it would then be safe to destroy the read
3291 structure and continue to use the PLTE, tRNS, and hIST data in the write
3294 This function only affects data that has already been allocated.
3295 You can call this function before calling after the png_set_*() functions
3296 to control whether the user or png_destroy_*() is supposed to free the data.
3297 When the user assumes responsibility for libpng-allocated data, the
3298 application must use
3299 png_free() to free it, and when the user transfers responsibility to libpng
3300 for data that the user has allocated, the user must have used png_malloc()
3301 or png_zalloc() to allocate it.
3303 If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3304 separately, do not transfer responsibility for freeing text_ptr to libpng,
3305 because when libpng fills a png_text structure it combines these members with
3306 the key member, and png_free_data() will free only text_ptr.key. Similarly,
3307 if you transfer responsibility for free'ing text_ptr from libpng to your
3308 application, your application must not separately free those members.
3309 For a more compact example of writing a PNG image, see the file example.c.
3311 .SH V. Modifying/Customizing libpng:
3313 There are two issues here. The first is changing how libpng does
3314 standard things like memory allocation, input/output, and error handling.
3315 The second deals with more complicated things like adding new chunks,
3316 adding new transformations, and generally changing how libpng works.
3317 Both of those are compile-time issues; that is, they are generally
3318 determined at the time the code is written, and there is rarely a need
3319 to provide the user with a means of changing them.
3321 Memory allocation, input/output, and error handling
3323 All of the memory allocation, input/output, and error handling in libpng
3324 goes through callbacks that are user-settable. The default routines are
3325 in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
3326 these functions, call the appropriate png_set_*_fn() function.
3328 Memory allocation is done through the functions png_malloc(), png_calloc(),
3329 and png_free(). These currently just call the standard C functions.
3330 png_calloc() calls png_malloc() and then png_memset() to clear the newly
3331 allocated memory to zero. If your pointers can't access more then 64K
3332 at a time, you will want to set MAXSEG_64K in zlib.h. Since it is
3333 unlikely that the method of handling memory allocation on a platform
3334 will change between applications, these functions must be modified in
3335 the library at compile time. If you prefer to use a different method
3336 of allocating and freeing data, you can use png_create_read_struct_2() or
3337 png_create_write_struct_2() to register your own functions as described
3338 above. These functions also provide a void pointer that can be retrieved
3341 mem_ptr=png_get_mem_ptr(png_ptr);
3343 Your replacement memory functions must have prototypes as follows:
3345 png_voidp malloc_fn(png_structp png_ptr,
3347 void free_fn(png_structp png_ptr, png_voidp ptr);
3349 Your malloc_fn() must return NULL in case of failure. The png_malloc()
3350 function will normally call png_error() if it receives a NULL from the
3351 system memory allocator or from your replacement malloc_fn().
3353 Your free_fn() will never be called with a NULL ptr, since libpng's
3354 png_free() checks for NULL before calling free_fn().
3356 Input/Output in libpng is done through png_read() and png_write(),
3357 which currently just call fread() and fwrite(). The FILE * is stored in
3358 png_struct and is initialized via png_init_io(). If you wish to change
3359 the method of I/O, the library supplies callbacks that you can set
3360 through the function png_set_read_fn() and png_set_write_fn() at run
3361 time, instead of calling the png_init_io() function. These functions
3362 also provide a void pointer that can be retrieved via the function
3363 png_get_io_ptr(). For example:
3365 png_set_read_fn(png_structp read_ptr,
3366 voidp read_io_ptr, png_rw_ptr read_data_fn)
3368 png_set_write_fn(png_structp write_ptr,
3369 voidp write_io_ptr, png_rw_ptr write_data_fn,
3370 png_flush_ptr output_flush_fn);
3372 voidp read_io_ptr = png_get_io_ptr(read_ptr);
3373 voidp write_io_ptr = png_get_io_ptr(write_ptr);
3375 The replacement I/O functions must have prototypes as follows:
3377 void user_read_data(png_structp png_ptr,
3378 png_bytep data, png_size_t length);
3379 void user_write_data(png_structp png_ptr,
3380 png_bytep data, png_size_t length);
3381 void user_flush_data(png_structp png_ptr);
3383 The user_read_data() function is responsible for detecting and
3384 handling end-of-data errors.
3386 Supplying NULL for the read, write, or flush functions sets them back
3387 to using the default C stream functions, which expect the io_ptr to
3388 point to a standard *FILE structure. It is probably a mistake
3389 to use NULL for one of write_data_fn and output_flush_fn but not both
3390 of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
3391 It is an error to read from a write stream, and vice versa.
3393 Error handling in libpng is done through png_error() and png_warning().
3394 Errors handled through png_error() are fatal, meaning that png_error()
3395 should never return to its caller. Currently, this is handled via
3396 setjmp() and longjmp() (unless you have compiled libpng with
3397 PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
3398 but you could change this to do things like exit() if you should wish.
3400 On non-fatal errors, png_warning() is called
3401 to print a warning message, and then control returns to the calling code.
3402 By default png_error() and png_warning() print a message on stderr via
3403 fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
3404 (because you don't want the messages) or PNG_NO_STDIO defined (because
3405 fprintf() isn't available). If you wish to change the behavior of the error
3406 functions, you will need to set up your own message callbacks. These
3407 functions are normally supplied at the time that the png_struct is created.
3408 It is also possible to redirect errors and warnings to your own replacement
3409 functions after png_create_*_struct() has been called by calling:
3411 png_set_error_fn(png_structp png_ptr,
3412 png_voidp error_ptr, png_error_ptr error_fn,
3413 png_error_ptr warning_fn);
3415 png_voidp error_ptr = png_get_error_ptr(png_ptr);
3417 If NULL is supplied for either error_fn or warning_fn, then the libpng
3418 default function will be used, calling fprintf() and/or longjmp() if a
3419 problem is encountered. The replacement error functions should have
3420 parameters as follows:
3422 void user_error_fn(png_structp png_ptr,
3423 png_const_charp error_msg);
3424 void user_warning_fn(png_structp png_ptr,
3425 png_const_charp warning_msg);
3427 The motivation behind using setjmp() and longjmp() is the C++ throw and
3428 catch exception handling methods. This makes the code much easier to write,
3429 as there is no need to check every return code of every function call.
3430 However, there are some uncertainties about the status of local variables
3431 after a longjmp, so the user may want to be careful about doing anything
3432 after setjmp returns non-zero besides returning itself. Consult your
3433 compiler documentation for more details. For an alternative approach, you
3434 may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net).
3438 If you need to read or write custom chunks, you may need to get deeper
3439 into the libpng code. The library now has mechanisms for storing
3440 and writing chunks of unknown type; you can even declare callbacks
3441 for custom chunks. However, this may not be good enough if the
3442 library code itself needs to know about interactions between your
3443 chunk and existing `intrinsic' chunks.
3445 If you need to write a new intrinsic chunk, first read the PNG
3446 specification. Acquire a first level of understanding of how it works.
3447 Pay particular attention to the sections that describe chunk names,
3448 and look at how other chunks were designed, so you can do things
3449 similarly. Second, check out the sections of libpng that read and
3450 write chunks. Try to find a chunk that is similar to yours and use
3451 it as a template. More details can be found in the comments inside
3452 the code. It is best to handle unknown chunks in a generic method,
3453 via callback functions, instead of by modifying libpng functions.
3455 If you wish to write your own transformation for the data, look through
3456 the part of the code that does the transformations, and check out some of
3457 the simpler ones to get an idea of how they work. Try to find a similar
3458 transformation to the one you want to add and copy off of it. More details
3459 can be found in the comments inside the code itself.
3461 .SS Configuring for 16 bit platforms
3463 You will want to look into zconf.h to tell zlib (and thus libpng) that
3464 it cannot allocate more then 64K at a time. Even if you can, the memory
3465 won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
3467 .SS Configuring for DOS
3469 For DOS users who only have access to the lower 640K, you will
3470 have to limit zlib's memory usage via a png_set_compression_mem_level()
3471 call. See zlib.h or zconf.h in the zlib library for more information.
3473 .SS Configuring for Medium Model
3475 Libpng's support for medium model has been tested on most of the popular
3476 compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
3477 defined, and FAR gets defined to far in pngconf.h, and you should be
3478 all set. Everything in the library (except for zlib's structure) is
3479 expecting far data. You must use the typedefs with the p or pp on
3480 the end for pointers (or at least look at them and be careful). Make
3481 note that the rows of data are defined as png_bytepp, which is an
3482 unsigned char far * far *.
3484 .SS Configuring for gui/windowing platforms:
3486 You will need to write new error and warning functions that use the GUI
3487 interface, as described previously, and set them to be the error and
3488 warning functions at the time that png_create_*_struct() is called,
3489 in order to have them available during the structure initialization.
3490 They can be changed later via png_set_error_fn(). On some compilers,
3491 you may also have to change the memory allocators (png_malloc, etc.).
3493 .SS Configuring for compiler xxx:
3495 All includes for libpng are in pngconf.h. If you need to add, change
3496 or delete an include, this is the place to do it.
3497 The includes that are not needed outside libpng are protected by the
3498 PNG_INTERNAL definition, which is only defined for those routines inside
3499 libpng itself. The files in libpng proper only include png.h, which
3502 .SS Configuring zlib:
3504 There are special functions to configure the compression. Perhaps the
3505 most useful one changes the compression level, which currently uses
3506 input compression values in the range 0 - 9. The library normally
3507 uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
3508 have shown that for a large majority of images, compression values in
3509 the range 3-6 compress nearly as well as higher levels, and do so much
3510 faster. For online applications it may be desirable to have maximum speed
3511 (Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
3512 specify no compression (Z_NO_COMPRESSION = 0), but this would create
3513 files larger than just storing the raw bitmap. You can specify the
3514 compression level by calling:
3516 png_set_compression_level(png_ptr, level);
3518 Another useful one is to reduce the memory level used by the library.
3519 The memory level defaults to 8, but it can be lowered if you are
3520 short on memory (running DOS, for example, where you only have 640K).
3521 Note that the memory level does have an effect on compression; among
3522 other things, lower levels will result in sections of incompressible
3523 data being emitted in smaller stored blocks, with a correspondingly
3524 larger relative overhead of up to 15% in the worst case.
3526 png_set_compression_mem_level(png_ptr, level);
3528 The other functions are for configuring zlib. They are not recommended
3529 for normal use and may result in writing an invalid PNG file. See
3530 zlib.h for more information on what these mean.
3532 png_set_compression_strategy(png_ptr,
3534 png_set_compression_window_bits(png_ptr,
3536 png_set_compression_method(png_ptr, method);
3537 png_set_compression_buffer_size(png_ptr, size);
3539 .SS Controlling row filtering
3541 If you want to control whether libpng uses filtering or not, which
3542 filters are used, and how it goes about picking row filters, you
3543 can call one of these functions. The selection and configuration
3544 of row filters can have a significant impact on the size and
3545 encoding speed and a somewhat lesser impact on the decoding speed
3546 of an image. Filtering is enabled by default for RGB and grayscale
3547 images (with and without alpha), but not for paletted images nor
3548 for any images with bit depths less than 8 bits/pixel.
3550 The 'method' parameter sets the main filtering method, which is
3551 currently only '0' in the PNG 1.2 specification. The 'filters'
3552 parameter sets which filter(s), if any, should be used for each
3553 scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
3554 to turn filtering on and off, respectively.
3556 Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3557 PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
3558 ORed together with '|' to specify one or more filters to use.
3559 These filters are described in more detail in the PNG specification.
3560 If you intend to change the filter type during the course of writing
3561 the image, you should start with flags set for all of the filters
3562 you intend to use so that libpng can initialize its internal
3563 structures appropriately for all of the filter types. (Note that this
3564 means the first row must always be adaptively filtered, because libpng
3565 currently does not allocate the filter buffers until png_write_row()
3566 is called for the first time.)
3568 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
3569 PNG_FILTER_UP | PNG_FILTER_AVG |
3570 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
3572 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3574 The second parameter can also be
3575 PNG_INTRAPIXEL_DIFFERENCING if you are
3576 writing a PNG to be embedded in a MNG
3577 datastream. This parameter must be the
3578 same as the value of filter_method used
3581 It is also possible to influence how libpng chooses from among the
3582 available filters. This is done in one or both of two ways - by
3583 telling it how important it is to keep the same filter for successive
3584 rows, and by telling it the relative computational costs of the filters.
3586 double weights[3] = {1.5, 1.3, 1.1},
3587 costs[PNG_FILTER_VALUE_LAST] =
3588 {1.0, 1.3, 1.3, 1.5, 1.7};
3590 png_set_filter_heuristics(png_ptr,
3591 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
3594 The weights are multiplying factors that indicate to libpng that the
3595 row filter should be the same for successive rows unless another row filter
3596 is that many times better than the previous filter. In the above example,
3597 if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
3598 "sum of absolute differences" 1.5 x 1.3 times higher than other filters
3599 and still be chosen, while the NONE filter could have a sum 1.1 times
3600 higher than other filters and still be chosen. Unspecified weights are
3601 taken to be 1.0, and the specified weights should probably be declining
3602 like those above in order to emphasize recent filters over older filters.
3604 The filter costs specify for each filter type a relative decoding cost
3605 to be considered when selecting row filters. This means that filters
3606 with higher costs are less likely to be chosen over filters with lower
3607 costs, unless their "sum of absolute differences" is that much smaller.
3608 The costs do not necessarily reflect the exact computational speeds of
3609 the various filters, since this would unduly influence the final image
3612 Note that the numbers above were invented purely for this example and
3613 are given only to help explain the function usage. Little testing has
3614 been done to find optimum values for either the costs or the weights.
3616 .SS Removing unwanted object code
3618 There are a bunch of #define's in pngconf.h that control what parts of
3619 libpng are compiled. All the defines end in _SUPPORTED. If you are
3620 never going to use a capability, you can change the #define to #undef
3621 before recompiling libpng and save yourself code and data space, or
3622 you can turn off individual capabilities with defines that begin with
3625 You can also turn all of the transforms and ancillary chunk capabilities
3626 off en masse with compiler directives that define
3627 PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3629 along with directives to turn on any of the capabilities that you do
3630 want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
3631 transformations but still leave the library fully capable of reading
3632 and writing PNG files with all known public chunks. Use of the
3633 PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
3634 that is incapable of reading or writing ancillary chunks. If you are
3635 not using the progressive reading capability, you can turn that off
3636 with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
3637 capability, which you'll still have).
3639 All the reading and writing specific code are in separate files, so the
3640 linker should only grab the files it needs. However, if you want to
3641 make sure, or if you are building a stand alone library, all the
3642 reading files start with pngr and all the writing files start with
3643 pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
3644 are used for both reading and writing, and always need to be included.
3645 The progressive reader is in pngpread.c
3647 If you are creating or distributing a dynamically linked library (a .so
3648 or DLL file), you should not remove or disable any parts of the library,
3649 as this will cause applications linked with different versions of the
3650 library to fail if they call functions not available in your library.
3651 The size of the library itself should not be an issue, because only
3652 those sections that are actually used will be loaded into memory.
3654 .SS Requesting debug printout
3656 The macro definition PNG_DEBUG can be used to request debugging
3657 printout. Set it to an integer value in the range 0 to 3. Higher
3658 numbers result in increasing amounts of debugging information. The
3659 information is printed to the "stderr" file, unless another file
3660 name is specified in the PNG_DEBUG_FILE macro definition.
3662 When PNG_DEBUG > 0, the following functions (macros) become available:
3664 png_debug(level, message)
3665 png_debug1(level, message, p1)
3666 png_debug2(level, message, p1, p2)
3668 in which "level" is compared to PNG_DEBUG to decide whether to print
3669 the message, "message" is the formatted string to be printed,
3670 and p1 and p2 are parameters that are to be embedded in the string
3671 according to printf-style formatting directives. For example,
3673 png_debug1(2, "foo=%d\n", foo);
3678 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
3680 When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3681 can still use PNG_DEBUG to control your own debugging:
3687 When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3688 having level = 0 will be printed. There aren't any such statements in
3689 this version of libpng, but if you insert some they will be printed.
3693 The MNG specification (available at http://www.libpng.org/pub/mng) allows
3694 certain extensions to PNG for PNG images that are embedded in MNG datastreams.
3695 Libpng can support some of these extensions. To enable them, use the
3696 png_permit_mng_features() function:
3698 feature_set = png_permit_mng_features(png_ptr, mask)
3699 mask is a png_uint_32 containing the bitwise OR of the
3700 features you want to enable. These include
3701 PNG_FLAG_MNG_EMPTY_PLTE
3702 PNG_FLAG_MNG_FILTER_64
3703 PNG_ALL_MNG_FEATURES
3704 feature_set is a png_uint_32 that is the bitwise AND of
3705 your mask with the set of MNG features that is
3706 supported by the version of libpng that you are using.
3708 It is an error to use this function when reading or writing a standalone
3709 PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
3710 in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
3711 and the MHDR and MEND chunks. Libpng does not provide support for these
3712 or any other MNG chunks; your application must provide its own support for
3713 them. You may wish to consider using libmng (available at
3714 http://www.libmng.com) instead.
3716 .SH VII. Changes to Libpng from version 0.88
3718 It should be noted that versions of libpng later than 0.96 are not
3719 distributed by the original libpng author, Guy Schalnat, nor by
3720 Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3721 distributed versions 0.89 through 0.96, but rather by another member
3722 of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3723 still alive and well, but they have moved on to other things.
3725 The old libpng functions png_read_init(), png_write_init(),
3726 png_info_init(), png_read_destroy(), and png_write_destroy() have been
3727 moved to PNG_INTERNAL in version 0.95 to discourage their use. These
3728 functions will be removed from libpng version 2.0.0.
3730 The preferred method of creating and initializing the libpng structures is
3731 via the png_create_read_struct(), png_create_write_struct(), and
3732 png_create_info_struct() because they isolate the size of the structures
3733 from the application, allow version error checking, and also allow the
3734 use of custom error handling routines during the initialization, which
3735 the old functions do not. The functions png_read_destroy() and
3736 png_write_destroy() do not actually free the memory that libpng
3737 allocated for these structs, but just reset the data structures, so they
3738 can be used instead of png_destroy_read_struct() and
3739 png_destroy_write_struct() if you feel there is too much system overhead
3740 allocating and freeing the png_struct for each image read.
3742 Setting the error callbacks via png_set_message_fn() before
3743 png_read_init() as was suggested in libpng-0.88 is no longer supported
3744 because this caused applications that do not use custom error functions
3745 to fail if the png_ptr was not initialized to zero. It is still possible
3746 to set the error callbacks AFTER png_read_init(), or to change them with
3747 png_set_error_fn(), which is essentially the same function, but with a new
3748 name to force compilation errors with applications that try to use the old
3751 Starting with version 1.0.7, you can find out which version of the library
3752 you are using at run-time:
3754 png_uint_32 libpng_vn = png_access_version_number();
3756 The number libpng_vn is constructed from the major version, minor
3757 version with leading zero, and release number with leading zero,
3758 (e.g., libpng_vn for version 1.0.7 is 10007).
3760 You can also check which version of png.h you used when compiling your
3763 png_uint_32 application_vn = PNG_LIBPNG_VER;
3765 .SH VIII. Changes to Libpng from version 1.0.x to 1.2.x
3767 Support for user memory management was enabled by default. To
3768 accomplish this, the functions png_create_read_struct_2(),
3769 png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
3770 png_malloc_default(), and png_free_default() were added.
3772 Support for the iTXt chunk has been enabled by default as of
3775 Support for certain MNG features was enabled.
3777 Support for numbered error messages was added. However, we never got
3778 around to actually numbering the error messages. The function
3779 png_set_strip_error_numbers() was added (Note: the prototype for this
3780 function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
3781 builds of libpng-1.2.15. It was restored in libpng-1.2.36).
3783 The png_malloc_warn() function was added at libpng-1.2.3. This issues
3784 a png_warning and returns NULL instead of aborting when it fails to
3785 acquire the requested memory allocation.
3787 Support for setting user limits on image width and height was enabled
3788 by default. The functions png_set_user_limits(), png_get_user_width_max(),
3789 and png_get_user_height_max() were added at libpng-1.2.6.
3791 The png_set_add_alpha() function was added at libpng-1.2.7.
3793 The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
3794 Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
3795 tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
3798 A number of macro definitions in support of runtime selection of
3799 assembler code features (especially Intel MMX code support) were
3800 added at libpng-1.2.0:
3802 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
3803 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
3804 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
3805 PNG_ASM_FLAG_MMX_READ_INTERLACE
3806 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
3807 PNG_ASM_FLAG_MMX_READ_FILTER_UP
3808 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
3809 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
3810 PNG_ASM_FLAGS_INITIALIZED
3816 We added the following functions in support of runtime
3817 selection of assembler code features:
3819 png_get_mmx_flagmask()
3820 png_set_mmx_thresholds()
3822 png_get_mmx_bitdepth_threshold()
3823 png_get_mmx_rowbytes_threshold()
3826 We replaced all of these functions with simple stubs in libpng-1.2.20,
3827 when the Intel assembler code was removed due to a licensing issue.
3829 These macros are deprecated:
3831 PNG_READ_TRANSFORMS_NOT_SUPPORTED
3832 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
3833 PNG_NO_SEQUENTIAL_READ_SUPPORTED
3834 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
3835 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
3836 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
3838 They have been replaced, respectively, by:
3840 PNG_NO_READ_TRANSFORMS
3841 PNG_NO_PROGRESSIVE_READ
3842 PNG_NO_SEQUENTIAL_READ
3843 PNG_NO_WRITE_TRANSFORMS
3844 PNG_NO_READ_ANCILLARY_CHUNKS
3845 PNG_NO_WRITE_ANCILLARY_CHUNKS
3847 PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
3848 deprecated since libpng-1.0.16 and libpng-1.2.6.
3851 png_check_sig(sig, num)
3853 !png_sig_cmp(sig, 0, num)
3854 It has been deprecated since libpng-0.90.
3857 png_set_gray_1_2_4_to_8()
3858 which also expands tRNS to alpha was replaced with
3859 png_set_expand_gray_1_2_4_to_8()
3860 which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
3865 .SH X. Detecting libpng
3867 The png_get_io_ptr() function has been present since libpng-0.88, has never
3868 changed, and is unaffected by conditional compilation macros. It is the
3869 best choice for use in configure scripts for detecting the presence of any
3870 libpng version since 0.88. In an autoconf "configure.in" you could use
3872 AC_CHECK_LIB(png, png_get_io_ptr, ...
3874 .SH XI. Source code repository
3876 Since about February 2009, version 1.2.34, libpng has been under "git" source
3877 control. The git repository was built from old libpng-x.y.z.tar.gz files
3878 going back to version 0.70. You can access the git repository (read only)
3881 git://libpng.git.sourceforge.net/gitroot/libpng
3883 or you can browse it via "gitweb" at
3885 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
3887 Patches can be sent to glennrp at users.sourceforge.net or to
3888 png-mng-implement at lists.sourceforge.net or you can upload them to
3889 the libpng bug tracker at
3891 http://libpng.sourceforge.net
3893 .SH XII. Coding style
3895 Our coding style is similar to the "Allman" style, with curly
3896 braces on separate lines:
3903 else if (another condition)
3908 The braces can be omitted from simple one-line actions:
3913 We use 3-space indentation, except for continued statements which
3914 are usually indented the same as the first line of the statement
3915 plus four more spaces.
3917 For macro definitions we use 2-space indentation, always leaving the "#"
3918 in the first column.
3920 #ifndef PNG_NO_FEATURE
3921 # ifndef PNG_FEATURE_SUPPORTED
3922 # define PNG_FEATURE_SUPPORTED
3926 Comments appear with the leading "/*" at the same indentation as
3927 the statement that follows the comment:
3929 /* Single-line comment */
3937 Very short comments can be placed at the end of the statement
3938 to which they pertain:
3940 statement; /* comment */
3942 We don't use C++ style ("//") comments. We have, however,
3943 used them in the past in some now-abandoned MMX assembler
3946 Functions and their curly braces are not indented, and
3947 exported functions are marked with PNGAPI:
3949 /* This is a public function that is visible to
3950 * application programers. It does thus-and-so.
3953 png_exported_function(png_ptr, png_info, foo)
3958 The prototypes for all exported functions appear in png.h,
3959 above the comment that says
3961 /* Maintainer: Put new public prototypes here ... */
3963 We mark all non-exported functions with "/* PRIVATE */"":
3966 png_non_exported_function(png_ptr, png_info, foo)
3971 The prototypes for non-exported functions (except for those in
3973 the PNG_INTERNAL section of png.h
3974 above the comment that says
3976 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
3978 The names of all exported functions and variables begin
3979 with "png_", and all publicly visible C preprocessor
3980 macros begin with "PNG_".
3982 We put a space after each comma and after each semicolon
3983 in "for" statments, and we put spaces before and after each
3984 C binary operator and after "for" or "while". We don't
3985 put a space between a typecast and the expression being
3986 cast, nor do we put one between a function name and the
3987 left parenthesis that follows it:
3989 for (i = 2; i > 0; --i)
3990 y[i] = a(x) + (int)b;
3992 We prefer #ifdef and #ifndef to #if defined() and if !defined()
3993 when there is only one macro being tested.
3995 We do not use the TAB character for indentation in the C sources.
3997 Lines do not exceed 80 characters.
3999 Other rules can be inferred by inspecting the libpng source.
4001 .SH XIII. Y2K Compliance in libpng
4005 Since the PNG Development group is an ad-hoc body, we can't make
4006 an official declaration.
4008 This is your unofficial assurance that libpng from version 0.71 and
4009 upward through 1.2.44 are Y2K compliant. It is my belief that earlier
4010 versions were also Y2K compliant.
4012 Libpng only has three year fields. One is a 2-byte unsigned integer that
4013 will hold years up to 65535. The other two hold the date in text
4014 format, and will hold years up to 9999.
4017 "png_uint_16 year" in png_time_struct.
4020 "png_charp time_buffer" in png_struct and
4021 "near_time_buffer", which is a local character string in png.c.
4023 There are seven time-related functions:
4025 png_convert_to_rfc_1123() in png.c
4026 (formerly png_convert_to_rfc_1152() in error)
4027 png_convert_from_struct_tm() in pngwrite.c, called
4029 png_convert_from_time_t() in pngwrite.c
4030 png_get_tIME() in pngget.c
4031 png_handle_tIME() in pngrutil.c, called in pngread.c
4032 png_set_tIME() in pngset.c
4033 png_write_tIME() in pngwutil.c, called in pngwrite.c
4035 All appear to handle dates properly in a Y2K environment. The
4036 png_convert_from_time_t() function calls gmtime() to convert from system
4037 clock time, which returns (year - 1900), which we properly convert to
4038 the full 4-digit year. There is a possibility that applications using
4039 libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
4040 function, or that they are incorrectly passing only a 2-digit year
4041 instead of "year - 1900" into the png_convert_from_struct_tm() function,
4042 but this is not under our control. The libpng documentation has always
4043 stated that it works with 4-digit years, and the APIs have been
4046 The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
4047 integer to hold the year, and can hold years as large as 65535.
4049 zlib, upon which libpng depends, is also Y2K compliant. It contains
4050 no date-related code.
4053 Glenn Randers-Pehrson
4055 PNG Development Group
4059 Note about libpng version numbers:
4061 Due to various miscommunications, unforeseen code incompatibilities
4062 and occasional factors outside the authors' control, version numbering
4063 on the library has not always been consistent and straightforward.
4064 The following table summarizes matters since version 0.89c, which was
4065 the first widely used release:
4067 source png.h png.h shared-lib
4068 version string int version
4069 ------- ------ ----- ----------
4070 0.89c ("beta 3") 0.89 89 1.0.89
4071 0.90 ("beta 4") 0.90 90 0.90
4072 0.95 ("beta 5") 0.95 95 0.95
4073 0.96 ("beta 6") 0.96 96 0.96
4074 0.97b ("beta 7") 1.00.97 97 1.0.1
4075 0.97c 0.97 97 2.0.97
4078 0.99a-m 0.99 99 2.0.99
4080 1.0.0 1.0.0 100 2.1.0
4081 1.0.0 (from here on, the 100 2.1.0
4082 1.0.1 png.h string is 10001 2.1.0
4083 1.0.1a-e identical to the 10002 from here on, the
4084 1.0.2 source version) 10002 shared library is 2.V
4085 1.0.2a-b 10003 where V is the source
4086 1.0.1 10001 code version except as
4087 1.0.1a-e 10002 2.1.0.1a-e noted.
4089 1.0.2a-b 10003 2.1.0.2a-b
4091 1.0.3a-d 10004 2.1.0.3a-d
4093 1.0.4a-f 10005 2.1.0.4a-f
4094 1.0.5 (+ 2 patches) 10005 2.1.0.5
4095 1.0.5a-d 10006 2.1.0.5a-d
4096 1.0.5e-r 10100 2.1.0.5e-r
4097 1.0.5s-v 10006 2.1.0.5s-v
4098 1.0.6 (+ 3 patches) 10006 2.1.0.6
4099 1.0.6d-g 10007 2.1.0.6d-g
4102 1.0.6j 10007 2.1.0.6j
4103 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
4104 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
4105 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
4106 1.0.7 1 10007 2.1.0.7
4107 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
4108 1.0.8rc1 1 10008 2.1.0.8rc1
4109 1.0.8 1 10008 2.1.0.8
4110 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
4111 1.0.9rc1 1 10009 2.1.0.9rc1
4112 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
4113 1.0.9rc2 1 10009 2.1.0.9rc2
4114 1.0.9 1 10009 2.1.0.9
4115 1.0.10beta1 1 10010 2.1.0.10beta1
4116 1.0.10rc1 1 10010 2.1.0.10rc1
4117 1.0.10 1 10010 2.1.0.10
4118 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
4119 1.0.11rc1 1 10011 2.1.0.11rc1
4120 1.0.11 1 10011 2.1.0.11
4121 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
4122 1.0.12rc1 2 10012 2.1.0.12rc1
4123 1.0.12 2 10012 2.1.0.12
4124 1.1.0a-f - 10100 2.1.1.0a-f abandoned
4125 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
4126 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
4127 1.2.0rc1 3 10200 3.1.2.0rc1
4128 1.2.0 3 10200 3.1.2.0
4129 1.2.1beta-4 3 10201 3.1.2.1beta1-4
4130 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
4131 1.2.1 3 10201 3.1.2.1
4132 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
4133 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
4134 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
4135 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
4136 1.0.13 10 10013 10.so.0.1.0.13
4137 1.2.2 12 10202 12.so.0.1.2.2
4138 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
4139 1.2.3 12 10203 12.so.0.1.2.3
4140 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
4141 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
4142 1.0.14 10 10014 10.so.0.1.0.14
4143 1.2.4 13 10204 12.so.0.1.2.4
4144 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
4145 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
4146 1.0.15 10 10015 10.so.0.1.0.15
4147 1.2.5 13 10205 12.so.0.1.2.5
4148 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
4149 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
4150 1.0.16 10 10016 10.so.0.1.0.16
4151 1.2.6 13 10206 12.so.0.1.2.6
4152 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
4153 1.0.17rc1 10 10017 10.so.0.1.0.17rc1
4154 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
4155 1.0.17 10 10017 10.so.0.1.0.17
4156 1.2.7 13 10207 12.so.0.1.2.7
4157 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
4158 1.0.18rc1-5 10 10018 10.so.0.1.0.18rc1-5
4159 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
4160 1.0.18 10 10018 10.so.0.1.0.18
4161 1.2.8 13 10208 12.so.0.1.2.8
4162 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
4163 1.2.9beta4-11 13 10209 12.so.0.9[.0]
4164 1.2.9rc1 13 10209 12.so.0.9[.0]
4165 1.2.9 13 10209 12.so.0.9[.0]
4166 1.2.10beta1-8 13 10210 12.so.0.10[.0]
4167 1.2.10rc1-3 13 10210 12.so.0.10[.0]
4168 1.2.10 13 10210 12.so.0.10[.0]
4169 1.2.11beta1-4 13 10211 12.so.0.11[.0]
4170 1.0.19rc1-5 10 10019 10.so.0.19[.0]
4171 1.2.11rc1-5 13 10211 12.so.0.11[.0]
4172 1.0.19 10 10019 10.so.0.19[.0]
4173 1.2.11 13 10211 12.so.0.11[.0]
4174 1.0.20 10 10020 10.so.0.20[.0]
4175 1.2.12 13 10212 12.so.0.12[.0]
4176 1.2.13beta1 13 10213 12.so.0.13[.0]
4177 1.0.21 10 10021 10.so.0.21[.0]
4178 1.2.13 13 10213 12.so.0.13[.0]
4179 1.2.14beta1-2 13 10214 12.so.0.14[.0]
4180 1.0.22rc1 10 10022 10.so.0.22[.0]
4181 1.2.14rc1 13 10214 12.so.0.14[.0]
4182 1.2.15beta1-6 13 10215 12.so.0.15[.0]
4183 1.0.23rc1-5 10 10023 10.so.0.23[.0]
4184 1.2.15rc1-5 13 10215 12.so.0.15[.0]
4185 1.0.23 10 10023 10.so.0.23[.0]
4186 1.2.15 13 10215 12.so.0.15[.0]
4187 1.2.16beta1-2 13 10216 12.so.0.16[.0]
4188 1.2.16rc1 13 10216 12.so.0.16[.0]
4189 1.0.24 10 10024 10.so.0.24[.0]
4190 1.2.16 13 10216 12.so.0.16[.0]
4191 1.2.17beta1-2 13 10217 12.so.0.17[.0]
4192 1.0.25rc1 10 10025 10.so.0.25[.0]
4193 1.2.17rc1-3 13 10217 12.so.0.17[.0]
4194 1.0.25 10 10025 10.so.0.25[.0]
4195 1.2.17 13 10217 12.so.0.17[.0]
4196 1.0.26 10 10026 10.so.0.26[.0]
4197 1.2.18 13 10218 12.so.0.18[.0]
4198 1.2.19beta1-31 13 10219 12.so.0.19[.0]
4199 1.0.27rc1-6 10 10027 10.so.0.27[.0]
4200 1.2.19rc1-6 13 10219 12.so.0.19[.0]
4201 1.0.27 10 10027 10.so.0.27[.0]
4202 1.2.19 13 10219 12.so.0.19[.0]
4203 1.2.20beta01-04 13 10220 12.so.0.20[.0]
4204 1.0.28rc1-6 10 10028 10.so.0.28[.0]
4205 1.2.20rc1-6 13 10220 12.so.0.20[.0]
4206 1.0.28 10 10028 10.so.0.28[.0]
4207 1.2.20 13 10220 12.so.0.20[.0]
4208 1.2.21beta1-2 13 10221 12.so.0.21[.0]
4209 1.2.21rc1-3 13 10221 12.so.0.21[.0]
4210 1.0.29 10 10029 10.so.0.29[.0]
4211 1.2.21 13 10221 12.so.0.21[.0]
4212 1.2.22beta1-4 13 10222 12.so.0.22[.0]
4213 1.0.30rc1 13 10030 10.so.0.30[.0]
4214 1.2.22rc1 13 10222 12.so.0.22[.0]
4215 1.0.30 10 10030 10.so.0.30[.0]
4216 1.2.22 13 10222 12.so.0.22[.0]
4217 1.2.23beta01-05 13 10223 12.so.0.23[.0]
4218 1.2.23rc01 13 10223 12.so.0.23[.0]
4219 1.2.23 13 10223 12.so.0.23[.0]
4220 1.2.24beta01-02 13 10224 12.so.0.24[.0]
4221 1.2.24rc01 13 10224 12.so.0.24[.0]
4222 1.2.24 13 10224 12.so.0.24[.0]
4223 1.2.25beta01-06 13 10225 12.so.0.25[.0]
4224 1.2.25rc01-02 13 10225 12.so.0.25[.0]
4225 1.0.31 10 10031 10.so.0.31[.0]
4226 1.2.25 13 10225 12.so.0.25[.0]
4227 1.2.26beta01-06 13 10226 12.so.0.26[.0]
4228 1.2.26rc01 13 10226 12.so.0.26[.0]
4229 1.2.26 13 10226 12.so.0.26[.0]
4230 1.0.32 10 10032 10.so.0.32[.0]
4231 1.2.27beta01-06 13 10227 12.so.0.27[.0]
4232 1.2.27rc01 13 10227 12.so.0.27[.0]
4233 1.0.33 10 10033 10.so.0.33[.0]
4234 1.2.27 13 10227 12.so.0.27[.0]
4235 1.0.34 10 10034 10.so.0.34[.0]
4236 1.2.28 13 10228 12.so.0.28[.0]
4237 1.2.29beta01-03 13 10229 12.so.0.29[.0]
4238 1.2.29rc01 13 10229 12.so.0.29[.0]
4239 1.0.35 10 10035 10.so.0.35[.0]
4240 1.2.29 13 10229 12.so.0.29[.0]
4241 1.0.37 10 10037 10.so.0.37[.0]
4242 1.2.30beta01-04 13 10230 12.so.0.30[.0]
4243 1.0.38rc01-08 10 10038 10.so.0.38[.0]
4244 1.2.30rc01-08 13 10230 12.so.0.30[.0]
4245 1.0.38 10 10038 10.so.0.38[.0]
4246 1.2.30 13 10230 12.so.0.30[.0]
4247 1.0.39rc01-03 10 10039 10.so.0.39[.0]
4248 1.2.31rc01-03 13 10231 12.so.0.31[.0]
4249 1.0.39 10 10039 10.so.0.39[.0]
4250 1.2.31 13 10231 12.so.0.31[.0]
4251 1.2.32beta01-02 13 10232 12.so.0.32[.0]
4252 1.0.40rc01 10 10040 10.so.0.40[.0]
4253 1.2.32rc01 13 10232 12.so.0.32[.0]
4254 1.0.40 10 10040 10.so.0.40[.0]
4255 1.2.32 13 10232 12.so.0.32[.0]
4256 1.2.33beta01-02 13 10233 12.so.0.33[.0]
4257 1.2.33rc01-02 13 10233 12.so.0.33[.0]
4258 1.0.41rc01 10 10041 10.so.0.41[.0]
4259 1.2.33 13 10233 12.so.0.33[.0]
4260 1.0.41 10 10041 10.so.0.41[.0]
4261 1.2.34beta01-07 13 10234 12.so.0.34[.0]
4262 1.0.42rc01 10 10042 10.so.0.42[.0]
4263 1.2.34rc01 13 10234 12.so.0.34[.0]
4264 1.0.42 10 10042 10.so.0.42[.0]
4265 1.2.34 13 10234 12.so.0.34[.0]
4266 1.2.35beta01-03 13 10235 12.so.0.35[.0]
4267 1.0.43rc01-02 10 10043 10.so.0.43[.0]
4268 1.2.35rc01-02 13 10235 12.so.0.35[.0]
4269 1.0.43 10 10043 10.so.0.43[.0]
4270 1.2.35 13 10235 12.so.0.35[.0]
4271 1.2.36beta01-05 13 10236 12.so.0.36[.0]
4272 1.2.36rc01 13 10236 12.so.0.36[.0]
4273 1.0.44 10 10044 10.so.0.44[.0]
4274 1.2.36 13 10236 12.so.0.36[.0]
4275 1.2.37beta01-03 13 10237 12.so.0.37[.0]
4276 1.2.37rc01 13 10237 12.so.0.37[.0]
4277 1.2.37 13 10237 12.so.0.37[.0]
4278 1.2.45 10 10045 12.so.0.45[.0]
4279 1.0.46 10 10046 10.so.0.46[.0]
4280 1.2.38beta01 13 10238 12.so.0.38[.0]
4281 1.2.38rc01-03 13 10238 12.so.0.38[.0]
4282 1.0.47 10 10047 10.so.0.47[.0]
4283 1.2.38 13 10238 12.so.0.38[.0]
4284 1.2.39beta01-05 13 10239 12.so.0.39[.0]
4285 1.2.39rc01 13 10239 12.so.0.39[.0]
4286 1.0.48 10 10048 10.so.0.48[.0]
4287 1.2.39 13 10239 12.so.0.39[.0]
4288 1.2.40beta01 13 10240 12.so.0.40[.0]
4289 1.2.40rc01 13 10240 12.so.0.40[.0]
4290 1.0.49 10 10049 10.so.0.49[.0]
4291 1.2.40 13 10240 12.so.0.40[.0]
4292 1.0.50 10 10050 10.so.0.50[.0]
4293 1.2.41beta01-18 13 10241 12.so.0.41[.0]
4294 1.0.51rc01 10 10051 10.so.0.51[.0]
4295 1.2.41rc01-03 13 10241 12.so.0.41[.0]
4296 1.0.51 10 10051 10.so.0.51[.0]
4297 1.2.41 13 10241 12.so.0.41[.0]
4298 1.2.42beta01-02 13 10242 12.so.0.42[.0]
4299 1.2.42rc01-05 13 10242 12.so.0.42[.0]
4300 1.0.52 10 10052 10.so.0.52[.0]
4301 1.2.42 13 10242 12.so.0.42[.0]
4302 1.2.43beta01-05 13 10243 12.so.0.43[.0]
4303 1.0.53rc01-02 10 10053 10.so.0.53[.0]
4304 1.2.43rc01-02 13 10243 12.so.0.43[.0]
4305 1.0.53 10 10053 10.so.0.53[.0]
4306 1.2.43 13 10243 12.so.0.43[.0]
4307 1.2.44beta01-03 13 10244 12.so.0.44[.0]
4308 1.2.44rc01-03 13 10244 12.so.0.44[.0]
4309 1.2.44 13 10244 12.so.0.44[.0]
4311 Henceforth the source version will match the shared-library minor
4312 and patch numbers; the shared-library major version number will be
4313 used for changes in backward compatibility, as it is intended. The
4314 PNG_PNGLIB_VER macro, which is not used within libpng but is available
4315 for applications, is an unsigned integer of the form xyyzz corresponding
4316 to the source version x.y.z (leading zeros in y and z). Beta versions
4317 were given the previous public release number plus a letter, until
4318 version 1.0.6j; from then on they were given the upcoming public
4319 release number plus "betaNN" or "rcN".
4322 .IR libpngpf(3) ", " png(5)
4326 http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
4327 http://www.libpng.org/pub/png
4332 (generally) at the same location as
4336 ftp://ftp.info-zip.org/pub/infozip/zlib
4339 .IR PNG specification: RFC 2083
4341 (generally) at the same location as
4345 ftp://ftp.rfc-editor.org:/in-notes/rfc2083.txt
4347 or (as a W3C Recommendation) at
4349 http://www.w3.org/TR/REC-png.html
4352 In the case of any inconsistency between the PNG specification
4353 and this library, the specification takes precedence.
4356 This man page: Glenn Randers-Pehrson
4357 <glennrp at users.sourceforge.net>
4359 The contributing authors would like to thank all those who helped
4360 with testing, bug fixes, and patience. This wouldn't have been
4361 possible without all of you.
4363 Thanks to Frank J. T. Wojcik for helping with the documentation.
4365 Libpng version 1.2.44 - June 26, 2010:
4366 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
4367 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
4369 Supported by the PNG development group
4371 png-mng-implement at lists.sf.net
4372 (subscription required; visit
4373 png-mng-implement at lists.sourceforge.net (subscription required; visit
4374 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
4377 .SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
4379 (This copy of the libpng notices is provided for your convenience. In case of
4380 any discrepancy between this copy and the notices in the file png.h that is
4381 included in the libpng distribution, the latter shall prevail.)
4383 If you modify libpng you may insert additional notices immediately following
4386 This code is released under the libpng license.
4388 libpng versions 1.2.6, August 15, 2004, through 1.2.44, June 26, 2010, are
4389 Copyright (c) 2004,2006-2008 Glenn Randers-Pehrson, and are
4390 distributed according to the same disclaimer and license as libpng-1.2.5
4391 with the following individual added to the list of Contributing Authors
4395 libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
4396 Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
4397 distributed according to the same disclaimer and license as libpng-1.0.6
4398 with the following individuals added to the list of Contributing Authors
4400 Simon-Pierre Cadieux
4404 and with the following additions to the disclaimer:
4406 There is no warranty against interference with your
4407 enjoyment of the library or against infringement.
4408 There is no warranty that our efforts or the library
4409 will fulfill any of your particular purposes or needs.
4410 This library is provided with all faults, and the entire
4411 risk of satisfactory quality, performance, accuracy, and
4412 effort is with the user.
4414 libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
4415 Copyright (c) 1998, 1999 Glenn Randers-Pehrson
4416 Distributed according to the same disclaimer and license as libpng-0.96,
4417 with the following individuals added to the list of Contributing Authors:
4420 Glenn Randers-Pehrson
4423 libpng versions 0.89, June 1996, through 0.96, May 1997, are
4424 Copyright (c) 1996, 1997 Andreas Dilger
4425 Distributed according to the same disclaimer and license as libpng-0.88,
4426 with the following individuals added to the list of Contributing Authors:
4435 libpng versions 0.5, May 1995, through 0.88, January 1996, are
4436 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
4438 For the purposes of this copyright and license, "Contributing Authors"
4439 is defined as the following set of individuals:
4447 The PNG Reference Library is supplied "AS IS". The Contributing Authors
4448 and Group 42, Inc. disclaim all warranties, expressed or implied,
4449 including, without limitation, the warranties of merchantability and of
4450 fitness for any purpose. The Contributing Authors and Group 42, Inc.
4451 assume no liability for direct, indirect, incidental, special, exemplary,
4452 or consequential damages, which may result from the use of the PNG
4453 Reference Library, even if advised of the possibility of such damage.
4455 Permission is hereby granted to use, copy, modify, and distribute this
4456 source code, or portions hereof, for any purpose, without fee, subject
4457 to the following restrictions:
4459 1. The origin of this source code must not be misrepresented.
4461 2. Altered versions must be plainly marked as such and
4462 must not be misrepresented as being the original source.
4464 3. This Copyright notice may not be removed or altered from
4465 any source or altered source distribution.
4467 The Contributing Authors and Group 42, Inc. specifically permit, without
4468 fee, and encourage the use of this source code as a component to
4469 supporting the PNG file format in commercial products. If you use this
4470 source code in a product, acknowledgment is not required but would be
4474 A "png_get_copyright" function is available, for convenient use in "about"
4477 printf("%s",png_get_copyright(NULL));
4479 Also, the PNG logo (in PNG format, of course) is supplied in the
4480 files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
4482 Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
4483 certification mark of the Open Source Initiative.
4485 Glenn Randers-Pehrson
4486 glennrp at users.sourceforge.net