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