OSDN Git Service

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