source: rtems-graphics-toolkit/libpng-1.5.12/libpng.3 @ 1cb4ff2

Last change on this file since 1cb4ff2 was 1cb4ff2, checked in by Alexandru-Sever Horin <alex.sever.h@…>, on 08/06/12 at 11:43:44

Added libpng-1.5.12 update.

  • Property mode set to 100644
File size: 236.8 KB
Line 
1.TH LIBPNG 3 "July 11, 2012"
2.SH NAME
3libpng \- Portable Network Graphics (PNG) Reference Library 1.5.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\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
16
17\fI\fB
18
19\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
20
21\fI\fB
22
23\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
24
25\fI\fB
26
27\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
28
29\fI\fB
30
31\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
32
33\fI\fB
34
35\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
36
37\fI\fB
38
39\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
40
41\fI\fB
42
43\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
44
45\fI\fB
46
47\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
48
49\fI\fB
50
51\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
52
53\fI\fB
54
55\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
56
57\fI\fB
58
59\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
60
61\fI\fB
62
63\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
64
65\fI\fB
66
67\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
68
69\fI\fB
70
71\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP
72
73\fI\fB
74
75\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
76
77\fI\fB
78
79\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
80
81\fI\fB
82
83\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
84
85\fI\fB
86
87\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
88
89\fI\fB
90
91\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
92
93\fI\fB
94
95\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
96
97\fI\fB
98
99\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
100
101\fI\fB
102
103\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
104
105\fI\fB
106
107\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
108
109\fI\fB
110
111\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
112
113\fI\fB
114
115\fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
116
117\fI\fB
118
119\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
120
121\fI\fB
122
123\fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
124
125\fI\fB
126
127\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
128
129\fI\fB
130
131\fBpng_uint_32 png_get_cHRM_XYZ (png_structp \fIpng_ptr,
132
133\fBpng_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*red_X\fP\fB, double \fP\fI*red_Y\fP\fB, double \fI*red_Z,
134
135\fBdouble \fP\fI*green_X\fP\fB, double \fP\fI*green_Y\fP\fB, double \fP\fI*green_Z\fP\fB, double \fI*blue_X,
136
137\fBdouble \fP\fI*blue_Y\fP\fB, double \fI*blue_Z\fP\fB);\fP
138
139\fI\fB
140
141\fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fI*int_red_X\fP\fB, png_fixed_point \fP\fI*int_red_Y\fP\fB, png_fixed_point \fP\fI*int_red_Z\fP\fB, png_fixed_point \fP\fI*int_green_X\fP\fB, png_fixed_point \fP\fI*int_green_Y\fP\fB, png_fixed_point \fP\fI*int_green_Z\fP\fB, png_fixed_point \fP\fI*int_blue_X\fP\fB, png_fixed_point \fP\fI*int_blue_Y\fP\fB, png_fixed_point \fI*int_blue_Z\fP\fB);\fP
142
143\fI\fB
144
145\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
146
147\fI\fB
148
149\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP
150
151\fI\fB
152
153\fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
154
155\fI\fB
156
157\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP
158
159\fI\fB
160
161\fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
162
163\fI\fB
164
165\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP
166
167\fI\fB
168
169\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP
170
171\fI\fB
172
173\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
174
175\fI\fB
176
177\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
178
179\fI\fB
180
181\fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
182
183\fI\fB
184
185\fBpng_uint_32 png_get_gAMA (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
186
187\fI\fB
188
189\fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
190
191\fI\fB
192
193\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
194
195\fI\fB
196
197\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP
198
199\fI\fB
200
201\fBpng_uint_32 png_get_hIST (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
202
203\fI\fB
204
205\fBpng_uint_32 png_get_iCCP (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_bytepp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
206
207\fI\fB
208
209\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
210
211\fI\fB
212
213\fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
214
215\fI\fB
216
217\fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
218
219\fI\fB
220
221\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
222
223\fI\fB
224
225\fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
226
227\fI\fB
228
229\fBpng_const_bytep png_get_io_chunk_name (png_structp \fIpng_ptr\fP\fB);\fP
230
231\fI\fB
232
233\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
234
235\fI\fB
236
237\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
238
239\fI\fB
240
241\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
242
243\fI\fB
244
245\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
246
247\fI\fB
248
249\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
250
251\fI\fB
252
253\fBpng_uint_32 png_get_oFFs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
254
255\fI\fB
256
257\fBpng_uint_32 png_get_pCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
258
259\fI\fB
260
261\fBpng_uint_32 png_get_pHYs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
262
263\fI\fB
264
265\fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
266
267\fI\fB
268
269\fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
270
271\fI\fB
272
273\fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
274
275\fI\fB
276
277\fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
278
279\fI\fB
280
281\fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
282
283\fI\fB
284
285\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
286
287\fI\fB
288
289\fBpng_uint_32 png_get_PLTE (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
290
291\fI\fB
292
293\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr)
294
295\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
296
297\fI\fB
298
299\fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
300
301\fI\fB
302
303\fBpng_uint_32 png_get_sBIT (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
304
305\fI\fB
306
307\fBvoid png_get_sCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, double* \fP\fIwidth\fP\fB, double* \fIheight\fP\fB);\fP
308
309\fI\fB
310
311\fBvoid png_get_sCAL_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_fixed_pointp \fP\fIwidth\fP\fB, png_fixed_pointp \fIheight\fP\fB);\fP
312
313\fI\fB
314
315\fBvoid png_get_sCAL_s (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_charpp \fP\fIwidth\fP\fB, png_charpp \fIheight\fP\fB);\fP
316
317\fI\fB
318
319\fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
320
321\fI\fB
322
323\fBpng_uint_32 png_get_sPLT (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
324
325\fI\fB
326
327\fBpng_uint_32 png_get_sRGB (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int \fI*file_srgb_intent\fP\fB);\fP
328
329\fI\fB
330
331\fBpng_uint_32 png_get_text (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
332
333\fI\fB
334
335\fBpng_uint_32 png_get_tIME (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
336
337\fI\fB
338
339\fBpng_uint_32 png_get_tRNS (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans_alpha\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_color\fP\fB);\fP
340
341\fI\fB
342
343\fB/* This function is really an inline macro. \fI*/
344
345\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
346
347\fI\fB
348
349\fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP
350
351\fI\fB
352
353\fB/* This function is really an inline macro. \fI*/
354
355\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
356
357\fI\fB
358
359\fBpng_uint_32 png_get_unknown_chunks (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
360
361\fI\fB
362
363\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
364
365\fI\fB
366
367\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
368
369\fI\fB
370
371\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
372
373\fI\fB
374
375\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
376
377\fI\fB
378
379\fBpng_uint_32 png_get_valid (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
380
381\fI\fB
382
383\fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
384
385\fI\fB
386
387\fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
388
389\fI\fB
390
391\fBpng_int_32 png_get_x_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
392
393\fI\fB
394
395\fBpng_int_32 png_get_x_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
396
397\fI\fB
398
399\fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
400
401\fI\fB
402
403\fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
404
405\fI\fB
406
407\fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
408
409\fI\fB
410
411\fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
412
413\fI\fB
414
415\fBpng_int_32 png_get_y_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
416
417\fI\fB
418
419\fBpng_int_32 png_get_y_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
420
421\fI\fB
422
423\fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
424
425\fI\fB
426
427\fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
428
429\fI\fB
430
431\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
432
433\fI\fB
434
435\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
436
437\fI\fB
438
439\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
440
441\fI\fB
442
443\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
444
445\fI\fB
446
447\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
448
449\fI\fB
450
451\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
452
453\fI\fB
454
455\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
456
457\fI\fB
458
459\fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP
460
461\fI\fB
462
463\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
464
465\fI\fB
466
467\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
468
469\fI\fB
470
471\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
472
473\fI\fB
474
475\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
476
477\fI\fB
478
479\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
480
481\fI\fB
482
483\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
484
485\fI\fB
486
487\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
488
489\fI\fB
490
491\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
492
493\fI\fB
494
495\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
496
497\fI\fB
498
499\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
500
501\fI\fB
502
503\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
504
505\fI\fB
506
507\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
508
509\fI\fB
510
511\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
512
513\fI\fB
514
515\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
516
517\fI\fB
518
519\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
520
521\fI\fB
522
523\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
524
525\fI\fB
526
527\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP
528
529\fI\fB
530
531\fBvoid png_set_alpha_mode_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, png_fixed_point \fIoutput_gamma\fP\fB);\fP
532
533\fI\fB
534
535\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
536
537\fI\fB
538
539\fBvoid png_set_background_fixed (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, png_uint_32 \fIbackground_gamma\fP\fB);\fP
540
541\fI\fB
542
543\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
544
545\fI\fB
546
547\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
548
549\fI\fB
550
551\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
552
553\fI\fB
554
555\fBvoid png_set_check_for_invalid_index(png_structrp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
556
557\fI\fB
558
559\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
560
561\fI\fB
562
563\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
564
565\fI\fB
566
567\fBvoid png_set_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIred_X\fP\fB, double \fP\fIred_Y\fP\fB, double \fP\fIred_Z\fP\fB, double \fP\fIgreen_X\fP\fB, double \fIgreen_Y,
568
569\fBdouble \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP
570
571\fI\fB
572
573\fBvoid png_set_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fIint_red_X\fP\fB, png_fixed_point \fP\fIint_red_Y\fP\fB, png_fixed_point \fP\fIint_red_Z\fP\fB, png_fixed_point \fP\fIint_green_X\fP\fB, png_fixed_point \fP\fIint_green_Y\fP\fB, png_fixed_point \fP\fIint_green_Z\fP\fB, png_fixed_point \fP\fIint_blue_X\fP\fB, png_fixed_point \fP\fIint_blue_Y\fP\fB, png_fixed_point \fIint_blue_Z\fP\fB);\fP
574
575\fI\fB
576
577\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
578
579\fI\fB
580
581\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
582
583\fI\fB
584
585\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
586
587\fI\fB
588
589\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
590
591\fI\fB
592
593\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
594
595\fI\fB
596
597\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
598
599\fI\fB
600
601\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
602
603\fI\fB
604
605\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
606
607\fI\fB
608
609\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
610
611\fI\fB
612
613\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
614
615\fI\fB
616
617\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
618
619\fI\fB
620
621\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
622
623\fI\fB
624
625\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
626
627\fI\fB
628
629\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
630
631\fI\fB
632
633\fBvoid png_set_filter_heuristics_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_fixed_point_p \fP\fIfilter_weights\fP\fB, png_fixed_point_p \fIfilter_costs\fP\fB);\fP
634
635\fI\fB
636
637\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
638
639\fI\fB
640
641\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
642
643\fI\fB
644
645\fBvoid png_set_gamma_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIscreen_gamma\fP\fB, png_uint_32 \fIdefault_file_gamma\fP\fB);\fP
646
647\fI\fB
648
649\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
650
651\fI\fB
652
653\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
654
655\fI\fB
656
657\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
658
659\fI\fB
660
661\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
662
663\fI\fB
664
665\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
666
667\fI\fB
668
669\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_const_bytep \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
670
671\fI\fB
672
673\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
674
675\fI\fB
676
677\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
678
679\fI\fB
680
681\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
682
683\fI\fB
684
685\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
686
687\fI\fB
688
689\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
690
691\fI\fB
692
693\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
694
695\fI\fB
696
697\fBjmp_buf* png_set_longjmp_fn (png_structp \fP\fIpng_ptr\fP\fB, png_longjmp_ptr \fP\fIlongjmp_fn\fP\fB, size_t \fIjmp_buf_size\fP\fB);\fP
698
699\fI\fB
700
701\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
702
703\fI\fB
704
705\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
706
707\fI\fB
708
709\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
710
711\fI\fB
712
713\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
714
715\fI\fB
716
717\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
718
719\fI\fB
720
721\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
722
723\fI\fB
724
725\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
726
727\fI\fB
728
729\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
730
731\fI\fB
732
733\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
734
735\fI\fB
736
737\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
738
739\fI\fB
740
741\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
742
743\fI\fB
744
745\fBvoid png_set_quantize (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_quantize\fP\fB);\fP
746
747\fI\fB
748
749\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
750
751\fI\fB
752
753\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
754
755\fI\fB
756
757\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
758
759\fI\fB
760
761\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
762
763\fI\fB
764
765\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
766
767\fI\fB
768
769\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_uint_32 \fP\fIred\fP\fB, png_uint_32 \fIgreen\fP\fB);\fP
770
771\fI\fB
772
773\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
774
775\fI\fB
776
777\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
778
779\fI\fB
780
781\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
782
783\fI\fB
784
785\fBvoid png_set_sCAL_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_fixed_point \fP\fIwidth\fP\fB, png_fixed_point \fIheight\fP\fB);\fP
786
787\fI\fB
788
789\fBvoid png_set_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
790
791\fI\fB
792
793\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
794
795\fI\fB
796
797\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
798
799\fI\fB
800
801\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
802
803\fI\fB
804
805\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
806
807\fI\fB
808
809\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
810
811\fI\fB
812
813\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
814
815\fI\fB
816
817\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
818
819\fI\fB
820
821\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
822
823\fI\fB
824
825\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
826
827\fI\fB
828
829\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
830
831\fI\fB
832
833\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
834
835\fI\fB
836
837\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
838
839\fI\fB
840
841\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
842
843\fI\fB
844
845\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
846
847\fI\fB
848
849\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
850
851\fI\fB
852
853\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
854
855\fI\fB
856
857\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
858
859\fI\fB
860
861\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
862
863\fI\fB
864
865\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans_alpha\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP
866
867\fI\fB
868
869\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
870
871\fI\fB
872
873\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
874
875\fI\fB
876
877\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
878
879\fI\fB
880
881\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
882
883\fI\fB
884
885\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
886
887\fI\fB
888
889\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
890
891\fI\fB
892
893\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
894
895\fI\fB
896
897\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
898
899\fI\fB
900
901\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
902
903\fI\fB
904
905\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
906
907\fI\fB
908
909\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
910
911\fI\fB
912
913\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
914
915\fI\fB
916
917\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
918
919\fI\fB
920
921\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
922
923\fI\fB
924
925\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
926
927\fI\fB
928
929\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
930
931\fI\fB
932
933\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
934
935\fI\fB
936
937\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
938
939\fI\fB
940
941\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
942
943\fI\fB
944
945\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
946
947\fI\fB
948
949\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
950
951\fI\fB
952
953\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
954
955\fI\fB
956
957\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
958
959\fI\fB
960
961\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
962
963\fI\fB
964
965\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
966
967\fI\fB
968
969\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
970
971\fI\fB
972
973.SH DESCRIPTION
974The
975.I libpng
976library supports encoding, decoding, and various manipulations of
977the Portable Network Graphics (PNG) format image files.  It uses the
978.IR zlib(3)
979compression library.
980Following is a copy of the libpng-manual.txt file that accompanies libpng.
981.SH LIBPNG.TXT
982Libpng-manual.txt - A description on how to use and modify libpng
983
984 libpng version 1.5.12 - July 11, 2012
985 Updated and distributed by Glenn Randers-Pehrson
986 <glennrp at users.sourceforge.net>
987 Copyright (c) 1998-2011 Glenn Randers-Pehrson
988
989 This document is released under the libpng license.
990 For conditions of distribution and use, see the disclaimer
991 and license in png.h
992
993 Based on:
994
995 libpng versions 0.97, January 1998, through 1.5.12 - July 11, 2012
996 Updated and distributed by Glenn Randers-Pehrson
997 Copyright (c) 1998-2011 Glenn Randers-Pehrson
998
999 libpng 1.0 beta 6  version 0.96 May 28, 1997
1000 Updated and distributed by Andreas Dilger
1001 Copyright (c) 1996, 1997 Andreas Dilger
1002
1003 libpng 1.0 beta 2 - version 0.88  January 26, 1996
1004 For conditions of distribution and use, see copyright
1005 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
1006 Schalnat, Group 42, Inc.
1007
1008 Updated/rewritten per request in the libpng FAQ
1009 Copyright (c) 1995, 1996 Frank J. T. Wojcik
1010 December 18, 1995 & January 20, 1996
1011
1012.SH I. Introduction
1013
1014This file describes how to use and modify the PNG reference library
1015(known as libpng) for your own use.  There are five sections to this
1016file: introduction, structures, reading, writing, and modification and
1017configuration notes for various special platforms.  In addition to this
1018file, example.c is a good starting point for using the library, as
1019it is heavily commented and should include everything most people
1020will need.  We assume that libpng is already installed; see the
1021INSTALL file for instructions on how to install libpng.
1022
1023For examples of libpng usage, see the files "example.c", "pngtest.c",
1024and the files in the "contrib" directory, all of which are included in
1025the libpng distribution.
1026
1027Libpng was written as a companion to the PNG specification, as a way
1028of reducing the amount of time and effort it takes to support the PNG
1029file format in application programs.
1030
1031The PNG specification (second edition), November 2003, is available as
1032a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
1033<http://www.w3.org/TR/2003/REC-PNG-20031110/
1034The W3C and ISO documents have identical technical content.
1035
1036The PNG-1.2 specification is available at
1037<http://www.libpng.org/pub/png/documents/>.  It is technically equivalent
1038to the PNG specification (second edition) but has some additional material.
1039
1040The PNG-1.0 specification is available
1041as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
1042W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
1043
1044Some additional chunks are described in the special-purpose public chunks
1045documents at <http://www.libpng.org/pub/png/documents/>.
1046
1047Other information
1048about PNG, and the latest version of libpng, can be found at the PNG home
1049page, <http://www.libpng.org/pub/png/>.
1050
1051Most users will not have to modify the library significantly; advanced
1052users may want to modify it more.  All attempts were made to make it as
1053complete as possible, while keeping the code easy to understand.
1054Currently, this library only supports C.  Support for other languages
1055is being considered.
1056
1057Libpng has been designed to handle multiple sessions at one time,
1058to be easily modifiable, to be portable to the vast majority of
1059machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
1060to use.  The ultimate goal of libpng is to promote the acceptance of
1061the PNG file format in whatever way possible.  While there is still
1062work to be done (see the TODO file), libpng should cover the
1063majority of the needs of its users.
1064
1065Libpng uses zlib for its compression and decompression of PNG files.
1066Further information about zlib, and the latest version of zlib, can
1067be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
1068The zlib compression utility is a general purpose utility that is
1069useful for more than PNG files, and can be used without libpng.
1070See the documentation delivered with zlib for more details.
1071You can usually find the source files for the zlib utility wherever you
1072find the libpng source files.
1073
1074Libpng is thread safe, provided the threads are using different
1075instances of the structures.  Each thread should have its own
1076png_struct and png_info instances, and thus its own image.
1077Libpng does not protect itself against two threads using the
1078same instance of a structure.
1079
1080.SH II. Structures
1081
1082There are two main structures that are important to libpng, png_struct
1083and png_info.  Both are internal structures that are no longer exposed
1084in the libpng interface (as of libpng 1.5.0).
1085
1086The png_info structure is designed to provide information about the
1087PNG file.  At one time, the fields of png_info were intended to be
1088directly accessible to the user.  However, this tended to cause problems
1089with applications using dynamically loaded libraries, and as a result
1090a set of interface functions for png_info (the png_get_*() and png_set_*()
1091functions) was developed, and direct access to the png_info fields was
1092deprecated..
1093
1094The png_struct structure is the object used by the library to decode a
1095single image.  As of 1.5.0 this structure is also not exposed.
1096
1097Almost all libpng APIs require a pointer to a png_struct as the first argument.
1098Many (in particular the png_set and png_get APIs) also require a pointer
1099to png_info as the second argument.  Some application visible macros
1100defined in png.h designed for basic data access (reading and writing
1101integers in the PNG format) don't take a png_info pointer, but it's almost
1102always safe to assume that a (png_struct*) has to be passed to call an API
1103function.
1104
1105You can have more than one png_info structure associated with an image,
1106as illustrated in pngtest.c, one for information valid prior to the
1107IDAT chunks and another (called "end_info" below) for things after them.
1108
1109The png.h header file is an invaluable reference for programming with libpng.
1110And while I'm on the topic, make sure you include the libpng header file:
1111
1112#include <png.h>
1113
1114and also (as of libpng-1.5.0) the zlib header file, if you need it:
1115
1116#include <zlib.h>
1117
1118.SS Types
1119
1120The png.h header file defines a number of integral types used by the
1121APIs.  Most of these are fairly obvious; for example types corresponding
1122to integers of particular sizes and types for passing color values.
1123
1124One exception is how non-integral numbers are handled.  For application
1125convenience most APIs that take such numbers have C (double) arguments;
1126however, internally PNG, and libpng, use 32 bit signed integers and encode
1127the value by multiplying by 100,000.  As of libpng 1.5.0 a convenience
1128macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
1129which is simply (png_int_32).
1130
1131All APIs that take (double) arguments also have a matching API that
1132takes the corresponding fixed point integer arguments.  The fixed point
1133API has the same name as the floating point one with "_fixed" appended.
1134The actual range of values permitted in the APIs is frequently less than
1135the full range of (png_fixed_point) (-21474 to +21474).  When APIs require
1136a non-negative argument the type is recorded as png_uint_32 above.  Consult
1137the header file and the text below for more information.
1138
1139Special care must be take with sCAL chunk handling because the chunk itself
1140uses non-integral values encoded as strings containing decimal floating point
1141numbers.  See the comments in the header file.
1142
1143.SS Configuration
1144
1145The main header file function declarations are frequently protected by C
1146preprocessing directives of the form:
1147
1148    #ifdef PNG_feature_SUPPORTED
1149    declare-function
1150    #endif
1151    ...
1152    #ifdef PNG_feature_SUPPORTED
1153    use-function
1154    #endif
1155
1156The library can be built without support for these APIs, although a
1157standard build will have all implemented APIs.  Application programs
1158should check the feature macros before using an API for maximum
1159portability.  From libpng 1.5.0 the feature macros set during the build
1160of libpng are recorded in the header file "pnglibconf.h" and this file
1161is always included by png.h.
1162
1163If you don't need to change the library configuration from the default, skip to
1164the next section ("Reading").
1165
1166Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
1167of the build project files in the 'projects' directory simply copy
1168scripts/pnglibconf.h.prebuilt to pnglibconf.h.  This means that these build
1169systems do not permit easy auto-configuration of the library - they only
1170support the default configuration.
1171
1172The easiest way to make minor changes to the libpng configuration when
1173auto-configuration is supported is to add definitions to the command line
1174using (typically) CPPFLAGS.  For example:
1175
1176CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
1177
1178will change the internal libpng math implementation for gamma correction and
1179other arithmetic calculations to fixed point, avoiding the need for fast
1180floating point support.  The result can be seen in the generated pnglibconf.h -
1181make sure it contains the changed feature macro setting.
1182
1183If you need to make more extensive configuration changes - more than one or two
1184feature macro settings - you can either add -DPNG_USER_CONFIG to the build
1185command line and put a list of feature macro settings in pngusr.h or you can set
1186DFA_XTRA (a makefile variable) to a file containing the same information in the
1187form of 'option' settings.
1188
1189A. Changing pnglibconf.h
1190
1191A variety of methods exist to build libpng.  Not all of these support
1192reconfiguration of pnglibconf.h.  To reconfigure pnglibconf.h it must either be
1193rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
1194
1195Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
1196pnglibconf.h and changing the lines defining the supported features, paying
1197very close attention to the 'option' information in scripts/pnglibconf.dfa
1198that describes those features and their requirements.  This is easy to get
1199wrong.
1200
1201B. Configuration using DFA_XTRA
1202
1203Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
1204variant such as 'nawk' or 'gawk', is available.  The configure build will
1205automatically find an appropriate awk and build pnglibconf.h.
1206The scripts/pnglibconf.mak file contains a set of make rules for doing the
1207same thing if configure is not used, and many of the makefiles in the scripts
1208directory use this approach.
1209
1210When rebuilding simply write a new file containing changed options and set
1211DFA_XTRA to the name of this file.  This causes the build to append the new file
1212to the end of scripts/pnglibconf.dfa.  The pngusr.dfa file should contain lines
1213of the following forms:
1214
1215everything = off
1216
1217This turns all optional features off.  Include it at the start of pngusr.dfa to
1218make it easier to build a minimal configuration.  You will need to turn at least
1219some features on afterward to enable either reading or writing code, or both.
1220
1221option feature on
1222option feature off
1223
1224Enable or disable a single feature.  This will automatically enable other
1225features required by a feature that is turned on or disable other features that
1226require a feature which is turned off.  Conflicting settings will cause an error
1227message to be emitted by awk.
1228
1229setting feature default value
1230
1231Changes the default value of setting 'feature' to 'value'.  There are a small
1232number of settings listed at the top of pnglibconf.h, they are documented in the
1233source code.  Most of these values have performance implications for the library
1234but most of them have no visible effect on the API.  Some can also be overridden
1235from the API.
1236
1237This method of building a customized pnglibconf.h is illustrated in
1238contrib/pngminim/*.  See the "$(PNGCONF):" target in the makefile and
1239pngusr.dfa in these directories.
1240
1241C. Configuration using PNG_USR_CONFIG
1242
1243If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
1244pngusr.h will automatically be included before the options in
1245scripts/pnglibconf.dfa are processed.  Your pngusr.h file should contain only
1246macro definitions turning features on or off or setting settings.
1247
1248Apart from the global setting "everything = off" all the options listed above
1249can be set using macros in pngusr.h:
1250
1251#define PNG_feature_SUPPORTED
1252
1253is equivalent to:
1254
1255option feature on
1256
1257#define PNG_NO_feature
1258
1259is equivalent to:
1260
1261option feature off
1262
1263#define PNG_feature value
1264
1265is equivalent to:
1266
1267setting feature default value
1268
1269Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
1270pngusr file you supply override the contents of scripts/pnglibconf.dfa
1271
1272If confusing or incomprehensible behavior results it is possible to
1273examine the intermediate file pnglibconf.dfn to find the full set of
1274dependency information for each setting and option.  Simply locate the
1275feature in the file and read the C comments that precede it.
1276
1277This method is also illustrated in the contrib/pngminim/* makefiles and
1278pngusr.h.
1279
1280.SH III. Reading
1281
1282We'll now walk you through the possible functions to call when reading
1283in a PNG file sequentially, briefly explaining the syntax and purpose
1284of each one.  See example.c and png.h for more detail.  While
1285progressive reading is covered in the next section, you will still
1286need some of the functions discussed in this section to read a PNG
1287file.
1288
1289.SS Setup
1290
1291You will want to do the I/O initialization(*) before you get into libpng,
1292so if it doesn't work, you don't have much to undo.  Of course, you
1293will also want to insure that you are, in fact, dealing with a PNG
1294file.  Libpng provides a simple check to see if a file is a PNG file.
1295To use it, pass in the first 1 to 8 bytes of the file to the function
1296png_sig_cmp(), and it will return 0 (false) if the bytes match the
1297corresponding bytes of the PNG signature, or nonzero (true) otherwise.
1298Of course, the more bytes you pass in, the greater the accuracy of the
1299prediction.
1300
1301If you are intending to keep the file pointer open for use in libpng,
1302you must ensure you don't read more than 8 bytes from the beginning
1303of the file, and you also have to make a call to png_set_sig_bytes_read()
1304with the number of bytes you read from the beginning.  Libpng will
1305then only check the bytes (if any) that your program didn't read.
1306
1307(*): If you are not using the standard I/O functions, you will need
1308to replace them with custom functions.  See the discussion under
1309Customizing libpng.
1310
1311
1312    FILE *fp = fopen(file_name, "rb");
1313    if (!fp)
1314    {
1315       return (ERROR);
1316    }
1317
1318    fread(header, 1, number, fp);
1319    is_png = !png_sig_cmp(header, 0, number);
1320
1321    if (!is_png)
1322    {
1323       return (NOT_PNG);
1324    }
1325
1326
1327Next, png_struct and png_info need to be allocated and initialized.  In
1328order to ensure that the size of these structures is correct even with a
1329dynamically linked libpng, there are functions to initialize and
1330allocate the structures.  We also pass the library version, optional
1331pointers to error handling functions, and a pointer to a data struct for
1332use by the error functions, if necessary (the pointer and functions can
1333be NULL if the default error handlers are to be used).  See the section
1334on Changes to Libpng below regarding the old initialization functions.
1335The structure allocation functions quietly return NULL if they fail to
1336create the structure, so your application should check for that.
1337
1338    png_structp png_ptr = png_create_read_struct
1339        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1340        user_error_fn, user_warning_fn);
1341
1342    if (!png_ptr)
1343       return (ERROR);
1344
1345    png_infop info_ptr = png_create_info_struct(png_ptr);
1346
1347    if (!info_ptr)
1348    {
1349       png_destroy_read_struct(&png_ptr,
1350           (png_infopp)NULL, (png_infopp)NULL);
1351       return (ERROR);
1352    }
1353
1354If you want to use your own memory allocation routines,
1355use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
1356png_create_read_struct_2() instead of png_create_read_struct():
1357
1358    png_structp png_ptr = png_create_read_struct_2
1359        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1360        user_error_fn, user_warning_fn, (png_voidp)
1361        user_mem_ptr, user_malloc_fn, user_free_fn);
1362
1363The error handling routines passed to png_create_read_struct()
1364and the memory alloc/free routines passed to png_create_struct_2()
1365are only necessary if you are not using the libpng supplied error
1366handling and memory alloc/free functions.
1367
1368When libpng encounters an error, it expects to longjmp back
1369to your routine.  Therefore, you will need to call setjmp and pass
1370your png_jmpbuf(png_ptr).  If you read the file from different
1371routines, you will need to update the longjmp buffer every time you enter
1372a new routine that will call a png_*() function.
1373
1374See your documentation of setjmp/longjmp for your compiler for more
1375information on setjmp/longjmp.  See the discussion on libpng error
1376handling in the Customizing Libpng section below for more information
1377on the libpng error handling.  If an error occurs, and libpng longjmp's
1378back to your setjmp, you will want to call png_destroy_read_struct() to
1379free any memory.
1380
1381    if (setjmp(png_jmpbuf(png_ptr)))
1382    {
1383       png_destroy_read_struct(&png_ptr, &info_ptr,
1384           &end_info);
1385       fclose(fp);
1386       return (ERROR);
1387    }
1388
1389Pass (png_infopp)NULL instead of &end_info if you didn't create
1390an end_info structure.
1391
1392If you would rather avoid the complexity of setjmp/longjmp issues,
1393you can compile libpng with PNG_NO_SETJMP, in which case
1394errors will result in a call to PNG_ABORT() which defaults to abort().
1395
1396You can #define PNG_ABORT() to a function that does something
1397more useful than abort(), as long as your function does not
1398return.
1399
1400Now you need to set up the input code.  The default for libpng is to
1401use the C function fread().  If you use this, you will need to pass a
1402valid FILE * in the function png_init_io().  Be sure that the file is
1403opened in binary mode.  If you wish to handle reading data in another
1404way, you need not call the png_init_io() function, but you must then
1405implement the libpng I/O methods discussed in the Customizing Libpng
1406section below.
1407
1408    png_init_io(png_ptr, fp);
1409
1410If you had previously opened the file and read any of the signature from
1411the beginning in order to see if this was a PNG file, you need to let
1412libpng know that there are some bytes missing from the start of the file.
1413
1414    png_set_sig_bytes(png_ptr, number);
1415
1416You can change the zlib compression buffer size to be used while
1417reading compressed data with
1418
1419    png_set_compression_buffer_size(png_ptr, buffer_size);
1420
1421where the default size is 8192 bytes.  Note that the buffer size
1422is changed immediately and the buffer is reallocated immediately,
1423instead of setting a flag to be acted upon later.
1424
1425If you want CRC errors to be handled in a different manner than
1426the default, use
1427
1428    png_set_crc_action(png_ptr, crit_action, ancil_action);
1429
1430The values for png_set_crc_action() say how libpng is to handle CRC errors in
1431ancillary and critical chunks, and whether to use the data contained
1432therein.  Note that it is impossible to "discard" data in a critical
1433chunk.
1434
1435Choices for (int) crit_action are
1436   PNG_CRC_DEFAULT      0  error/quit
1437   PNG_CRC_ERROR_QUIT   1  error/quit
1438   PNG_CRC_WARN_USE     3  warn/use data
1439   PNG_CRC_QUIET_USE    4  quiet/use data
1440   PNG_CRC_NO_CHANGE    5  use the current value
1441
1442Choices for (int) ancil_action are
1443   PNG_CRC_DEFAULT      0  error/quit
1444   PNG_CRC_ERROR_QUIT   1  error/quit
1445   PNG_CRC_WARN_DISCARD 2  warn/discard data
1446   PNG_CRC_WARN_USE     3  warn/use data
1447   PNG_CRC_QUIET_USE    4  quiet/use data
1448   PNG_CRC_NO_CHANGE    5  use the current value
1449
1450.SS Setting up callback code
1451
1452You can set up a callback function to handle any unknown chunks in the
1453input stream. You must supply the function
1454
1455    read_chunk_callback(png_structp png_ptr,
1456         png_unknown_chunkp chunk);
1457    {
1458       /* The unknown chunk structure contains your
1459          chunk data, along with similar data for any other
1460          unknown chunks: */
1461
1462           png_byte name[5];
1463           png_byte *data;
1464           png_size_t size;
1465
1466       /* Note that libpng has already taken care of
1467          the CRC handling */
1468
1469       /* put your code here.  Search for your chunk in the
1470          unknown chunk structure, process it, and return one
1471          of the following: */
1472
1473       return (-n); /* chunk had an error */
1474       return (0); /* did not recognize */
1475       return (n); /* success */
1476    }
1477
1478(You can give your function another name that you like instead of
1479"read_chunk_callback")
1480
1481To inform libpng about your function, use
1482
1483    png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1484        read_chunk_callback);
1485
1486This names not only the callback function, but also a user pointer that
1487you can retrieve with
1488
1489    png_get_user_chunk_ptr(png_ptr);
1490
1491If you call the png_set_read_user_chunk_fn() function, then all unknown
1492chunks will be saved when read, in case your callback function will need
1493one or more of them.  This behavior can be changed with the
1494png_set_keep_unknown_chunks() function, described below.
1495
1496At this point, you can set up a callback function that will be
1497called after each row has been read, which you can use to control
1498a progress meter or the like.  It's demonstrated in pngtest.c.
1499You must supply a function
1500
1501    void read_row_callback(png_structp png_ptr,
1502       png_uint_32 row, int pass);
1503    {
1504      /* put your code here */
1505    }
1506
1507(You can give it another name that you like instead of "read_row_callback")
1508
1509To inform libpng about your function, use
1510
1511    png_set_read_status_fn(png_ptr, read_row_callback);
1512
1513When this function is called the row has already been completely processed and
1514the 'row' and 'pass' refer to the next row to be handled.  For the
1515non-interlaced case the row that was just handled is simply one less than the
1516passed in row number, and pass will always be 0.  For the interlaced case the
1517same applies unless the row value is 0, in which case the row just handled was
1518the last one from one of the preceding passes.  Because interlacing may skip a
1519pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1520need to know what the last pass is record (row,pass) from the callback and use
1521the last recorded value each time.
1522
1523As with the user transform you can find the output row using the
1524PNG_ROW_FROM_PASS_ROW macro.
1525
1526.SS Unknown-chunk handling
1527
1528Now you get to set the way the library processes unknown chunks in the
1529input PNG stream. Both known and unknown chunks will be read.  Normal
1530behavior is that known chunks will be parsed into information in
1531various info_ptr members while unknown chunks will be discarded. This
1532behavior can be wasteful if your application will never use some known
1533chunk types. To change this, you can call:
1534
1535    png_set_keep_unknown_chunks(png_ptr, keep,
1536        chunk_list, num_chunks);
1537    keep       - 0: default unknown chunk handling
1538                 1: ignore; do not keep
1539                 2: keep only if safe-to-copy
1540                 3: keep even if unsafe-to-copy
1541
1542               You can use these definitions:
1543                 PNG_HANDLE_CHUNK_AS_DEFAULT   0
1544                 PNG_HANDLE_CHUNK_NEVER        1
1545                 PNG_HANDLE_CHUNK_IF_SAFE      2
1546                 PNG_HANDLE_CHUNK_ALWAYS       3
1547
1548    chunk_list - list of chunks affected (a byte string,
1549                 five bytes per chunk, NULL or '\0' if
1550                 num_chunks is 0)
1551
1552    num_chunks - number of chunks affected; if 0, all
1553                 unknown chunks are affected.  If nonzero,
1554                 only the chunks in the list are affected
1555
1556Unknown chunks declared in this way will be saved as raw data onto a
1557list of png_unknown_chunk structures.  If a chunk that is normally
1558known to libpng is named in the list, it will be handled as unknown,
1559according to the "keep" directive.  If a chunk is named in successive
1560instances of png_set_keep_unknown_chunks(), the final instance will
1561take precedence.  The IHDR and IEND chunks should not be named in
1562chunk_list; if they are, libpng will process them normally anyway.
1563If you know that your application will never make use of some particular
1564chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
1565
1566Here is an example of the usage of png_set_keep_unknown_chunks(),
1567where the private "vpAg" chunk will later be processed by a user chunk
1568callback function:
1569
1570    png_byte vpAg[5]={118, 112,  65, 103, (png_byte) '\0'};
1571
1572    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1573      png_byte unused_chunks[]=
1574      {
1575        104,  73,  83,  84, (png_byte) '\0',   /* hIST */
1576        105,  84,  88, 116, (png_byte) '\0',   /* iTXt */
1577        112,  67,  65,  76, (png_byte) '\0',   /* pCAL */
1578        115,  67,  65,  76, (png_byte) '\0',   /* sCAL */
1579        115,  80,  76,  84, (png_byte) '\0',   /* sPLT */
1580        116,  73,  77,  69, (png_byte) '\0',   /* tIME */
1581      };
1582    #endif
1583
1584    ...
1585
1586    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1587      /* ignore all unknown chunks: */
1588      png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
1589
1590      /* except for vpAg: */
1591      png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
1592
1593      /* also ignore unused known chunks: */
1594      png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1595         (int)sizeof(unused_chunks)/5);
1596    #endif
1597
1598.SS User limits
1599
1600The PNG specification allows the width and height of an image to be as
1601large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1602Since very few applications really need to process such large images,
1603we have imposed an arbitrary 1-million limit on rows and columns.
1604Larger images will be rejected immediately with a png_error() call. If
1605you wish to change this limit, you can use
1606
1607   png_set_user_limits(png_ptr, width_max, height_max);
1608
1609to set your own limits, or use width_max = height_max = 0x7fffffffL
1610to allow all valid dimensions (libpng may reject some very large images
1611anyway because of potential buffer overflow conditions).
1612
1613You should put this statement after you create the PNG structure and
1614before calling png_read_info(), png_read_png(), or png_process_data().
1615
1616When writing a PNG datastream, put this statement before calling
1617png_write_info() or png_write_png().
1618
1619If you need to retrieve the limits that are being applied, use
1620
1621   width_max = png_get_user_width_max(png_ptr);
1622   height_max = png_get_user_height_max(png_ptr);
1623
1624The PNG specification sets no limit on the number of ancillary chunks
1625allowed in a PNG datastream.  You can impose a limit on the total number
1626of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1627
1628   png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1629
1630where 0x7fffffffL means unlimited.  You can retrieve this limit with
1631
1632   chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1633
1634This limit also applies to the number of buffers that can be allocated
1635by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1636
1637You can also set a limit on the amount of memory that a compressed chunk
1638other than IDAT can occupy, with
1639
1640   png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1641
1642and you can retrieve the limit with
1643
1644   chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1645
1646Any chunks that would cause either of these limits to be exceeded will
1647be ignored.
1648
1649.SS Information about your system
1650
1651If you intend to display the PNG or to incorporate it in other image data you
1652need to tell libpng information about your display or drawing surface so that
1653libpng can convert the values in the image to match the display.
1654
1655From libpng-1.5.4 this information can be set before reading the PNG file
1656header.  In earlier versions png_set_gamma() existed but behaved incorrectly if
1657called before the PNG file header had been read and png_set_alpha_mode() did not
1658exist.
1659
1660If you need to support versions prior to libpng-1.5.4 test the version number
1661as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1662described in the appropriate manual page.
1663
1664You give libpng the encoding expected by your system expressed as a 'gamma'
1665value.  You can also specify a default encoding for the PNG file in
1666case the required information is missing from the file.  By default libpng
1667assumes that the PNG data matches your system, to keep this default call:
1668
1669   png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
1670
1671or you can use the fixed point equivalent:
1672
1673   png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
1674
1675If you don't know the gamma for your system it is probably 2.2 - a good
1676approximation to the IEC standard for display systems (sRGB).  If images are
1677too contrasty or washed out you got the value wrong - check your system
1678documentation!
1679
1680Many systems permit the system gamma to be changed via a lookup table in the
1681display driver, a few systems, including older Macs, change the response by
1682default.  As of 1.5.4 three special values are available to handle common
1683situations:
1684
1685   PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
1686                     standard.  This matches almost all systems.
1687   PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6)
1688                     Apple Macintosh system with the default settings.
1689   PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
1690                     system expects data with no gamma encoding.
1691
1692You would use the linear (unencoded) value if you need to process the pixel
1693values further because this avoids the need to decode and reencode each
1694component value whenever arithmetic is performed.  A lot of graphics software
1695uses linear values for this reason, often with higher precision component values
1696to preserve overall accuracy.
1697
1698The second thing you may need to tell libpng about is how your system handles
1699alpha channel information.  Some, but not all, PNG files contain an alpha
1700channel.  To display these files correctly you need to compose the data onto a
1701suitable background, as described in the PNG specification.
1702
1703Libpng only supports composing onto a single color (using png_set_background;
1704see below).  Otherwise you must do the composition yourself and, in this case,
1705you may need to call png_set_alpha_mode:
1706
1707#if PNG_LIBPNG_VER >= 10504
1708   png_set_alpha_mode(png_ptr, mode, screen_gamma);
1709#else
1710   png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);
1711#endif
1712
1713The screen_gamma value is the same as the argument to png_set_gamma; however,
1714how it affects the output depends on the mode.  png_set_alpha_mode() sets the
1715file gamma default to 1/screen_gamma, so normally you don't need to call
1716png_set_gamma.  If you need different defaults call png_set_gamma() before
1717png_set_alpha_mode() - if you call it after it will override the settings made
1718by png_set_alpha_mode().
1719
1720The mode is as follows:
1721
1722    PNG_ALPHA_PNG: The data is encoded according to the PNG specification.  Red,
1723green and blue, or gray, components are gamma encoded color
1724values and are not premultiplied by the alpha value.  The
1725alpha value is a linear measure of the contribution of the
1726pixel to the corresponding final output pixel.
1727
1728You should normally use this format if you intend to perform
1729color correction on the color values; most, maybe all, color
1730correction software has no handling for the alpha channel and,
1731anyway, the math to handle pre-multiplied component values is
1732unnecessarily complex.
1733
1734Before you do any arithmetic on the component values you need
1735to remove the gamma encoding and multiply out the alpha
1736channel.  See the PNG specification for more detail.  It is
1737important to note that when an image with an alpha channel is
1738scaled, linear encoded, pre-multiplied component values must
1739be used!
1740
1741The remaining modes assume you don't need to do any further color correction or
1742that if you do, your color correction software knows all about alpha (it
1743probably doesn't!)
1744
1745    PNG_ALPHA_STANDARD:  The data libpng produces
1746is encoded in the standard way
1747assumed by most correctly written graphics software.
1748The gamma encoding will be removed by libpng and the
1749linear component values will be pre-multiplied by the
1750alpha channel.
1751
1752With this format the final image must be re-encoded to
1753match the display gamma before the image is displayed.
1754If your system doesn't do that, yet still seems to
1755perform arithmetic on the pixels without decoding them,
1756it is broken - check out the modes below.
1757
1758With PNG_ALPHA_STANDARD libpng always produces linear
1759component values, whatever screen_gamma you supply.  The
1760screen_gamma value is, however, used as a default for
1761the file gamma if the PNG file has no gamma information.
1762
1763If you call png_set_gamma() after png_set_alpha_mode() you
1764will override the linear encoding.  Instead the
1765pre-multiplied pixel values will be gamma encoded but
1766the alpha channel will still be linear.  This may
1767actually match the requirements of some broken software,
1768but it is unlikely.
1769
1770While linear 8-bit data is often used it has
1771insufficient precision for any image with a reasonable
1772dynamic range.  To avoid problems, and if your software
1773supports it, use png_set_expand_16() to force all
1774components to 16 bits.
1775
1776    PNG_ALPHA_OPTIMIZED: This mode is the same
1777as PNG_ALPHA_STANDARD except that
1778completely opaque pixels are gamma encoded according to
1779the screen_gamma value.  Pixels with alpha less than 1.0
1780will still have linear components.
1781
1782Use this format if you have control over your
1783compositing software and so don't do other arithmetic
1784(such as scaling) on the data you get from libpng.  Your
1785compositing software can simply copy opaque pixels to
1786the output but still has linear values for the
1787non-opaque pixels.
1788
1789In normal compositing, where the alpha channel encodes
1790partial pixel coverage (as opposed to broad area
1791translucency), the inaccuracies of the 8-bit
1792representation of non-opaque pixels are irrelevant.
1793
1794You can also try this format if your software is broken;
1795it might look better.
1796
1797    PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD;
1798however, all component values,
1799including the alpha channel are gamma encoded.  This is
1800an appropriate format to try if your software, or more
1801likely hardware, is totally broken, i.e., if it performs
1802linear arithmetic directly on gamma encoded values.
1803
1804In most cases of broken software or hardware the bug in the final display
1805manifests as a subtle halo around composited parts of the image.  You may not
1806even perceive this as a halo; the composited part of the image may simply appear
1807separate from the background, as though it had been cut out of paper and pasted
1808on afterward.
1809
1810If you don't have to deal with bugs in software or hardware, or if you can fix
1811them, there are three recommended ways of using png_set_alpha_mode():
1812
1813   png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
1814       screen_gamma);
1815
1816You can do color correction on the result (libpng does not currently
1817support color correction internally).  When you handle the alpha channel
1818you need to undo the gamma encoding and multiply out the alpha.
1819
1820   png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
1821       screen_gamma);
1822   png_set_expand_16(png_ptr);
1823
1824If you are using the high level interface, don't call png_set_expand_16();
1825instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
1826
1827With this mode you can't do color correction, but you can do arithmetic,
1828including composition and scaling, on the data without further processing.
1829
1830   png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1831       screen_gamma);
1832
1833You can avoid the expansion to 16-bit components with this mode, but you
1834lose the ability to scale the image or perform other linear arithmetic.
1835All you can do is compose the result onto a matching output.  Since this
1836mode is libpng-specific you also need to write your own composition
1837software.
1838
1839If you don't need, or can't handle, the alpha channel you can call
1840png_set_background() to remove it by compositing against a fixed color.  Don't
1841call png_set_strip_alpha() to do this - it will leave spurious pixel values in
1842transparent parts of this image.
1843
1844   png_set_background(png_ptr, &background_color,
1845       PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
1846
1847The background_color is an RGB or grayscale value according to the data format
1848libpng will produce for you.  Because you don't yet know the format of the PNG
1849file, if you call png_set_background at this point you must arrange for the
1850format produced by libpng to always have 8-bit or 16-bit components and then
1851store the color as an 8-bit or 16-bit color as appropriate.  The color contains
1852separate gray and RGB component values, so you can let libpng produce gray or
1853RGB output according to the input format, but low bit depth grayscale images
1854must always be converted to at least 8-bit format.  (Even though low bit depth
1855grayscale images can't have an alpha channel they can have a transparent
1856color!)
1857
1858You set the transforms you need later, either as flags to the high level
1859interface or libpng API calls for the low level interface.  For reference the
1860settings and API calls required are:
1861
18628-bit values:
1863   PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
1864   png_set_expand(png_ptr); png_set_scale_16(png_ptr);
1865
1866   If you must get exactly the same inaccurate results
1867   produced by default in versions prior to libpng-1.5.4,
1868   use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
1869   instead.
1870
187116-bit values:
1872   PNG_TRANSFORM_EXPAND_16
1873   png_set_expand_16(png_ptr);
1874
1875In either case palette image data will be expanded to RGB.  If you just want
1876color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1877to the list.
1878
1879Calling png_set_background before the PNG file header is read will not work
1880prior to libpng-1.5.4.  Because the failure may result in unexpected warnings or
1881errors it is therefore much safer to call png_set_background after the head has
1882been read.  Unfortunately this means that prior to libpng-1.5.4 it cannot be
1883used with the high level interface.
1884
1885.SS The high-level read interface
1886
1887At this point there are two ways to proceed; through the high-level
1888read interface, or through a sequence of low-level read operations.
1889You can use the high-level interface if (a) you are willing to read
1890the entire image into memory, and (b) the input transformations
1891you want to do are limited to the following set:
1892
1893    PNG_TRANSFORM_IDENTITY      No transformation
1894    PNG_TRANSFORM_SCALE_16      Strip 16-bit samples to
1895                                8-bit accurately
1896    PNG_TRANSFORM_STRIP_16      Chop 16-bit samples to
1897                                8-bit less accurately
1898    PNG_TRANSFORM_STRIP_ALPHA   Discard the alpha channel
1899    PNG_TRANSFORM_PACKING       Expand 1, 2 and 4-bit
1900                                samples to bytes
1901    PNG_TRANSFORM_PACKSWAP      Change order of packed
1902                                pixels to LSB first
1903    PNG_TRANSFORM_EXPAND        Perform set_expand()
1904    PNG_TRANSFORM_INVERT_MONO   Invert monochrome images
1905    PNG_TRANSFORM_SHIFT         Normalize pixels to the
1906                                sBIT depth
1907    PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA
1908                                to BGRA
1909    PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA
1910                                to AG
1911    PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity
1912                                to transparency
1913    PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples
1914    PNG_TRANSFORM_GRAY_TO_RGB   Expand grayscale samples
1915                                to RGB (or GA to RGBA)
1916    PNG_TRANSFORM_EXPAND_16     Expand samples to 16 bits
1917
1918(This excludes setting a background color, doing gamma transformation,
1919quantizing, and setting filler.)  If this is the case, simply do this:
1920
1921    png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1922
1923where png_transforms is an integer containing the bitwise OR of some
1924set of transformation flags.  This call is equivalent to png_read_info(),
1925followed the set of transformations indicated by the transform mask,
1926then png_read_image(), and finally png_read_end().
1927
1928(The final parameter of this call is not yet used.  Someday it might point
1929to transformation parameters required by some future input transform.)
1930
1931You must use png_transforms and not call any png_set_transform() functions
1932when you use png_read_png().
1933
1934After you have called png_read_png(), you can retrieve the image data
1935with
1936
1937   row_pointers = png_get_rows(png_ptr, info_ptr);
1938
1939where row_pointers is an array of pointers to the pixel data for each row:
1940
1941   png_bytep row_pointers[height];
1942
1943If you know your image size and pixel size ahead of time, you can allocate
1944row_pointers prior to calling png_read_png() with
1945
1946   if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
1947      png_error (png_ptr,
1948          "Image is too tall to process in memory");
1949
1950   if (width > PNG_UINT_32_MAX/pixel_size)
1951      png_error (png_ptr,
1952          "Image is too wide to process in memory");
1953
1954   row_pointers = png_malloc(png_ptr,
1955       height*png_sizeof(png_bytep));
1956
1957   for (int i=0; i<height, i++)
1958      row_pointers[i]=NULL;  /* security precaution */
1959
1960   for (int i=0; i<height, i++)
1961      row_pointers[i]=png_malloc(png_ptr,
1962          width*pixel_size);
1963
1964   png_set_rows(png_ptr, info_ptr, &row_pointers);
1965
1966Alternatively you could allocate your image in one big block and define
1967row_pointers[i] to point into the proper places in your block.
1968
1969If you use png_set_rows(), the application is responsible for freeing
1970row_pointers (and row_pointers[i], if they were separately allocated).
1971
1972If you don't allocate row_pointers ahead of time, png_read_png() will
1973do it, and it'll be free'ed by libpng when you call png_destroy_*().
1974
1975.SS The low-level read interface
1976
1977If you are going the low-level route, you are now ready to read all
1978the file information up to the actual image data.  You do this with a
1979call to png_read_info().
1980
1981    png_read_info(png_ptr, info_ptr);
1982
1983This will process all chunks up to but not including the image data.
1984
1985This also copies some of the data from the PNG file into the decode structure
1986for use in later transformations.  Important information copied in is:
1987
19881) The PNG file gamma from the gAMA chunk.  This overwrites the default value
1989provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1990
19912) Prior to libpng-1.5.4 the background color from a bKGd chunk.  This
1992damages the information provided by an earlier call to png_set_background
1993resulting in unexpected behavior.  Libpng-1.5.4 no longer does this.
1994
19953) The number of significant bits in each component value.  Libpng uses this to
1996optimize gamma handling by reducing the internal lookup table sizes.
1997
19984) The transparent color information from a tRNS chunk.  This can be modified by
1999a later call to png_set_tRNS.
2000
2001.SS Querying the info structure
2002
2003Functions are used to get the information from the info_ptr once it
2004has been read.  Note that these fields may not be completely filled
2005in until png_read_end() has read the chunk data following the image.
2006
2007    png_get_IHDR(png_ptr, info_ptr, &width, &height,
2008       &bit_depth, &color_type, &interlace_type,
2009       &compression_type, &filter_method);
2010
2011    width          - holds the width of the image
2012                     in pixels (up to 2^31).
2013
2014    height         - holds the height of the image
2015                     in pixels (up to 2^31).
2016
2017    bit_depth      - holds the bit depth of one of the
2018                     image channels.  (valid values are
2019                     1, 2, 4, 8, 16 and depend also on
2020                     the color_type.  See also
2021                     significant bits (sBIT) below).
2022
2023    color_type     - describes which color/alpha channels
2024                         are present.
2025                     PNG_COLOR_TYPE_GRAY
2026                        (bit depths 1, 2, 4, 8, 16)
2027                     PNG_COLOR_TYPE_GRAY_ALPHA
2028                        (bit depths 8, 16)
2029                     PNG_COLOR_TYPE_PALETTE
2030                        (bit depths 1, 2, 4, 8)
2031                     PNG_COLOR_TYPE_RGB
2032                        (bit_depths 8, 16)
2033                     PNG_COLOR_TYPE_RGB_ALPHA
2034                        (bit_depths 8, 16)
2035
2036                     PNG_COLOR_MASK_PALETTE
2037                     PNG_COLOR_MASK_COLOR
2038                     PNG_COLOR_MASK_ALPHA
2039
2040    interlace_type - (PNG_INTERLACE_NONE or
2041                     PNG_INTERLACE_ADAM7)
2042
2043    compression_type - (must be PNG_COMPRESSION_TYPE_BASE
2044                     for PNG 1.0)
2045
2046    filter_method  - (must be PNG_FILTER_TYPE_BASE
2047                     for PNG 1.0, and can also be
2048                     PNG_INTRAPIXEL_DIFFERENCING if
2049                     the PNG datastream is embedded in
2050                     a MNG-1.0 datastream)
2051
2052    Any or all of interlace_type, compression_type, or
2053    filter_method can be NULL if you are
2054    not interested in their values.
2055
2056    Note that png_get_IHDR() returns 32-bit data into
2057    the application's width and height variables.
2058    This is an unsafe situation if these are 16-bit
2059    variables.  In such situations, the
2060    png_get_image_width() and png_get_image_height()
2061    functions described below are safer.
2062
2063    width            = png_get_image_width(png_ptr,
2064                         info_ptr);
2065
2066    height           = png_get_image_height(png_ptr,
2067                         info_ptr);
2068
2069    bit_depth        = png_get_bit_depth(png_ptr,
2070                         info_ptr);
2071
2072    color_type       = png_get_color_type(png_ptr,
2073                         info_ptr);
2074
2075    interlace_type   = png_get_interlace_type(png_ptr,
2076                         info_ptr);
2077
2078    compression_type = png_get_compression_type(png_ptr,
2079                         info_ptr);
2080
2081    filter_method    = png_get_filter_type(png_ptr,
2082                         info_ptr);
2083
2084    channels = png_get_channels(png_ptr, info_ptr);
2085
2086    channels       - number of channels of info for the
2087                     color type (valid values are 1 (GRAY,
2088                     PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
2089                     4 (RGB_ALPHA or RGB + filler byte))
2090
2091    rowbytes = png_get_rowbytes(png_ptr, info_ptr);
2092
2093    rowbytes       - number of bytes needed to hold a row
2094
2095    signature = png_get_signature(png_ptr, info_ptr);
2096
2097    signature      - holds the signature read from the
2098                     file (if any).  The data is kept in
2099                     the same offset it would be if the
2100                     whole signature were read (i.e. if an
2101                     application had already read in 4
2102                     bytes of signature before starting
2103                     libpng, the remaining 4 bytes would
2104                     be in signature[4] through signature[7]
2105                     (see png_set_sig_bytes())).
2106
2107These are also important, but their validity depends on whether the chunk
2108has been read.  The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
2109png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
2110data has been read, or zero if it is missing.  The parameters to the
2111png_get_<chunk> are set directly if they are simple data types, or a
2112pointer into the info_ptr is returned for any complex types.
2113
2114The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks
2115is simply returned to give the application information about how the
2116image was encoded.  Libpng itself only does transformations using the file
2117gamma when combining semitransparent pixels with the background color.
2118
2119    png_get_PLTE(png_ptr, info_ptr, &palette,
2120                     &num_palette);
2121
2122    palette        - the palette for the file
2123                     (array of png_color)
2124
2125    num_palette    - number of entries in the palette
2126
2127    png_get_gAMA(png_ptr, info_ptr, &file_gamma);
2128    png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
2129
2130    file_gamma     - the gamma at which the file was
2131                     written (PNG_INFO_gAMA)
2132
2133    int_file_gamma - 100,000 times the gamma at which the
2134                     file is written
2135
2136    png_get_cHRM(png_ptr, info_ptr,  &white_x, &white_y, &red_x, &red_y,
2137                     &green_x, &green_y, &blue_x, &blue_y)
2138    png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X,
2139                     &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z)
2140    png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y,
2141                     &int_red_x, &int_red_y, &int_green_x, &int_green_y,
2142                     &int_blue_x, &int_blue_y)
2143    png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
2144                     &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z,
2145                     &int_blue_X, &int_blue_Y, &int_blue_Z)
2146
2147    {white,red,green,blue}_{x,y}
2148                     A color space encoding specified using the chromaticities
2149                     of the end points and the white point. (PNG_INFO_cHRM)
2150
2151    {red,green,blue}_{X,Y,Z}
2152                     A color space encoding specified using the encoding end
2153                     points - the CIE tristimulus specification of the intended
2154                     color of the red, green and blue channels in the PNG RGB
2155                     data.  The white point is simply the sum of the three end
2156                     points. (PNG_INFO_cHRM)
2157
2158    png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
2159
2160    file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
2161                     The presence of the sRGB chunk
2162                     means that the pixel data is in the
2163                     sRGB color space.  This chunk also
2164                     implies specific values of gAMA and
2165                     cHRM.
2166
2167    png_get_iCCP(png_ptr, info_ptr, &name,
2168       &compression_type, &profile, &proflen);
2169
2170    name             - The profile name.
2171
2172    compression_type - The compression type; always
2173                       PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2174                       You may give NULL to this argument to
2175                       ignore it.
2176
2177    profile          - International Color Consortium color
2178                       profile data. May contain NULs.
2179
2180    proflen          - length of profile data in bytes.
2181
2182    png_get_sBIT(png_ptr, info_ptr, &sig_bit);
2183
2184    sig_bit        - the number of significant bits for
2185                     (PNG_INFO_sBIT) each of the gray,
2186                     red, green, and blue channels,
2187                     whichever are appropriate for the
2188                     given color type (png_color_16)
2189
2190    png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
2191                     &num_trans, &trans_color);
2192
2193    trans_alpha    - array of alpha (transparency)
2194                     entries for palette (PNG_INFO_tRNS)
2195
2196    num_trans      - number of transparent entries
2197                     (PNG_INFO_tRNS)
2198
2199    trans_color    - graylevel or color sample values of
2200                     the single transparent color for
2201                     non-paletted images (PNG_INFO_tRNS)
2202
2203    png_get_hIST(png_ptr, info_ptr, &hist);
2204                     (PNG_INFO_hIST)
2205
2206    hist           - histogram of palette (array of
2207                     png_uint_16)
2208
2209    png_get_tIME(png_ptr, info_ptr, &mod_time);
2210
2211    mod_time       - time image was last modified
2212                    (PNG_VALID_tIME)
2213
2214    png_get_bKGD(png_ptr, info_ptr, &background);
2215
2216    background     - background color (of type
2217                     png_color_16p) (PNG_VALID_bKGD)
2218                     valid 16-bit red, green and blue
2219                     values, regardless of color_type
2220
2221    num_comments   = png_get_text(png_ptr, info_ptr,
2222                     &text_ptr, &num_text);
2223
2224    num_comments   - number of comments
2225
2226    text_ptr       - array of png_text holding image
2227                     comments
2228
2229    text_ptr[i].compression - type of compression used
2230                 on "text" PNG_TEXT_COMPRESSION_NONE
2231                           PNG_TEXT_COMPRESSION_zTXt
2232                           PNG_ITXT_COMPRESSION_NONE
2233                           PNG_ITXT_COMPRESSION_zTXt
2234
2235    text_ptr[i].key   - keyword for comment.  Must contain
2236                         1-79 characters.
2237
2238    text_ptr[i].text  - text comments for current
2239                         keyword.  Can be empty.
2240
2241    text_ptr[i].text_length - length of text string,
2242                 after decompression, 0 for iTXt
2243
2244    text_ptr[i].itxt_length - length of itxt string,
2245                 after decompression, 0 for tEXt/zTXt
2246
2247    text_ptr[i].lang  - language of comment (empty
2248                         string for unknown).
2249
2250    text_ptr[i].lang_key  - keyword in UTF-8
2251                         (empty string for unknown).
2252
2253    Note that the itxt_length, lang, and lang_key
2254    members of the text_ptr structure only exist when the
2255    library is built with iTXt chunk support.  Prior to
2256    libpng-1.4.0 the library was built by default without
2257    iTXt support. Also note that when iTXt is supported,
2258    they contain NULL pointers when the "compression"
2259    field contains PNG_TEXT_COMPRESSION_NONE or
2260    PNG_TEXT_COMPRESSION_zTXt.
2261
2262    num_text       - number of comments (same as
2263                     num_comments; you can put NULL here
2264                     to avoid the duplication)
2265
2266    Note while png_set_text() will accept text, language,
2267    and translated keywords that can be NULL pointers, the
2268    structure returned by png_get_text will always contain
2269    regular zero-terminated C strings.  They might be
2270    empty strings but they will never be NULL pointers.
2271
2272    num_spalettes = png_get_sPLT(png_ptr, info_ptr,
2273       &palette_ptr);
2274
2275    num_spalettes  - number of sPLT chunks read.
2276
2277    palette_ptr    - array of palette structures holding
2278                     contents of one or more sPLT chunks
2279                     read.
2280
2281    png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
2282       &unit_type);
2283
2284    offset_x       - positive offset from the left edge
2285                     of the screen (can be negative)
2286
2287    offset_y       - positive offset from the top edge
2288                     of the screen (can be negative)
2289
2290    unit_type      - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2291
2292    png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
2293       &unit_type);
2294
2295    res_x          - pixels/unit physical resolution in
2296                     x direction
2297
2298    res_y          - pixels/unit physical resolution in
2299                     x direction
2300
2301    unit_type      - PNG_RESOLUTION_UNKNOWN,
2302                     PNG_RESOLUTION_METER
2303
2304    png_get_sCAL(png_ptr, info_ptr, &unit, &width,
2305       &height)
2306
2307    unit        - physical scale units (an integer)
2308
2309    width       - width of a pixel in physical scale units
2310
2311    height      - height of a pixel in physical scale units
2312                 (width and height are doubles)
2313
2314    png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
2315       &height)
2316
2317    unit        - physical scale units (an integer)
2318
2319    width       - width of a pixel in physical scale units
2320                  (expressed as a string)
2321
2322    height      - height of a pixel in physical scale units
2323                 (width and height are strings like "2.54")
2324
2325    num_unknown_chunks = png_get_unknown_chunks(png_ptr,
2326       info_ptr, &unknowns)
2327
2328    unknowns          - array of png_unknown_chunk
2329                        structures holding unknown chunks
2330
2331    unknowns[i].name  - name of unknown chunk
2332
2333    unknowns[i].data  - data of unknown chunk
2334
2335    unknowns[i].size  - size of unknown chunk's data
2336
2337    unknowns[i].location - position of chunk in file
2338
2339    The value of "i" corresponds to the order in which the
2340    chunks were read from the PNG file or inserted with the
2341    png_set_unknown_chunks() function.
2342
2343    The value of "location" is a bitwise "or" of
2344
2345         PNG_HAVE_IHDR  (0x01)
2346         PNG_HAVE_PLTE  (0x02)
2347         PNG_AFTER_IDAT (0x08)
2348
2349The data from the pHYs chunk can be retrieved in several convenient
2350forms:
2351
2352    res_x = png_get_x_pixels_per_meter(png_ptr,
2353       info_ptr)
2354
2355    res_y = png_get_y_pixels_per_meter(png_ptr,
2356       info_ptr)
2357
2358    res_x_and_y = png_get_pixels_per_meter(png_ptr,
2359       info_ptr)
2360
2361    res_x = png_get_x_pixels_per_inch(png_ptr,
2362       info_ptr)
2363
2364    res_y = png_get_y_pixels_per_inch(png_ptr,
2365       info_ptr)
2366
2367    res_x_and_y = png_get_pixels_per_inch(png_ptr,
2368       info_ptr)
2369
2370    aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
2371       info_ptr)
2372
2373    Each of these returns 0 [signifying "unknown"] if
2374       the data is not present or if res_x is 0;
2375       res_x_and_y is 0 if res_x != res_y
2376
2377    Note that because of the way the resolutions are
2378       stored internally, the inch conversions won't
2379       come out to exactly even number.  For example,
2380       72 dpi is stored as 0.28346 pixels/meter, and
2381       when this is retrieved it is 71.9988 dpi, so
2382       be sure to round the returned value appropriately
2383       if you want to display a reasonable-looking result.
2384
2385The data from the oFFs chunk can be retrieved in several convenient
2386forms:
2387
2388    x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
2389
2390    y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
2391
2392    x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
2393
2394    y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
2395
2396    Each of these returns 0 [signifying "unknown" if both
2397       x and y are 0] if the data is not present or if the
2398       chunk is present but the unit is the pixel.  The
2399       remark about inexact inch conversions applies here
2400       as well, because a value in inches can't always be
2401       converted to microns and back without some loss
2402       of precision.
2403
2404For more information, see the
2405PNG specification for chunk contents.  Be careful with trusting
2406rowbytes, as some of the transformations could increase the space
2407needed to hold a row (expand, filler, gray_to_rgb, etc.).
2408See png_read_update_info(), below.
2409
2410A quick word about text_ptr and num_text.  PNG stores comments in
2411keyword/text pairs, one pair per chunk, with no limit on the number
2412of text chunks, and a 2^31 byte limit on their size.  While there are
2413suggested keywords, there is no requirement to restrict the use to these
2414strings.  It is strongly suggested that keywords and text be sensible
2415to humans (that's the point), so don't use abbreviations.  Non-printing
2416symbols are not allowed.  See the PNG specification for more details.
2417There is also no requirement to have text after the keyword.
2418
2419Keywords should be limited to 79 Latin-1 characters without leading or
2420trailing spaces, but non-consecutive spaces are allowed within the
2421keyword.  It is possible to have the same keyword any number of times.
2422The text_ptr is an array of png_text structures, each holding a
2423pointer to a language string, a pointer to a keyword and a pointer to
2424a text string.  The text string, language code, and translated
2425keyword may be empty or NULL pointers.  The keyword/text
2426pairs are put into the array in the order that they are received.
2427However, some or all of the text chunks may be after the image, so, to
2428make sure you have read all the text chunks, don't mess with these
2429until after you read the stuff after the image.  This will be
2430mentioned again below in the discussion that goes with png_read_end().
2431
2432.SS Input transformations
2433
2434After you've read the header information, you can set up the library
2435to handle any special transformations of the image data.  The various
2436ways to transform the data will be described in the order that they
2437should occur.  This is important, as some of these change the color
2438type and/or bit depth of the data, and some others only work on
2439certain color types and bit depths.
2440
2441Transformations you request are ignored if they don't have any meaning for a
2442particular input data format.  However some transformations can have an effect
2443as a result of a previous transformation.  If you specify a contradictory set of
2444transformations, for example both adding and removing the alpha channel, you
2445cannot predict the final result.
2446
2447The color used for the transparency values should be supplied in the same
2448format/depth as the current image data.  It is stored in the same format/depth
2449as the image data in a tRNS chunk, so this is what libpng expects for this data.
2450
2451The color used for the background value depends on the need_expand argument as
2452described below.
2453
2454Data will be decoded into the supplied row buffers packed into bytes
2455unless the library has been told to transform it into another format.
2456For example, 4 bit/pixel paletted or grayscale data will be returned
24572 pixels/byte with the leftmost pixel in the high-order bits of the
2458byte, unless png_set_packing() is called.  8-bit RGB data will be stored
2459in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2460is called to insert filler bytes, either before or after each RGB triplet.
246116-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
2462byte of the color value first, unless png_set_scale_16() is called to
2463transform it to regular RGB RGB triplets, or png_set_filler() or
2464png_set_add alpha() is called to insert filler bytes, either before or
2465after each RRGGBB triplet.  Similarly, 8-bit or 16-bit grayscale data can
2466be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2467or png_set_scale_16().
2468
2469The following code transforms grayscale images of less than 8 to 8 bits,
2470changes paletted images to RGB, and adds a full alpha channel if there is
2471transparency information in a tRNS chunk.  This is most useful on
2472grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2473viewing application that wishes to treat all images in the same way.
2474
2475    if (color_type == PNG_COLOR_TYPE_PALETTE)
2476        png_set_palette_to_rgb(png_ptr);
2477
2478    if (png_get_valid(png_ptr, info_ptr,
2479        PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2480
2481    if (color_type == PNG_COLOR_TYPE_GRAY &&
2482        bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2483
2484The first two functions are actually aliases for png_set_expand(), added
2485in libpng version 1.0.4, with the function names expanded to improve code
2486readability.  In some future version they may actually do different
2487things.
2488
2489As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2490added.  It expands the sample depth without changing tRNS to alpha.
2491
2492As of libpng version 1.5.2, png_set_expand_16() was added.  It behaves as
2493png_set_expand(); however, the resultant channels have 16 bits rather than 8.
2494Use this when the output color or gray channels are made linear to avoid fairly
2495severe accuracy loss.
2496
2497   if (bit_depth < 16)
2498      png_set_expand_16(png_ptr);
2499
2500PNG can have files with 16 bits per channel.  If you only can handle
25018 bits per channel, this will strip the pixels down to 8-bit.
2502
2503    if (bit_depth == 16)
2504#if PNG_LIBPNG_VER >= 10504
2505       png_set_scale_16(png_ptr);
2506#else
2507       png_set_strip_16(png_ptr);
2508#endif
2509
2510(The more accurate "png_set_scale_16()" API became available in libpng version
25111.5.4).
2512
2513If you need to process the alpha channel on the image separately from the image
2514data (for example if you convert it to a bitmap mask) it is possible to have
2515libpng strip the channel leaving just RGB or gray data:
2516
2517    if (color_type & PNG_COLOR_MASK_ALPHA)
2518       png_set_strip_alpha(png_ptr);
2519
2520If you strip the alpha channel you need to find some other way of dealing with
2521the information.  If, instead, you want to convert the image to an opaque
2522version with no alpha channel use png_set_background; see below.
2523
2524As of libpng version 1.5.2, almost all useful expansions are supported, the
2525major ommissions are conversion of grayscale to indexed images (which can be
2526done trivially in the application) and conversion of indexed to grayscale (which
2527can be done by a trivial manipulation of the palette.)
2528
2529In the following table, the 01 means grayscale with depth<8, 31 means
2530indexed with depth<8, other numerals represent the color type, "T" means
2531the tRNS chunk is present, A means an alpha channel is present, and O
2532means tRNS or alpha is present but all pixels in the image are opaque.
2533
2534  FROM  01  31   0  0T  0O   2  2T  2O   3  3T  3O  4A  4O  6A  6O
2535   TO
2536   01    -  [G]  -   -   -   -   -   -   -   -   -   -   -   -   -
2537   31   [Q]  Q  [Q] [Q] [Q]  Q   Q   Q   Q   Q   Q  [Q] [Q]  Q   Q
2538    0    1   G   +   .   .   G   G   G   G   G   G   B   B  GB  GB
2539   0T    lt  Gt  t   +   .   Gt  G   G   Gt  G   G   Bt  Bt GBt GBt
2540   0O    lt  Gt  t   .   +   Gt  Gt  G   Gt  Gt  G   Bt  Bt GBt GBt
2541    2    C   P   C   C   C   +   .   .   C   -   -  CB  CB   B   B
2542   2T    Ct  -   Ct  C   C   t   +   t   -   -   -  CBt CBt  Bt  Bt
2543   2O    Ct  -   Ct  C   C   t   t   +   -   -   -  CBt CBt  Bt  Bt
2544    3   [Q]  p  [Q] [Q] [Q]  Q   Q   Q   +   .   .  [Q] [Q]  Q   Q
2545   3T   [Qt] p  [Qt][Q] [Q]  Qt  Qt  Qt  t   +   t  [Qt][Qt] Qt  Qt
2546   3O   [Qt] p  [Qt][Q] [Q]  Qt  Qt  Qt  t   t   +  [Qt][Qt] Qt  Qt
2547   4A    lA  G   A   T   T   GA  GT  GT  GA  GT  GT  +   BA  G  GBA
2548   4O    lA GBA  A   T   T   GA  GT  GT  GA  GT  GT  BA  +  GBA  G
2549   6A    CA  PA  CA  C   C   A   T  tT   PA  P   P   C  CBA  +   BA
2550   6O    CA PBA  CA  C   C   A  tT   T   PA  P   P  CBA  C   BA  +
2551
2552Within the matrix,
2553     "+" identifies entries where 'from' and 'to' are the same.
2554     "-" means the transformation is not supported.
2555     "." means nothing is necessary (a tRNS chunk can just be ignored).
2556     "t" means the transformation is obtained by png_set_tRNS.
2557     "A" means the transformation is obtained by png_set_add_alpha().
2558     "X" means the transformation is obtained by png_set_expand().
2559     "1" means the transformation is obtained by
2560         png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() if there
2561         is no transparency in the original or the final format).
2562     "C" means the transformation is obtained by png_set_gray_to_rgb().
2563     "G" means the transformation is obtained by png_set_rgb_to_gray().
2564     "P" means the transformation is obtained by
2565         png_set_expand_palette_to_rgb().
2566     "p" means the transformation is obtained by png_set_packing().
2567     "Q" means the transformation is obtained by png_set_quantize().
2568     "T" means the transformation is obtained by png_set_tRNS_to_alpha().
2569     "B" means the transformation is obtained by png_set_background(), or
2570         png_strip_alpha().
2571
2572When an entry has multiple transforms listed all are required to cause the
2573right overall transformation.  When two transforms are separated by a comma
2574either will do the job.  When transforms are enclosed in [] the transform should
2575do the job but this is currently unimplemented - a different format will result
2576if the suggested transformations are used.
2577
2578In PNG files, the alpha channel in an image
2579is the level of opacity.  If you need the alpha channel in an image to
2580be the level of transparency instead of opacity, you can invert the
2581alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2582fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2583images) is fully transparent, with
2584
2585    png_set_invert_alpha(png_ptr);
2586
2587PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2588they can, resulting in, for example, 8 pixels per byte for 1 bit
2589files.  This code expands to 1 pixel per byte without changing the
2590values of the pixels:
2591
2592    if (bit_depth < 8)
2593       png_set_packing(png_ptr);
2594
2595PNG files have possible bit depths of 1, 2, 4, 8, and 16.  All pixels
2596stored in a PNG image have been "scaled" or "shifted" up to the next
2597higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2598to 8 bits/sample in the range [0, 255]).  However, it is also possible
2599to convert the PNG pixel data back to the original bit depth of the
2600image.  This call reduces the pixels back down to the original bit depth:
2601
2602    png_color_8p sig_bit;
2603
2604    if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
2605       png_set_shift(png_ptr, sig_bit);
2606
2607PNG files store 3-color pixels in red, green, blue order.  This code
2608changes the storage of the pixels to blue, green, red:
2609
2610    if (color_type == PNG_COLOR_TYPE_RGB ||
2611        color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2612       png_set_bgr(png_ptr);
2613
2614PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2615into 4 or 8 bytes for windowing systems that need them in this format:
2616
2617    if (color_type == PNG_COLOR_TYPE_RGB)
2618       png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
2619
2620where "filler" is the 8 or 16-bit number to fill with, and the location is
2621either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2622you want the filler before the RGB or after.  This transformation
2623does not affect images that already have full alpha channels.  To add an
2624opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2625will generate RGBA pixels.
2626
2627Note that png_set_filler() does not change the color type.  If you want
2628to do that, you can add a true alpha channel with
2629
2630    if (color_type == PNG_COLOR_TYPE_RGB ||
2631       color_type == PNG_COLOR_TYPE_GRAY)
2632       png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
2633
2634where "filler" contains the alpha value to assign to each pixel.
2635This function was added in libpng-1.2.7.
2636
2637If you are reading an image with an alpha channel, and you need the
2638data as ARGB instead of the normal PNG format RGBA:
2639
2640    if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2641       png_set_swap_alpha(png_ptr);
2642
2643For some uses, you may want a grayscale image to be represented as
2644RGB.  This code will do that conversion:
2645
2646    if (color_type == PNG_COLOR_TYPE_GRAY ||
2647        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2648       png_set_gray_to_rgb(png_ptr);
2649
2650Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
2651with alpha.
2652
2653    if (color_type == PNG_COLOR_TYPE_RGB ||
2654        color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2655       png_set_rgb_to_gray(png_ptr, error_action, double red_weight,
2656          double green_weight);
2657
2658    error_action = 1: silently do the conversion
2659
2660    error_action = 2: issue a warning if the original
2661                      image has any pixel where
2662                      red != green or red != blue
2663
2664    error_action = 3: issue an error and abort the
2665                      conversion if the original
2666                      image has any pixel where
2667                      red != green or red != blue
2668
2669    red_weight:       weight of red component
2670
2671    green_weight:     weight of green component
2672                      If either weight is negative, default
2673                      weights are used.
2674
2675In the corresponding fixed point API the red_weight and green_weight values are
2676simply scaled by 100,000:
2677
2678    png_set_rgb_to_gray(png_ptr, error_action, png_fixed_point red_weight,
2679       png_fixed_point green_weight);
2680
2681If you have set error_action = 1 or 2, you can
2682later check whether the image really was gray, after processing
2683the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2684It will return a png_byte that is zero if the image was gray or
26851 if there were any non-gray pixels.  Background and sBIT data
2686will be silently converted to grayscale, using the green channel
2687data for sBIT, regardless of the error_action setting.
2688
2689The default values come from the PNG file cHRM chunk if present; otherwise, the
2690defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2691space, as recommended in the Charles Poynton's Colour FAQ,
2692<http://www.poynton.com/>, in section 9:
2693
2694   <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
2695
2696    Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
2697
2698Previous versions of this document, 1998 through 2002, recommended a slightly
2699different formula:
2700
2701    Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2702
2703Libpng uses an integer approximation:
2704
2705    Y = (6968 * R + 23434 * G + 2366 * B)/32768
2706
2707The calculation is done in a linear colorspace, if the image gamma
2708can be determined.
2709
2710The png_set_background() function has been described already; it tells libpng to
2711composite images with alpha or simple transparency against the supplied
2712background color.  For compatibility with versions of libpng earlier than
2713libpng-1.5.4 it is recommended that you call the function after reading the file
2714header, even if you don't want to use the color in a bKGD chunk, if one exists.
2715
2716If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2717you may use this color, or supply another color more suitable for
2718the current display (e.g., the background color from a web page).  You
2719need to tell libpng how the color is represented, both the format of the
2720component values in the color (the number of bits) and the gamma encoding of the
2721color.  The function takes two arguments, background_gamma_mode and need_expand
2722to convey this information; however, only two combinations are likely to be
2723useful:
2724
2725    png_color_16 my_background;
2726    png_color_16p image_background;
2727
2728    if (png_get_bKGD(png_ptr, info_ptr, &image_background))
2729       png_set_background(png_ptr, image_background,
2730           PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
2731    else
2732       png_set_background(png_ptr, &my_background,
2733           PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
2734
2735The second call was described above - my_background is in the format of the
2736final, display, output produced by libpng.  Because you now know the format of
2737the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2738output and to retain palette images (the palette colors will be modified
2739appropriately and the tRNS chunk removed.)  However, if you are doing this,
2740take great care not to ask for transformations without checking first that
2741they apply!
2742
2743In the first call the background color has the original bit depth and color type
2744of the PNG file.  So, for palette images the color is supplied as a palette
2745index and for low bit greyscale images the color is a reduced bit value in
2746image_background->gray.
2747
2748If you didn't call png_set_gamma() before reading the file header, for example
2749if you need your code to remain compatible with older versions of libpng prior
2750to libpng-1.5.4, this is the place to call it.
2751
2752Do not call it if you called png_set_alpha_mode(); doing so will damage the
2753settings put in place by png_set_alpha_mode().  (If png_set_alpha_mode() is
2754supported then you can certainly do png_set_gamma() before reading the PNG
2755header.)
2756
2757This API unconditionally sets the screen and file gamma values, so it will
2758override the value in the PNG file unless it is called before the PNG file
2759reading starts.  For this reason you must always call it with the PNG file
2760value when you call it in this position:
2761
2762   if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
2763      png_set_gamma(png_ptr, screen_gamma, file_gamma);
2764
2765   else
2766      png_set_gamma(png_ptr, screen_gamma, 0.45455);
2767
2768If you need to reduce an RGB file to a paletted file, or if a paletted
2769file has more entries then will fit on your screen, png_set_quantize()
2770will do that.  Note that this is a simple match quantization that merely
2771finds the closest color available.  This should work fairly well with
2772optimized palettes, but fairly badly with linear color cubes.  If you
2773pass a palette that is larger than maximum_colors, the file will
2774reduce the number of colors in the palette so it will fit into
2775maximum_colors.  If there is a histogram, libpng will use it to make
2776more intelligent choices when reducing the palette.  If there is no
2777histogram, it may not do as good a job.
2778
2779   if (color_type & PNG_COLOR_MASK_COLOR)
2780   {
2781      if (png_get_valid(png_ptr, info_ptr,
2782          PNG_INFO_PLTE))
2783      {
2784         png_uint_16p histogram = NULL;
2785
2786         png_get_hIST(png_ptr, info_ptr,
2787             &histogram);
2788         png_set_quantize(png_ptr, palette, num_palette,
2789            max_screen_colors, histogram, 1);
2790      }
2791
2792      else
2793      {
2794         png_color std_color_cube[MAX_SCREEN_COLORS] =
2795            { ... colors ... };
2796
2797         png_set_quantize(png_ptr, std_color_cube,
2798            MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2799            NULL,0);
2800      }
2801   }
2802
2803PNG files describe monochrome as black being zero and white being one.
2804The following code will reverse this (make black be one and white be
2805zero):
2806
2807   if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2808      png_set_invert_mono(png_ptr);
2809
2810This function can also be used to invert grayscale and gray-alpha images:
2811
2812   if (color_type == PNG_COLOR_TYPE_GRAY ||
2813       color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2814      png_set_invert_mono(png_ptr);
2815
2816PNG files store 16-bit pixels in network byte order (big-endian,
2817ie. most significant bits first).  This code changes the storage to the
2818other way (little-endian, i.e. least significant bits first, the
2819way PCs store them):
2820
2821    if (bit_depth == 16)
2822       png_set_swap(png_ptr);
2823
2824If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2825need to change the order the pixels are packed into bytes, you can use:
2826
2827    if (bit_depth < 8)
2828       png_set_packswap(png_ptr);
2829
2830Finally, you can write your own transformation function if none of
2831the existing ones meets your needs.  This is done by setting a callback
2832with
2833
2834    png_set_read_user_transform_fn(png_ptr,
2835        read_transform_fn);
2836
2837You must supply the function
2838
2839    void read_transform_fn(png_structp png_ptr, png_row_infop
2840        row_info, png_bytep data)
2841
2842See pngtest.c for a working example.  Your function will be called
2843after all of the other transformations have been processed.  Take care with
2844interlaced images if you do the interlace yourself - the width of the row is the
2845width in 'row_info', not the overall image width.
2846
2847If supported, libpng provides two information routines that you can use to find
2848where you are in processing the image:
2849
2850   png_get_current_pass_number(png_structp png_ptr);
2851   png_get_current_row_number(png_structp png_ptr);
2852
2853Don't try using these outside a transform callback - firstly they are only
2854supported if user transforms are supported, secondly they may well return
2855unexpected results unless the row is actually being processed at the moment they
2856are called.
2857
2858With interlaced
2859images the value returned is the row in the input sub-image image.  Use
2860PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2861find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2862
2863The discussion of interlace handling above contains more information on how to
2864use these values.
2865
2866You can also set up a pointer to a user structure for use by your
2867callback function, and you can inform libpng that your transform
2868function will change the number of channels or bit depth with the
2869function
2870
2871    png_set_user_transform_info(png_ptr, user_ptr,
2872        user_depth, user_channels);
2873
2874The user's application, not libpng, is responsible for allocating and
2875freeing any memory required for the user structure.
2876
2877You can retrieve the pointer via the function
2878png_get_user_transform_ptr().  For example:
2879
2880    voidp read_user_transform_ptr =
2881        png_get_user_transform_ptr(png_ptr);
2882
2883The last thing to handle is interlacing; this is covered in detail below,
2884but you must call the function here if you want libpng to handle expansion
2885of the interlaced image.
2886
2887    number_of_passes = png_set_interlace_handling(png_ptr);
2888
2889After setting the transformations, libpng can update your png_info
2890structure to reflect any transformations you've requested with this
2891call.
2892
2893    png_read_update_info(png_ptr, info_ptr);
2894
2895This is most useful to update the info structure's rowbytes
2896field so you can use it to allocate your image memory.  This function
2897will also update your palette with the correct screen_gamma and
2898background if these have been given with the calls above.  You may
2899only call png_read_update_info() once with a particular info_ptr.
2900
2901After you call png_read_update_info(), you can allocate any
2902memory you need to hold the image.  The row data is simply
2903raw byte data for all forms of images.  As the actual allocation
2904varies among applications, no example will be given.  If you
2905are allocating one large chunk, you will need to build an
2906array of pointers to each row, as it will be needed for some
2907of the functions below.
2908
2909Remember: Before you call png_read_update_info(), the png_get_*()
2910functions return the values corresponding to the original PNG image.
2911After you call png_read_update_info the values refer to the image
2912that libpng will output.  Consequently you must call all the png_set_
2913functions before you call png_read_update_info().  This is particularly
2914important for png_set_interlace_handling() - if you are going to call
2915png_read_update_info() you must call png_set_interlace_handling() before
2916it unless you want to receive interlaced output.
2917
2918.SS Reading image data
2919
2920After you've allocated memory, you can read the image data.
2921The simplest way to do this is in one function call.  If you are
2922allocating enough memory to hold the whole image, you can just
2923call png_read_image() and libpng will read in all the image data
2924and put it in the memory area supplied.  You will need to pass in
2925an array of pointers to each row.
2926
2927This function automatically handles interlacing, so you don't
2928need to call png_set_interlace_handling() (unless you call
2929png_read_update_info()) or call this function multiple times, or any
2930of that other stuff necessary with png_read_rows().
2931
2932   png_read_image(png_ptr, row_pointers);
2933
2934where row_pointers is:
2935
2936   png_bytep row_pointers[height];
2937
2938You can point to void or char or whatever you use for pixels.
2939
2940If you don't want to read in the whole image at once, you can
2941use png_read_rows() instead.  If there is no interlacing (check
2942interlace_type == PNG_INTERLACE_NONE), this is simple:
2943
2944    png_read_rows(png_ptr, row_pointers, NULL,
2945        number_of_rows);
2946
2947where row_pointers is the same as in the png_read_image() call.
2948
2949If you are doing this just one row at a time, you can do this with
2950a single row_pointer instead of an array of row_pointers:
2951
2952    png_bytep row_pointer = row;
2953    png_read_row(png_ptr, row_pointer, NULL);
2954
2955If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2956get somewhat harder.  The only current (PNG Specification version 1.2)
2957interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
2958a somewhat complicated 2D interlace scheme, known as Adam7, that
2959breaks down an image into seven smaller images of varying size, based
2960on an 8x8 grid.  This number is defined (from libpng 1.5) as
2961PNG_INTERLACE_ADAM7_PASSES in png.h
2962
2963libpng can fill out those images or it can give them to you "as is".
2964It is almost always better to have libpng handle the interlacing for you.
2965If you want the images filled out, there are two ways to do that.  The one
2966mentioned in the PNG specification is to expand each pixel to cover
2967those pixels that have not been read yet (the "rectangle" method).
2968This results in a blocky image for the first pass, which gradually
2969smooths out as more pixels are read.  The other method is the "sparkle"
2970method, where pixels are drawn only in their final locations, with the
2971rest of the image remaining whatever colors they were initialized to
2972before the start of the read.  The first method usually looks better,
2973but tends to be slower, as there are more pixels to put in the rows.
2974
2975If, as is likely, you want libpng to expand the images, call this before
2976calling png_start_read_image() or png_read_update_info():
2977
2978    if (interlace_type == PNG_INTERLACE_ADAM7)
2979       number_of_passes
2980           = png_set_interlace_handling(png_ptr);
2981
2982This will return the number of passes needed.  Currently, this is seven,
2983but may change if another interlace type is added.  This function can be
2984called even if the file is not interlaced, where it will return one pass.
2985You then need to read the whole image 'number_of_passes' times.  Each time
2986will distribute the pixels from the current pass to the correct place in
2987the output image, so you need to supply the same rows to png_read_rows in
2988each pass.
2989
2990If you are not going to display the image after each pass, but are
2991going to wait until the entire image is read in, use the sparkle
2992effect.  This effect is faster and the end result of either method
2993is exactly the same.  If you are planning on displaying the image
2994after each pass, the "rectangle" effect is generally considered the
2995better looking one.
2996
2997If you only want the "sparkle" effect, just call png_read_rows() as
2998normal, with the third parameter NULL.  Make sure you make pass over
2999the image number_of_passes times, and you don't change the data in the
3000rows between calls.  You can change the locations of the data, just
3001not the data.  Each pass only writes the pixels appropriate for that
3002pass, and assumes the data from previous passes is still valid.
3003
3004    png_read_rows(png_ptr, row_pointers, NULL,
3005        number_of_rows);
3006
3007If you only want the first effect (the rectangles), do the same as
3008before except pass the row buffer in the third parameter, and leave
3009the second parameter NULL.
3010
3011    png_read_rows(png_ptr, NULL, row_pointers,
3012        number_of_rows);
3013
3014If you don't want libpng to handle the interlacing details, just call
3015png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
3016Each of the images is a valid image by itself; however, you will almost
3017certainly need to distribute the pixels from each sub-image to the
3018correct place.  This is where everything gets very tricky.
3019
3020If you want to retrieve the separate images you must pass the correct
3021number of rows to each successive call of png_read_rows().  The calculation
3022gets pretty complicated for small images, where some sub-images may
3023not even exist because either their width or height ends up zero.
3024libpng provides two macros to help you in 1.5 and later versions:
3025
3026   png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
3027   png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
3028
3029Respectively these tell you the width and height of the sub-image
3030corresponding to the numbered pass.  'pass' is in in the range 0 to 6 -
3031this can be confusing because the specification refers to the same passes
3032as 1 to 7!  Be careful, you must check both the width and height before
3033calling png_read_rows() and not call it for that pass if either is zero.
3034
3035You can, of course, read each sub-image row by row.  If you want to
3036produce optimal code to make a pixel-by-pixel transformation of an
3037interlaced image this is the best approach; read each row of each pass,
3038transform it, and write it out to a new interlaced image.
3039
3040If you want to de-interlace the image yourself libpng provides further
3041macros to help that tell you where to place the pixels in the output image.
3042Because the interlacing scheme is rectangular - sub-image pixels are always
3043arranged on a rectangular grid - all you need to know for each pass is the
3044starting column and row in the output image of the first pixel plus the
3045spacing between each pixel.  As of libpng 1.5 there are four macros to
3046retrieve this information:
3047
3048   png_uint_32 x = PNG_PASS_START_COL(pass);
3049   png_uint_32 y = PNG_PASS_START_ROW(pass);
3050   png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
3051   png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
3052
3053These allow you to write the obvious loop:
3054
3055   png_uint_32 input_y = 0;
3056   png_uint_32 output_y = PNG_PASS_START_ROW(pass);
3057
3058   while (output_y < output_image_height)
3059   {
3060      png_uint_32 input_x = 0;
3061      png_uint_32 output_x = PNG_PASS_START_COL(pass);
3062
3063      while (output_x < output_image_width)
3064      {
3065         image[output_y][output_x] =
3066             subimage[pass][input_y][input_x++];
3067
3068         output_x += xStep;
3069      }
3070
3071      ++input_y;
3072      output_y += yStep;
3073   }
3074
3075Notice that the steps between successive output rows and columns are
3076returned as shifts.  This is possible because the pixels in the subimages
3077are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
3078image.  In practice you may need to directly calculate the output coordinate
3079given an input coordinate.  libpng provides two further macros for this
3080purpose:
3081
3082   png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
3083   png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
3084
3085Finally a pair of macros are provided to tell you if a particular image
3086row or column appears in a given pass:
3087
3088   int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
3089   int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
3090
3091Bear in mind that you will probably also need to check the width and height
3092of the pass in addition to the above to be sure the pass even exists!
3093
3094With any luck you are convinced by now that you don't want to do your own
3095interlace handling.  In reality normally the only good reason for doing this
3096is if you are processing PNG files on a pixel-by-pixel basis and don't want
3097to load the whole file into memory when it is interlaced.
3098
3099libpng includes a test program, pngvalid, that illustrates reading and
3100writing of interlaced images.  If you can't get interlacing to work in your
3101code and don't want to leave it to libpng (the recommended approach), see
3102how pngvalid.c does it.
3103
3104.SS Finishing a sequential read
3105
3106After you are finished reading the image through the
3107low-level interface, you can finish reading the file.  If you are
3108interested in comments or time, which may be stored either before or
3109after the image data, you should pass the separate png_info struct if
3110you want to keep the comments from before and after the image
3111separate.
3112
3113    png_infop end_info = png_create_info_struct(png_ptr);
3114
3115    if (!end_info)
3116    {
3117       png_destroy_read_struct(&png_ptr, &info_ptr,
3118           (png_infopp)NULL);
3119       return (ERROR);
3120    }
3121
3122   png_read_end(png_ptr, end_info);
3123
3124If you are not interested, you should still call png_read_end()
3125but you can pass NULL, avoiding the need to create an end_info structure.
3126
3127   png_read_end(png_ptr, (png_infop)NULL);
3128
3129If you don't call png_read_end(), then your file pointer will be
3130left pointing to the first chunk after the last IDAT, which is probably
3131not what you want if you expect to read something beyond the end of
3132the PNG datastream.
3133
3134When you are done, you can free all memory allocated by libpng like this:
3135
3136   png_destroy_read_struct(&png_ptr, &info_ptr,
3137       &end_info);
3138
3139or, if you didn't create an end_info structure,
3140
3141   png_destroy_read_struct(&png_ptr, &info_ptr,
3142       (png_infopp)NULL);
3143
3144It is also possible to individually free the info_ptr members that
3145point to libpng-allocated storage with the following function:
3146
3147    png_free_data(png_ptr, info_ptr, mask, seq)
3148
3149    mask - identifies data to be freed, a mask
3150           containing the bitwise OR of one or
3151           more of
3152             PNG_FREE_PLTE, PNG_FREE_TRNS,
3153             PNG_FREE_HIST, PNG_FREE_ICCP,
3154             PNG_FREE_PCAL, PNG_FREE_ROWS,
3155             PNG_FREE_SCAL, PNG_FREE_SPLT,
3156             PNG_FREE_TEXT, PNG_FREE_UNKN,
3157           or simply PNG_FREE_ALL
3158
3159    seq  - sequence number of item to be freed
3160           (-1 for all items)
3161
3162This function may be safely called when the relevant storage has
3163already been freed, or has not yet been allocated, or was allocated
3164by the user and not by libpng,  and will in those cases do nothing.
3165The "seq" parameter is ignored if only one item of the selected data
3166type, such as PLTE, is allowed.  If "seq" is not -1, and multiple items
3167are allowed for the data type identified in the mask, such as text or
3168sPLT, only the n'th item in the structure is freed, where n is "seq".
3169
3170The default behavior is only to free data that was allocated internally
3171by libpng.  This can be changed, so that libpng will not free the data,
3172or so that it will free data that was allocated by the user with png_malloc()
3173or png_zalloc() and passed in via a png_set_*() function, with
3174
3175    png_data_freer(png_ptr, info_ptr, freer, mask)
3176
3177    freer  - one of
3178               PNG_DESTROY_WILL_FREE_DATA
3179               PNG_SET_WILL_FREE_DATA
3180               PNG_USER_WILL_FREE_DATA
3181
3182    mask   - which data elements are affected
3183             same choices as in png_free_data()
3184
3185This function only affects data that has already been allocated.
3186You can call this function after reading the PNG data but before calling
3187any png_set_*() functions, to control whether the user or the png_set_*()
3188function is responsible for freeing any existing data that might be present,
3189and again after the png_set_*() functions to control whether the user
3190or png_destroy_*() is supposed to free the data.  When the user assumes
3191responsibility for libpng-allocated data, the application must use
3192png_free() to free it, and when the user transfers responsibility to libpng
3193for data that the user has allocated, the user must have used png_malloc()
3194or png_zalloc() to allocate it.
3195
3196If you allocated your row_pointers in a single block, as suggested above in
3197the description of the high level read interface, you must not transfer
3198responsibility for freeing it to the png_set_rows or png_read_destroy function,
3199because they would also try to free the individual row_pointers[i].
3200
3201If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3202separately, do not transfer responsibility for freeing text_ptr to libpng,
3203because when libpng fills a png_text structure it combines these members with
3204the key member, and png_free_data() will free only text_ptr.key.  Similarly,
3205if you transfer responsibility for free'ing text_ptr from libpng to your
3206application, your application must not separately free those members.
3207
3208The png_free_data() function will turn off the "valid" flag for anything
3209it frees.  If you need to turn the flag off for a chunk that was freed by
3210your application instead of by libpng, you can use
3211
3212    png_set_invalid(png_ptr, info_ptr, mask);
3213
3214    mask - identifies the chunks to be made invalid,
3215           containing the bitwise OR of one or
3216           more of
3217             PNG_INFO_gAMA, PNG_INFO_sBIT,
3218             PNG_INFO_cHRM, PNG_INFO_PLTE,
3219             PNG_INFO_tRNS, PNG_INFO_bKGD,
3220             PNG_INFO_hIST, PNG_INFO_pHYs,
3221             PNG_INFO_oFFs, PNG_INFO_tIME,
3222             PNG_INFO_pCAL, PNG_INFO_sRGB,
3223             PNG_INFO_iCCP, PNG_INFO_sPLT,
3224             PNG_INFO_sCAL, PNG_INFO_IDAT
3225
3226For a more compact example of reading a PNG image, see the file example.c.
3227
3228.SS Reading PNG files progressively
3229
3230The progressive reader is slightly different then the non-progressive
3231reader.  Instead of calling png_read_info(), png_read_rows(), and
3232png_read_end(), you make one call to png_process_data(), which calls
3233callbacks when it has the info, a row, or the end of the image.  You
3234set up these callbacks with png_set_progressive_read_fn().  You don't
3235have to worry about the input/output functions of libpng, as you are
3236giving the library the data directly in png_process_data().  I will
3237assume that you have read the section on reading PNG files above,
3238so I will only highlight the differences (although I will show
3239all of the code).
3240
3241png_structp png_ptr;
3242png_infop info_ptr;
3243
3244 /*  An example code fragment of how you would
3245     initialize the progressive reader in your
3246     application. */
3247 int
3248 initialize_png_reader()
3249 {
3250    png_ptr = png_create_read_struct
3251        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3252         user_error_fn, user_warning_fn);
3253
3254    if (!png_ptr)
3255        return (ERROR);
3256
3257    info_ptr = png_create_info_struct(png_ptr);
3258
3259    if (!info_ptr)
3260    {
3261       png_destroy_read_struct(&png_ptr,
3262          (png_infopp)NULL, (png_infopp)NULL);
3263       return (ERROR);
3264    }
3265
3266    if (setjmp(png_jmpbuf(png_ptr)))
3267    {
3268       png_destroy_read_struct(&png_ptr, &info_ptr,
3269          (png_infopp)NULL);
3270       return (ERROR);
3271    }
3272
3273    /* This one's new.  You can provide functions
3274       to be called when the header info is valid,
3275       when each row is completed, and when the image
3276       is finished.  If you aren't using all functions,
3277       you can specify NULL parameters.  Even when all
3278       three functions are NULL, you need to call
3279       png_set_progressive_read_fn().  You can use
3280       any struct as the user_ptr (cast to a void pointer
3281       for the function call), and retrieve the pointer
3282       from inside the callbacks using the function
3283
3284          png_get_progressive_ptr(png_ptr);
3285
3286       which will return a void pointer, which you have
3287       to cast appropriately.
3288     */
3289    png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
3290        info_callback, row_callback, end_callback);
3291
3292    return 0;
3293 }
3294
3295 /* A code fragment that you call as you receive blocks
3296   of data */
3297 int
3298 process_data(png_bytep buffer, png_uint_32 length)
3299 {
3300    if (setjmp(png_jmpbuf(png_ptr)))
3301    {
3302       png_destroy_read_struct(&png_ptr, &info_ptr,
3303           (png_infopp)NULL);
3304       return (ERROR);
3305    }
3306
3307    /* This one's new also.  Simply give it a chunk
3308       of data from the file stream (in order, of
3309       course).  On machines with segmented memory
3310       models machines, don't give it any more than
3311       64K.  The library seems to run fine with sizes
3312       of 4K. Although you can give it much less if
3313       necessary (I assume you can give it chunks of
3314       1 byte, I haven't tried less then 256 bytes
3315       yet).  When this function returns, you may
3316       want to display any rows that were generated
3317       in the row callback if you don't already do
3318       so there.
3319     */
3320    png_process_data(png_ptr, info_ptr, buffer, length);
3321
3322    /* At this point you can call png_process_data_skip if
3323       you want to handle data the library will skip yourself;
3324       it simply returns the number of bytes to skip (and stops
3325       libpng skipping that number of bytes on the next
3326       png_process_data call).
3327    return 0;
3328 }
3329
3330 /* This function is called (as set by
3331    png_set_progressive_read_fn() above) when enough data
3332    has been supplied so all of the header has been
3333    read.
3334 */
3335 void
3336 info_callback(png_structp png_ptr, png_infop info)
3337 {
3338    /* Do any setup here, including setting any of
3339       the transformations mentioned in the Reading
3340       PNG files section.  For now, you _must_ call
3341       either png_start_read_image() or
3342       png_read_update_info() after all the
3343       transformations are set (even if you don't set
3344       any).  You may start getting rows before
3345       png_process_data() returns, so this is your
3346       last chance to prepare for that.
3347
3348       This is where you turn on interlace handling,
3349       assuming you don't want to do it yourself.
3350
3351       If you need to you can stop the processing of
3352       your original input data at this point by calling
3353       png_process_data_pause.  This returns the number
3354       of unprocessed bytes from the last png_process_data
3355       call - it is up to you to ensure that the next call
3356       sees these bytes again.  If you don't want to bother
3357       with this you can get libpng to cache the unread
3358       bytes by setting the 'save' parameter (see png.h) but
3359       then libpng will have to copy the data internally.
3360     */
3361 }
3362
3363 /* This function is called when each row of image
3364    data is complete */
3365 void
3366 row_callback(png_structp png_ptr, png_bytep new_row,
3367    png_uint_32 row_num, int pass)
3368 {
3369    /* If the image is interlaced, and you turned
3370       on the interlace handler, this function will
3371       be called for every row in every pass.  Some
3372       of these rows will not be changed from the
3373       previous pass.  When the row is not changed,
3374       the new_row variable will be NULL.  The rows
3375       and passes are called in order, so you don't
3376       really need the row_num and pass, but I'm
3377       supplying them because it may make your life
3378       easier.
3379
3380       If you did not turn on interlace handling then
3381       the callback is called for each row of each
3382       sub-image when the image is interlaced.  In this
3383       case 'row_num' is the row in the sub-image, not
3384       the row in the output image as it is in all other
3385       cases.
3386
3387       For the non-NULL rows of interlaced images when
3388       you have switched on libpng interlace handling,
3389       you must call png_progressive_combine_row()
3390       passing in the row and the old row.  You can
3391       call this function for NULL rows (it will just
3392       return) and for non-interlaced images (it just
3393       does the memcpy for you) if it will make the
3394       code easier.  Thus, you can just do this for
3395       all cases if you switch on interlace handling;
3396     */
3397
3398        png_progressive_combine_row(png_ptr, old_row,
3399          new_row);
3400
3401    /* where old_row is what was displayed for
3402       previously for the row.  Note that the first
3403       pass (pass == 0, really) will completely cover
3404       the old row, so the rows do not have to be
3405       initialized.  After the first pass (and only
3406       for interlaced images), you will have to pass
3407       the current row, and the function will combine
3408       the old row and the new row.
3409
3410       You can also call png_process_data_pause in this
3411       callback - see above.
3412    */
3413 }
3414
3415 void
3416 end_callback(png_structp png_ptr, png_infop info)
3417 {
3418    /* This function is called after the whole image
3419       has been read, including any chunks after the
3420       image (up to and including the IEND).  You
3421       will usually have the same info chunk as you
3422       had in the header, although some data may have
3423       been added to the comments and time fields.
3424
3425       Most people won't do much here, perhaps setting
3426       a flag that marks the image as finished.
3427     */
3428 }
3429
3430
3431
3432.SH IV. Writing
3433
3434Much of this is very similar to reading.  However, everything of
3435importance is repeated here, so you won't have to constantly look
3436back up in the reading section to understand writing.
3437
3438.SS Setup
3439
3440You will want to do the I/O initialization before you get into libpng,
3441so if it doesn't work, you don't have anything to undo. If you are not
3442using the standard I/O functions, you will need to replace them with
3443custom writing functions.  See the discussion under Customizing libpng.
3444
3445    FILE *fp = fopen(file_name, "wb");
3446
3447    if (!fp)
3448       return (ERROR);
3449
3450Next, png_struct and png_info need to be allocated and initialized.
3451As these can be both relatively large, you may not want to store these
3452on the stack, unless you have stack space to spare.  Of course, you
3453will want to check if they return NULL.  If you are also reading,
3454you won't want to name your read structure and your write structure
3455both "png_ptr"; you can call them anything you like, such as
3456"read_ptr" and "write_ptr".  Look at pngtest.c, for example.
3457
3458    png_structp png_ptr = png_create_write_struct
3459       (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3460        user_error_fn, user_warning_fn);
3461
3462    if (!png_ptr)
3463       return (ERROR);
3464
3465    png_infop info_ptr = png_create_info_struct(png_ptr);
3466    if (!info_ptr)
3467    {
3468       png_destroy_write_struct(&png_ptr,
3469           (png_infopp)NULL);
3470       return (ERROR);
3471    }
3472
3473If you want to use your own memory allocation routines,
3474define PNG_USER_MEM_SUPPORTED and use
3475png_create_write_struct_2() instead of png_create_write_struct():
3476
3477    png_structp png_ptr = png_create_write_struct_2
3478       (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3479        user_error_fn, user_warning_fn, (png_voidp)
3480        user_mem_ptr, user_malloc_fn, user_free_fn);
3481
3482After you have these structures, you will need to set up the
3483error handling.  When libpng encounters an error, it expects to
3484longjmp() back to your routine.  Therefore, you will need to call
3485setjmp() and pass the png_jmpbuf(png_ptr).  If you
3486write the file from different routines, you will need to update
3487the png_jmpbuf(png_ptr) every time you enter a new routine that will
3488call a png_*() function.  See your documentation of setjmp/longjmp
3489for your compiler for more information on setjmp/longjmp.  See
3490the discussion on libpng error handling in the Customizing Libpng
3491section below for more information on the libpng error handling.
3492
3493    if (setjmp(png_jmpbuf(png_ptr)))
3494    {
3495    png_destroy_write_struct(&png_ptr, &info_ptr);
3496       fclose(fp);
3497       return (ERROR);
3498    }
3499    ...
3500    return;
3501
3502If you would rather avoid the complexity of setjmp/longjmp issues,
3503you can compile libpng with PNG_NO_SETJMP, in which case
3504errors will result in a call to PNG_ABORT() which defaults to abort().
3505
3506You can #define PNG_ABORT() to a function that does something
3507more useful than abort(), as long as your function does not
3508return.
3509
3510Now you need to set up the output code.  The default for libpng is to
3511use the C function fwrite().  If you use this, you will need to pass a
3512valid FILE * in the function png_init_io().  Be sure that the file is
3513opened in binary mode.  Again, if you wish to handle writing data in
3514another way, see the discussion on libpng I/O handling in the Customizing
3515Libpng section below.
3516
3517    png_init_io(png_ptr, fp);
3518
3519If you are embedding your PNG into a datastream such as MNG, and don't
3520want libpng to write the 8-byte signature, or if you have already
3521written the signature in your application, use
3522
3523    png_set_sig_bytes(png_ptr, 8);
3524
3525to inform libpng that it should not write a signature.
3526
3527.SS Write callbacks
3528
3529At this point, you can set up a callback function that will be
3530called after each row has been written, which you can use to control
3531a progress meter or the like.  It's demonstrated in pngtest.c.
3532You must supply a function
3533
3534    void write_row_callback(png_structp png_ptr, png_uint_32 row,
3535       int pass);
3536    {
3537      /* put your code here */
3538    }
3539
3540(You can give it another name that you like instead of "write_row_callback")
3541
3542To inform libpng about your function, use
3543
3544    png_set_write_status_fn(png_ptr, write_row_callback);
3545
3546When this function is called the row has already been completely processed and
3547it has also been written out.  The 'row' and 'pass' refer to the next row to be
3548handled.  For the
3549non-interlaced case the row that was just handled is simply one less than the
3550passed in row number, and pass will always be 0.  For the interlaced case the
3551same applies unless the row value is 0, in which case the row just handled was
3552the last one from one of the preceding passes.  Because interlacing may skip a
3553pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3554need to know what the last pass is record (row,pass) from the callback and use
3555the last recorded value each time.
3556
3557As with the user transform you can find the output row using the
3558PNG_ROW_FROM_PASS_ROW macro.
3559
3560You now have the option of modifying how the compression library will
3561run.  The following functions are mainly for testing, but may be useful
3562in some cases, like if you need to write PNG files extremely fast and
3563are willing to give up some compression, or if you want to get the
3564maximum possible compression at the expense of slower writing.  If you
3565have no special needs in this area, let the library do what it wants by
3566not calling this function at all, as it has been tuned to deliver a good
3567speed/compression ratio. The second parameter to png_set_filter() is
3568the filter method, for which the only valid values are 0 (as of the
3569July 1999 PNG specification, version 1.2) or 64 (if you are writing
3570a PNG datastream that is to be embedded in a MNG datastream).  The third
3571parameter is a flag that indicates which filter type(s) are to be tested
3572for each scanline.  See the PNG specification for details on the specific
3573filter types.
3574
3575
3576    /* turn on or off filtering, and/or choose
3577       specific filters.  You can use either a single
3578       PNG_FILTER_VALUE_NAME or the bitwise OR of one
3579       or more PNG_FILTER_NAME masks.
3580     */
3581    png_set_filter(png_ptr, 0,
3582       PNG_FILTER_NONE  | PNG_FILTER_VALUE_NONE |
3583       PNG_FILTER_SUB   | PNG_FILTER_VALUE_SUB  |
3584       PNG_FILTER_UP    | PNG_FILTER_VALUE_UP   |
3585       PNG_FILTER_AVG   | PNG_FILTER_VALUE_AVG  |
3586       PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3587       PNG_ALL_FILTERS);
3588
3589If an application wants to start and stop using particular filters during
3590compression, it should start out with all of the filters (to ensure that
3591the previous row of pixels will be stored in case it's needed later),
3592and then add and remove them after the start of compression.
3593
3594If you are writing a PNG datastream that is to be embedded in a MNG
3595datastream, the second parameter can be either 0 or 64.
3596
3597The png_set_compression_*() functions interface to the zlib compression
3598library, and should mostly be ignored unless you really know what you are
3599doing.  The only generally useful call is png_set_compression_level()
3600which changes how much time zlib spends on trying to compress the image
3601data.  See the Compression Library (zlib.h and algorithm.txt, distributed
3602with zlib) for details on the compression levels.
3603
3604    #include zlib.h
3605
3606    /* Set the zlib compression level */
3607    png_set_compression_level(png_ptr,
3608        Z_BEST_COMPRESSION);
3609
3610    /* Set other zlib parameters for compressing IDAT */
3611    png_set_compression_mem_level(png_ptr, 8);
3612    png_set_compression_strategy(png_ptr,
3613        Z_DEFAULT_STRATEGY);
3614    png_set_compression_window_bits(png_ptr, 15);
3615    png_set_compression_method(png_ptr, 8);
3616    png_set_compression_buffer_size(png_ptr, 8192)
3617
3618    /* Set zlib parameters for text compression
3619     * If you don't call these, the parameters
3620     * fall back on those defined for IDAT chunks
3621     */
3622    png_set_text_compression_mem_level(png_ptr, 8);
3623    png_set_text_compression_strategy(png_ptr,
3624        Z_DEFAULT_STRATEGY);
3625    png_set_text_compression_window_bits(png_ptr, 15);
3626    png_set_text_compression_method(png_ptr, 8);
3627
3628.SS Setting the contents of info for output
3629
3630You now need to fill in the png_info structure with all the data you
3631wish to write before the actual image.  Note that the only thing you
3632are allowed to write after the image is the text chunks and the time
3633chunk (as of PNG Specification 1.2, anyway).  See png_write_end() and
3634the latest PNG specification for more information on that.  If you
3635wish to write them before the image, fill them in now, and flag that
3636data as being valid.  If you want to wait until after the data, don't
3637fill them until png_write_end().  For all the fields in png_info and
3638their data types, see png.h.  For explanations of what the fields
3639contain, see the PNG specification.
3640
3641Some of the more important parts of the png_info are:
3642
3643    png_set_IHDR(png_ptr, info_ptr, width, height,
3644       bit_depth, color_type, interlace_type,
3645       compression_type, filter_method)
3646
3647    width          - holds the width of the image
3648                     in pixels (up to 2^31).
3649
3650    height         - holds the height of the image
3651                     in pixels (up to 2^31).
3652
3653    bit_depth      - holds the bit depth of one of the
3654                     image channels.
3655                     (valid values are 1, 2, 4, 8, 16
3656                     and depend also on the
3657                     color_type.  See also significant
3658                     bits (sBIT) below).
3659
3660    color_type     - describes which color/alpha
3661                     channels are present.
3662                     PNG_COLOR_TYPE_GRAY
3663                        (bit depths 1, 2, 4, 8, 16)
3664                     PNG_COLOR_TYPE_GRAY_ALPHA
3665                        (bit depths 8, 16)
3666                     PNG_COLOR_TYPE_PALETTE
3667                        (bit depths 1, 2, 4, 8)
3668                     PNG_COLOR_TYPE_RGB
3669                        (bit_depths 8, 16)
3670                     PNG_COLOR_TYPE_RGB_ALPHA
3671                        (bit_depths 8, 16)
3672
3673                     PNG_COLOR_MASK_PALETTE
3674                     PNG_COLOR_MASK_COLOR
3675                     PNG_COLOR_MASK_ALPHA
3676
3677    interlace_type - PNG_INTERLACE_NONE or
3678                     PNG_INTERLACE_ADAM7
3679
3680    compression_type - (must be
3681                     PNG_COMPRESSION_TYPE_DEFAULT)
3682
3683    filter_method  - (must be PNG_FILTER_TYPE_DEFAULT
3684                     or, if you are writing a PNG to
3685                     be embedded in a MNG datastream,
3686                     can also be
3687                     PNG_INTRAPIXEL_DIFFERENCING)
3688
3689If you call png_set_IHDR(), the call must appear before any of the
3690other png_set_*() functions, because they might require access to some of
3691the IHDR settings.  The remaining png_set_*() functions can be called
3692in any order.
3693
3694If you wish, you can reset the compression_type, interlace_type, or
3695filter_method later by calling png_set_IHDR() again; if you do this, the
3696width, height, bit_depth, and color_type must be the same in each call.
3697
3698    png_set_PLTE(png_ptr, info_ptr, palette,
3699       num_palette);
3700
3701    palette        - the palette for the file
3702                     (array of png_color)
3703    num_palette    - number of entries in the palette
3704
3705    png_set_gAMA(png_ptr, info_ptr, file_gamma);
3706    png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
3707
3708    file_gamma     - the gamma at which the image was
3709                     created (PNG_INFO_gAMA)
3710
3711    int_file_gamma - 100,000 times the gamma at which
3712                     the image was created
3713
3714    png_set_cHRM(png_ptr, info_ptr,  white_x, white_y, red_x, red_y,
3715                     green_x, green_y, blue_x, blue_y)
3716    png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,
3717                     green_Y, green_Z, blue_X, blue_Y, blue_Z)
3718    png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,
3719                     int_red_x, int_red_y, int_green_x, int_green_y,
3720                     int_blue_x, int_blue_y)
3721    png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,
3722                     int_red_Z, int_green_X, int_green_Y, int_green_Z,
3723                     int_blue_X, int_blue_Y, int_blue_Z)
3724
3725    {white,red,green,blue}_{x,y}
3726                     A color space encoding specified using the chromaticities
3727                     of the end points and the white point.
3728
3729    {red,green,blue}_{X,Y,Z}
3730                     A color space encoding specified using the encoding end
3731                     points - the CIE tristimulus specification of the intended
3732                     color of the red, green and blue channels in the PNG RGB
3733                     data.  The white point is simply the sum of the three end
3734                     points.
3735
3736    png_set_sRGB(png_ptr, info_ptr, srgb_intent);
3737
3738    srgb_intent    - the rendering intent
3739                     (PNG_INFO_sRGB) The presence of
3740                     the sRGB chunk means that the pixel
3741                     data is in the sRGB color space.
3742                     This chunk also implies specific
3743                     values of gAMA and cHRM.  Rendering
3744                     intent is the CSS-1 property that
3745                     has been defined by the International
3746                     Color Consortium
3747                     (http://www.color.org).
3748                     It can be one of
3749                     PNG_sRGB_INTENT_SATURATION,
3750                     PNG_sRGB_INTENT_PERCEPTUAL,
3751                     PNG_sRGB_INTENT_ABSOLUTE, or
3752                     PNG_sRGB_INTENT_RELATIVE.
3753
3754
3755    png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
3756       srgb_intent);
3757
3758    srgb_intent    - the rendering intent
3759                     (PNG_INFO_sRGB) The presence of the
3760                     sRGB chunk means that the pixel
3761                     data is in the sRGB color space.
3762                     This function also causes gAMA and
3763                     cHRM chunks with the specific values
3764                     that are consistent with sRGB to be
3765                     written.
3766
3767    png_set_iCCP(png_ptr, info_ptr, name, compression_type,
3768                       profile, proflen);
3769
3770    name             - The profile name.
3771
3772    compression_type - The compression type; always
3773                       PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
3774                       You may give NULL to this argument to
3775                       ignore it.
3776
3777    profile          - International Color Consortium color
3778                       profile data. May contain NULs.
3779
3780    proflen          - length of profile data in bytes.
3781
3782    png_set_sBIT(png_ptr, info_ptr, sig_bit);
3783
3784    sig_bit        - the number of significant bits for
3785                     (PNG_INFO_sBIT) each of the gray, red,
3786                     green, and blue channels, whichever are
3787                     appropriate for the given color type
3788                     (png_color_16)
3789
3790    png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3791       num_trans, trans_color);
3792
3793    trans_alpha    - array of alpha (transparency)
3794                     entries for palette (PNG_INFO_tRNS)
3795
3796    num_trans      - number of transparent entries
3797                     (PNG_INFO_tRNS)
3798
3799    trans_color    - graylevel or color sample values
3800                     (in order red, green, blue) of the
3801                     single transparent color for
3802                     non-paletted images (PNG_INFO_tRNS)
3803
3804    png_set_hIST(png_ptr, info_ptr, hist);
3805
3806    hist           - histogram of palette (array of
3807                     png_uint_16) (PNG_INFO_hIST)
3808
3809    png_set_tIME(png_ptr, info_ptr, mod_time);
3810
3811    mod_time       - time image was last modified
3812                     (PNG_VALID_tIME)
3813
3814    png_set_bKGD(png_ptr, info_ptr, background);
3815
3816    background     - background color (of type
3817                     png_color_16p) (PNG_VALID_bKGD)
3818
3819    png_set_text(png_ptr, info_ptr, text_ptr, num_text);
3820
3821    text_ptr       - array of png_text holding image
3822                     comments
3823
3824    text_ptr[i].compression - type of compression used
3825                 on "text" PNG_TEXT_COMPRESSION_NONE
3826                           PNG_TEXT_COMPRESSION_zTXt
3827                           PNG_ITXT_COMPRESSION_NONE
3828                           PNG_ITXT_COMPRESSION_zTXt
3829    text_ptr[i].key   - keyword for comment.  Must contain
3830                 1-79 characters.
3831    text_ptr[i].text  - text comments for current
3832                         keyword.  Can be NULL or empty.
3833    text_ptr[i].text_length - length of text string,
3834                 after decompression, 0 for iTXt
3835    text_ptr[i].itxt_length - length of itxt string,
3836                 after decompression, 0 for tEXt/zTXt
3837    text_ptr[i].lang  - language of comment (NULL or
3838                         empty for unknown).
3839    text_ptr[i].translated_keyword  - keyword in UTF-8 (NULL
3840                         or empty for unknown).
3841
3842    Note that the itxt_length, lang, and lang_key
3843    members of the text_ptr structure only exist when the
3844    library is built with iTXt chunk support.  Prior to
3845    libpng-1.4.0 the library was built by default without
3846    iTXt support. Also note that when iTXt is supported,
3847    they contain NULL pointers when the "compression"
3848    field contains PNG_TEXT_COMPRESSION_NONE or
3849    PNG_TEXT_COMPRESSION_zTXt.
3850
3851    num_text       - number of comments
3852
3853    png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3854       num_spalettes);
3855
3856    palette_ptr    - array of png_sPLT_struct structures
3857                     to be added to the list of palettes
3858                     in the info structure.
3859    num_spalettes  - number of palette structures to be
3860                     added.
3861
3862    png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
3863        unit_type);
3864
3865    offset_x  - positive offset from the left
3866                     edge of the screen
3867
3868    offset_y  - positive offset from the top
3869                     edge of the screen
3870
3871    unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
3872
3873    png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
3874        unit_type);
3875
3876    res_x       - pixels/unit physical resolution
3877                  in x direction
3878
3879    res_y       - pixels/unit physical resolution
3880                  in y direction
3881
3882    unit_type   - PNG_RESOLUTION_UNKNOWN,
3883                  PNG_RESOLUTION_METER
3884
3885    png_set_sCAL(png_ptr, info_ptr, unit, width, height)
3886
3887    unit        - physical scale units (an integer)
3888
3889    width       - width of a pixel in physical scale units
3890
3891    height      - height of a pixel in physical scale units
3892                  (width and height are doubles)
3893
3894    png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
3895
3896    unit        - physical scale units (an integer)
3897
3898    width       - width of a pixel in physical scale units
3899                  expressed as a string
3900
3901    height      - height of a pixel in physical scale units
3902                 (width and height are strings like "2.54")
3903
3904    png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
3905       num_unknowns)
3906
3907    unknowns          - array of png_unknown_chunk
3908                        structures holding unknown chunks
3909    unknowns[i].name  - name of unknown chunk
3910    unknowns[i].data  - data of unknown chunk
3911    unknowns[i].size  - size of unknown chunk's data
3912    unknowns[i].location - position to write chunk in file
3913                           0: do not write chunk
3914                           PNG_HAVE_IHDR: before PLTE
3915                           PNG_HAVE_PLTE: before IDAT
3916                           PNG_AFTER_IDAT: after IDAT
3917
3918The "location" member is set automatically according to
3919what part of the output file has already been written.
3920You can change its value after calling png_set_unknown_chunks()
3921as demonstrated in pngtest.c.  Within each of the "locations",
3922the chunks are sequenced according to their position in the
3923structure (that is, the value of "i", which is the order in which
3924the chunk was either read from the input file or defined with
3925png_set_unknown_chunks).
3926
3927A quick word about text and num_text.  text is an array of png_text
3928structures.  num_text is the number of valid structures in the array.
3929Each png_text structure holds a language code, a keyword, a text value,
3930and a compression type.
3931
3932The compression types have the same valid numbers as the compression
3933types of the image data.  Currently, the only valid number is zero.
3934However, you can store text either compressed or uncompressed, unlike
3935images, which always have to be compressed.  So if you don't want the
3936text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
3937Because tEXt and zTXt chunks don't have a language field, if you
3938specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3939any language code or translated keyword will not be written out.
3940
3941Until text gets around a few hundred bytes, it is not worth compressing it.
3942After the text has been written out to the file, the compression type
3943is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3944so that it isn't written out again at the end (in case you are calling
3945png_write_end() with the same struct).
3946
3947The keywords that are given in the PNG Specification are:
3948
3949    Title            Short (one line) title or
3950                     caption for image
3951
3952    Author           Name of image's creator
3953
3954    Description      Description of image (possibly long)
3955
3956    Copyright        Copyright notice
3957
3958    Creation Time    Time of original image creation
3959                     (usually RFC 1123 format, see below)
3960
3961    Software         Software used to create the image
3962
3963    Disclaimer       Legal disclaimer
3964
3965    Warning          Warning of nature of content
3966
3967    Source           Device used to create the image
3968
3969    Comment          Miscellaneous comment; conversion
3970                     from other image format
3971
3972The keyword-text pairs work like this.  Keywords should be short
3973simple descriptions of what the comment is about.  Some typical
3974keywords are found in the PNG specification, as is some recommendations
3975on keywords.  You can repeat keywords in a file.  You can even write
3976some text before the image and some after.  For example, you may want
3977to put a description of the image before the image, but leave the
3978disclaimer until after, so viewers working over modem connections
3979don't have to wait for the disclaimer to go over the modem before
3980they start seeing the image.  Finally, keywords should be full
3981words, not abbreviations.  Keywords and text are in the ISO 8859-1
3982(Latin-1) character set (a superset of regular ASCII) and can not
3983contain NUL characters, and should not contain control or other
3984unprintable characters.  To make the comments widely readable, stick
3985with basic ASCII, and avoid machine specific character set extensions
3986like the IBM-PC character set.  The keyword must be present, but
3987you can leave off the text string on non-compressed pairs.
3988Compressed pairs must have a text string, as only the text string
3989is compressed anyway, so the compression would be meaningless.
3990
3991PNG supports modification time via the png_time structure.  Two
3992conversion routines are provided, png_convert_from_time_t() for
3993time_t and png_convert_from_struct_tm() for struct tm.  The
3994time_t routine uses gmtime().  You don't have to use either of
3995these, but if you wish to fill in the png_time structure directly,
3996you should provide the time in universal time (GMT) if possible
3997instead of your local time.  Note that the year number is the full
3998year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
3999that months start with 1.
4000
4001If you want to store the time of the original image creation, you should
4002use a plain tEXt chunk with the "Creation Time" keyword.  This is
4003necessary because the "creation time" of a PNG image is somewhat vague,
4004depending on whether you mean the PNG file, the time the image was
4005created in a non-PNG format, a still photo from which the image was
4006scanned, or possibly the subject matter itself.  In order to facilitate
4007machine-readable dates, it is recommended that the "Creation Time"
4008tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
4009although this isn't a requirement.  Unlike the tIME chunk, the
4010"Creation Time" tEXt chunk is not expected to be automatically changed
4011by the software.  To facilitate the use of RFC 1123 dates, a function
4012png_convert_to_rfc1123(png_timep) is provided to convert from PNG
4013time to an RFC 1123 format string.
4014
4015.SS Writing unknown chunks
4016
4017You can use the png_set_unknown_chunks function to queue up chunks
4018for writing.  You give it a chunk name, raw data, and a size; that's
4019all there is to it.  The chunks will be written by the next following
4020png_write_info_before_PLTE, png_write_info, or png_write_end function.
4021Any chunks previously read into the info structure's unknown-chunk
4022list will also be written out in a sequence that satisfies the PNG
4023specification's ordering rules.
4024
4025.SS The high-level write interface
4026
4027At this point there are two ways to proceed; through the high-level
4028write interface, or through a sequence of low-level write operations.
4029You can use the high-level interface if your image data is present
4030in the info structure.  All defined output
4031transformations are permitted, enabled by the following masks.
4032
4033    PNG_TRANSFORM_IDENTITY      No transformation
4034    PNG_TRANSFORM_PACKING       Pack 1, 2 and 4-bit samples
4035    PNG_TRANSFORM_PACKSWAP      Change order of packed
4036                                pixels to LSB first
4037    PNG_TRANSFORM_INVERT_MONO   Invert monochrome images
4038    PNG_TRANSFORM_SHIFT         Normalize pixels to the
4039                                sBIT depth
4040    PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA
4041                                to BGRA
4042    PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA
4043                                to AG
4044    PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity
4045                                to transparency
4046    PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples
4047    PNG_TRANSFORM_STRIP_FILLER        Strip out filler
4048                                      bytes (deprecated).
4049    PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
4050                                      filler bytes
4051    PNG_TRANSFORM_STRIP_FILLER_AFTER  Strip out trailing
4052                                      filler bytes
4053
4054If you have valid image data in the info structure (you can use
4055png_set_rows() to put image data in the info structure), simply do this:
4056
4057    png_write_png(png_ptr, info_ptr, png_transforms, NULL)
4058
4059where png_transforms is an integer containing the bitwise OR of some set of
4060transformation flags.  This call is equivalent to png_write_info(),
4061followed the set of transformations indicated by the transform mask,
4062then png_write_image(), and finally png_write_end().
4063
4064(The final parameter of this call is not yet used.  Someday it might point
4065to transformation parameters required by some future output transform.)
4066
4067You must use png_transforms and not call any png_set_transform() functions
4068when you use png_write_png().
4069
4070.SS The low-level write interface
4071
4072If you are going the low-level route instead, you are now ready to
4073write all the file information up to the actual image data.  You do
4074this with a call to png_write_info().
4075
4076    png_write_info(png_ptr, info_ptr);
4077
4078Note that there is one transformation you may need to do before
4079png_write_info().  In PNG files, the alpha channel in an image is the
4080level of opacity.  If your data is supplied as a level of transparency,
4081you can invert the alpha channel before you write it, so that 0 is
4082fully transparent and 255 (in 8-bit or paletted images) or 65535
4083(in 16-bit images) is fully opaque, with
4084
4085    png_set_invert_alpha(png_ptr);
4086
4087This must appear before png_write_info() instead of later with the
4088other transformations because in the case of paletted images the tRNS
4089chunk data has to be inverted before the tRNS chunk is written.  If
4090your image is not a paletted image, the tRNS data (which in such cases
4091represents a single color to be rendered as transparent) won't need to
4092be changed, and you can safely do this transformation after your
4093png_write_info() call.
4094
4095If you need to write a private chunk that you want to appear before
4096the PLTE chunk when PLTE is present, you can write the PNG info in
4097two steps, and insert code to write your own chunk between them:
4098
4099    png_write_info_before_PLTE(png_ptr, info_ptr);
4100    png_set_unknown_chunks(png_ptr, info_ptr, ...);
4101    png_write_info(png_ptr, info_ptr);
4102
4103After you've written the file information, you can set up the library
4104to handle any special transformations of the image data.  The various
4105ways to transform the data will be described in the order that they
4106should occur.  This is important, as some of these change the color
4107type and/or bit depth of the data, and some others only work on
4108certain color types and bit depths.  Even though each transformation
4109checks to see if it has data that it can do something with, you should
4110make sure to only enable a transformation if it will be valid for the
4111data.  For example, don't swap red and blue on grayscale data.
4112
4113PNG files store RGB pixels packed into 3 or 6 bytes.  This code tells
4114the library to strip input data that has 4 or 8 bytes per pixel down
4115to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
4116bytes per pixel).
4117
4118    png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
4119
4120where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
4121PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
4122is stored XRGB or RGBX.
4123
4124PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
4125they can, resulting in, for example, 8 pixels per byte for 1 bit files.
4126If the data is supplied at 1 pixel per byte, use this code, which will
4127correctly pack the pixels into a single byte:
4128
4129    png_set_packing(png_ptr);
4130
4131PNG files reduce possible bit depths to 1, 2, 4, 8, and 16.  If your
4132data is of another bit depth, you can write an sBIT chunk into the
4133file so that decoders can recover the original data if desired.
4134
4135    /* Set the true bit depth of the image data */
4136    if (color_type & PNG_COLOR_MASK_COLOR)
4137    {
4138       sig_bit.red = true_bit_depth;
4139       sig_bit.green = true_bit_depth;
4140       sig_bit.blue = true_bit_depth;
4141    }
4142
4143    else
4144    {
4145       sig_bit.gray = true_bit_depth;
4146    }
4147
4148    if (color_type & PNG_COLOR_MASK_ALPHA)
4149    {
4150       sig_bit.alpha = true_bit_depth;
4151    }
4152
4153    png_set_sBIT(png_ptr, info_ptr, &sig_bit);
4154
4155If the data is stored in the row buffer in a bit depth other than
4156one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
4157this will scale the values to appear to be the correct bit depth as
4158is required by PNG.
4159
4160    png_set_shift(png_ptr, &sig_bit);
4161
4162PNG files store 16-bit pixels in network byte order (big-endian,
4163ie. most significant bits first).  This code would be used if they are
4164supplied the other way (little-endian, i.e. least significant bits
4165first, the way PCs store them):
4166
4167    if (bit_depth > 8)
4168       png_set_swap(png_ptr);
4169
4170If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
4171need to change the order the pixels are packed into bytes, you can use:
4172
4173    if (bit_depth < 8)
4174       png_set_packswap(png_ptr);
4175
4176PNG files store 3 color pixels in red, green, blue order.  This code
4177would be used if they are supplied as blue, green, red:
4178
4179    png_set_bgr(png_ptr);
4180
4181PNG files describe monochrome as black being zero and white being
4182one. This code would be used if the pixels are supplied with this reversed
4183(black being one and white being zero):
4184
4185    png_set_invert_mono(png_ptr);
4186
4187Finally, you can write your own transformation function if none of
4188the existing ones meets your needs.  This is done by setting a callback
4189with
4190
4191    png_set_write_user_transform_fn(png_ptr,
4192       write_transform_fn);
4193
4194You must supply the function
4195
4196    void write_transform_fn(png_structp png_ptr, png_row_infop
4197       row_info, png_bytep data)
4198
4199See pngtest.c for a working example.  Your function will be called
4200before any of the other transformations are processed.  If supported
4201libpng also supplies an information routine that may be called from
4202your callback:
4203
4204   png_get_current_row_number(png_ptr);
4205   png_get_current_pass_number(png_ptr);
4206
4207This returns the current row passed to the transform.  With interlaced
4208images the value returned is the row in the input sub-image image.  Use
4209PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
4210find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
4211
4212The discussion of interlace handling above contains more information on how to
4213use these values.
4214
4215You can also set up a pointer to a user structure for use by your
4216callback function.
4217
4218    png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
4219
4220The user_channels and user_depth parameters of this function are ignored
4221when writing; you can set them to zero as shown.
4222
4223You can retrieve the pointer via the function png_get_user_transform_ptr().
4224For example:
4225
4226    voidp write_user_transform_ptr =
4227       png_get_user_transform_ptr(png_ptr);
4228
4229It is possible to have libpng flush any pending output, either manually,
4230or automatically after a certain number of lines have been written.  To
4231flush the output stream a single time call:
4232
4233    png_write_flush(png_ptr);
4234
4235and to have libpng flush the output stream periodically after a certain
4236number of scanlines have been written, call:
4237
4238    png_set_flush(png_ptr, nrows);
4239
4240Note that the distance between rows is from the last time png_write_flush()
4241was called, or the first row of the image if it has never been called.
4242So if you write 50 lines, and then png_set_flush 25, it will flush the
4243output on the next scanline, and every 25 lines thereafter, unless
4244png_write_flush() is called before 25 more lines have been written.
4245If nrows is too small (less than about 10 lines for a 640 pixel wide
4246RGB image) the image compression may decrease noticeably (although this
4247may be acceptable for real-time applications).  Infrequent flushing will
4248only degrade the compression performance by a few percent over images
4249that do not use flushing.
4250
4251.SS Writing the image data
4252
4253That's it for the transformations.  Now you can write the image data.
4254The simplest way to do this is in one function call.  If you have the
4255whole image in memory, you can just call png_write_image() and libpng
4256will write the image.  You will need to pass in an array of pointers to
4257each row.  This function automatically handles interlacing, so you don't
4258need to call png_set_interlace_handling() or call this function multiple
4259times, or any of that other stuff necessary with png_write_rows().
4260
4261    png_write_image(png_ptr, row_pointers);
4262
4263where row_pointers is:
4264
4265    png_byte *row_pointers[height];
4266
4267You can point to void or char or whatever you use for pixels.
4268
4269If you don't want to write the whole image at once, you can
4270use png_write_rows() instead.  If the file is not interlaced,
4271this is simple:
4272
4273    png_write_rows(png_ptr, row_pointers,
4274       number_of_rows);
4275
4276row_pointers is the same as in the png_write_image() call.
4277
4278If you are just writing one row at a time, you can do this with
4279a single row_pointer instead of an array of row_pointers:
4280
4281    png_bytep row_pointer = row;
4282
4283    png_write_row(png_ptr, row_pointer);
4284
4285When the file is interlaced, things can get a good deal more complicated.
4286The only currently (as of the PNG Specification version 1.2, dated July
42871999) defined interlacing scheme for PNG files is the "Adam7" interlace
4288scheme, that breaks down an image into seven smaller images of varying
4289size.  libpng will build these images for you, or you can do them
4290yourself.  If you want to build them yourself, see the PNG specification
4291for details of which pixels to write when.
4292
4293If you don't want libpng to handle the interlacing details, just
4294use png_set_interlace_handling() and call png_write_rows() the
4295correct number of times to write all the sub-images
4296(png_set_interlace_handling() returns the number of sub-images.)
4297
4298If you want libpng to build the sub-images, call this before you start
4299writing any rows:
4300
4301    number_of_passes = png_set_interlace_handling(png_ptr);
4302
4303This will return the number of passes needed.  Currently, this is seven,
4304but may change if another interlace type is added.
4305
4306Then write the complete image number_of_passes times.
4307
4308    png_write_rows(png_ptr, row_pointers, number_of_rows);
4309
4310Think carefully before you write an interlaced image.  Typically code that
4311reads such images reads all the image data into memory, uncompressed, before
4312doing any processing.  Only code that can display an image on the fly can
4313take advantage of the interlacing and even then the image has to be exactly
4314the correct size for the output device, because scaling an image requires
4315adjacent pixels and these are not available until all the passes have been
4316read.
4317
4318If you do write an interlaced image you will hardly ever need to handle
4319the interlacing yourself.  Call png_set_interlace_handling() and use the
4320approach described above.
4321
4322The only time it is conceivable that you will really need to write an
4323interlaced image pass-by-pass is when you have read one pass by pass and
4324made some pixel-by-pixel transformation to it, as described in the read
4325code above.  In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
4326to determine the size of each sub-image in turn and simply write the rows
4327you obtained from the read code.
4328
4329.SS Finishing a sequential write
4330
4331After you are finished writing the image, you should finish writing
4332the file.  If you are interested in writing comments or time, you should
4333pass an appropriately filled png_info pointer.  If you are not interested,
4334you can pass NULL.
4335
4336    png_write_end(png_ptr, info_ptr);
4337
4338When you are done, you can free all memory used by libpng like this:
4339
4340    png_destroy_write_struct(&png_ptr, &info_ptr);
4341
4342It is also possible to individually free the info_ptr members that
4343point to libpng-allocated storage with the following function:
4344
4345    png_free_data(png_ptr, info_ptr, mask, seq)
4346
4347    mask  - identifies data to be freed, a mask
4348            containing the bitwise OR of one or
4349            more of
4350              PNG_FREE_PLTE, PNG_FREE_TRNS,
4351              PNG_FREE_HIST, PNG_FREE_ICCP,
4352              PNG_FREE_PCAL, PNG_FREE_ROWS,
4353              PNG_FREE_SCAL, PNG_FREE_SPLT,
4354              PNG_FREE_TEXT, PNG_FREE_UNKN,
4355            or simply PNG_FREE_ALL
4356
4357    seq   - sequence number of item to be freed
4358            (-1 for all items)
4359
4360This function may be safely called when the relevant storage has
4361already been freed, or has not yet been allocated, or was allocated
4362by the user  and not by libpng,  and will in those cases do nothing.
4363The "seq" parameter is ignored if only one item of the selected data
4364type, such as PLTE, is allowed.  If "seq" is not -1, and multiple items
4365are allowed for the data type identified in the mask, such as text or
4366sPLT, only the n'th item in the structure is freed, where n is "seq".
4367
4368If you allocated data such as a palette that you passed in to libpng
4369with png_set_*, you must not free it until just before the call to
4370png_destroy_write_struct().
4371
4372The default behavior is only to free data that was allocated internally
4373by libpng.  This can be changed, so that libpng will not free the data,
4374or so that it will free data that was allocated by the user with png_malloc()
4375or png_zalloc() and passed in via a png_set_*() function, with
4376
4377    png_data_freer(png_ptr, info_ptr, freer, mask)
4378
4379    freer  - one of
4380               PNG_DESTROY_WILL_FREE_DATA
4381               PNG_SET_WILL_FREE_DATA
4382               PNG_USER_WILL_FREE_DATA
4383
4384    mask   - which data elements are affected
4385             same choices as in png_free_data()
4386
4387For example, to transfer responsibility for some data from a read structure
4388to a write structure, you could use
4389
4390    png_data_freer(read_ptr, read_info_ptr,
4391       PNG_USER_WILL_FREE_DATA,
4392       PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4393
4394    png_data_freer(write_ptr, write_info_ptr,
4395       PNG_DESTROY_WILL_FREE_DATA,
4396       PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4397
4398thereby briefly reassigning responsibility for freeing to the user but
4399immediately afterwards reassigning it once more to the write_destroy
4400function.  Having done this, it would then be safe to destroy the read
4401structure and continue to use the PLTE, tRNS, and hIST data in the write
4402structure.
4403
4404This function only affects data that has already been allocated.
4405You can call this function before calling after the png_set_*() functions
4406to control whether the user or png_destroy_*() is supposed to free the data.
4407When the user assumes responsibility for libpng-allocated data, the
4408application must use
4409png_free() to free it, and when the user transfers responsibility to libpng
4410for data that the user has allocated, the user must have used png_malloc()
4411or png_zalloc() to allocate it.
4412
4413If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
4414separately, do not transfer responsibility for freeing text_ptr to libpng,
4415because when libpng fills a png_text structure it combines these members with
4416the key member, and png_free_data() will free only text_ptr.key.  Similarly,
4417if you transfer responsibility for free'ing text_ptr from libpng to your
4418application, your application must not separately free those members.
4419For a more compact example of writing a PNG image, see the file example.c.
4420
4421.SH V. Modifying/Customizing libpng:
4422
4423There are two issues here.  The first is changing how libpng does
4424standard things like memory allocation, input/output, and error handling.
4425The second deals with more complicated things like adding new chunks,
4426adding new transformations, and generally changing how libpng works.
4427Both of those are compile-time issues; that is, they are generally
4428determined at the time the code is written, and there is rarely a need
4429to provide the user with a means of changing them.
4430
4431Memory allocation, input/output, and error handling
4432
4433All of the memory allocation, input/output, and error handling in libpng
4434goes through callbacks that are user-settable.  The default routines are
4435in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively.  To change
4436these functions, call the appropriate png_set_*_fn() function.
4437
4438Memory allocation is done through the functions png_malloc(), png_calloc(),
4439and png_free().  These currently just call the standard C functions.
4440png_calloc() calls png_malloc() and then clears the newly
4441allocated memory to zero.  There is limited support for certain systems
4442with segmented memory architectures and the types of pointers declared by
4443png.h match this; you will have to use appropriate pointers in your
4444application.  Since it is
4445unlikely that the method of handling memory allocation on a platform
4446will change between applications, these functions must be modified in
4447the library at compile time.  If you prefer to use a different method
4448of allocating and freeing data, you can use png_create_read_struct_2() or
4449png_create_write_struct_2() to register your own functions as described
4450above.  These functions also provide a void pointer that can be retrieved
4451via
4452
4453    mem_ptr=png_get_mem_ptr(png_ptr);
4454
4455Your replacement memory functions must have prototypes as follows:
4456
4457    png_voidp malloc_fn(png_structp png_ptr,
4458       png_alloc_size_t size);
4459
4460    void free_fn(png_structp png_ptr, png_voidp ptr);
4461
4462Your malloc_fn() must return NULL in case of failure.  The png_malloc()
4463function will normally call png_error() if it receives a NULL from the
4464system memory allocator or from your replacement malloc_fn().
4465
4466Your free_fn() will never be called with a NULL ptr, since libpng's
4467png_free() checks for NULL before calling free_fn().
4468
4469Input/Output in libpng is done through png_read() and png_write(),
4470which currently just call fread() and fwrite().  The FILE * is stored in
4471png_struct and is initialized via png_init_io().  If you wish to change
4472the method of I/O, the library supplies callbacks that you can set
4473through the function png_set_read_fn() and png_set_write_fn() at run
4474time, instead of calling the png_init_io() function.  These functions
4475also provide a void pointer that can be retrieved via the function
4476png_get_io_ptr().  For example:
4477
4478    png_set_read_fn(png_structp read_ptr,
4479        voidp read_io_ptr, png_rw_ptr read_data_fn)
4480
4481    png_set_write_fn(png_structp write_ptr,
4482        voidp write_io_ptr, png_rw_ptr write_data_fn,
4483        png_flush_ptr output_flush_fn);
4484
4485    voidp read_io_ptr = png_get_io_ptr(read_ptr);
4486    voidp write_io_ptr = png_get_io_ptr(write_ptr);
4487
4488The replacement I/O functions must have prototypes as follows:
4489
4490    void user_read_data(png_structp png_ptr,
4491        png_bytep data, png_size_t length);
4492
4493    void user_write_data(png_structp png_ptr,
4494        png_bytep data, png_size_t length);
4495
4496    void user_flush_data(png_structp png_ptr);
4497
4498The user_read_data() function is responsible for detecting and
4499handling end-of-data errors.
4500
4501Supplying NULL for the read, write, or flush functions sets them back
4502to using the default C stream functions, which expect the io_ptr to
4503point to a standard *FILE structure.  It is probably a mistake
4504to use NULL for one of write_data_fn and output_flush_fn but not both
4505of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4506It is an error to read from a write stream, and vice versa.
4507
4508Error handling in libpng is done through png_error() and png_warning().
4509Errors handled through png_error() are fatal, meaning that png_error()
4510should never return to its caller.  Currently, this is handled via
4511setjmp() and longjmp() (unless you have compiled libpng with
4512PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
4513but you could change this to do things like exit() if you should wish,
4514as long as your function does not return.
4515
4516On non-fatal errors, png_warning() is called
4517to print a warning message, and then control returns to the calling code.
4518By default png_error() and png_warning() print a message on stderr via
4519fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
4520(because you don't want the messages) or PNG_NO_STDIO defined (because
4521fprintf() isn't available).  If you wish to change the behavior of the error
4522functions, you will need to set up your own message callbacks.  These
4523functions are normally supplied at the time that the png_struct is created.
4524It is also possible to redirect errors and warnings to your own replacement
4525functions after png_create_*_struct() has been called by calling:
4526
4527    png_set_error_fn(png_structp png_ptr,
4528        png_voidp error_ptr, png_error_ptr error_fn,
4529        png_error_ptr warning_fn);
4530
4531    png_voidp error_ptr = png_get_error_ptr(png_ptr);
4532
4533If NULL is supplied for either error_fn or warning_fn, then the libpng
4534default function will be used, calling fprintf() and/or longjmp() if a
4535problem is encountered.  The replacement error functions should have
4536parameters as follows:
4537
4538    void user_error_fn(png_structp png_ptr,
4539        png_const_charp error_msg);
4540
4541    void user_warning_fn(png_structp png_ptr,
4542        png_const_charp warning_msg);
4543
4544The motivation behind using setjmp() and longjmp() is the C++ throw and
4545catch exception handling methods.  This makes the code much easier to write,
4546as there is no need to check every return code of every function call.
4547However, there are some uncertainties about the status of local variables
4548after a longjmp, so the user may want to be careful about doing anything
4549after setjmp returns non-zero besides returning itself.  Consult your
4550compiler documentation for more details.  For an alternative approach, you
4551may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4552which is illustrated in pngvalid.c and in contrib/visupng.
4553
4554.SS Custom chunks
4555
4556If you need to read or write custom chunks, you may need to get deeper
4557into the libpng code.  The library now has mechanisms for storing
4558and writing chunks of unknown type; you can even declare callbacks
4559for custom chunks.  However, this may not be good enough if the
4560library code itself needs to know about interactions between your
4561chunk and existing `intrinsic' chunks.
4562
4563If you need to write a new intrinsic chunk, first read the PNG
4564specification. Acquire a first level of understanding of how it works.
4565Pay particular attention to the sections that describe chunk names,
4566and look at how other chunks were designed, so you can do things
4567similarly.  Second, check out the sections of libpng that read and
4568write chunks.  Try to find a chunk that is similar to yours and use
4569it as a template.  More details can be found in the comments inside
4570the code.  It is best to handle private or unknown chunks in a generic method,
4571via callback functions, instead of by modifying libpng functions. This
4572is illustrated in pngtest.c, which uses a callback function to handle a
4573private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4574libpng.
4575
4576If you wish to write your own transformation for the data, look through
4577the part of the code that does the transformations, and check out some of
4578the simpler ones to get an idea of how they work.  Try to find a similar
4579transformation to the one you want to add and copy off of it.  More details
4580can be found in the comments inside the code itself.
4581
4582.SS Configuring for 16-bit platforms
4583
4584You will want to look into zconf.h to tell zlib (and thus libpng) that
4585it cannot allocate more then 64K at a time.  Even if you can, the memory
4586won't be accessible.  So limit zlib and libpng to 64K by defining MAXSEG_64K.
4587
4588.SS Configuring for DOS
4589
4590For DOS users who only have access to the lower 640K, you will
4591have to limit zlib's memory usage via a png_set_compression_mem_level()
4592call.  See zlib.h or zconf.h in the zlib library for more information.
4593
4594.SS Configuring for Medium Model
4595
4596Libpng's support for medium model has been tested on most of the popular
4597compilers.  Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4598defined, and FAR gets defined to far in pngconf.h, and you should be
4599all set.  Everything in the library (except for zlib's structure) is
4600expecting far data.  You must use the typedefs with the p or pp on
4601the end for pointers (or at least look at them and be careful).  Make
4602note that the rows of data are defined as png_bytepp, which is
4603an "unsigned char far * far *".
4604
4605.SS Configuring for gui/windowing platforms:
4606
4607You will need to write new error and warning functions that use the GUI
4608interface, as described previously, and set them to be the error and
4609warning functions at the time that png_create_*_struct() is called,
4610in order to have them available during the structure initialization.
4611They can be changed later via png_set_error_fn().  On some compilers,
4612you may also have to change the memory allocators (png_malloc, etc.).
4613
4614.SS Configuring for compiler xxx:
4615
4616All includes for libpng are in pngconf.h.  If you need to add, change
4617or delete an include, this is the place to do it.
4618The includes that are not needed outside libpng are placed in pngpriv.h,
4619which is only used by the routines inside libpng itself.
4620The files in libpng proper only include pngpriv.h and png.h, which
4621%14%in turn includes pngconf.h.
4622in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
4623As of libpng-1.5.0, pngpriv.h also includes three other private header
4624files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
4625that previously appeared in the public headers.
4626
4627.SS Configuring zlib:
4628
4629There are special functions to configure the compression.  Perhaps the
4630most useful one changes the compression level, which currently uses
4631input compression values in the range 0 - 9.  The library normally
4632uses the default compression level (Z_DEFAULT_COMPRESSION = 6).  Tests
4633have shown that for a large majority of images, compression values in
4634the range 3-6 compress nearly as well as higher levels, and do so much
4635faster.  For online applications it may be desirable to have maximum speed
4636(Z_BEST_SPEED = 1).  With versions of zlib after v0.99, you can also
4637specify no compression (Z_NO_COMPRESSION = 0), but this would create
4638files larger than just storing the raw bitmap.  You can specify the
4639compression level by calling:
4640
4641    #include zlib.h
4642    png_set_compression_level(png_ptr, level);
4643
4644Another useful one is to reduce the memory level used by the library.
4645The memory level defaults to 8, but it can be lowered if you are
4646short on memory (running DOS, for example, where you only have 640K).
4647Note that the memory level does have an effect on compression; among
4648other things, lower levels will result in sections of incompressible
4649data being emitted in smaller stored blocks, with a correspondingly
4650larger relative overhead of up to 15% in the worst case.
4651
4652    #include zlib.h
4653    png_set_compression_mem_level(png_ptr, level);
4654
4655The other functions are for configuring zlib.  They are not recommended
4656for normal use and may result in writing an invalid PNG file.  See
4657zlib.h for more information on what these mean.
4658
4659    #include zlib.h
4660    png_set_compression_strategy(png_ptr,
4661        strategy);
4662
4663    png_set_compression_window_bits(png_ptr,
4664        window_bits);
4665
4666    png_set_compression_method(png_ptr, method);
4667
4668    png_set_compression_buffer_size(png_ptr, size);
4669
4670As of libpng version 1.5.4, additional APIs became
4671available to set these separately for non-IDAT
4672compressed chunks such as zTXt, iTXt, and iCCP:
4673
4674    #include zlib.h
4675    #if PNG_LIBPNG_VER >= 10504
4676    png_set_text_compression_level(png_ptr, level);
4677
4678    png_set_text_compression_mem_level(png_ptr, level);
4679
4680    png_set_text_compression_strategy(png_ptr,
4681        strategy);
4682
4683    png_set_text_compression_window_bits(png_ptr,
4684        window_bits);
4685
4686    png_set_text_compression_method(png_ptr, method);
4687    #endif
4688
4689.SS Controlling row filtering
4690
4691If you want to control whether libpng uses filtering or not, which
4692filters are used, and how it goes about picking row filters, you
4693can call one of these functions.  The selection and configuration
4694of row filters can have a significant impact on the size and
4695encoding speed and a somewhat lesser impact on the decoding speed
4696of an image.  Filtering is enabled by default for RGB and grayscale
4697images (with and without alpha), but not for paletted images nor
4698for any images with bit depths less than 8 bits/pixel.
4699
4700The 'method' parameter sets the main filtering method, which is
4701currently only '0' in the PNG 1.2 specification.  The 'filters'
4702parameter sets which filter(s), if any, should be used for each
4703scanline.  Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
4704to turn filtering on and off, respectively.
4705
4706Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
4707PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
4708ORed together with '|' to specify one or more filters to use.
4709These filters are described in more detail in the PNG specification.
4710If you intend to change the filter type during the course of writing
4711the image, you should start with flags set for all of the filters
4712you intend to use so that libpng can initialize its internal
4713structures appropriately for all of the filter types.  (Note that this
4714means the first row must always be adaptively filtered, because libpng
4715currently does not allocate the filter buffers until png_write_row()
4716is called for the first time.)
4717
4718    filters = PNG_FILTER_NONE | PNG_FILTER_SUB
4719              PNG_FILTER_UP | PNG_FILTER_AVG |
4720              PNG_FILTER_PAETH | PNG_ALL_FILTERS;
4721
4722    png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
4723       filters);
4724              The second parameter can also be
4725              PNG_INTRAPIXEL_DIFFERENCING if you are
4726              writing a PNG to be embedded in a MNG
4727              datastream.  This parameter must be the
4728              same as the value of filter_method used
4729              in png_set_IHDR().
4730
4731It is also possible to influence how libpng chooses from among the
4732available filters.  This is done in one or both of two ways - by
4733telling it how important it is to keep the same filter for successive
4734rows, and by telling it the relative computational costs of the filters.
4735
4736    double weights[3] = {1.5, 1.3, 1.1},
4737       costs[PNG_FILTER_VALUE_LAST] =
4738       {1.0, 1.3, 1.3, 1.5, 1.7};
4739
4740    png_set_filter_heuristics(png_ptr,
4741       PNG_FILTER_HEURISTIC_WEIGHTED, 3,
4742       weights, costs);
4743
4744The weights are multiplying factors that indicate to libpng that the
4745row filter should be the same for successive rows unless another row filter
4746is that many times better than the previous filter.  In the above example,
4747if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
4748"sum of absolute differences" 1.5 x 1.3 times higher than other filters
4749and still be chosen, while the NONE filter could have a sum 1.1 times
4750higher than other filters and still be chosen.  Unspecified weights are
4751taken to be 1.0, and the specified weights should probably be declining
4752like those above in order to emphasize recent filters over older filters.
4753
4754The filter costs specify for each filter type a relative decoding cost
4755to be considered when selecting row filters.  This means that filters
4756with higher costs are less likely to be chosen over filters with lower
4757costs, unless their "sum of absolute differences" is that much smaller.
4758The costs do not necessarily reflect the exact computational speeds of
4759the various filters, since this would unduly influence the final image
4760size.
4761
4762Note that the numbers above were invented purely for this example and
4763are given only to help explain the function usage.  Little testing has
4764been done to find optimum values for either the costs or the weights.
4765
4766.SS Removing unwanted object code
4767
4768There are a bunch of #define's in pngconf.h that control what parts of
4769libpng are compiled.  All the defines end in _SUPPORTED.  If you are
4770never going to use a capability, you can change the #define to #undef
4771before recompiling libpng and save yourself code and data space, or
4772you can turn off individual capabilities with defines that begin with
4773PNG_NO_.
4774
4775In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
4776
4777You can also turn all of the transforms and ancillary chunk capabilities
4778off en masse with compiler directives that define
4779PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
4780or all four,
4781along with directives to turn on any of the capabilities that you do
4782want.  The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
4783transformations but still leave the library fully capable of reading
4784and writing PNG files with all known public chunks. Use of the
4785PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
4786that is incapable of reading or writing ancillary chunks.  If you are
4787not using the progressive reading capability, you can turn that off
4788with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
4789capability, which you'll still have).
4790
4791All the reading and writing specific code are in separate files, so the
4792linker should only grab the files it needs.  However, if you want to
4793make sure, or if you are building a stand alone library, all the
4794reading files start with "pngr" and all the writing files start with "pngw".
4795The files that don't match either (like png.c, pngtrans.c, etc.)
4796are used for both reading and writing, and always need to be included.
4797The progressive reader is in pngpread.c
4798
4799If you are creating or distributing a dynamically linked library (a .so
4800or DLL file), you should not remove or disable any parts of the library,
4801as this will cause applications linked with different versions of the
4802library to fail if they call functions not available in your library.
4803The size of the library itself should not be an issue, because only
4804those sections that are actually used will be loaded into memory.
4805
4806.SS Requesting debug printout
4807
4808The macro definition PNG_DEBUG can be used to request debugging
4809printout.  Set it to an integer value in the range 0 to 3.  Higher
4810numbers result in increasing amounts of debugging information.  The
4811information is printed to the "stderr" file, unless another file
4812name is specified in the PNG_DEBUG_FILE macro definition.
4813
4814When PNG_DEBUG > 0, the following functions (macros) become available:
4815
4816   png_debug(level, message)
4817   png_debug1(level, message, p1)
4818   png_debug2(level, message, p1, p2)
4819
4820in which "level" is compared to PNG_DEBUG to decide whether to print
4821the message, "message" is the formatted string to be printed,
4822and p1 and p2 are parameters that are to be embedded in the string
4823according to printf-style formatting directives.  For example,
4824
4825   png_debug1(2, "foo=%d\n", foo);
4826
4827is expanded to
4828
4829   if (PNG_DEBUG > 2)
4830      fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
4831
4832When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
4833can still use PNG_DEBUG to control your own debugging:
4834
4835   #ifdef PNG_DEBUG
4836       fprintf(stderr, ...
4837   #endif
4838
4839When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
4840having level = 0 will be printed.  There aren't any such statements in
4841this version of libpng, but if you insert some they will be printed.
4842
4843.SH VI.  MNG support
4844
4845The MNG specification (available at http://www.libpng.org/pub/mng) allows
4846certain extensions to PNG for PNG images that are embedded in MNG datastreams.
4847Libpng can support some of these extensions.  To enable them, use the
4848png_permit_mng_features() function:
4849
4850   feature_set = png_permit_mng_features(png_ptr, mask)
4851
4852   mask is a png_uint_32 containing the bitwise OR of the
4853        features you want to enable.  These include
4854        PNG_FLAG_MNG_EMPTY_PLTE
4855        PNG_FLAG_MNG_FILTER_64
4856        PNG_ALL_MNG_FEATURES
4857
4858   feature_set is a png_uint_32 that is the bitwise AND of
4859      your mask with the set of MNG features that is
4860      supported by the version of libpng that you are using.
4861
4862It is an error to use this function when reading or writing a standalone
4863PNG file with the PNG 8-byte signature.  The PNG datastream must be wrapped
4864in a MNG datastream.  As a minimum, it must have the MNG 8-byte signature
4865and the MHDR and MEND chunks.  Libpng does not provide support for these
4866or any other MNG chunks; your application must provide its own support for
4867them.  You may wish to consider using libmng (available at
4868http://www.libmng.com) instead.
4869
4870.SH VII.  Changes to Libpng from version 0.88
4871
4872It should be noted that versions of libpng later than 0.96 are not
4873distributed by the original libpng author, Guy Schalnat, nor by
4874Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
4875distributed versions 0.89 through 0.96, but rather by another member
4876of the original PNG Group, Glenn Randers-Pehrson.  Guy and Andreas are
4877still alive and well, but they have moved on to other things.
4878
4879The old libpng functions png_read_init(), png_write_init(),
4880png_info_init(), png_read_destroy(), and png_write_destroy() have been
4881moved to PNG_INTERNAL in version 0.95 to discourage their use.  These
4882functions will be removed from libpng version 1.4.0.
4883
4884The preferred method of creating and initializing the libpng structures is
4885via the png_create_read_struct(), png_create_write_struct(), and
4886png_create_info_struct() because they isolate the size of the structures
4887from the application, allow version error checking, and also allow the
4888use of custom error handling routines during the initialization, which
4889the old functions do not.  The functions png_read_destroy() and
4890png_write_destroy() do not actually free the memory that libpng
4891allocated for these structs, but just reset the data structures, so they
4892can be used instead of png_destroy_read_struct() and
4893png_destroy_write_struct() if you feel there is too much system overhead
4894allocating and freeing the png_struct for each image read.
4895
4896Setting the error callbacks via png_set_message_fn() before
4897png_read_init() as was suggested in libpng-0.88 is no longer supported
4898because this caused applications that do not use custom error functions
4899to fail if the png_ptr was not initialized to zero.  It is still possible
4900to set the error callbacks AFTER png_read_init(), or to change them with
4901png_set_error_fn(), which is essentially the same function, but with a new
4902name to force compilation errors with applications that try to use the old
4903method.
4904
4905Starting with version 1.0.7, you can find out which version of the library
4906you are using at run-time:
4907
4908   png_uint_32 libpng_vn = png_access_version_number();
4909
4910The number libpng_vn is constructed from the major version, minor
4911version with leading zero, and release number with leading zero,
4912(e.g., libpng_vn for version 1.0.7 is 10007).
4913
4914Note that this function does not take a png_ptr, so you can call it
4915before you've created one.
4916
4917You can also check which version of png.h you used when compiling your
4918application:
4919
4920   png_uint_32 application_vn = PNG_LIBPNG_VER;
4921
4922.SH VIII.  Changes to Libpng from version 1.0.x to 1.2.x
4923
4924Support for user memory management was enabled by default.  To
4925accomplish this, the functions png_create_read_struct_2(),
4926png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
4927png_malloc_default(), and png_free_default() were added.
4928
4929Support for the iTXt chunk has been enabled by default as of
4930version 1.2.41.
4931
4932Support for certain MNG features was enabled.
4933
4934Support for numbered error messages was added.  However, we never got
4935around to actually numbering the error messages.  The function
4936png_set_strip_error_numbers() was added (Note: the prototype for this
4937function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
4938builds of libpng-1.2.15.  It was restored in libpng-1.2.36).
4939
4940The png_malloc_warn() function was added at libpng-1.2.3.  This issues
4941a png_warning and returns NULL instead of aborting when it fails to
4942acquire the requested memory allocation.
4943
4944Support for setting user limits on image width and height was enabled
4945by default.  The functions png_set_user_limits(), png_get_user_width_max(),
4946and png_get_user_height_max() were added at libpng-1.2.6.
4947
4948The png_set_add_alpha() function was added at libpng-1.2.7.
4949
4950The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
4951Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
4952tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
4953deprecated.
4954
4955A number of macro definitions in support of runtime selection of
4956assembler code features (especially Intel MMX code support) were
4957added at libpng-1.2.0:
4958
4959    PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
4960    PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
4961    PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
4962    PNG_ASM_FLAG_MMX_READ_INTERLACE
4963    PNG_ASM_FLAG_MMX_READ_FILTER_SUB
4964    PNG_ASM_FLAG_MMX_READ_FILTER_UP
4965    PNG_ASM_FLAG_MMX_READ_FILTER_AVG
4966    PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
4967    PNG_ASM_FLAGS_INITIALIZED
4968    PNG_MMX_READ_FLAGS
4969    PNG_MMX_FLAGS
4970    PNG_MMX_WRITE_FLAGS
4971    PNG_MMX_FLAGS
4972
4973We added the following functions in support of runtime
4974selection of assembler code features:
4975
4976    png_get_mmx_flagmask()
4977    png_set_mmx_thresholds()
4978    png_get_asm_flags()
4979    png_get_mmx_bitdepth_threshold()
4980    png_get_mmx_rowbytes_threshold()
4981    png_set_asm_flags()
4982
4983We replaced all of these functions with simple stubs in libpng-1.2.20,
4984when the Intel assembler code was removed due to a licensing issue.
4985
4986These macros are deprecated:
4987
4988    PNG_READ_TRANSFORMS_NOT_SUPPORTED
4989    PNG_PROGRESSIVE_READ_NOT_SUPPORTED
4990    PNG_NO_SEQUENTIAL_READ_SUPPORTED
4991    PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
4992    PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
4993    PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
4994
4995They have been replaced, respectively, by:
4996
4997    PNG_NO_READ_TRANSFORMS
4998    PNG_NO_PROGRESSIVE_READ
4999    PNG_NO_SEQUENTIAL_READ
5000    PNG_NO_WRITE_TRANSFORMS
5001    PNG_NO_READ_ANCILLARY_CHUNKS
5002    PNG_NO_WRITE_ANCILLARY_CHUNKS
5003
5004PNG_MAX_UINT was replaced with PNG_UINT_31_MAX.  It has been
5005deprecated since libpng-1.0.16 and libpng-1.2.6.
5006
5007The function
5008    png_check_sig(sig, num)
5009was replaced with
5010    !png_sig_cmp(sig, 0, num)
5011It has been deprecated since libpng-0.90.
5012
5013The function
5014    png_set_gray_1_2_4_to_8()
5015which also expands tRNS to alpha was replaced with
5016    png_set_expand_gray_1_2_4_to_8()
5017which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
5018
5019.SH IX.  Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
5020
5021Private libpng prototypes and macro definitions were moved from
5022png.h and pngconf.h into a new pngpriv.h header file.
5023
5024Functions png_set_benign_errors(), png_benign_error(), and
5025png_chunk_benign_error() were added.
5026
5027Support for setting the maximum amount of memory that the application
5028will allocate for reading chunks was added, as a security measure.
5029The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
5030were added to the library.
5031
5032We implemented support for I/O states by adding png_ptr member io_state
5033and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
5034
5035We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
5036input transforms.
5037
5038Checking for and reporting of errors in the IHDR chunk is more thorough.
5039
5040Support for global arrays was removed, to improve thread safety.
5041
5042Some obsolete/deprecated macros and functions have been removed.
5043
5044Typecasted NULL definitions such as
5045   #define png_voidp_NULL            (png_voidp)NULL
5046were eliminated.  If you used these in your application, just use
5047NULL instead.
5048
5049The png_struct and info_struct members "trans" and "trans_values" were
5050changed to "trans_alpha" and "trans_color", respectively.
5051
5052The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
5053were removed.
5054
5055The PNG_1_0_X and PNG_1_2_X macros were eliminated.
5056
5057The PNG_LEGACY_SUPPORTED macro was eliminated.
5058
5059Many WIN32_WCE #ifdefs were removed.
5060
5061The functions png_read_init(info_ptr), png_write_init(info_ptr),
5062png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
5063have been removed.  They have been deprecated since libpng-0.95.
5064
5065The png_permit_empty_plte() was removed. It has been deprecated
5066since libpng-1.0.9.  Use png_permit_mng_features() instead.
5067
5068We removed the obsolete stub functions png_get_mmx_flagmask(),
5069png_set_mmx_thresholds(), png_get_asm_flags(),
5070png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
5071png_set_asm_flags(), and png_mmx_supported()
5072
5073We removed the obsolete png_check_sig(), png_memcpy_check(), and
5074png_memset_check() functions.  Instead use !png_sig_cmp(), memcpy(),
5075and memset(), respectively.
5076
5077The function png_set_gray_1_2_4_to_8() was removed. It has been
5078deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
5079png_set_expand_gray_1_2_4_to_8() because the former function also
5080expanded any tRNS chunk to an alpha channel.
5081
5082Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
5083were added and are used by default instead of the corresponding
5084functions. Unfortunately,
5085from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5086function) incorrectly returned a value of type png_uint_32.
5087
5088We changed the prototype for png_malloc() from
5089    png_malloc(png_structp png_ptr, png_uint_32 size)
5090to
5091    png_malloc(png_structp png_ptr, png_alloc_size_t size)
5092
5093This also applies to the prototype for the user replacement malloc_fn().
5094
5095The png_calloc() function was added and is used in place of
5096of "png_malloc(); memset();" except in the case in png_read_png()
5097where the array consists of pointers; in this case a "for" loop is used
5098after the png_malloc() to set the pointers to NULL, to give robust.
5099behavior in case the application runs out of memory part-way through
5100the process.
5101
5102We changed the prototypes of png_get_compression_buffer_size() and
5103png_set_compression_buffer_size() to work with png_size_t instead of
5104png_uint_32.
5105
5106Support for numbered error messages was removed by default, since we
5107never got around to actually numbering the error messages. The function
5108png_set_strip_error_numbers() was removed from the library by default.
5109
5110The png_zalloc() and png_zfree() functions are no longer exported.
5111The png_zalloc() function no longer zeroes out the memory that it
5112allocates.
5113
5114Support for dithering was disabled by default in libpng-1.4.0, because
5115it has not been well tested and doesn't actually "dither".
5116The code was not
5117removed, however, and could be enabled by building libpng with
5118PNG_READ_DITHER_SUPPORTED defined.  In libpng-1.4.2, this support
5119was reenabled, but the function was renamed png_set_quantize() to
5120reflect more accurately what it actually does.  At the same time,
5121the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
5122PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5123was renamed to PNG_READ_QUANTIZE_SUPPORTED.
5124
5125We removed the trailing '.' from the warning and error messages.
5126
5127.SH X.  Changes to Libpng from version 1.4.x to 1.5.x
5128
5129From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5130function) incorrectly returned a value of type png_uint_32.
5131
5132Checking for invalid palette index on read or write was added at libpng
51331.5.10.  When an invalid index is found, libpng issues a benign error.
5134This is enabled by default but can be disabled in each png_ptr with
5135
5136   png_set_check_for_invalid_index(png_ptr, allowed);
5137
5138      allowed  - one of
5139                 0: disable
5140                 1: enable
5141
5142A. Changes that affect users of libpng
5143
5144There are no substantial API changes between the non-deprecated parts of
5145the 1.4.5 API and the 1.5.0 API; however, the ability to directly access
5146the main libpng control structures, png_struct and png_info, deprecated
5147in earlier versions of libpng, has been completely removed from
5148libpng 1.5.
5149
5150We no longer include zlib.h in png.h.  Applications that need access
5151to information in zlib.h will need to add the '#include "zlib.h"'
5152directive.  It does not matter whether it is placed prior to or after
5153the '"#include png.h"' directive.
5154
5155We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
5156png_memcmp(), png_sprintf, and png_memcpy() macros into a private
5157header file (pngpriv.h) that is not accessible to applications.
5158
5159In png_get_iCCP, the type of "profile" was changed from png_charpp
5160to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
5161
5162There are changes of form in png.h, including new and changed macros to
5163declare parts of the API.  Some API functions with arguments that are
5164pointers to data not modified within the function have been corrected to
5165declare these arguments with PNG_CONST.
5166
5167Much of the internal use of C macros to control the library build has also
5168changed and some of this is visible in the exported header files, in
5169particular the use of macros to control data and API elements visible
5170during application compilation may require significant revision to
5171application code.  (It is extremely rare for an application to do this.)
5172
5173Any program that compiled against libpng 1.4 and did not use deprecated
5174features or access internal library structures should compile and work
5175against libpng 1.5, except for the change in the prototype for
5176png_get_iCCP() and png_set_iCCP() API functions mentioned above.
5177
5178libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5179interlaced images.  The macros return the number of rows and columns in
5180each pass and information that can be used to de-interlace and (if
5181absolutely necessary) interlace an image.
5182
5183libpng 1.5.0 adds an API png_longjmp(png_ptr, value).  This API calls
5184the application-provided png_longjmp_ptr on the internal, but application
5185initialized, longjmp buffer.  It is provided as a convenience to avoid
5186the need to use the png_jmpbuf macro, which had the unnecessary side
5187effect of resetting the internal png_longjmp_ptr value.
5188
5189libpng 1.5.0 includes a complete fixed point API.  By default this is
5190present along with the corresponding floating point API.  In general the
5191fixed point API is faster and smaller than the floating point one because
5192the PNG file format used fixed point, not floating point.  This applies
5193even if the library uses floating point in internal calculations.  A new
5194macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5195uses floating point arithmetic (the default) or fixed point arithmetic
5196internally for performance critical calculations such as gamma correction.
5197In some cases, the gamma calculations may produce slightly different
5198results.  This has changed the results in png_rgb_to_gray and in alpha
5199composition (png_set_background for example). This applies even if the
5200original image was already linear (gamma == 1.0) and, therefore, it is
5201not necessary to linearize the image.  This is because libpng has *not*
5202been changed to optimize that case correctly, yet.
5203
5204Fixed point support for the sCAL chunk comes with an important caveat;
5205the sCAL specification uses a decimal encoding of floating point values
5206and the accuracy of PNG fixed point values is insufficient for
5207representation of these values. Consequently a "string" API
5208(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5209arbitrary sCAL chunks in the absence of either the floating point API or
5210internal floating point calculations.
5211
5212Applications no longer need to include the optional distribution header
5213file pngusr.h or define the corresponding macros during application
5214build in order to see the correct variant of the libpng API.  From 1.5.0
5215application code can check for the corresponding _SUPPORTED macro:
5216
5217#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
5218   /* code that uses the inch conversion APIs. */
5219#endif
5220
5221This macro will only be defined if the inch conversion functions have been
5222compiled into libpng.  The full set of macros, and whether or not support
5223has been compiled in, are available in the header file pnglibconf.h.
5224This header file is specific to the libpng build.  Notice that prior to
52251.5.0 the _SUPPORTED macros would always have the default definition unless
5226reset by pngusr.h or by explicit settings on the compiler command line.
5227These settings may produce compiler warnings or errors in 1.5.0 because
5228of macro redefinition.
5229
5230From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5231function) incorrectly returned a value of type png_uint_32.  libpng 1.5.0
5232is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5233did not exist.)
5234
5235Applications can now choose whether to use these macros or to call the
5236corresponding function by defining PNG_USE_READ_MACROS or
5237PNG_NO_USE_READ_MACROS before including png.h.  Notice that this is
5238only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
5239will lead to a link failure.
5240
5241Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
5242when compressing the IDAT data and textual data such as zTXt and iCCP.
5243In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
5244We added five png_set_text_*() functions for setting the parameters to
5245use with textual data.
5246
5247Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
5248option was off by default, and slightly inaccurate scaling occurred.
5249This option can no longer be turned off, and the choice of accurate
5250or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5251API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5252chopping.
5253
5254Prior to libpng-1.5.4, the png_set_user_limits() function could only be
5255used to reduce the width and height limits from the value of
5256PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5257that it could be used to override them.  Now this function will reduce or
5258increase the limits.
5259
5260Starting in libpng-1.5.10, the user limits can be set en masse with the
5261configuration option PNG_SAFE_LIMITS_SUPPORTED.  If this option is enabled,
5262a set of "safe" limits is applied in pngpriv.h.  These can be overridden by
5263application calls to png_set_user_limits(), png_set_user_chunk_cache_max(),
5264and/or png_set_user_malloc_max() that increase or decrease the limits.  Also,
5265in libpng-1.5.10 the default width and height limits were increased
5266from 1,000,000 to 0x7ffffff (i.e., made unlimited).  Therefore, the
5267limits are now
5268                               default      safe
5269   png_user_width_max        0x7fffffff    1,000,000
5270   png_user_height_max       0x7fffffff    1,000,000
5271   png_user_chunk_cache_max  0 (unlimited)   128
5272   png_user_chunk_malloc_max 0 (unlimited) 8,000,000
5273
5274B. Changes to the build and configuration of libpng
5275
5276Details of internal changes to the library code can be found in the CHANGES
5277file and in the GIT repository logs.  These will be of no concern to the vast
5278majority of library users or builders; however, the few who configure libpng
5279to a non-default feature set may need to change how this is done.
5280
5281There should be no need for library builders to alter build scripts if
5282these use the distributed build support - configure or the makefiles -
5283however, users of the makefiles may care to update their build scripts
5284to build pnglibconf.h where the corresponding makefile does not do so.
5285
5286Building libpng with a non-default configuration has changed completely.
5287The old method using pngusr.h should still work correctly even though the
5288way pngusr.h is used in the build has been changed; however, library
5289builders will probably want to examine the changes to take advantage of
5290new capabilities and to simplify their build system.
5291
5292B.1 Specific changes to library configuration capabilities
5293
5294The library now supports a complete fixed point implementation and can
5295thus be used on systems that have no floating point support or very
5296limited or slow support.  Previously gamma correction, an essential part
5297of complete PNG support, required reasonably fast floating point.
5298
5299As part of this the choice of internal implementation has been made
5300independent of the choice of fixed versus floating point APIs and all the
5301missing fixed point APIs have been implemented.
5302
5303The exact mechanism used to control attributes of API functions has
5304changed.  A single set of operating system independent macro definitions
5305is used and operating system specific directives are defined in
5306pnglibconf.h
5307
5308As part of this the mechanism used to choose procedure call standards on
5309those systems that allow a choice has been changed.  At present this only
5310affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
5311running on Intel processors.  As before, PNGAPI is defined where required
5312to control the exported API functions; however, two new macros, PNGCBAPI
5313and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5314(PNGCAPI) for functions that must match a C library prototype (currently
5315only png_longjmp_ptr, which must match the C longjmp function.)  The new
5316approach is documented in pngconf.h
5317
5318Despite these changes, libpng 1.5.0 only supports the native C function
5319calling standard on those platforms tested so far (__cdecl on Microsoft
5320Windows).  This is because the support requirements for alternative
5321calling conventions seem to no longer exist.  Developers who find it
5322necessary to set PNG_API_RULE to 1 should advise the mailing list
5323(png-mng-implement) of this and library builders who use Openwatcom and
5324therefore set PNG_API_RULE to 2 should also contact the mailing list.
5325
5326A new test program, pngvalid, is provided in addition to pngtest.
5327pngvalid validates the arithmetic accuracy of the gamma correction
5328calculations and includes a number of validations of the file format.
5329A subset of the full range of tests is run when "make check" is done
5330(in the 'configure' build.)  pngvalid also allows total allocated memory
5331usage to be evaluated and performs additional memory overwrite validation.
5332
5333Many changes to individual feature macros have been made. The following
5334are the changes most likely to be noticed by library builders who
5335configure libpng:
5336
53371) All feature macros now have consistent naming:
5338
5339#define PNG_NO_feature turns the feature off
5340#define PNG_feature_SUPPORTED turns the feature on
5341
5342pnglibconf.h contains one line for each feature macro which is either:
5343
5344#define PNG_feature_SUPPORTED
5345
5346if the feature is supported or:
5347
5348/*#undef PNG_feature_SUPPORTED*/
5349
5350if it is not.  Library code consistently checks for the 'SUPPORTED' macro.
5351It does not, and libpng applications should not, check for the 'NO' macro
5352which will not normally be defined even if the feature is not supported.
5353The 'NO' macros are only used internally for setting or not setting the
5354corresponding 'SUPPORTED' macros.
5355
5356Compatibility with the old names is provided as follows:
5357
5358PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5359
5360And the following definitions disable the corresponding feature:
5361
5362PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5363PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5364PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5365PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5366PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5367PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5368
5369Library builders should remove use of the above, inconsistent, names.
5370
53712) Warning and error message formatting was previously conditional on
5372the STDIO feature. The library has been changed to use the
5373CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5374the library no longer uses the printf(3) functions, even though the
5375default read/write implementations use (FILE) style stdio.h functions.
5376
53773) Three feature macros now control the fixed/floating point decisions:
5378
5379PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5380
5381PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5382practice these are normally required internally anyway (because the PNG
5383file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5384merely stops the function from being exported.
5385
5386PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5387point implementation or the fixed point one.  Typically the fixed point
5388implementation is larger and slower than the floating point implementation
5389on a system that supports floating point; however, it may be faster on a
5390system which lacks floating point hardware and therefore uses a software
5391emulation.
5392
53934) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED.  This allows the
5394functions to read and write ints to be disabled independently of
5395PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5396even though the default is to use the macros - this allows applications
5397to choose at app buildtime whether or not to use macros (previously
5398impossible because the functions weren't in the default build.)
5399
5400B.2 Changes to the configuration mechanism
5401
5402Prior to libpng-1.5.0 library builders who needed to configure libpng
5403had either to modify the exported pngconf.h header file to add system
5404specific configuration or had to write feature selection macros into
5405pngusr.h and cause this to be included into pngconf.h by defining
5406PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5407application built without PNG_USER_CONFIG defined would see the
5408unmodified, default, libpng API and thus would probably fail to link.
5409
5410These mechanisms still work in the configure build and in any makefile
5411build that builds pnglibconf.h, although the feature selection macros
5412have changed somewhat as described above.  In 1.5.0, however, pngusr.h is
5413processed only once, when the exported header file pnglibconf.h is built.
5414pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
5415build of pnglibconf.h and it is never included in an application build.
5416
5417The rarely used alternative of adding a list of feature macros to the
5418CFLAGS setting in the build also still works; however, the macros will be
5419copied to pnglibconf.h and this may produce macro redefinition warnings
5420when the individual C files are compiled.
5421
5422All configuration now only works if pnglibconf.h is built from
5423scripts/pnglibconf.dfa.  This requires the program awk.  Brian Kernighan
5424(the original author of awk) maintains C source code of that awk and this
5425and all known later implementations (often called by subtly different
5426names - nawk and gawk for example) are adequate to build pnglibconf.h.
5427The Sun Microsystems (now Oracle) program 'awk' is an earlier version
5428and does not work; this may also apply to other systems that have a
5429functioning awk called 'nawk'.
5430
5431Configuration options are now documented in scripts/pnglibconf.dfa.  This
5432file also includes dependency information that ensures a configuration is
5433consistent; that is, if a feature is switched off dependent features are
5434also removed.  As a recommended alternative to using feature macros in
5435pngusr.h a system builder may also define equivalent options in pngusr.dfa
5436(or, indeed, any file) and add that to the configuration by setting
5437DFA_XTRA to the file name.  The makefiles in contrib/pngminim illustrate
5438how to do this, and a case where pngusr.h is still required.
5439
5440.SH XI. Detecting libpng
5441
5442The png_get_io_ptr() function has been present since libpng-0.88, has never
5443changed, and is unaffected by conditional compilation macros.  It is the
5444best choice for use in configure scripts for detecting the presence of any
5445libpng version since 0.88.  In an autoconf "configure.in" you could use
5446
5447    AC_CHECK_LIB(png, png_get_io_ptr, ...
5448
5449.SH XII. Source code repository
5450
5451Since about February 2009, version 1.2.34, libpng has been under "git" source
5452control.  The git repository was built from old libpng-x.y.z.tar.gz files
5453going back to version 0.70.  You can access the git repository (read only)
5454at
5455
5456    git://libpng.git.sourceforge.net/gitroot/libpng
5457
5458or you can browse it via "gitweb" at
5459
5460    http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
5461
5462Patches can be sent to glennrp at users.sourceforge.net or to
5463png-mng-implement at lists.sourceforge.net or you can upload them to
5464the libpng bug tracker at
5465
5466    http://libpng.sourceforge.net
5467
5468We also accept patches built from the tar or zip distributions, and
5469simple verbal discriptions of bug fixes, reported either to the
5470SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5471mailing list, or directly to glennrp.
5472
5473.SH XIII. Coding style
5474
5475Our coding style is similar to the "Allman" style, with curly
5476braces on separate lines:
5477
5478    if (condition)
5479    {
5480       action;
5481    }
5482
5483    else if (another condition)
5484    {
5485       another action;
5486    }
5487
5488The braces can be omitted from simple one-line actions:
5489
5490    if (condition)
5491       return (0);
5492
5493We use 3-space indentation, except for continued statements which
5494are usually indented the same as the first line of the statement
5495plus four more spaces.
5496
5497For macro definitions we use 2-space indentation, always leaving the "#"
5498in the first column.
5499
5500    #ifndef PNG_NO_FEATURE
5501    #  ifndef PNG_FEATURE_SUPPORTED
5502    #    define PNG_FEATURE_SUPPORTED
5503    #  endif
5504    #endif
5505
5506Comments appear with the leading "/*" at the same indentation as
5507the statement that follows the comment:
5508
5509    /* Single-line comment */
5510    statement;
5511
5512    /* This is a multiple-line
5513     * comment.
5514     */
5515    statement;
5516
5517Very short comments can be placed after the end of the statement
5518to which they pertain:
5519
5520    statement;    /* comment */
5521
5522We don't use C++ style ("//") comments. We have, however,
5523used them in the past in some now-abandoned MMX assembler
5524code.
5525
5526Functions and their curly braces are not indented, and
5527exported functions are marked with PNGAPI:
5528
5529 /* This is a public function that is visible to
5530  * application programmers. It does thus-and-so.
5531  */
5532 void PNGAPI
5533 png_exported_function(png_ptr, png_info, foo)
5534 {
5535    body;
5536 }
5537
5538The prototypes for all exported functions appear in png.h,
5539above the comment that says
5540
5541    /* Maintainer: Put new public prototypes here ... */
5542
5543We mark all non-exported functions with "/* PRIVATE */"":
5544
5545 void /* PRIVATE */
5546 png_non_exported_function(png_ptr, png_info, foo)
5547 {
5548    body;
5549 }
5550
5551The prototypes for non-exported functions (except for those in
5552pngtest) appear in
5553pngpriv.h
5554above the comment that says
5555
5556  /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
5557
5558To avoid polluting the global namespace, the names of all exported
5559functions and variables begin with "png_", and all publicly visible C
5560preprocessor macros begin with "PNG".  We request that applications that
5561use libpng *not* begin any of their own symbols with either of these strings.
5562
5563We put a space after each comma and after each semicolon
5564in "for" statements, and we put spaces before and after each
5565C binary operator and after "for" or "while", and before
5566"?".  We don't put a space between a typecast and the expression
5567being cast, nor do we put one between a function name and the
5568left parenthesis that follows it:
5569
5570    for (i = 2; i > 0; --i)
5571       y[i] = a(x) + (int)b;
5572
5573We prefer #ifdef and #ifndef to #if defined() and if !defined()
5574when there is only one macro being tested.
5575
5576We prefer to express integers that are used as bit masks in hex format,
5577with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
5578
5579We do not use the TAB character for indentation in the C sources.
5580
5581Lines do not exceed 80 characters.
5582
5583Other rules can be inferred by inspecting the libpng source.
5584
5585.SH XIV. Y2K Compliance in libpng
5586
5587July 11, 2012
5588
5589Since the PNG Development group is an ad-hoc body, we can't make
5590an official declaration.
5591
5592This is your unofficial assurance that libpng from version 0.71 and
5593upward through 1.5.12 are Y2K compliant.  It is my belief that earlier
5594versions were also Y2K compliant.
5595
5596Libpng only has two year fields.  One is a 2-byte unsigned integer that
5597will hold years up to 65535.  The other holds the date in text
5598format, and will hold years up to 9999.
5599
5600The integer is
5601    "png_uint_16 year" in png_time_struct.
5602
5603The string is
5604    "char time_buffer[29]" in png_struct.  This will no
5605longer be used in libpng-1.6.x and will be removed from libpng-1.7.0.
5606
5607There are seven time-related functions:
5608
5609    png_convert_to_rfc_1123() in png.c
5610      (formerly png_convert_to_rfc_1152() in error)
5611    png_convert_from_struct_tm() in pngwrite.c, called
5612      in pngwrite.c
5613    png_convert_from_time_t() in pngwrite.c
5614    png_get_tIME() in pngget.c
5615    png_handle_tIME() in pngrutil.c, called in pngread.c
5616    png_set_tIME() in pngset.c
5617    png_write_tIME() in pngwutil.c, called in pngwrite.c
5618
5619All appear to handle dates properly in a Y2K environment.  The
5620png_convert_from_time_t() function calls gmtime() to convert from system
5621clock time, which returns (year - 1900), which we properly convert to
5622the full 4-digit year.  There is a possibility that applications using
5623libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
5624function, or that they are incorrectly passing only a 2-digit year
5625instead of "year - 1900" into the png_convert_from_struct_tm() function,
5626but this is not under our control.  The libpng documentation has always
5627stated that it works with 4-digit years, and the APIs have been
5628documented as such.
5629
5630The tIME chunk itself is also Y2K compliant.  It uses a 2-byte unsigned
5631integer to hold the year, and can hold years as large as 65535.
5632
5633zlib, upon which libpng depends, is also Y2K compliant.  It contains
5634no date-related code.
5635
5636
5637   Glenn Randers-Pehrson
5638   libpng maintainer
5639   PNG Development Group
5640
5641.SH NOTE
5642
5643Note about libpng version numbers:
5644
5645Due to various miscommunications, unforeseen code incompatibilities
5646and occasional factors outside the authors' control, version numbering
5647on the library has not always been consistent and straightforward.
5648The following table summarizes matters since version 0.89c, which was
5649the first widely used release:
5650
5651 source             png.h  png.h  shared-lib
5652 version            string   int  version
5653 -------            ------  ----- ----------
5654 0.89c ("beta 3")  0.89       89  1.0.89
5655 0.90  ("beta 4")  0.90       90  0.90
5656 0.95  ("beta 5")  0.95       95  0.95
5657 0.96  ("beta 6")  0.96       96  0.96
5658 0.97b ("beta 7")  1.00.97    97  1.0.1
5659 0.97c             0.97       97  2.0.97
5660 0.98              0.98       98  2.0.98
5661 0.99              0.99       98  2.0.99
5662 0.99a-m           0.99       99  2.0.99
5663 1.00              1.00      100  2.1.0
5664 1.0.0             1.0.0     100  2.1.0
5665 1.0.0   (from here on, the  100  2.1.0
5666 1.0.1    png.h string is  10001  2.1.0
5667 1.0.1a-e identical to the 10002  from here on, the
5668 1.0.2    source version)  10002  shared library is 2.V
5669 1.0.2a-b                  10003  where V is the source
5670 1.0.1                     10001  code version except as
5671 1.0.1a-e                  10002  2.1.0.1a-e   noted.
5672 1.0.2                     10002  2.1.0.2
5673 1.0.2a-b                  10003  2.1.0.2a-b
5674 1.0.3                     10003  2.1.0.3
5675 1.0.3a-d                  10004  2.1.0.3a-d
5676 1.0.4                     10004  2.1.0.4
5677 1.0.4a-f                  10005  2.1.0.4a-f
5678 1.0.5 (+ 2 patches)       10005  2.1.0.5
5679 1.0.5a-d                  10006  2.1.0.5a-d
5680 1.0.5e-r                  10100  2.1.0.5e-r
5681 1.0.5s-v                  10006  2.1.0.5s-v
5682 1.0.6 (+ 3 patches)       10006  2.1.0.6
5683 1.0.6d-g                  10007  2.1.0.6d-g
5684 1.0.6h                    10007  10.6h
5685 1.0.6i                    10007  10.6i
5686 1.0.6j                    10007  2.1.0.6j
5687 1.0.7beta11-14    DLLNUM  10007  2.1.0.7beta11-14
5688 1.0.7beta15-18       1    10007  2.1.0.7beta15-18
5689 1.0.7rc1-2           1    10007  2.1.0.7rc1-2
5690 1.0.7                1    10007  2.1.0.7
5691 1.0.8beta1-4         1    10008  2.1.0.8beta1-4
5692 1.0.8rc1             1    10008  2.1.0.8rc1
5693 1.0.8                1    10008  2.1.0.8
5694 1.0.9beta1-6         1    10009  2.1.0.9beta1-6
5695 1.0.9rc1             1    10009  2.1.0.9rc1
5696 1.0.9beta7-10        1    10009  2.1.0.9beta7-10
5697 1.0.9rc2             1    10009  2.1.0.9rc2
5698 1.0.9                1    10009  2.1.0.9
5699 1.0.10beta1          1    10010  2.1.0.10beta1
5700 1.0.10rc1            1    10010  2.1.0.10rc1
5701 1.0.10               1    10010  2.1.0.10
5702 1.0.11beta1-3        1    10011  2.1.0.11beta1-3
5703 1.0.11rc1            1    10011  2.1.0.11rc1
5704 1.0.11               1    10011  2.1.0.11
5705 1.0.12beta1-2        2    10012  2.1.0.12beta1-2
5706 1.0.12rc1            2    10012  2.1.0.12rc1
5707 1.0.12               2    10012  2.1.0.12
5708 1.1.0a-f             -    10100  2.1.1.0a-f abandoned
5709 1.2.0beta1-2         2    10200  2.1.2.0beta1-2
5710 1.2.0beta3-5         3    10200  3.1.2.0beta3-5
5711 1.2.0rc1             3    10200  3.1.2.0rc1
5712 1.2.0                3    10200  3.1.2.0
5713 1.2.1beta-4          3    10201  3.1.2.1beta1-4
5714 1.2.1rc1-2           3    10201  3.1.2.1rc1-2
5715 1.2.1                3    10201  3.1.2.1
5716 1.2.2beta1-6        12    10202  12.so.0.1.2.2beta1-6
5717 1.0.13beta1         10    10013  10.so.0.1.0.13beta1
5718 1.0.13rc1           10    10013  10.so.0.1.0.13rc1
5719 1.2.2rc1            12    10202  12.so.0.1.2.2rc1
5720 1.0.13              10    10013  10.so.0.1.0.13
5721 1.2.2               12    10202  12.so.0.1.2.2
5722 1.2.3rc1-6          12    10203  12.so.0.1.2.3rc1-6
5723 1.2.3               12    10203  12.so.0.1.2.3
5724 1.2.4beta1-3        13    10204  12.so.0.1.2.4beta1-3
5725 1.2.4rc1            13    10204  12.so.0.1.2.4rc1
5726 1.0.14              10    10014  10.so.0.1.0.14
5727 1.2.4               13    10204  12.so.0.1.2.4
5728 1.2.5beta1-2        13    10205  12.so.0.1.2.5beta1-2
5729 1.0.15rc1           10    10015  10.so.0.1.0.15rc1
5730 1.0.15              10    10015  10.so.0.1.0.15
5731 1.2.5               13    10205  12.so.0.1.2.5
5732 1.2.6beta1-4        13    10206  12.so.0.1.2.6beta1-4
5733 1.2.6rc1-5          13    10206  12.so.0.1.2.6rc1-5
5734 1.0.16              10    10016  10.so.0.1.0.16
5735 1.2.6               13    10206  12.so.0.1.2.6
5736 1.2.7beta1-2        13    10207  12.so.0.1.2.7beta1-2
5737 1.0.17rc1           10    10017  12.so.0.1.0.17rc1
5738 1.2.7rc1            13    10207  12.so.0.1.2.7rc1
5739 1.0.17              10    10017  12.so.0.1.0.17
5740 1.2.7               13    10207  12.so.0.1.2.7
5741 1.2.8beta1-5        13    10208  12.so.0.1.2.8beta1-5
5742 1.0.18rc1-5         10    10018  12.so.0.1.0.18rc1-5
5743 1.2.8rc1-5          13    10208  12.so.0.1.2.8rc1-5
5744 1.0.18              10    10018  12.so.0.1.0.18
5745 1.2.8               13    10208  12.so.0.1.2.8
5746 1.2.9beta1-3        13    10209  12.so.0.1.2.9beta1-3
5747 1.2.9beta4-11       13    10209  12.so.0.9[.0]
5748 1.2.9rc1            13    10209  12.so.0.9[.0]
5749 1.2.9               13    10209  12.so.0.9[.0]
5750 1.2.10beta1-7       13    10210  12.so.0.10[.0]
5751 1.2.10rc1-2         13    10210  12.so.0.10[.0]
5752 1.2.10              13    10210  12.so.0.10[.0]
5753 1.4.0beta1-6        14    10400  14.so.0.0[.0]
5754 1.2.11beta1-4       13    10210  12.so.0.11[.0]
5755 1.4.0beta7-8        14    10400  14.so.0.0[.0]
5756 1.2.11              13    10211  12.so.0.11[.0]
5757 1.2.12              13    10212  12.so.0.12[.0]
5758 1.4.0beta9-14       14    10400  14.so.0.0[.0]
5759 1.2.13              13    10213  12.so.0.13[.0]
5760 1.4.0beta15-36      14    10400  14.so.0.0[.0]
5761 1.4.0beta37-87      14    10400  14.so.14.0[.0]
5762 1.4.0rc01           14    10400  14.so.14.0[.0]
5763 1.4.0beta88-109     14    10400  14.so.14.0[.0]
5764 1.4.0rc02-08        14    10400  14.so.14.0[.0]
5765 1.4.0               14    10400  14.so.14.0[.0]
5766 1.4.1beta01-03      14    10401  14.so.14.1[.0]
5767 1.4.1rc01           14    10401  14.so.14.1[.0]
5768 1.4.1beta04-12      14    10401  14.so.14.1[.0]
5769 1.4.1               14    10401  14.so.14.1[.0]
5770 1.4.2               14    10402  14.so.14.2[.0]
5771 1.4.3               14    10403  14.so.14.3[.0]
5772 1.4.4               14    10404  14.so.14.4[.0]
5773 1.5.0beta01-58      15    10500  15.so.15.0[.0]
5774 1.5.0rc01-07        15    10500  15.so.15.0[.0]
5775 1.5.0               15    10500  15.so.15.0[.0]
5776 1.5.1beta01-11      15    10501  15.so.15.1[.0]
5777 1.5.1rc01-02        15    10501  15.so.15.1[.0]
5778 1.5.1               15    10501  15.so.15.1[.0]
5779 1.5.2beta01-03      15    10502  15.so.15.2[.0]
5780 1.5.2rc01-03        15    10502  15.so.15.2[.0]
5781 1.5.2               15    10502  15.so.15.2[.0]
5782 1.5.3beta01-10      15    10503  15.so.15.3[.0]
5783 1.5.3rc01-02        15    10503  15.so.15.3[.0]
5784 1.5.3beta11         15    10503  15.so.15.3[.0]
5785 1.5.3 [omitted]
5786 1.5.4beta01-08      15    10504  15.so.15.4[.0]
5787 1.5.4rc01           15    10504  15.so.15.4[.0]
5788 1.5.4               15    10504  15.so.15.4[.0]
5789 1.5.5beta01-08      15    10505  15.so.15.5[.0]
5790 1.5.5rc01           15    10505  15.so.15.5[.0]
5791 1.5.5               15    10505  15.so.15.5[.0]
5792 1.5.6beta01-07      15    10506  15.so.15.6[.0]
5793 1.5.6rc01-03        15    10506  15.so.15.6[.0]
5794 1.5.6               15    10506  15.so.15.6[.0]
5795 1.5.7beta01-05      15    10507  15.so.15.7[.0]
5796 1.5.7rc01-03        15    10507  15.so.15.7[.0]
5797 1.5.7               15    10507  15.so.15.7[.0]
5798 1.5.8beta01         15    10508  15.so.15.8[.0]
5799 1.5.8rc01           15    10508  15.so.15.8[.0]
5800 1.5.8               15    10508  15.so.15.8[.0]
5801 1.5.9beta01-02      15    10509  15.so.15.9[.0]
5802 1.5.9rc01           15    10509  15.so.15.9[.0]
5803 1.5.9               15    10509  15.so.15.9[.0]
5804 1.5.10beta01-05     15    10510  15.so.15.10[.0]
5805 1.5.10              15    10510  15.so.15.10[.0]
5806 1.5.11beta01        15    10511  15.so.15.11[.0]
5807 1.5.11rc01-05       15    10511  15.so.15.11[.0]
5808 1.5.11              15    10511  15.so.15.11[.0]
5809 1.5.12              15    10512  15.so.15.12[.0]
5810
5811Henceforth the source version will match the shared-library minor
5812and patch numbers; the shared-library major version number will be
5813used for changes in backward compatibility, as it is intended.  The
5814PNG_PNGLIB_VER macro, which is not used within libpng but is available
5815for applications, is an unsigned integer of the form xyyzz corresponding
5816to the source version x.y.z (leading zeros in y and z).  Beta versions
5817were given the previous public release number plus a letter, until
5818version 1.0.6j; from then on they were given the upcoming public
5819release number plus "betaNN" or "rcN".
5820
5821.SH "SEE ALSO"
5822.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
5823
5824.LP
5825.IR libpng :
5826.IP
5827http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
5828http://www.libpng.org/pub/png
5829
5830.LP
5831.IR zlib :
5832.IP
5833(generally) at the same location as
5834.I libpng
5835or at
5836.br
5837ftp://ftp.info-zip.org/pub/infozip/zlib
5838
5839.LP
5840.IR PNG specification: RFC 2083
5841.IP
5842(generally) at the same location as
5843.I libpng
5844or at
5845.br
5846ftp://ds.internic.net/rfc/rfc2083.txt
5847.br
5848or (as a W3C Recommendation) at
5849.br
5850http://www.w3.org/TR/REC-png.html
5851
5852.LP
5853In the case of any inconsistency between the PNG specification
5854and this library, the specification takes precedence.
5855
5856.SH AUTHORS
5857This man page: Glenn Randers-Pehrson
5858<glennrp at users.sourceforge.net>
5859
5860The contributing authors would like to thank all those who helped
5861with testing, bug fixes, and patience.  This wouldn't have been
5862possible without all of you.
5863
5864Thanks to Frank J. T. Wojcik for helping with the documentation.
5865
5866Libpng version 1.5.12 - July 11, 2012:
5867Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
5868Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
5869
5870Supported by the PNG development group
5871.br
5872png-mng-implement at lists.sf.net
5873(subscription required; visit
5874png-mng-implement at lists.sourceforge.net (subscription required; visit
5875https://lists.sourceforge.net/lists/listinfo/png-mng-implement
5876to subscribe).
5877
5878.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
5879
5880(This copy of the libpng notices is provided for your convenience.  In case of
5881any discrepancy between this copy and the notices in the file png.h that is
5882included in the libpng distribution, the latter shall prevail.)
5883
5884If you modify libpng you may insert additional notices immediately following
5885this sentence.
5886
5887This code is released under the libpng license.
5888
5889libpng versions 1.2.6, August 15, 2004, through 1.5.12, July 11, 2012, are
5890Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
5891distributed according to the same disclaimer and license as libpng-1.2.5
5892with the following individual added to the list of Contributing Authors
5893
5894   Cosmin Truta
5895
5896libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
5897Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
5898distributed according to the same disclaimer and license as libpng-1.0.6
5899with the following individuals added to the list of Contributing Authors
5900
5901   Simon-Pierre Cadieux
5902   Eric S. Raymond
5903   Gilles Vollant
5904
5905and with the following additions to the disclaimer:
5906
5907   There is no warranty against interference with your
5908   enjoyment of the library or against infringement.
5909   There is no warranty that our efforts or the library
5910   will fulfill any of your particular purposes or needs.
5911   This library is provided with all faults, and the entire
5912   risk of satisfactory quality, performance, accuracy, and
5913   effort is with the user.
5914
5915libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
5916Copyright (c) 1998, 1999 Glenn Randers-Pehrson
5917Distributed according to the same disclaimer and license as libpng-0.96,
5918with the following individuals added to the list of Contributing Authors:
5919
5920   Tom Lane
5921   Glenn Randers-Pehrson
5922   Willem van Schaik
5923
5924libpng versions 0.89, June 1996, through 0.96, May 1997, are
5925Copyright (c) 1996, 1997 Andreas Dilger
5926Distributed according to the same disclaimer and license as libpng-0.88,
5927with the following individuals added to the list of Contributing Authors:
5928
5929   John Bowler
5930   Kevin Bracey
5931   Sam Bushell
5932   Magnus Holmgren
5933   Greg Roelofs
5934   Tom Tanner
5935
5936libpng versions 0.5, May 1995, through 0.88, January 1996, are
5937Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
5938
5939For the purposes of this copyright and license, "Contributing Authors"
5940is defined as the following set of individuals:
5941
5942   Andreas Dilger
5943   Dave Martindale
5944   Guy Eric Schalnat
5945   Paul Schmidt
5946   Tim Wegner
5947
5948The PNG Reference Library is supplied "AS IS".  The Contributing Authors
5949and Group 42, Inc. disclaim all warranties, expressed or implied,
5950including, without limitation, the warranties of merchantability and of
5951fitness for any purpose.  The Contributing Authors and Group 42, Inc.
5952assume no liability for direct, indirect, incidental, special, exemplary,
5953or consequential damages, which may result from the use of the PNG
5954Reference Library, even if advised of the possibility of such damage.
5955
5956Permission is hereby granted to use, copy, modify, and distribute this
5957source code, or portions hereof, for any purpose, without fee, subject
5958to the following restrictions:
5959
59601. The origin of this source code must not be misrepresented.
5961
59622. Altered versions must be plainly marked as such and
5963   must not be misrepresented as being the original source.
5964
59653. This Copyright notice may not be removed or altered from
5966   any source or altered source distribution.
5967
5968The Contributing Authors and Group 42, Inc. specifically permit, without
5969fee, and encourage the use of this source code as a component to
5970supporting the PNG file format in commercial products.  If you use this
5971source code in a product, acknowledgment is not required but would be
5972appreciated.
5973
5974
5975A "png_get_copyright" function is available, for convenient use in "about"
5976boxes and the like:
5977
5978   printf("%s",png_get_copyright(NULL));
5979
5980Also, the PNG logo (in PNG format, of course) is supplied in the
5981files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
5982
5983Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is a
5984certification mark of the Open Source Initiative.
5985
5986Glenn Randers-Pehrson
5987glennrp at users.sourceforge.net
5988July 11, 2012
5989
5990.\" end of man page
5991
Note: See TracBrowser for help on using the repository browser.