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