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