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