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