blob: 55fc8ade3b1d23565c6825d6938f1bb5d4b587e4 [file] [log] [blame]
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001.TH LIBPNG 3 "February 21, 2006"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003libpng \- Portable Network Graphics (PNG) Reference Library 1.2.9beta1
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004.SH SYNOPSIS
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05007\fB#include <png.h>\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06008
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05009\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060010
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -050011\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
12
13\fI\fB
14
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050015\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060016
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050017\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060018
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050019\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060020
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050021\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060022
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050023\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060024
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050025\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060026
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050027\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060028
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050029\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050030
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050031\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060032
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050033\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060034
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050035\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060036
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050037\fI\fB
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060038
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050039\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060040
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050041\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060042
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060043\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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050044
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
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060051\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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050052
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
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060091\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
92
93\fI\fB
94
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050095\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
96
97\fI\fB
98
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060099\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600100
101\fI\fB
102
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500103\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
104
105\fI\fB
106
107\fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
108
109\fI\fB
110
111\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
112
113\fI\fB
114
115\fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
116
117\fI\fB
118
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600119\fBpng_uint_32 png_get_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
120
121\fI\fB
122
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500123\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
124
125\fI\fB
126
127\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
128
129\fI\fB
130
131\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
132
133\fI\fB
134
135\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
136
137\fI\fB
138
139\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
140
141\fI\fB
142
143\fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
144
145\fI\fB
146
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600147\fBpng_uint_32 png_get_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
148
149\fI\fB
150
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600151\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
152
153\fI\fB
154
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500155\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
156
157\fI\fB
158
159\fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
160
161\fI\fB
162
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600163\fBpng_uint_32 png_get_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_charpp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600164
165\fI\fB
166
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500167\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP
168
169\fI\fB
170
171\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
172
173\fI\fB
174
175\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
176
177\fI\fB
178
179\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
180
181\fI\fB
182
183\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
184
185\fI\fB
186
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600187\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
188
189\fI\fB
190
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500191\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
192
193\fI\fB
194
195\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
196
197\fI\fB
198
199\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
200
201\fI\fB
202
203\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
204
205\fI\fB
206
207\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
208
209\fI\fB
210
211\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
212
213\fI\fB
214
215\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
216
217\fI\fB
218
219\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
220
221\fI\fB
222
223\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
224
225\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
226
227\fI\fB
228
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600229\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
230
231\fI\fB
232
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500233\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
234
235\fI\fB
236
237\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
238
239\fI\fB
240
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500241\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600242
243\fI\fB
244
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500245\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
246
247\fI\fB
248
249\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
250
251\fI\fB
252
253\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
254
255\fI\fB
256
257\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP
258
259\fI\fB
260
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600261\fBpng_uint_32 png_get_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
262
263\fI\fB
264
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600265\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
266
267\fI\fB
268
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500269\fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP
270
271\fI\fB
272
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500273\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
274
275\fI\fB
276
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500277\fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP
278
279\fI\fB
280
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500281\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
282
283\fI\fB
284
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500285\fBpng_int_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500286
287\fI\fB
288
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500289\fBpng_int_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500290
291\fI\fB
292
293\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
294
295\fI\fB
296
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500297\fBpng_int_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500298
299\fI\fB
300
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500301\fBpng_int_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500302
303\fI\fB
304
305\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
306
307\fI\fB
308
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500309\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
310
311\fI\fB
312
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600313\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
314
315\fI\fB
316
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500317\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500318
319\fI\fB
320
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500321\fBDEPRECATED: void png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP
322
323\fI\fB
324
325\fBDEPRECATED: void png_info_init_2 (png_infopp \fP\fIptr_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500326
327\fI\fB
328
329\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
330
331\fI\fB
332
333\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
334
335\fI\fB
336
337\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
338
339\fI\fB
340
341\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
342
343\fI\fB
344
345\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
346
347\fI\fB
348
349\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
350
351\fI\fB
352
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500353\fBDEPRECATED: void png_permit_empty_plte (png_structp \fP\fIpng_ptr\fP\fB, int \fIempty_plte_permitted\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500354
355\fI\fB
356
357\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP
358
359\fI\fB
360
361\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP
362
363\fI\fB
364
365\fBvoid png_read_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_infop \fIend_info_ptr\fP\fB);\fP
366
367\fI\fB
368
369\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
370
371\fI\fB
372
373\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
374
375\fI\fB
376
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500377\fBDEPRECATED: void png_read_init (png_structp \fIpng_ptr\fP\fB);\fP
378
379\fI\fB
380
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500381\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
382
383\fI\fB
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500384
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500385\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
386
387\fI\fB
388
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600389\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
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600390
391\fI\fB
392
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500393\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
394
395\fI\fB
396
397\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
398
399\fI\fB
400
401\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
402
403\fI\fB
404
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -0500405\fB#if \fI!defined(PNG_1_0_X)
406
407\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
408
409\fI\fB#endif
410
411\fI\fB
412
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500413\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
414
415\fI\fB
416
417\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
418
419\fI\fB
420
421\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
422
423\fI\fB
424
425\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
426
427\fI\fB
428
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600429\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
430
431\fI\fB
432
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500433\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
434
435\fI\fB
436
437\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
438
439\fI\fB
440
441\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
442
443\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600444
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500445\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600446
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500447\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600448
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500449\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600450
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500451\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500452
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500453\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600454
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500455\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600456
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500457\fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600458
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500459\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600460
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500461\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600462
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500463\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600464
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500465\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600466
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500467\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600468
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500469\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600470
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500471\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600472
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500473\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600474
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500475\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600476
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500477\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500478
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500479\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600480
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500481\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600482
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500483\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600484
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500485\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600486
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500487\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600488
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500489\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600490
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500491\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600492
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600493\fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP
494
495\fI\fB
496
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500497\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600498
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500499\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600500
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500501\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600502
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500503\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600504
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500505\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600506
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500507\fI\fB
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600508
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600509\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600510
511\fI\fB
512
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500513\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600514
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500515\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600516
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500517\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
518
519\fI\fB
520
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500521\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600522
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500523\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600524
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500525\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600526
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500527\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600528
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500529\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600530
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500531\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600532
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600533\fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600534
535\fI\fB
536
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500537\fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600538
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500539\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600540
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500541\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600542
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500543\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600544
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500545\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600546
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500547\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600548
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500549\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600550
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500551\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600552
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500553\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600554
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500555\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500556
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500557\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600558
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500559\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600560
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500561\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600562
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500563\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600564
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500565\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600566
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500567\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600568
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500569\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600570
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500571\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600572
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500573\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600574
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500575\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600576
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500577\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600578
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500579\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600580
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500581\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600582
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500583\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600584
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600585\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
586
587\fI\fB
588
589\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_fixed_point \fP\fIred\fP\fB, png_fixed_point \fIgreen\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600590
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500591\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600592
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600593\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
594
595\fI\fB
596
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500597\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600598
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500599\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600600
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600601\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
602
603\fI\fB
604
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500605\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600606
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500607\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600608
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500609\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600610
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500611\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600612
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600613\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600614
615\fI\fB
616
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500617\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600618
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500619\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600620
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500621\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600622
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500623\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600624
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500625\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600626
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500627\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600628
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500629\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600630
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500631\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600632
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500633\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600634
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500635\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600636
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500637\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600638
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500639\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600640
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500641\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600642
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500643\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600644
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500645\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600646
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500647\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600648
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500649\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_values\fP\fB);\fP
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500650
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500651\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600652
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500653\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600654
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500655\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600656
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600657\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
658
659\fI\fB
660
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500661\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
662
663\fI\fB
664
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600665\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600666
667\fI\fB
668
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500669\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
670
671\fI\fB
672
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500673\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600674
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500675\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600676
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500677\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600678
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500679\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600680
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500681\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600682
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500683\fI\fB
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600684
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500685\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600686
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500687\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600688
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500689\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
690
691\fI\fB
692
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500693\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600694
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500695\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600696
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500697\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600698
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500699\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600700
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500701\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600702
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500703\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600704
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500705\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600706
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500707\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600708
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500709\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600710
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500711\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600712
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500713\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600714
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500715\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600716
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500717\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600718
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500719\fI\fB
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600720
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500721\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600722
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500723\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600724
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500725\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600726
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500727\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600728
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500729\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600730
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500731\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600732
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500733\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600734
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500735\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600736
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500737\fBDEPRECATED: void png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
738
739\fI\fB
740
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500741\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
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500742
743\fI\fB
744
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500745\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600746
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500747\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500748
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600749\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
750
751\fI\fB
752
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600753\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
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600754
755\fI\fB
756
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500757\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600758
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500759\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600760
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500761\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600762
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500763\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600764
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500765\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
766
767\fI\fB
768
769\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
770
771\fI\fB
772
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600773.SH DESCRIPTION
774The
775.I libpng
776library supports encoding, decoding, and various manipulations of
777the Portable Network Graphics (PNG) format image files. It uses the
778.IR zlib(3)
779compression library.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600780Following is a copy of the libpng.txt file that accompanies libpng.
781.SH LIBPNG.TXT
782libpng.txt - A description on how to use and modify libpng
783
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600784 libpng version 1.2.9beta1 - February 21, 2006
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600785 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -0600786 <glennrp at users.sourceforge.net>
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600787 Copyright (c) 1998-2005 Glenn Randers-Pehrson
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600788 For conditions of distribution and use, see copyright
789 notice in png.h.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600790
791 based on:
792
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600793 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600794 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600795 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600796
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600797 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600798 For conditions of distribution and use, see copyright
799 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600800 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600801
802 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600803 Copyright (c) 1995, 1996 Frank J. T. Wojcik
804 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600805
806.SH I. Introduction
807
808This file describes how to use and modify the PNG reference library
809(known as libpng) for your own use. There are five sections to this
810file: introduction, structures, reading, writing, and modification and
811configuration notes for various special platforms. In addition to this
812file, example.c is a good starting point for using the library, as
813it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600814will need. We assume that libpng is already installed; see the
815INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600816
817Libpng was written as a companion to the PNG specification, as a way
818of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500819file format in application programs.
820
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500821The PNG specification (second edition), November 2003, is available as
822a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
823<http://www.w3.org/TR/2003/REC-PNG-20031110/
824The W3C and ISO documents have identical technical content.
825
826The PNG-1.2 specification is available at
827<http://www.libpng.org/pub/png/documents/>
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500828
829The PNG-1.0 specification is available
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500830as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600831W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
832additional chunks are described in the special-purpose public chunks
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500833documents at <http://www.libpng.org/pub/png/documents/>.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500834
835Other information
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600836about PNG, and the latest version of libpng, can be found at the PNG home
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500837page, <http://www.libpng.org/pub/png/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600838
839Most users will not have to modify the library significantly; advanced
840users may want to modify it more. All attempts were made to make it as
841complete as possible, while keeping the code easy to understand.
842Currently, this library only supports C. Support for other languages
843is being considered.
844
845Libpng has been designed to handle multiple sessions at one time,
846to be easily modifiable, to be portable to the vast majority of
847machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
848to use. The ultimate goal of libpng is to promote the acceptance of
849the PNG file format in whatever way possible. While there is still
850work to be done (see the TODO file), libpng should cover the
851majority of the needs of its users.
852
853Libpng uses zlib for its compression and decompression of PNG files.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600854Further information about zlib, and the latest version of zlib, can
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -0600855be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600856The zlib compression utility is a general purpose utility that is
857useful for more than PNG files, and can be used without libpng.
858See the documentation delivered with zlib for more details.
859You can usually find the source files for the zlib utility wherever you
860find the libpng source files.
861
862Libpng is thread safe, provided the threads are using different
863instances of the structures. Each thread should have its own
864png_struct and png_info instances, and thus its own image.
865Libpng does not protect itself against two threads using the
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -0500866same instance of a structure. Note: thread safety may be defeated
867by use of some of the MMX assembler code in pnggccrd.c, which is only
868compiled when the user defines PNG_THREAD_UNSAFE_OK.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600869
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600870.SH II. Structures
871
872There are two main structures that are important to libpng, png_struct
873and png_info. The first, png_struct, is an internal structure that
874will not, for the most part, be used by a user except as the first
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600875variable passed to every libpng function call.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600876
877The png_info structure is designed to provide information about the
878PNG file. At one time, the fields of png_info were intended to be
879directly accessible to the user. However, this tended to cause problems
880with applications using dynamically loaded libraries, and as a result
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500881a set of interface functions for png_info (the png_get_*() and png_set_*()
882functions) was developed. The fields of png_info are still available for
883older applications, but it is suggested that applications use the new
884interfaces if at all possible.
885
886Applications that do make direct access to the members of png_struct (except
887for png_ptr->jmpbuf) must be recompiled whenever the library is updated,
888and applications that make direct access to the members of png_info must
889be recompiled if they were compiled or loaded with libpng version 1.0.6,
890in which the members were in a different order. In version 1.0.7, the
891members of the png_info structure reverted to the old order, as they were
892in versions 0.97c through 1.0.5. Starting with version 2.0.0, both
893structures are going to be hidden, and the contents of the structures will
894only be accessible through the png_get/png_set functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600895
896The png.h header file is an invaluable reference for programming with libpng.
897And while I'm on the topic, make sure you include the libpng header file:
898
899#include <png.h>
900
901.SH III. Reading
902
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600903We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600904in a PNG file sequentially, briefly explaining the syntax and purpose
905of each one. See example.c and png.h for more detail. While
906progressive reading is covered in the next section, you will still
907need some of the functions discussed in this section to read a PNG
908file.
909
910.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600911
912You will want to do the I/O initialization(*) before you get into libpng,
913so if it doesn't work, you don't have much to undo. Of course, you
914will also want to insure that you are, in fact, dealing with a PNG
915file. Libpng provides a simple check to see if a file is a PNG file.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500916To use it, pass in the first 1 to 8 bytes of the file to the function
917png_sig_cmp(), and it will return 0 if the bytes match the corresponding
918bytes of the PNG signature, or nonzero otherwise. Of course, the more bytes
919you pass in, the greater the accuracy of the prediction.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600920
921If you are intending to keep the file pointer open for use in libpng,
922you must ensure you don't read more than 8 bytes from the beginning
923of the file, and you also have to make a call to png_set_sig_bytes_read()
924with the number of bytes you read from the beginning. Libpng will
925then only check the bytes (if any) that your program didn't read.
926
927(*): If you are not using the standard I/O functions, you will need
928to replace them with custom functions. See the discussion under
929Customizing libpng.
930
931
932 FILE *fp = fopen(file_name, "rb");
933 if (!fp)
934 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500935 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600936 }
937 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600938 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600939 if (!is_png)
940 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500941 return (NOT_PNG);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600942 }
943
944
945Next, png_struct and png_info need to be allocated and initialized. In
946order to ensure that the size of these structures is correct even with a
947dynamically linked libpng, there are functions to initialize and
948allocate the structures. We also pass the library version, optional
949pointers to error handling functions, and a pointer to a data struct for
950use by the error functions, if necessary (the pointer and functions can
951be NULL if the default error handlers are to be used). See the section
952on Changes to Libpng below regarding the old initialization functions.
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500953The structure allocation functions quietly return NULL if they fail to
954create the structure, so your application should check for that.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600955
956 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500957 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600958 user_error_fn, user_warning_fn);
959 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500960 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600961
962 png_infop info_ptr = png_create_info_struct(png_ptr);
963 if (!info_ptr)
964 {
965 png_destroy_read_struct(&png_ptr,
966 (png_infopp)NULL, (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500967 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600968 }
969
970 png_infop end_info = png_create_info_struct(png_ptr);
971 if (!end_info)
972 {
973 png_destroy_read_struct(&png_ptr, &info_ptr,
974 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500975 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600976 }
977
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500978If you want to use your own memory allocation routines,
979define PNG_USER_MEM_SUPPORTED and use
980png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600981
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500982 png_structp png_ptr = png_create_read_struct_2
983 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
984 user_error_fn, user_warning_fn, (png_voidp)
985 user_mem_ptr, user_malloc_fn, user_free_fn);
986
987The error handling routines passed to png_create_read_struct()
988and the memory alloc/free routines passed to png_create_struct_2()
989are only necessary if you are not using the libpng supplied error
990handling and memory alloc/free functions.
991
992When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600993to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600994your png_jmpbuf(png_ptr). If you read the file from different
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600995routines, you will need to update the jmpbuf field every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600996a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600997
998See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600999information on setjmp/longjmp. See the discussion on libpng error
1000handling in the Customizing Libpng section below for more information
1001on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001002back to your setjmp, you will want to call png_destroy_read_struct() to
1003free any memory.
1004
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001005 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001006 {
1007 png_destroy_read_struct(&png_ptr, &info_ptr,
1008 &end_info);
1009 fclose(fp);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001010 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001011 }
1012
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001013If you would rather avoid the complexity of setjmp/longjmp issues,
1014you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
1015errors will result in a call to PNG_ABORT() which defaults to abort().
1016
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001017Now you need to set up the input code. The default for libpng is to
1018use the C function fread(). If you use this, you will need to pass a
1019valid FILE * in the function png_init_io(). Be sure that the file is
1020opened in binary mode. If you wish to handle reading data in another
1021way, you need not call the png_init_io() function, but you must then
1022implement the libpng I/O methods discussed in the Customizing Libpng
1023section below.
1024
1025 png_init_io(png_ptr, fp);
1026
1027If you had previously opened the file and read any of the signature from
1028the beginning in order to see if this was a PNG file, you need to let
1029libpng know that there are some bytes missing from the start of the file.
1030
1031 png_set_sig_bytes(png_ptr, number);
1032
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001033.SS Setting up callback code
1034
1035You can set up a callback function to handle any unknown chunks in the
1036input stream. You must supply the function
1037
1038 read_chunk_callback(png_ptr ptr,
1039 png_unknown_chunkp chunk);
1040 {
1041 /* The unknown chunk structure contains your
1042 chunk data: */
1043 png_byte name[5];
1044 png_byte *data;
1045 png_size_t size;
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001046 /* Note that libpng has already taken care of
1047 the CRC handling */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001048
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001049 /* put your code here. Return one of the
1050 following: */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001051
1052 return (-n); /* chunk had an error */
1053 return (0); /* did not recognize */
1054 return (n); /* success */
1055 }
1056
1057(You can give your function another name that you like instead of
1058"read_chunk_callback")
1059
1060To inform libpng about your function, use
1061
1062 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1063 read_chunk_callback);
1064
1065This names not only the callback function, but also a user pointer that
1066you can retrieve with
1067
1068 png_get_user_chunk_ptr(png_ptr);
1069
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001070At this point, you can set up a callback function that will be
1071called after each row has been read, which you can use to control
1072a progress meter or the like. It's demonstrated in pngtest.c.
1073You must supply a function
1074
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001075 void read_row_callback(png_ptr ptr, png_uint_32 row,
1076 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001077 {
1078 /* put your code here */
1079 }
1080
1081(You can give it another name that you like instead of "read_row_callback")
1082
1083To inform libpng about your function, use
1084
1085 png_set_read_status_fn(png_ptr, read_row_callback);
1086
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05001087.SS Width and height limits
1088
1089The PNG specification allows the width and height of an image to be as
1090large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1091Since very few applications really need to process such large images,
1092we have imposed an arbitrary 1-million limit on rows and columns.
1093Larger images will be rejected immediately with a png_error() call. If
1094you wish to override this limit, you can use
1095
1096 png_set_user_limits(png_ptr, width_max, height_max);
1097
1098to set your own limits, or use width_max = height_max = 0x7fffffffL
1099to allow all valid dimensions (libpng may reject some very large images
1100anyway because of potential buffer overflow conditions).
1101
1102You should put this statement after you create the PNG structure and
1103before calling png_read_info(), png_read_png(), or png_process_data().
1104If you need to retrieve the limits that are being applied, use
1105
1106 width_max = png_get_user_width_max(png_ptr);
1107 height_max = png_get_user_height_max(png_ptr);
1108
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001109.SS Unknown-chunk handling
1110
1111Now you get to set the way the library processes unknown chunks in the
1112input PNG stream. Both known and unknown chunks will be read. Normal
1113behavior is that known chunks will be parsed into information in
1114various info_ptr members; unknown chunks will be discarded. To change
1115this, you can call:
1116
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001117 png_set_keep_unknown_chunks(png_ptr, keep,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001118 chunk_list, num_chunks);
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001119 keep - 0: do not handle as unknown
1120 1: do not keep
1121 2: keep only if safe-to-copy
1122 3: keep even if unsafe-to-copy
1123 You can use these definitions:
1124 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1125 PNG_HANDLE_CHUNK_NEVER 1
1126 PNG_HANDLE_CHUNK_IF_SAFE 2
1127 PNG_HANDLE_CHUNK_ALWAYS 3
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001128 chunk_list - list of chunks affected (a byte string,
1129 five bytes per chunk, NULL or '\0' if
1130 num_chunks is 0)
1131 num_chunks - number of chunks affected; if 0, all
Glenn Randers-Pehrsondff799e2004-08-07 21:42:49 -05001132 unknown chunks are affected. If nonzero,
1133 only the chunks in the list are affected
1134
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001135Unknown chunks declared in this way will be saved as raw data onto a
1136list of png_unknown_chunk structures. If a chunk that is normally
1137known to libpng is named in the list, it will be handled as unknown,
1138according to the "keep" directive. If a chunk is named in successive
1139instances of png_set_keep_unknown_chunks(), the final instance will
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001140take precedence. The IHDR and IEND chunks should not be named in
1141chunk_list; if they are, libpng will process them normally anyway.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001142
1143.SS The high-level read interface
1144
1145At this point there are two ways to proceed; through the high-level
1146read interface, or through a sequence of low-level read operations.
1147You can use the high-level interface if (a) you are willing to read
1148the entire image into memory, and (b) the input transformations
1149you want to do are limited to the following set:
1150
1151 PNG_TRANSFORM_IDENTITY No transformation
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001152 PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
1153 8 bits
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001154 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001155 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1156 samples to bytes
1157 PNG_TRANSFORM_PACKSWAP Change order of packed
1158 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001159 PNG_TRANSFORM_EXPAND Perform set_expand()
1160 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001161 PNG_TRANSFORM_SHIFT Normalize pixels to the
1162 sBIT depth
1163 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1164 to BGRA
1165 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1166 to AG
1167 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1168 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001169 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
1170
1171(This excludes setting a background color, doing gamma transformation,
1172dithering, and setting filler.) If this is the case, simply do this:
1173
1174 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1175
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001176where png_transforms is an integer containing the logical OR of
1177some set of transformation flags. This call is equivalent to png_read_info(),
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001178followed the set of transformations indicated by the transform mask,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001179then png_read_image(), and finally png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001180
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001181(The final parameter of this call is not yet used. Someday it might point
1182to transformation parameters required by some future input transform.)
1183
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001184You must use png_transforms and not call any png_set_transform() functions
1185when you use png_read_png().
1186
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001187After you have called png_read_png(), you can retrieve the image data
1188with
1189
1190 row_pointers = png_get_rows(png_ptr, info_ptr);
1191
1192where row_pointers is an array of pointers to the pixel data for each row:
1193
1194 png_bytep row_pointers[height];
1195
1196If you know your image size and pixel size ahead of time, you can allocate
1197row_pointers prior to calling png_read_png() with
1198
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001199 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
1200 png_error (png_ptr,
1201 "Image is too tall to process in memory");
1202 if (width > PNG_UINT_32_MAX/pixel_size)
1203 png_error (png_ptr,
1204 "Image is too wide to process in memory");
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001205 row_pointers = png_malloc(png_ptr,
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001206 height*png_sizeof(png_bytep));
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001207 for (int i=0; i<height, i++)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001208 row_pointers[i]=png_malloc(png_ptr,
1209 width*pixel_size);
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001210 png_set_rows(png_ptr, info_ptr, &row_pointers);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001211
1212Alternatively you could allocate your image in one big block and define
1213row_pointers[i] to point into the proper places in your block.
1214
1215If you use png_set_rows(), the application is responsible for freeing
1216row_pointers (and row_pointers[i], if they were separately allocated).
1217
1218If you don't allocate row_pointers ahead of time, png_read_png() will
1219do it, and it'll be free'ed when you call png_destroy_*().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001220
1221.SS The low-level read interface
1222
1223If you are going the low-level route, you are now ready to read all
1224the file information up to the actual image data. You do this with a
1225call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001226
1227 png_read_info(png_ptr, info_ptr);
1228
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001229This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001230
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001231.SS Querying the info structure
1232
1233Functions are used to get the information from the info_ptr once it
1234has been read. Note that these fields may not be completely filled
1235in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001236
1237 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1238 &bit_depth, &color_type, &interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001239 &compression_type, &filter_method);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001240
1241 width - holds the width of the image
1242 in pixels (up to 2^31).
1243 height - holds the height of the image
1244 in pixels (up to 2^31).
1245 bit_depth - holds the bit depth of one of the
1246 image channels. (valid values are
1247 1, 2, 4, 8, 16 and depend also on
1248 the color_type. See also
1249 significant bits (sBIT) below).
1250 color_type - describes which color/alpha channels
1251 are present.
1252 PNG_COLOR_TYPE_GRAY
1253 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001254 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001255 (bit depths 8, 16)
1256 PNG_COLOR_TYPE_PALETTE
1257 (bit depths 1, 2, 4, 8)
1258 PNG_COLOR_TYPE_RGB
1259 (bit_depths 8, 16)
1260 PNG_COLOR_TYPE_RGB_ALPHA
1261 (bit_depths 8, 16)
1262
1263 PNG_COLOR_MASK_PALETTE
1264 PNG_COLOR_MASK_COLOR
1265 PNG_COLOR_MASK_ALPHA
1266
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001267 filter_method - (must be PNG_FILTER_TYPE_BASE
1268 for PNG 1.0, and can also be
1269 PNG_INTRAPIXEL_DIFFERENCING if
1270 the PNG datastream is embedded in
1271 a MNG-1.0 datastream)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001272 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1273 for PNG 1.0)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001274 interlace_type - (PNG_INTERLACE_NONE or
1275 PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001276 Any or all of interlace_type, compression_type, of
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001277 filter_method can be NULL if you are
1278 not interested in their values.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001279
1280 channels = png_get_channels(png_ptr, info_ptr);
1281 channels - number of channels of info for the
1282 color type (valid values are 1 (GRAY,
1283 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1284 4 (RGB_ALPHA or RGB + filler byte))
1285 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1286 rowbytes - number of bytes needed to hold a row
1287
1288 signature = png_get_signature(png_ptr, info_ptr);
1289 signature - holds the signature read from the
1290 file (if any). The data is kept in
1291 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001292 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001293 application had already read in 4
1294 bytes of signature before starting
1295 libpng, the remaining 4 bytes would
1296 be in signature[4] through signature[7]
1297 (see png_set_sig_bytes())).
1298
1299
1300 width = png_get_image_width(png_ptr,
1301 info_ptr);
1302 height = png_get_image_height(png_ptr,
1303 info_ptr);
1304 bit_depth = png_get_bit_depth(png_ptr,
1305 info_ptr);
1306 color_type = png_get_color_type(png_ptr,
1307 info_ptr);
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001308 filter_method = png_get_filter_type(png_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001309 info_ptr);
1310 compression_type = png_get_compression_type(png_ptr,
1311 info_ptr);
1312 interlace_type = png_get_interlace_type(png_ptr,
1313 info_ptr);
1314
1315
1316These are also important, but their validity depends on whether the chunk
1317has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1318png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1319data has been read, or zero if it is missing. The parameters to the
1320png_get_<chunk> are set directly if they are simple data types, or a pointer
1321into the info_ptr is returned for any complex types.
1322
1323 png_get_PLTE(png_ptr, info_ptr, &palette,
1324 &num_palette);
1325 palette - the palette for the file
1326 (array of png_color)
1327 num_palette - number of entries in the palette
1328
1329 png_get_gAMA(png_ptr, info_ptr, &gamma);
1330 gamma - the gamma the file is written
1331 at (PNG_INFO_gAMA)
1332
1333 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1334 srgb_intent - the rendering intent (PNG_INFO_sRGB)
1335 The presence of the sRGB chunk
1336 means that the pixel data is in the
1337 sRGB color space. This chunk also
1338 implies specific values of gAMA and
1339 cHRM.
1340
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001341 png_get_iCCP(png_ptr, info_ptr, &name,
1342 &compression_type, &profile, &proflen);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001343 name - The profile name.
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001344 compression - The compression type; always
1345 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1346 You may give NULL to this argument to
1347 ignore it.
1348 profile - International Color Consortium color
1349 profile data. May contain NULs.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001350 proflen - length of profile data in bytes.
1351
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001352 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1353 sig_bit - the number of significant bits for
1354 (PNG_INFO_sBIT) each of the gray,
1355 red, green, and blue channels,
1356 whichever are appropriate for the
1357 given color type (png_color_16)
1358
1359 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
1360 &trans_values);
1361 trans - array of transparent entries for
1362 palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05001363 trans_values - graylevel or color sample values of
1364 the single transparent color for
1365 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001366 num_trans - number of transparent entries
1367 (PNG_INFO_tRNS)
1368
1369 png_get_hIST(png_ptr, info_ptr, &hist);
1370 (PNG_INFO_hIST)
1371 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001372 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001373
1374 png_get_tIME(png_ptr, info_ptr, &mod_time);
1375 mod_time - time image was last modified
1376 (PNG_VALID_tIME)
1377
1378 png_get_bKGD(png_ptr, info_ptr, &background);
1379 background - background color (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001380 valid 16-bit red, green and blue
1381 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001382
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001383 num_comments = png_get_text(png_ptr, info_ptr,
1384 &text_ptr, &num_text);
1385 num_comments - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001386 text_ptr - array of png_text holding image
1387 comments
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001388 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001389 on "text" PNG_TEXT_COMPRESSION_NONE
1390 PNG_TEXT_COMPRESSION_zTXt
1391 PNG_ITXT_COMPRESSION_NONE
1392 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001393 text_ptr[i].key - keyword for comment. Must contain
1394 1-79 characters.
1395 text_ptr[i].text - text comments for current
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001396 keyword. Can be empty.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001397 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001398 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001399 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001400 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001401 text_ptr[i].lang - language of comment (empty
1402 string for unknown).
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06001403 text_ptr[i].lang_key - keyword in UTF-8
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001404 (empty string for unknown).
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001405 num_text - number of comments (same as
1406 num_comments; you can put NULL here
1407 to avoid the duplication)
1408 Note while png_set_text() will accept text, language,
1409 and translated keywords that can be NULL pointers, the
1410 structure returned by png_get_text will always contain
1411 regular zero-terminated C strings. They might be
1412 empty strings but they will never be NULL pointers.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001413
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001414 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1415 &palette_ptr);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001416 palette_ptr - array of palette structures holding
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001417 contents of one or more sPLT chunks
1418 read.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001419 num_spalettes - number of sPLT chunks read.
1420
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001421 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001422 &unit_type);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001423 offset_x - positive offset from the left edge
1424 of the screen
1425 offset_y - positive offset from the top edge
1426 of the screen
1427 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1428
1429 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001430 &unit_type);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001431 res_x - pixels/unit physical resolution in
1432 x direction
1433 res_y - pixels/unit physical resolution in
1434 x direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001435 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001436 PNG_RESOLUTION_METER
1437
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001438 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1439 &height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001440 unit - physical scale units (an integer)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001441 width - width of a pixel in physical scale units
1442 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001443 (width and height are doubles)
1444
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001445 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1446 &height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001447 unit - physical scale units (an integer)
1448 width - width of a pixel in physical scale units
1449 height - height of a pixel in physical scale units
1450 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001451
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001452 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1453 info_ptr, &unknowns)
1454 unknowns - array of png_unknown_chunk
1455 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001456 unknowns[i].name - name of unknown chunk
1457 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001458 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001459 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001460
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001461 The value of "i" corresponds to the order in which the
1462 chunks were read from the PNG file or inserted with the
1463 png_set_unknown_chunks() function.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001464
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001465The data from the pHYs chunk can be retrieved in several convenient
1466forms:
1467
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001468 res_x = png_get_x_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001469 info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001470 res_y = png_get_y_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001471 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001472 res_x_and_y = png_get_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001473 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001474 res_x = png_get_x_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001475 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001476 res_y = png_get_y_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001477 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001478 res_x_and_y = png_get_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001479 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001480 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001481 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001482
1483 (Each of these returns 0 [signifying "unknown"] if
1484 the data is not present or if res_x is 0;
1485 res_x_and_y is 0 if res_x != res_y)
1486
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001487The data from the oFFs chunk can be retrieved in several convenient
1488forms:
1489
1490 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1491 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1492 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1493 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1494
1495 (Each of these returns 0 [signifying "unknown" if both
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001496 x and y are 0] if the data is not present or if the
1497 chunk is present but the unit is the pixel)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001498
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001499For more information, see the png_info definition in png.h and the
1500PNG specification for chunk contents. Be careful with trusting
1501rowbytes, as some of the transformations could increase the space
1502needed to hold a row (expand, filler, gray_to_rgb, etc.).
1503See png_read_update_info(), below.
1504
1505A quick word about text_ptr and num_text. PNG stores comments in
1506keyword/text pairs, one pair per chunk, with no limit on the number
1507of text chunks, and a 2^31 byte limit on their size. While there are
1508suggested keywords, there is no requirement to restrict the use to these
1509strings. It is strongly suggested that keywords and text be sensible
1510to humans (that's the point), so don't use abbreviations. Non-printing
1511symbols are not allowed. See the PNG specification for more details.
1512There is also no requirement to have text after the keyword.
1513
1514Keywords should be limited to 79 Latin-1 characters without leading or
1515trailing spaces, but non-consecutive spaces are allowed within the
1516keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001517The text_ptr is an array of png_text structures, each holding a
1518pointer to a language string, a pointer to a keyword and a pointer to
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001519a text string. The text string, language code, and translated
1520keyword may be empty or NULL pointers. The keyword/text
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001521pairs are put into the array in the order that they are received.
1522However, some or all of the text chunks may be after the image, so, to
1523make sure you have read all the text chunks, don't mess with these
1524until after you read the stuff after the image. This will be
1525mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001526
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001527.SS Input transformations
1528
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001529After you've read the header information, you can set up the library
1530to handle any special transformations of the image data. The various
1531ways to transform the data will be described in the order that they
1532should occur. This is important, as some of these change the color
1533type and/or bit depth of the data, and some others only work on
1534certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001535checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001536make sure to only enable a transformation if it will be valid for the
1537data. For example, don't swap red and blue on grayscale data.
1538
1539The colors used for the background and transparency values should be
1540supplied in the same format/depth as the current image data. They
1541are stored in the same format/depth as the image data in a bKGD or tRNS
1542chunk, so this is what libpng expects for this data. The colors are
1543transformed to keep in sync with the image data when an application
1544calls the png_read_update_info() routine (see below).
1545
1546Data will be decoded into the supplied row buffers packed into bytes
1547unless the library has been told to transform it into another format.
1548For example, 4 bit/pixel paletted or grayscale data will be returned
15492 pixels/byte with the leftmost pixel in the high-order bits of the
1550byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001551in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
1552is called to insert filler bytes, either before or after each RGB triplet.
155316-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
1554byte of the color value first, unless png_set_strip_16() is called to
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06001555transform it to regular RGB RGB triplets, or png_set_filler() or
1556png_set_add alpha() is called to insert filler bytes, either before or
1557after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
1558be modified with
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001559png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001560
1561The following code transforms grayscale images of less than 8 to 8 bits,
1562changes paletted images to RGB, and adds a full alpha channel if there is
1563transparency information in a tRNS chunk. This is most useful on
1564grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1565viewing application that wishes to treat all images in the same way.
1566
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001567 if (color_type == PNG_COLOR_TYPE_PALETTE)
1568 png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001569
1570 if (color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001571 bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001572
1573 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001574 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1575
1576These three functions are actually aliases for png_set_expand(), added
1577in libpng version 1.0.4, with the function names expanded to improve code
1578readability. In some future version they may actually do different
1579things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001580
1581PNG can have files with 16 bits per channel. If you only can handle
15828 bits per channel, this will strip the pixels down to 8 bit.
1583
1584 if (bit_depth == 16)
1585 png_set_strip_16(png_ptr);
1586
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001587If, for some reason, you don't need the alpha channel on an image,
1588and you want to remove it rather than combining it with the background
1589(but the image author certainly had in mind that you *would* combine
1590it with the background, so that's what you should probably do):
1591
1592 if (color_type & PNG_COLOR_MASK_ALPHA)
1593 png_set_strip_alpha(png_ptr);
1594
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001595In PNG files, the alpha channel in an image
1596is the level of opacity. If you need the alpha channel in an image to
1597be the level of transparency instead of opacity, you can invert the
1598alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1599fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1600images) is fully transparent, with
1601
1602 png_set_invert_alpha(png_ptr);
1603
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001604PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1605they can, resulting in, for example, 8 pixels per byte for 1 bit
1606files. This code expands to 1 pixel per byte without changing the
1607values of the pixels:
1608
1609 if (bit_depth < 8)
1610 png_set_packing(png_ptr);
1611
1612PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1613stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001614higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060016158 bits/sample in the range [0, 255]). However, it is also possible to
1616convert the PNG pixel data back to the original bit depth of the image.
1617This call reduces the pixels back down to the original bit depth:
1618
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05001619 png_color_8p sig_bit;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001620
1621 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1622 png_set_shift(png_ptr, sig_bit);
1623
1624PNG files store 3-color pixels in red, green, blue order. This code
1625changes the storage of the pixels to blue, green, red:
1626
1627 if (color_type == PNG_COLOR_TYPE_RGB ||
1628 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1629 png_set_bgr(png_ptr);
1630
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001631PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
1632into 4 or 8 bytes for windowing systems that need them in this format:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001633
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001634 if (color_type == PNG_COLOR_TYPE_RGB)
1635 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001636
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001637where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001638either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1639you want the filler before the RGB or after. This transformation
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001640does not affect images that already have full alpha channels. To add an
1641opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
1642will generate RGBA pixels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001643
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001644Note that png_set_filler() does not change the color type. If you want
1645to do that, you can add a true alpha channel with
1646
1647 if (color_type == PNG_COLOR_TYPE_RGB ||
1648 color_type == PNG_COLOR_TYPE_GRAY)
1649 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
1650
1651where "filler" contains the alpha value to assign to each pixel.
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06001652This function was added in libpng-1.2.7.
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001653
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001654If you are reading an image with an alpha channel, and you need the
1655data as ARGB instead of the normal PNG format RGBA:
1656
1657 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1658 png_set_swap_alpha(png_ptr);
1659
1660For some uses, you may want a grayscale image to be represented as
1661RGB. This code will do that conversion:
1662
1663 if (color_type == PNG_COLOR_TYPE_GRAY ||
1664 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1665 png_set_gray_to_rgb(png_ptr);
1666
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001667Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001668with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001669
1670 if (color_type == PNG_COLOR_TYPE_RGB ||
1671 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001672 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1673 int red_weight, int green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001674
1675 error_action = 1: silently do the conversion
1676 error_action = 2: issue a warning if the original
1677 image has any pixel where
1678 red != green or red != blue
1679 error_action = 3: issue an error and abort the
1680 conversion if the original
1681 image has any pixel where
1682 red != green or red != blue
1683
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001684 red_weight: weight of red component times 100000
1685 green_weight: weight of green component times 100000
1686 If either weight is negative, default
1687 weights (21268, 71514) are used.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001688
1689If you have set error_action = 1 or 2, you can
1690later check whether the image really was gray, after processing
1691the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1692It will return a png_byte that is zero if the image was gray or
16931 if there were any non-gray pixels. bKGD and sBIT data
1694will be silently converted to grayscale, using the green channel
1695data, regardless of the error_action setting.
1696
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001697With red_weight+green_weight<=100000,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001698the normalized graylevel is computed:
1699
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001700 int rw = red_weight * 65536;
1701 int gw = green_weight * 65536;
1702 int bw = 65536 - (rw + gw);
1703 gray = (rw*red + gw*green + bw*blue)/65536;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001704
1705The default values approximate those recommended in the Charles
1706Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06001707Copyright (c) 1998-01-04 Charles Poynton <poynton at inforamp.net>
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001708
1709 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1710
1711Libpng approximates this with
1712
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001713 Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001714
1715which can be expressed with integers as
1716
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001717 Y = (6969 * R + 23434 * G + 2365 * B)/32768
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001718
1719The calculation is done in a linear colorspace, if the image gamma
1720is known.
1721
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06001722If you have a grayscale and you are using png_set_expand_depth(),
1723png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001724a higher bit-depth, you must either supply the background color as a gray
1725value at the original file bit-depth (need_expand = 1) or else supply the
1726background color as an RGB triplet at the final, expanded bit depth
1727(need_expand = 0). Similarly, if you are reading a paletted image, you
1728must either supply the background color as a palette index (need_expand = 1)
1729or as an RGB triplet that may or may not be in the palette (need_expand = 0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001730
1731 png_color_16 my_background;
1732 png_color_16p image_background;
1733
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001734 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1735 png_set_background(png_ptr, image_background,
1736 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001737 else
1738 png_set_background(png_ptr, &my_background,
1739 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1740
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001741The png_set_background() function tells libpng to composite images
1742with alpha or simple transparency against the supplied background
1743color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1744you may use this color, or supply another color more suitable for
1745the current display (e.g., the background color from a web page). You
1746need to tell libpng whether the color is in the gamma space of the
1747display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
1748(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
1749that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
1750know why anyone would use this, but it's here).
1751
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001752To properly display PNG images on any kind of system, the application needs
1753to know what the display gamma is. Ideally, the user will know this, and
1754the application will allow them to set it. One method of allowing the user
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001755to set the display gamma separately for each system is to check for a
1756SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
1757correctly set.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001758
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001759Note that display_gamma is the overall gamma correction required to produce
1760pleasing results, which depends on the lighting conditions in the surrounding
1761environment. In a dim or brightly lit room, no compensation other than
1762the physical gamma exponent of the monitor is needed, while in a dark room
1763a slightly smaller exponent is better.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001764
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001765 double gamma, screen_gamma;
1766
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001767 if (/* We have a user-defined screen
1768 gamma value */)
1769 {
1770 screen_gamma = user_defined_screen_gamma;
1771 }
1772 /* One way that applications can share the same
1773 screen gamma value */
1774 else if ((gamma_str = getenv("SCREEN_GAMMA"))
1775 != NULL)
1776 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001777 screen_gamma = (double)atof(gamma_str);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001778 }
1779 /* If we don't have another value */
1780 else
1781 {
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001782 screen_gamma = 2.2; /* A good guess for a
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001783 PC monitor in a bright office or a dim room */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001784 screen_gamma = 2.0; /* A good guess for a
1785 PC monitor in a dark room */
1786 screen_gamma = 1.7 or 1.0; /* A good
1787 guess for Mac systems */
1788 }
1789
1790The png_set_gamma() function handles gamma transformations of the data.
1791Pass both the file gamma and the current screen_gamma. If the file does
1792not have a gamma value, you can pass one anyway if you have an idea what
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001793it is (usually 0.45455 is a good guess for GIF images on PCs). Note
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001794that file gammas are inverted from screen gammas. See the discussions
1795on gamma in the PNG specification for an excellent description of what
1796gamma is, and why all applications should support it. It is strongly
1797recommended that PNG viewers support gamma correction.
1798
1799 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
1800 png_set_gamma(png_ptr, screen_gamma, gamma);
1801 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001802 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001803
1804If you need to reduce an RGB file to a paletted file, or if a paletted
1805file has more entries then will fit on your screen, png_set_dither()
1806will do that. Note that this is a simple match dither that merely
1807finds the closest color available. This should work fairly well with
1808optimized palettes, and fairly badly with linear color cubes. If you
1809pass a palette that is larger then maximum_colors, the file will
1810reduce the number of colors in the palette so it will fit into
1811maximum_colors. If there is a histogram, it will use it to make
1812more intelligent choices when reducing the palette. If there is no
1813histogram, it may not do as good a job.
1814
1815 if (color_type & PNG_COLOR_MASK_COLOR)
1816 {
1817 if (png_get_valid(png_ptr, info_ptr,
1818 PNG_INFO_PLTE))
1819 {
Glenn Randers-Pehrson865f4f02002-09-15 20:30:38 -05001820 png_uint_16p histogram = NULL;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001821
1822 png_get_hIST(png_ptr, info_ptr,
1823 &histogram);
1824 png_set_dither(png_ptr, palette, num_palette,
1825 max_screen_colors, histogram, 1);
1826 }
1827 else
1828 {
1829 png_color std_color_cube[MAX_SCREEN_COLORS] =
1830 { ... colors ... };
1831
1832 png_set_dither(png_ptr, std_color_cube,
1833 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
1834 NULL,0);
1835 }
1836 }
1837
1838PNG files describe monochrome as black being zero and white being one.
1839The following code will reverse this (make black be one and white be
1840zero):
1841
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05001842 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
1843 png_set_invert_mono(png_ptr);
1844
1845This function can also be used to invert grayscale and gray-alpha images:
1846
1847 if (color_type == PNG_COLOR_TYPE_GRAY ||
1848 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001849 png_set_invert_mono(png_ptr);
1850
1851PNG files store 16 bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001852ie. most significant bits first). This code changes the storage to the
1853other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001854way PCs store them):
1855
1856 if (bit_depth == 16)
1857 png_set_swap(png_ptr);
1858
1859If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
1860need to change the order the pixels are packed into bytes, you can use:
1861
1862 if (bit_depth < 8)
1863 png_set_packswap(png_ptr);
1864
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001865Finally, you can write your own transformation function if none of
1866the existing ones meets your needs. This is done by setting a callback
1867with
1868
1869 png_set_read_user_transform_fn(png_ptr,
1870 read_transform_fn);
1871
1872You must supply the function
1873
1874 void read_transform_fn(png_ptr ptr, row_info_ptr
1875 row_info, png_bytep data)
1876
1877See pngtest.c for a working example. Your function will be called
1878after all of the other transformations have been processed.
1879
1880You can also set up a pointer to a user structure for use by your
1881callback function, and you can inform libpng that your transform
1882function will change the number of channels or bit depth with the
1883function
1884
1885 png_set_user_transform_info(png_ptr, user_ptr,
1886 user_depth, user_channels);
1887
1888The user's application, not libpng, is responsible for allocating and
1889freeing any memory required for the user structure.
1890
1891You can retrieve the pointer via the function
1892png_get_user_transform_ptr(). For example:
1893
1894 voidp read_user_transform_ptr =
1895 png_get_user_transform_ptr(png_ptr);
1896
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001897The last thing to handle is interlacing; this is covered in detail below,
1898but you must call the function here if you want libpng to handle expansion
1899of the interlaced image.
1900
1901 number_of_passes = png_set_interlace_handling(png_ptr);
1902
1903After setting the transformations, libpng can update your png_info
1904structure to reflect any transformations you've requested with this
1905call. This is most useful to update the info structure's rowbytes
1906field so you can use it to allocate your image memory. This function
1907will also update your palette with the correct screen_gamma and
1908background if these have been given with the calls above.
1909
1910 png_read_update_info(png_ptr, info_ptr);
1911
1912After you call png_read_update_info(), you can allocate any
1913memory you need to hold the image. The row data is simply
1914raw byte data for all forms of images. As the actual allocation
1915varies among applications, no example will be given. If you
1916are allocating one large chunk, you will need to build an
1917array of pointers to each row, as it will be needed for some
1918of the functions below.
1919
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001920.SS Reading image data
1921
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001922After you've allocated memory, you can read the image data.
1923The simplest way to do this is in one function call. If you are
1924allocating enough memory to hold the whole image, you can just
1925call png_read_image() and libpng will read in all the image data
1926and put it in the memory area supplied. You will need to pass in
1927an array of pointers to each row.
1928
1929This function automatically handles interlacing, so you don't need
1930to call png_set_interlace_handling() or call this function multiple
1931times, or any of that other stuff necessary with png_read_rows().
1932
1933 png_read_image(png_ptr, row_pointers);
1934
1935where row_pointers is:
1936
1937 png_bytep row_pointers[height];
1938
1939You can point to void or char or whatever you use for pixels.
1940
1941If you don't want to read in the whole image at once, you can
1942use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001943interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001944
1945 png_read_rows(png_ptr, row_pointers, NULL,
1946 number_of_rows);
1947
1948where row_pointers is the same as in the png_read_image() call.
1949
1950If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001951a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001952
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001953 png_bytep row_pointer = row;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001954 png_read_row(png_ptr, row_pointer, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001955
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001956If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
1957get somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001958interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001959is a somewhat complicated 2D interlace scheme, known as Adam7, that
1960breaks down an image into seven smaller images of varying size, based
1961on an 8x8 grid.
1962
1963libpng can fill out those images or it can give them to you "as is".
1964If you want them filled out, there are two ways to do that. The one
1965mentioned in the PNG specification is to expand each pixel to cover
1966those pixels that have not been read yet (the "rectangle" method).
1967This results in a blocky image for the first pass, which gradually
1968smooths out as more pixels are read. The other method is the "sparkle"
1969method, where pixels are drawn only in their final locations, with the
1970rest of the image remaining whatever colors they were initialized to
1971before the start of the read. The first method usually looks better,
1972but tends to be slower, as there are more pixels to put in the rows.
1973
1974If you don't want libpng to handle the interlacing details, just call
1975png_read_rows() seven times to read in all seven images. Each of the
1976images is a valid image by itself, or they can all be combined on an
19778x8 grid to form a single image (although if you intend to combine them
1978you would be far better off using the libpng interlace handling).
1979
1980The first pass will return an image 1/8 as wide as the entire image
1981(every 8th column starting in column 0) and 1/8 as high as the original
1982(every 8th row starting in row 0), the second will be 1/8 as wide
1983(starting in column 4) and 1/8 as high (also starting in row 0). The
1984third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
19851/8 as high (every 8th row starting in row 4), and the fourth pass will
1986be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
1987and every 4th row starting in row 0). The fifth pass will return an
1988image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
1989while the sixth pass will be 1/2 as wide and 1/2 as high as the original
1990(starting in column 1 and row 0). The seventh and final pass will be as
1991wide as the original, and 1/2 as high, containing all of the odd
1992numbered scanlines. Phew!
1993
1994If you want libpng to expand the images, call this before calling
1995png_start_read_image() or png_read_update_info():
1996
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001997 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001998 number_of_passes
1999 = png_set_interlace_handling(png_ptr);
2000
2001This will return the number of passes needed. Currently, this
2002is seven, but may change if another interlace type is added.
2003This function can be called even if the file is not interlaced,
2004where it will return one pass.
2005
2006If you are not going to display the image after each pass, but are
2007going to wait until the entire image is read in, use the sparkle
2008effect. This effect is faster and the end result of either method
2009is exactly the same. If you are planning on displaying the image
2010after each pass, the "rectangle" effect is generally considered the
2011better looking one.
2012
2013If you only want the "sparkle" effect, just call png_read_rows() as
2014normal, with the third parameter NULL. Make sure you make pass over
2015the image number_of_passes times, and you don't change the data in the
2016rows between calls. You can change the locations of the data, just
2017not the data. Each pass only writes the pixels appropriate for that
2018pass, and assumes the data from previous passes is still valid.
2019
2020 png_read_rows(png_ptr, row_pointers, NULL,
2021 number_of_rows);
2022
2023If you only want the first effect (the rectangles), do the same as
2024before except pass the row buffer in the third parameter, and leave
2025the second parameter NULL.
2026
2027 png_read_rows(png_ptr, NULL, row_pointers,
2028 number_of_rows);
2029
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002030.SS Finishing a sequential read
2031
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06002032After you are finished reading the image through the
2033low-level interface, you can finish reading the file. If you are
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002034interested in comments or time, which may be stored either before or
2035after the image data, you should pass the separate png_info struct if
2036you want to keep the comments from before and after the image
2037separate. If you are not interested, you can pass NULL.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002038
2039 png_read_end(png_ptr, end_info);
2040
2041When you are done, you can free all memory allocated by libpng like this:
2042
2043 png_destroy_read_struct(&png_ptr, &info_ptr,
2044 &end_info);
2045
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002046It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002047point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002048
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002049 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002050 mask - identifies data to be freed, a mask
2051 containing the logical OR of one or
2052 more of
2053 PNG_FREE_PLTE, PNG_FREE_TRNS,
2054 PNG_FREE_HIST, PNG_FREE_ICCP,
2055 PNG_FREE_PCAL, PNG_FREE_ROWS,
2056 PNG_FREE_SCAL, PNG_FREE_SPLT,
2057 PNG_FREE_TEXT, PNG_FREE_UNKN,
2058 or simply PNG_FREE_ALL
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002059 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002060 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002061
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002062This function may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002063already been freed, or has not yet been allocated, or was allocated
2064by the user and not by libpng, and will in those
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002065cases do nothing. The "seq" parameter is ignored if only one item
2066of the selected data type, such as PLTE, is allowed. If "seq" is not
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002067-1, and multiple items are allowed for the data type identified in
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002068the mask, such as text or sPLT, only the n'th item in the structure
2069is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002070
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002071The default behavior is only to free data that was allocated internally
2072by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002073or so that it will free data that was allocated by the user with png_malloc()
2074or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002075
2076 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002077 mask - which data elements are affected
2078 same choices as in png_free_data()
2079 freer - one of
2080 PNG_DESTROY_WILL_FREE_DATA
2081 PNG_SET_WILL_FREE_DATA
2082 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002083
2084This function only affects data that has already been allocated.
2085You can call this function after reading the PNG data but before calling
2086any png_set_*() functions, to control whether the user or the png_set_*()
2087function is responsible for freeing any existing data that might be present,
2088and again after the png_set_*() functions to control whether the user
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002089or png_destroy_*() is supposed to free the data. When the user assumes
2090responsibility for libpng-allocated data, the application must use
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002091png_free() to free it, and when the user transfers responsibility to libpng
2092for data that the user has allocated, the user must have used png_malloc()
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05002093or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002094
2095If you allocated your row_pointers in a single block, as suggested above in
2096the description of the high level read interface, you must not transfer
2097responsibility for freeing it to the png_set_rows or png_read_destroy function,
2098because they would also try to free the individual row_pointers[i].
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002099
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002100If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2101separately, do not transfer responsibility for freeing text_ptr to libpng,
2102because when libpng fills a png_text structure it combines these members with
2103the key member, and png_free_data() will free only text_ptr.key. Similarly,
2104if you transfer responsibility for free'ing text_ptr from libpng to your
2105application, your application must not separately free those members.
2106
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002107The png_free_data() function will turn off the "valid" flag for anything
2108it frees. If you need to turn the flag off for a chunk that was freed by your
2109application instead of by libpng, you can use
2110
2111 png_set_invalid(png_ptr, info_ptr, mask);
2112 mask - identifies the chunks to be made invalid,
2113 containing the logical OR of one or
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06002114 more of
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002115 PNG_INFO_gAMA, PNG_INFO_sBIT,
2116 PNG_INFO_cHRM, PNG_INFO_PLTE,
2117 PNG_INFO_tRNS, PNG_INFO_bKGD,
2118 PNG_INFO_hIST, PNG_INFO_pHYs,
2119 PNG_INFO_oFFs, PNG_INFO_tIME,
2120 PNG_INFO_pCAL, PNG_INFO_sRGB,
2121 PNG_INFO_iCCP, PNG_INFO_sPLT,
2122 PNG_INFO_sCAL, PNG_INFO_IDAT
2123
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002124For a more compact example of reading a PNG image, see the file example.c.
2125
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002126.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002127
2128The progressive reader is slightly different then the non-progressive
2129reader. Instead of calling png_read_info(), png_read_rows(), and
2130png_read_end(), you make one call to png_process_data(), which calls
2131callbacks when it has the info, a row, or the end of the image. You
2132set up these callbacks with png_set_progressive_read_fn(). You don't
2133have to worry about the input/output functions of libpng, as you are
2134giving the library the data directly in png_process_data(). I will
2135assume that you have read the section on reading PNG files above,
2136so I will only highlight the differences (although I will show
2137all of the code).
2138
2139png_structp png_ptr;
2140png_infop info_ptr;
2141
2142 /* An example code fragment of how you would
2143 initialize the progressive reader in your
2144 application. */
2145 int
2146 initialize_png_reader()
2147 {
2148 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002149 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002150 user_error_fn, user_warning_fn);
2151 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002152 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002153 info_ptr = png_create_info_struct(png_ptr);
2154 if (!info_ptr)
2155 {
2156 png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
2157 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002158 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002159 }
2160
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002161 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002162 {
2163 png_destroy_read_struct(&png_ptr, &info_ptr,
2164 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002165 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002166 }
2167
2168 /* This one's new. You can provide functions
2169 to be called when the header info is valid,
2170 when each row is completed, and when the image
2171 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002172 you can specify NULL parameters. Even when all
2173 three functions are NULL, you need to call
2174 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002175 any struct as the user_ptr (cast to a void pointer
2176 for the function call), and retrieve the pointer
2177 from inside the callbacks using the function
2178
2179 png_get_progressive_ptr(png_ptr);
2180
2181 which will return a void pointer, which you have
2182 to cast appropriately.
2183 */
2184 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
2185 info_callback, row_callback, end_callback);
2186
2187 return 0;
2188 }
2189
2190 /* A code fragment that you call as you receive blocks
2191 of data */
2192 int
2193 process_data(png_bytep buffer, png_uint_32 length)
2194 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002195 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002196 {
2197 png_destroy_read_struct(&png_ptr, &info_ptr,
2198 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002199 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002200 }
2201
2202 /* This one's new also. Simply give it a chunk
2203 of data from the file stream (in order, of
2204 course). On machines with segmented memory
2205 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002206 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002207 of 4K. Although you can give it much less if
2208 necessary (I assume you can give it chunks of
2209 1 byte, I haven't tried less then 256 bytes
2210 yet). When this function returns, you may
2211 want to display any rows that were generated
2212 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002213 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002214 */
2215 png_process_data(png_ptr, info_ptr, buffer, length);
2216 return 0;
2217 }
2218
2219 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002220 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002221 has been supplied so all of the header has been
2222 read.
2223 */
2224 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002225 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002226 {
2227 /* Do any setup here, including setting any of
2228 the transformations mentioned in the Reading
2229 PNG files section. For now, you _must_ call
2230 either png_start_read_image() or
2231 png_read_update_info() after all the
2232 transformations are set (even if you don't set
2233 any). You may start getting rows before
2234 png_process_data() returns, so this is your
2235 last chance to prepare for that.
2236 */
2237 }
2238
2239 /* This function is called when each row of image
2240 data is complete */
2241 void
2242 row_callback(png_structp png_ptr, png_bytep new_row,
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05002243 png_uint_32 row_num, int pass)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002244 {
2245 /* If the image is interlaced, and you turned
2246 on the interlace handler, this function will
2247 be called for every row in every pass. Some
2248 of these rows will not be changed from the
2249 previous pass. When the row is not changed,
2250 the new_row variable will be NULL. The rows
2251 and passes are called in order, so you don't
2252 really need the row_num and pass, but I'm
2253 supplying them because it may make your life
2254 easier.
2255
2256 For the non-NULL rows of interlaced images,
2257 you must call png_progressive_combine_row()
2258 passing in the row and the old row. You can
2259 call this function for NULL rows (it will just
2260 return) and for non-interlaced images (it just
2261 does the memcpy for you) if it will make the
2262 code easier. Thus, you can just do this for
2263 all cases:
2264 */
2265
2266 png_progressive_combine_row(png_ptr, old_row,
2267 new_row);
2268
2269 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05002270 previously for the row. Note that the first
2271 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002272 the old row, so the rows do not have to be
2273 initialized. After the first pass (and only
2274 for interlaced images), you will have to pass
2275 the current row, and the function will combine
2276 the old row and the new row.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002277 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002278 }
2279
2280 void
2281 end_callback(png_structp png_ptr, png_infop info)
2282 {
2283 /* This function is called after the whole image
2284 has been read, including any chunks after the
2285 image (up to and including the IEND). You
2286 will usually have the same info chunk as you
2287 had in the header, although some data may have
2288 been added to the comments and time fields.
2289
2290 Most people won't do much here, perhaps setting
2291 a flag that marks the image as finished.
2292 */
2293 }
2294
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002295
2296
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002297.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002298
2299Much of this is very similar to reading. However, everything of
2300importance is repeated here, so you won't have to constantly look
2301back up in the reading section to understand writing.
2302
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002303.SS Setup
2304
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002305You will want to do the I/O initialization before you get into libpng,
2306so if it doesn't work, you don't have anything to undo. If you are not
2307using the standard I/O functions, you will need to replace them with
2308custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002309
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002310 FILE *fp = fopen(file_name, "wb");
2311 if (!fp)
2312 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002313 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002314 }
2315
2316Next, png_struct and png_info need to be allocated and initialized.
2317As these can be both relatively large, you may not want to store these
2318on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002319will want to check if they return NULL. If you are also reading,
2320you won't want to name your read structure and your write structure
2321both "png_ptr"; you can call them anything you like, such as
2322"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002323
2324 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002325 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002326 user_error_fn, user_warning_fn);
2327 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002328 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002329
2330 png_infop info_ptr = png_create_info_struct(png_ptr);
2331 if (!info_ptr)
2332 {
2333 png_destroy_write_struct(&png_ptr,
2334 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002335 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002336 }
2337
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002338If you want to use your own memory allocation routines,
2339define PNG_USER_MEM_SUPPORTED and use
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002340png_create_write_struct_2() instead of png_create_write_struct():
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002341
2342 png_structp png_ptr = png_create_write_struct_2
2343 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2344 user_error_fn, user_warning_fn, (png_voidp)
2345 user_mem_ptr, user_malloc_fn, user_free_fn);
2346
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002347After you have these structures, you will need to set up the
2348error handling. When libpng encounters an error, it expects to
2349longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002350setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002351write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002352the png_jmpbuf(png_ptr) every time you enter a new routine that will
2353call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002354for your compiler for more information on setjmp/longjmp. See
2355the discussion on libpng error handling in the Customizing Libpng
2356section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002357
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002358 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002359 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002360 png_destroy_write_struct(&png_ptr, &info_ptr);
2361 fclose(fp);
2362 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002363 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002364 ...
2365 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002366
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002367If you would rather avoid the complexity of setjmp/longjmp issues,
2368you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
2369errors will result in a call to PNG_ABORT() which defaults to abort().
2370
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002371Now you need to set up the output code. The default for libpng is to
2372use the C function fwrite(). If you use this, you will need to pass a
2373valid FILE * in the function png_init_io(). Be sure that the file is
2374opened in binary mode. Again, if you wish to handle writing data in
2375another way, see the discussion on libpng I/O handling in the Customizing
2376Libpng section below.
2377
2378 png_init_io(png_ptr, fp);
2379
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002380.SS Write callbacks
2381
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002382At this point, you can set up a callback function that will be
2383called after each row has been written, which you can use to control
2384a progress meter or the like. It's demonstrated in pngtest.c.
2385You must supply a function
2386
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002387 void write_row_callback(png_ptr, png_uint_32 row,
2388 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002389 {
2390 /* put your code here */
2391 }
2392
2393(You can give it another name that you like instead of "write_row_callback")
2394
2395To inform libpng about your function, use
2396
2397 png_set_write_status_fn(png_ptr, write_row_callback);
2398
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002399You now have the option of modifying how the compression library will
2400run. The following functions are mainly for testing, but may be useful
2401in some cases, like if you need to write PNG files extremely fast and
2402are willing to give up some compression, or if you want to get the
2403maximum possible compression at the expense of slower writing. If you
2404have no special needs in this area, let the library do what it wants by
2405not calling this function at all, as it has been tuned to deliver a good
2406speed/compression ratio. The second parameter to png_set_filter() is
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002407the filter method, for which the only valid values are 0 (as of the
2408July 1999 PNG specification, version 1.2) or 64 (if you are writing
2409a PNG datastream that is to be embedded in a MNG datastream). The third
2410parameter is a flag that indicates which filter type(s) are to be tested
2411for each scanline. See the PNG specification for details on the specific filter
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002412types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002413
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002414
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002415 /* turn on or off filtering, and/or choose
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002416 specific filters. You can use either a single
2417 PNG_FILTER_VALUE_NAME or the logical OR of one
2418 or more PNG_FILTER_NAME masks. */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002419 png_set_filter(png_ptr, 0,
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002420 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
2421 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
2422 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
2423 PNG_FILTER_AVE | PNG_FILTER_VALUE_AVE |
2424 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
2425 PNG_ALL_FILTERS);
2426
2427If an application
2428wants to start and stop using particular filters during compression,
2429it should start out with all of the filters (to ensure that the previous
2430row of pixels will be stored in case it's needed later), and then add
2431and remove them after the start of compression.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002432
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002433If you are writing a PNG datastream that is to be embedded in a MNG
2434datastream, the second parameter can be either 0 or 64.
2435
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002436The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002437library, and should mostly be ignored unless you really know what you are
2438doing. The only generally useful call is png_set_compression_level()
2439which changes how much time zlib spends on trying to compress the image
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002440data. See the Compression Library (zlib.h and algorithm.txt, distributed
2441with zlib) for details on the compression levels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002442
2443 /* set the zlib compression level */
2444 png_set_compression_level(png_ptr,
2445 Z_BEST_COMPRESSION);
2446
2447 /* set other zlib parameters */
2448 png_set_compression_mem_level(png_ptr, 8);
2449 png_set_compression_strategy(png_ptr,
2450 Z_DEFAULT_STRATEGY);
2451 png_set_compression_window_bits(png_ptr, 15);
2452 png_set_compression_method(png_ptr, 8);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002453 png_set_compression_buffer_size(png_ptr, 8192)
2454
2455extern PNG_EXPORT(void,png_set_zbuf_size)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002456
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002457.SS Setting the contents of info for output
2458
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002459You now need to fill in the png_info structure with all the data you
2460wish to write before the actual image. Note that the only thing you
2461are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002462chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002463the latest PNG specification for more information on that. If you
2464wish to write them before the image, fill them in now, and flag that
2465data as being valid. If you want to wait until after the data, don't
2466fill them until png_write_end(). For all the fields in png_info and
2467their data types, see png.h. For explanations of what the fields
2468contain, see the PNG specification.
2469
2470Some of the more important parts of the png_info are:
2471
2472 png_set_IHDR(png_ptr, info_ptr, width, height,
2473 bit_depth, color_type, interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002474 compression_type, filter_method)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002475 width - holds the width of the image
2476 in pixels (up to 2^31).
2477 height - holds the height of the image
2478 in pixels (up to 2^31).
2479 bit_depth - holds the bit depth of one of the
2480 image channels.
2481 (valid values are 1, 2, 4, 8, 16
2482 and depend also on the
2483 color_type. See also significant
2484 bits (sBIT) below).
2485 color_type - describes which color/alpha
2486 channels are present.
2487 PNG_COLOR_TYPE_GRAY
2488 (bit depths 1, 2, 4, 8, 16)
2489 PNG_COLOR_TYPE_GRAY_ALPHA
2490 (bit depths 8, 16)
2491 PNG_COLOR_TYPE_PALETTE
2492 (bit depths 1, 2, 4, 8)
2493 PNG_COLOR_TYPE_RGB
2494 (bit_depths 8, 16)
2495 PNG_COLOR_TYPE_RGB_ALPHA
2496 (bit_depths 8, 16)
2497
2498 PNG_COLOR_MASK_PALETTE
2499 PNG_COLOR_MASK_COLOR
2500 PNG_COLOR_MASK_ALPHA
2501
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002502 interlace_type - PNG_INTERLACE_NONE or
2503 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002504 compression_type - (must be
2505 PNG_COMPRESSION_TYPE_DEFAULT)
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002506 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
2507 or, if you are writing a PNG to
2508 be embedded in a MNG datastream,
2509 can also be
2510 PNG_INTRAPIXEL_DIFFERENCING)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002511
2512 png_set_PLTE(png_ptr, info_ptr, palette,
2513 num_palette);
2514 palette - the palette for the file
2515 (array of png_color)
2516 num_palette - number of entries in the palette
2517
2518 png_set_gAMA(png_ptr, info_ptr, gamma);
2519 gamma - the gamma the image was created
2520 at (PNG_INFO_gAMA)
2521
2522 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2523 srgb_intent - the rendering intent
2524 (PNG_INFO_sRGB) The presence of
2525 the sRGB chunk means that the pixel
2526 data is in the sRGB color space.
2527 This chunk also implies specific
2528 values of gAMA and cHRM. Rendering
2529 intent is the CSS-1 property that
2530 has been defined by the International
2531 Color Consortium
2532 (http://www.color.org).
2533 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002534 PNG_sRGB_INTENT_SATURATION,
2535 PNG_sRGB_INTENT_PERCEPTUAL,
2536 PNG_sRGB_INTENT_ABSOLUTE, or
2537 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002538
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002539
2540 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2541 srgb_intent);
2542 srgb_intent - the rendering intent
2543 (PNG_INFO_sRGB) The presence of the
2544 sRGB chunk means that the pixel
2545 data is in the sRGB color space.
2546 This function also causes gAMA and
2547 cHRM chunks with the specific values
2548 that are consistent with sRGB to be
2549 written.
2550
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002551 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2552 profile, proflen);
2553 name - The profile name.
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002554 compression - The compression type; always
2555 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2556 You may give NULL to this argument to
2557 ignore it.
2558 profile - International Color Consortium color
2559 profile data. May contain NULs.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002560 proflen - length of profile data in bytes.
2561
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002562 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2563 sig_bit - the number of significant bits for
2564 (PNG_INFO_sBIT) each of the gray, red,
2565 green, and blue channels, whichever are
2566 appropriate for the given color type
2567 (png_color_16)
2568
2569 png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
2570 trans_values);
2571 trans - array of transparent entries for
2572 palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05002573 trans_values - graylevel or color sample values of
2574 the single transparent color for
2575 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002576 num_trans - number of transparent entries
2577 (PNG_INFO_tRNS)
2578
2579 png_set_hIST(png_ptr, info_ptr, hist);
2580 (PNG_INFO_hIST)
2581 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002582 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002583
2584 png_set_tIME(png_ptr, info_ptr, mod_time);
2585 mod_time - time image was last modified
2586 (PNG_VALID_tIME)
2587
2588 png_set_bKGD(png_ptr, info_ptr, background);
2589 background - background color (PNG_VALID_bKGD)
2590
2591 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2592 text_ptr - array of png_text holding image
2593 comments
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002594 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002595 on "text" PNG_TEXT_COMPRESSION_NONE
2596 PNG_TEXT_COMPRESSION_zTXt
2597 PNG_ITXT_COMPRESSION_NONE
2598 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002599 text_ptr[i].key - keyword for comment. Must contain
2600 1-79 characters.
2601 text_ptr[i].text - text comments for current
2602 keyword. Can be NULL or empty.
2603 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002604 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002605 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002606 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002607 text_ptr[i].lang - language of comment (NULL or
2608 empty for unknown).
2609 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
2610 or empty for unknown).
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002611 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002612
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002613 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
2614 num_spalettes);
2615 palette_ptr - array of png_sPLT_struct structures
2616 to be added to the list of palettes
2617 in the info structure.
2618 num_spalettes - number of palette structures to be
2619 added.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002620
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002621 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2622 unit_type);
2623 offset_x - positive offset from the left
2624 edge of the screen
2625 offset_y - positive offset from the top
2626 edge of the screen
2627 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2628
2629 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2630 unit_type);
2631 res_x - pixels/unit physical resolution
2632 in x direction
2633 res_y - pixels/unit physical resolution
2634 in y direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002635 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002636 PNG_RESOLUTION_METER
2637
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002638 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002639 unit - physical scale units (an integer)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002640 width - width of a pixel in physical scale units
2641 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002642 (width and height are doubles)
2643
2644 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
2645 unit - physical scale units (an integer)
2646 width - width of a pixel in physical scale units
2647 height - height of a pixel in physical scale units
2648 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002649
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002650 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
2651 num_unknowns)
2652 unknowns - array of png_unknown_chunk
2653 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002654 unknowns[i].name - name of unknown chunk
2655 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002656 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002657 unknowns[i].location - position to write chunk in file
2658 0: do not write chunk
2659 PNG_HAVE_IHDR: before PLTE
2660 PNG_HAVE_PLTE: before IDAT
2661 PNG_AFTER_IDAT: after IDAT
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002662
2663The "location" member is set automatically according to
2664what part of the output file has already been written.
2665You can change its value after calling png_set_unknown_chunks()
2666as demonstrated in pngtest.c. Within each of the "locations",
2667the chunks are sequenced according to their position in the
2668structure (that is, the value of "i", which is the order in which
2669the chunk was either read from the input file or defined with
2670png_set_unknown_chunks).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002671
2672A quick word about text and num_text. text is an array of png_text
2673structures. num_text is the number of valid structures in the array.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002674Each png_text structure holds a language code, a keyword, a text value,
2675and a compression type.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002676
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002677The compression types have the same valid numbers as the compression
2678types of the image data. Currently, the only valid number is zero.
2679However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002680images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002681text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002682Because tEXt and zTXt chunks don't have a language field, if you
2683specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
2684any language code or translated keyword will not be written out.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002685
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002686Until text gets around 1000 bytes, it is not worth compressing it.
2687After the text has been written out to the file, the compression type
2688is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2689so that it isn't written out again at the end (in case you are calling
2690png_write_end() with the same struct.
2691
2692The keywords that are given in the PNG Specification are:
2693
2694 Title Short (one line) title or
2695 caption for image
2696 Author Name of image's creator
2697 Description Description of image (possibly long)
2698 Copyright Copyright notice
2699 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002700 (usually RFC 1123 format, see below)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002701 Software Software used to create the image
2702 Disclaimer Legal disclaimer
2703 Warning Warning of nature of content
2704 Source Device used to create the image
2705 Comment Miscellaneous comment; conversion
2706 from other image format
2707
2708The keyword-text pairs work like this. Keywords should be short
2709simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002710keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002711on keywords. You can repeat keywords in a file. You can even write
2712some text before the image and some after. For example, you may want
2713to put a description of the image before the image, but leave the
2714disclaimer until after, so viewers working over modem connections
2715don't have to wait for the disclaimer to go over the modem before
2716they start seeing the image. Finally, keywords should be full
2717words, not abbreviations. Keywords and text are in the ISO 8859-1
2718(Latin-1) character set (a superset of regular ASCII) and can not
2719contain NUL characters, and should not contain control or other
2720unprintable characters. To make the comments widely readable, stick
2721with basic ASCII, and avoid machine specific character set extensions
2722like the IBM-PC character set. The keyword must be present, but
2723you can leave off the text string on non-compressed pairs.
2724Compressed pairs must have a text string, as only the text string
2725is compressed anyway, so the compression would be meaningless.
2726
2727PNG supports modification time via the png_time structure. Two
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002728conversion routines are provided, png_convert_from_time_t() for
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002729time_t and png_convert_from_struct_tm() for struct tm. The
2730time_t routine uses gmtime(). You don't have to use either of
2731these, but if you wish to fill in the png_time structure directly,
2732you should provide the time in universal time (GMT) if possible
2733instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002734year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002735that months start with 1.
2736
2737If you want to store the time of the original image creation, you should
2738use a plain tEXt chunk with the "Creation Time" keyword. This is
2739necessary because the "creation time" of a PNG image is somewhat vague,
2740depending on whether you mean the PNG file, the time the image was
2741created in a non-PNG format, a still photo from which the image was
2742scanned, or possibly the subject matter itself. In order to facilitate
2743machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002744tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002745although this isn't a requirement. Unlike the tIME chunk, the
2746"Creation Time" tEXt chunk is not expected to be automatically changed
2747by the software. To facilitate the use of RFC 1123 dates, a function
2748png_convert_to_rfc1123(png_timep) is provided to convert from PNG
2749time to an RFC 1123 format string.
2750
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002751.SS Writing unknown chunks
2752
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002753You can use the png_set_unknown_chunks function to queue up chunks
2754for writing. You give it a chunk name, raw data, and a size; that's
2755all there is to it. The chunks will be written by the next following
2756png_write_info_before_PLTE, png_write_info, or png_write_end function.
2757Any chunks previously read into the info structure's unknown-chunk
2758list will also be written out in a sequence that satisfies the PNG
2759specification's ordering rules.
2760
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002761.SS The high-level write interface
2762
2763At this point there are two ways to proceed; through the high-level
2764write interface, or through a sequence of low-level write operations.
2765You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002766in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002767transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002768
2769 PNG_TRANSFORM_IDENTITY No transformation
2770 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002771 PNG_TRANSFORM_PACKSWAP Change order of packed
2772 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002773 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002774 PNG_TRANSFORM_SHIFT Normalize pixels to the
2775 sBIT depth
2776 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
2777 to BGRA
2778 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
2779 to AG
2780 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
2781 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002782 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
2783 PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
2784
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002785If you have valid image data in the info structure (you can use
2786png_set_rows() to put image data in the info structure), simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002787
2788 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
2789
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002790where png_transforms is an integer containing the logical OR of some set of
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002791transformation flags. This call is equivalent to png_write_info(),
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002792followed the set of transformations indicated by the transform mask,
2793then png_write_image(), and finally png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002794
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002795(The final parameter of this call is not yet used. Someday it might point
2796to transformation parameters required by some future output transform.)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002797
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05002798You must use png_transforms and not call any png_set_transform() functions
2799when you use png_write_png().
2800
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002801.SS The low-level write interface
2802
2803If you are going the low-level route instead, you are now ready to
2804write all the file information up to the actual image data. You do
2805this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002806
2807 png_write_info(png_ptr, info_ptr);
2808
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002809Note that there is one transformation you may need to do before
2810png_write_info(). In PNG files, the alpha channel in an image is the
2811level of opacity. If your data is supplied as a level of
2812transparency, you can invert the alpha channel before you write it, so
2813that 0 is fully transparent and 255 (in 8-bit or paletted images) or
281465535 (in 16-bit images) is fully opaque, with
2815
2816 png_set_invert_alpha(png_ptr);
2817
2818This must appear before png_write_info() instead of later with the
2819other transformations because in the case of paletted images the tRNS
2820chunk data has to be inverted before the tRNS chunk is written. If
2821your image is not a paletted image, the tRNS data (which in such cases
2822represents a single color to be rendered as transparent) won't need to
2823be changed, and you can safely do this transformation after your
2824png_write_info() call.
2825
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002826If you need to write a private chunk that you want to appear before
2827the PLTE chunk when PLTE is present, you can write the PNG info in
2828two steps, and insert code to write your own chunk between them:
2829
2830 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002831 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002832 png_write_info(png_ptr, info_ptr);
2833
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002834After you've written the file information, you can set up the library
2835to handle any special transformations of the image data. The various
2836ways to transform the data will be described in the order that they
2837should occur. This is important, as some of these change the color
2838type and/or bit depth of the data, and some others only work on
2839certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002840checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002841make sure to only enable a transformation if it will be valid for the
2842data. For example, don't swap red and blue on grayscale data.
2843
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002844PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002845the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002846to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
2847bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002848
2849 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
2850
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002851where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002852PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
2853is stored XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002854
2855PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2856they can, resulting in, for example, 8 pixels per byte for 1 bit files.
2857If the data is supplied at 1 pixel per byte, use this code, which will
2858correctly pack the pixels into a single byte:
2859
2860 png_set_packing(png_ptr);
2861
2862PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
2863data is of another bit depth, you can write an sBIT chunk into the
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002864file so that decoders can recover the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002865
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002866 /* Set the true bit depth of the image data */
2867 if (color_type & PNG_COLOR_MASK_COLOR)
2868 {
2869 sig_bit.red = true_bit_depth;
2870 sig_bit.green = true_bit_depth;
2871 sig_bit.blue = true_bit_depth;
2872 }
2873 else
2874 {
2875 sig_bit.gray = true_bit_depth;
2876 }
2877 if (color_type & PNG_COLOR_MASK_ALPHA)
2878 {
2879 sig_bit.alpha = true_bit_depth;
2880 }
2881
2882 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
2883
2884If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002885one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002886this will scale the values to appear to be the correct bit depth as
2887is required by PNG.
2888
2889 png_set_shift(png_ptr, &sig_bit);
2890
2891PNG files store 16 bit pixels in network byte order (big-endian,
2892ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002893supplied the other way (little-endian, i.e. least significant bits
2894first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002895
2896 if (bit_depth > 8)
2897 png_set_swap(png_ptr);
2898
2899If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2900need to change the order the pixels are packed into bytes, you can use:
2901
2902 if (bit_depth < 8)
2903 png_set_packswap(png_ptr);
2904
2905PNG files store 3 color pixels in red, green, blue order. This code
2906would be used if they are supplied as blue, green, red:
2907
2908 png_set_bgr(png_ptr);
2909
2910PNG files describe monochrome as black being zero and white being
2911one. This code would be used if the pixels are supplied with this reversed
2912(black being one and white being zero):
2913
2914 png_set_invert_mono(png_ptr);
2915
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002916Finally, you can write your own transformation function if none of
2917the existing ones meets your needs. This is done by setting a callback
2918with
2919
2920 png_set_write_user_transform_fn(png_ptr,
2921 write_transform_fn);
2922
2923You must supply the function
2924
2925 void write_transform_fn(png_ptr ptr, row_info_ptr
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002926 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002927
2928See pngtest.c for a working example. Your function will be called
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002929before any of the other transformations are processed.
2930
2931You can also set up a pointer to a user structure for use by your
2932callback function.
2933
2934 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
2935
2936The user_channels and user_depth parameters of this function are ignored
2937when writing; you can set them to zero as shown.
2938
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002939You can retrieve the pointer via the function png_get_user_transform_ptr().
2940For example:
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002941
2942 voidp write_user_transform_ptr =
2943 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002944
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002945It is possible to have libpng flush any pending output, either manually,
2946or automatically after a certain number of lines have been written. To
2947flush the output stream a single time call:
2948
2949 png_write_flush(png_ptr);
2950
2951and to have libpng flush the output stream periodically after a certain
2952number of scanlines have been written, call:
2953
2954 png_set_flush(png_ptr, nrows);
2955
2956Note that the distance between rows is from the last time png_write_flush()
2957was called, or the first row of the image if it has never been called.
2958So if you write 50 lines, and then png_set_flush 25, it will flush the
2959output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002960png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002961If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002962RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002963may be acceptable for real-time applications). Infrequent flushing will
2964only degrade the compression performance by a few percent over images
2965that do not use flushing.
2966
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002967.SS Writing the image data
2968
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002969That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002970The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002971whole image in memory, you can just call png_write_image() and libpng
2972will write the image. You will need to pass in an array of pointers to
2973each row. This function automatically handles interlacing, so you don't
2974need to call png_set_interlace_handling() or call this function multiple
2975times, or any of that other stuff necessary with png_write_rows().
2976
2977 png_write_image(png_ptr, row_pointers);
2978
2979where row_pointers is:
2980
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002981 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002982
2983You can point to void or char or whatever you use for pixels.
2984
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002985If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002986use png_write_rows() instead. If the file is not interlaced,
2987this is simple:
2988
2989 png_write_rows(png_ptr, row_pointers,
2990 number_of_rows);
2991
2992row_pointers is the same as in the png_write_image() call.
2993
2994If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002995a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002996
2997 png_bytep row_pointer = row;
2998
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002999 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003000
3001When the file is interlaced, things can get a good deal more
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003002complicated. The only currently (as of the PNG Specification
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003003version 1.2, dated July 1999) defined interlacing scheme for PNG files
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003004is the "Adam7" interlace scheme, that breaks down an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003005image into seven smaller images of varying size. libpng will build
3006these images for you, or you can do them yourself. If you want to
3007build them yourself, see the PNG specification for details of which
3008pixels to write when.
3009
3010If you don't want libpng to handle the interlacing details, just
3011use png_set_interlace_handling() and call png_write_rows() the
3012correct number of times to write all seven sub-images.
3013
3014If you want libpng to build the sub-images, call this before you start
3015writing any rows:
3016
3017 number_of_passes =
3018 png_set_interlace_handling(png_ptr);
3019
3020This will return the number of passes needed. Currently, this
3021is seven, but may change if another interlace type is added.
3022
3023Then write the complete image number_of_passes times.
3024
3025 png_write_rows(png_ptr, row_pointers,
3026 number_of_rows);
3027
3028As some of these rows are not used, and thus return immediately,
3029you may want to read about interlacing in the PNG specification,
3030and only update the rows that are actually used.
3031
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003032.SS Finishing a sequential write
3033
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003034After you are finished writing the image, you should finish writing
3035the file. If you are interested in writing comments or time, you should
3036pass an appropriately filled png_info pointer. If you are not interested,
3037you can pass NULL.
3038
3039 png_write_end(png_ptr, info_ptr);
3040
3041When you are done, you can free all memory used by libpng like this:
3042
3043 png_destroy_write_struct(&png_ptr, &info_ptr);
3044
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003045It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003046point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003047
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003048 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003049 mask - identifies data to be freed, a mask
3050 containing the logical OR of one or
3051 more of
3052 PNG_FREE_PLTE, PNG_FREE_TRNS,
3053 PNG_FREE_HIST, PNG_FREE_ICCP,
3054 PNG_FREE_PCAL, PNG_FREE_ROWS,
3055 PNG_FREE_SCAL, PNG_FREE_SPLT,
3056 PNG_FREE_TEXT, PNG_FREE_UNKN,
3057 or simply PNG_FREE_ALL
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003058 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003059 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003060
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003061This function may be safely called when the relevant storage has
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003062already been freed, or has not yet been allocated, or was allocated
3063by the user and not by libpng, and will in those
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003064cases do nothing. The "seq" parameter is ignored if only one item
3065of the selected data type, such as PLTE, is allowed. If "seq" is not
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003066-1, and multiple items are allowed for the data type identified in
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003067the mask, such as text or sPLT, only the n'th item in the structure
3068is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003069
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003070If you allocated data such as a palette that you passed
3071in to libpng with png_set_*, you must not free it until just before the call to
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003072png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003073
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003074The default behavior is only to free data that was allocated internally
3075by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003076or so that it will free data that was allocated by the user with png_malloc()
3077or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003078
3079 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003080 mask - which data elements are affected
3081 same choices as in png_free_data()
3082 freer - one of
3083 PNG_DESTROY_WILL_FREE_DATA
3084 PNG_SET_WILL_FREE_DATA
3085 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003086
3087For example, to transfer responsibility for some data from a read structure
3088to a write structure, you could use
3089
3090 png_data_freer(read_ptr, read_info_ptr,
3091 PNG_USER_WILL_FREE_DATA,
3092 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3093 png_data_freer(write_ptr, write_info_ptr,
3094 PNG_DESTROY_WILL_FREE_DATA,
3095 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3096
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003097thereby briefly reassigning responsibility for freeing to the user but
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003098immediately afterwards reassigning it once more to the write_destroy
3099function. Having done this, it would then be safe to destroy the read
3100structure and continue to use the PLTE, tRNS, and hIST data in the write
3101structure.
3102
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003103This function only affects data that has already been allocated.
3104You can call this function before calling after the png_set_*() functions
3105to control whether the user or png_destroy_*() is supposed to free the data.
3106When the user assumes responsibility for libpng-allocated data, the
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003107application must use
3108png_free() to free it, and when the user transfers responsibility to libpng
3109for data that the user has allocated, the user must have used png_malloc()
3110or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003111
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003112If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3113separately, do not transfer responsibility for freeing text_ptr to libpng,
3114because when libpng fills a png_text structure it combines these members with
3115the key member, and png_free_data() will free only text_ptr.key. Similarly,
3116if you transfer responsibility for free'ing text_ptr from libpng to your
3117application, your application must not separately free those members.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003118For a more compact example of writing a PNG image, see the file example.c.
3119
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003120.SH V. Modifying/Customizing libpng:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003121
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003122There are three issues here. The first is changing how libpng does
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003123standard things like memory allocation, input/output, and error handling.
3124The second deals with more complicated things like adding new chunks,
3125adding new transformations, and generally changing how libpng works.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003126Both of those are compile-time issues; that is, they are generally
3127determined at the time the code is written, and there is rarely a need
3128to provide the user with a means of changing them. The third is a
3129run-time issue: choosing between and/or tuning one or more alternate
3130versions of computationally intensive routines; specifically, optimized
3131assembly-language (and therefore compiler- and platform-dependent)
3132versions.
3133
3134Memory allocation, input/output, and error handling
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003135
3136All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003137goes through callbacks that are user-settable. The default routines are
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003138in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003139these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003140
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -05003141Memory allocation is done through the functions png_malloc()
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003142and png_free(). These currently just call the standard C functions. If
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003143your pointers can't access more then 64K at a time, you will want to set
3144MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
3145memory allocation on a platform will change between applications, these
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003146functions must be modified in the library at compile time. If you prefer
3147to use a different method of allocating and freeing data, you can use
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -05003148png_create_read_struct_2() or png_create_write_struct_2() to register
3149your own functions as described above.
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -05003150These functions also provide a void pointer that can be retrieved via
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003151
3152 mem_ptr=png_get_mem_ptr(png_ptr);
3153
3154Your replacement memory functions must have prototypes as follows:
3155
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003156 png_voidp malloc_fn(png_structp png_ptr,
Glenn Randers-Pehrsonae498dc2001-11-24 14:53:31 -06003157 png_size_t size);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003158 void free_fn(png_structp png_ptr, png_voidp ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003159
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003160Your malloc_fn() must return NULL in case of failure. The png_malloc()
3161function will normally call png_error() if it receives a NULL from the
3162system memory allocator or from your replacement malloc_fn().
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05003163
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003164Input/Output in libpng is done through png_read() and png_write(),
3165which currently just call fread() and fwrite(). The FILE * is stored in
3166png_struct and is initialized via png_init_io(). If you wish to change
3167the method of I/O, the library supplies callbacks that you can set
3168through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003169time, instead of calling the png_init_io() function. These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003170also provide a void pointer that can be retrieved via the function
3171png_get_io_ptr(). For example:
3172
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003173 png_set_read_fn(png_structp read_ptr,
3174 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003175
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003176 png_set_write_fn(png_structp write_ptr,
3177 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003178 png_flush_ptr output_flush_fn);
3179
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003180 voidp read_io_ptr = png_get_io_ptr(read_ptr);
3181 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003182
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003183The replacement I/O functions must have prototypes as follows:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003184
3185 void user_read_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05003186 png_bytep data, png_size_t length);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003187 void user_write_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05003188 png_bytep data, png_size_t length);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003189 void user_flush_data(png_structp png_ptr);
3190
3191Supplying NULL for the read, write, or flush functions sets them back
3192to using the default C stream functions. It is an error to read from
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003193a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003194
3195Error handling in libpng is done through png_error() and png_warning().
3196Errors handled through png_error() are fatal, meaning that png_error()
3197should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003198setjmp() and longjmp() (unless you have compiled libpng with
3199PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
3200but you could change this to do things like exit() if you should wish.
3201
3202On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003203to print a warning message, and then control returns to the calling code.
3204By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003205fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
3206(because you don't want the messages) or PNG_NO_STDIO defined (because
3207fprintf() isn't available). If you wish to change the behavior of the error
3208functions, you will need to set up your own message callbacks. These
3209functions are normally supplied at the time that the png_struct is created.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003210It is also possible to redirect errors and warnings to your own replacement
3211functions after png_create_*_struct() has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003212
3213 png_set_error_fn(png_structp png_ptr,
3214 png_voidp error_ptr, png_error_ptr error_fn,
3215 png_error_ptr warning_fn);
3216
3217 png_voidp error_ptr = png_get_error_ptr(png_ptr);
3218
3219If NULL is supplied for either error_fn or warning_fn, then the libpng
3220default function will be used, calling fprintf() and/or longjmp() if a
3221problem is encountered. The replacement error functions should have
3222parameters as follows:
3223
3224 void user_error_fn(png_structp png_ptr,
3225 png_const_charp error_msg);
3226 void user_warning_fn(png_structp png_ptr,
3227 png_const_charp warning_msg);
3228
3229The motivation behind using setjmp() and longjmp() is the C++ throw and
3230catch exception handling methods. This makes the code much easier to write,
3231as there is no need to check every return code of every function call.
3232However, there are some uncertainties about the status of local variables
3233after a longjmp, so the user may want to be careful about doing anything after
3234setjmp returns non-zero besides returning itself. Consult your compiler
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003235documentation for more details. For an alternative approach, you may wish
3236to use the "cexcept" facility (see http://cexcept.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003237
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003238.SS Custom chunks
3239
3240If you need to read or write custom chunks, you may need to get deeper
3241into the libpng code. The library now has mechanisms for storing
3242and writing chunks of unknown type; you can even declare callbacks
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003243for custom chunks. However, this may not be good enough if the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003244library code itself needs to know about interactions between your
3245chunk and existing `intrinsic' chunks.
3246
3247If you need to write a new intrinsic chunk, first read the PNG
3248specification. Acquire a first level of
3249understanding of how it works. Pay particular attention to the
3250sections that describe chunk names, and look at how other chunks were
3251designed, so you can do things similarly. Second, check out the
3252sections of libpng that read and write chunks. Try to find a chunk
3253that is similar to yours and use it as a template. More details can
3254be found in the comments inside the code. It is best to handle unknown
3255chunks in a generic method, via callback functions, instead of by
3256modifying libpng functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003257
3258If you wish to write your own transformation for the data, look through
3259the part of the code that does the transformations, and check out some of
3260the simpler ones to get an idea of how they work. Try to find a similar
3261transformation to the one you want to add and copy off of it. More details
3262can be found in the comments inside the code itself.
3263
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003264.SS Configuring for 16 bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003265
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003266You will want to look into zconf.h to tell zlib (and thus libpng) that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003267it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003268won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003269
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003270.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003271
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003272For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003273have to limit zlib's memory usage via a png_set_compression_mem_level()
3274call. See zlib.h or zconf.h in the zlib library for more information.
3275
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003276.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003277
3278Libpng's support for medium model has been tested on most of the popular
3279compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
3280defined, and FAR gets defined to far in pngconf.h, and you should be
3281all set. Everything in the library (except for zlib's structure) is
3282expecting far data. You must use the typedefs with the p or pp on
3283the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003284note that the rows of data are defined as png_bytepp, which is an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003285unsigned char far * far *.
3286
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003287.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003288
3289You will need to write new error and warning functions that use the GUI
3290interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003291warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003292in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003293They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003294you may also have to change the memory allocators (png_malloc, etc.).
3295
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003296.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003297
3298All includes for libpng are in pngconf.h. If you need to add/change/delete
3299an include, this is the place to do it. The includes that are not
3300needed outside libpng are protected by the PNG_INTERNAL definition,
3301which is only defined for those routines inside libpng itself. The
3302files in libpng proper only include png.h, which includes pngconf.h.
3303
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003304.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003305
3306There are special functions to configure the compression. Perhaps the
3307most useful one changes the compression level, which currently uses
3308input compression values in the range 0 - 9. The library normally
3309uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
3310have shown that for a large majority of images, compression values in
3311the range 3-6 compress nearly as well as higher levels, and do so much
3312faster. For online applications it may be desirable to have maximum speed
3313(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
3314specify no compression (Z_NO_COMPRESSION = 0), but this would create
3315files larger than just storing the raw bitmap. You can specify the
3316compression level by calling:
3317
3318 png_set_compression_level(png_ptr, level);
3319
3320Another useful one is to reduce the memory level used by the library.
3321The memory level defaults to 8, but it can be lowered if you are
3322short on memory (running DOS, for example, where you only have 640K).
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003323Note that the memory level does have an effect on compression; among
3324other things, lower levels will result in sections of incompressible
3325data being emitted in smaller stored blocks, with a correspondingly
3326larger relative overhead of up to 15% in the worst case.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003327
3328 png_set_compression_mem_level(png_ptr, level);
3329
3330The other functions are for configuring zlib. They are not recommended
3331for normal use and may result in writing an invalid PNG file. See
3332zlib.h for more information on what these mean.
3333
3334 png_set_compression_strategy(png_ptr,
3335 strategy);
3336 png_set_compression_window_bits(png_ptr,
3337 window_bits);
3338 png_set_compression_method(png_ptr, method);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003339 png_set_compression_buffer_size(png_ptr, size);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003340
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003341.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003342
3343If you want to control whether libpng uses filtering or not, which
3344filters are used, and how it goes about picking row filters, you
3345can call one of these functions. The selection and configuration
3346of row filters can have a significant impact on the size and
3347encoding speed and a somewhat lesser impact on the decoding speed
3348of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003349images (with and without alpha), but not for paletted images nor
3350for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003351
3352The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003353currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003354parameter sets which filter(s), if any, should be used for each
3355scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
3356to turn filtering on and off, respectively.
3357
3358Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3359PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003360ORed together with '|' to specify one or more filters to use.
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003361These filters are described in more detail in the PNG specification.
3362If you intend to change the filter type during the course of writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003363the image, you should start with flags set for all of the filters
3364you intend to use so that libpng can initialize its internal
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003365structures appropriately for all of the filter types. (Note that this
3366means the first row must always be adaptively filtered, because libpng
3367currently does not allocate the filter buffers until png_write_row()
3368is called for the first time.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003369
3370 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003371 PNG_FILTER_UP | PNG_FILTER_AVE |
3372 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003373
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003374 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3375 filters);
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003376 The second parameter can also be
3377 PNG_INTRAPIXEL_DIFFERENCING if you are
3378 writing a PNG to be embedded in a MNG
3379 datastream. This parameter must be the
3380 same as the value of filter_method used
3381 in png_set_IHDR().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003382
3383It is also possible to influence how libpng chooses from among the
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003384available filters. This is done in one or both of two ways - by
3385telling it how important it is to keep the same filter for successive
3386rows, and by telling it the relative computational costs of the filters.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003387
3388 double weights[3] = {1.5, 1.3, 1.1},
3389 costs[PNG_FILTER_VALUE_LAST] =
3390 {1.0, 1.3, 1.3, 1.5, 1.7};
3391
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003392 png_set_filter_heuristics(png_ptr,
3393 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003394 weights, costs);
3395
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003396The weights are multiplying factors that indicate to libpng that the
3397row filter should be the same for successive rows unless another row filter
3398is that many times better than the previous filter. In the above example,
3399if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003400"sum of absolute differences" 1.5 x 1.3 times higher than other filters
3401and still be chosen, while the NONE filter could have a sum 1.1 times
3402higher than other filters and still be chosen. Unspecified weights are
3403taken to be 1.0, and the specified weights should probably be declining
3404like those above in order to emphasize recent filters over older filters.
3405
3406The filter costs specify for each filter type a relative decoding cost
3407to be considered when selecting row filters. This means that filters
3408with higher costs are less likely to be chosen over filters with lower
3409costs, unless their "sum of absolute differences" is that much smaller.
3410The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003411the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003412size.
3413
3414Note that the numbers above were invented purely for this example and
3415are given only to help explain the function usage. Little testing has
3416been done to find optimum values for either the costs or the weights.
3417
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003418.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003419
3420There are a bunch of #define's in pngconf.h that control what parts of
3421libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003422never going to use a capability, you can change the #define to #undef
3423before recompiling libpng and save yourself code and data space, or
3424you can turn off individual capabilities with defines that begin with
3425PNG_NO_.
3426
3427You can also turn all of the transforms and ancillary chunk capabilities
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003428off en masse with compiler directives that define
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003429PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3430or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003431along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003432want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003433the extra transformations but still leave the library fully capable of reading
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003434and writing PNG files with all known public chunks
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003435Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003436produces a library that is incapable of reading or writing ancillary chunks.
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003437If you are not using the progressive reading capability, you can
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003438turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003439this with the INTERLACING capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003440
3441All the reading and writing specific code are in separate files, so the
3442linker should only grab the files it needs. However, if you want to
3443make sure, or if you are building a stand alone library, all the
3444reading files start with pngr and all the writing files start with
3445pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
3446are used for both reading and writing, and always need to be included.
3447The progressive reader is in pngpread.c
3448
3449If you are creating or distributing a dynamically linked library (a .so
3450or DLL file), you should not remove or disable any parts of the library,
3451as this will cause applications linked with different versions of the
3452library to fail if they call functions not available in your library.
3453The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003454those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003455
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003456.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003457
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003458The macro definition PNG_DEBUG can be used to request debugging
3459printout. Set it to an integer value in the range 0 to 3. Higher
3460numbers result in increasing amounts of debugging information. The
3461information is printed to the "stderr" file, unless another file
3462name is specified in the PNG_DEBUG_FILE macro definition.
3463
3464When PNG_DEBUG > 0, the following functions (macros) become available:
3465
3466 png_debug(level, message)
3467 png_debug1(level, message, p1)
3468 png_debug2(level, message, p1, p2)
3469
3470in which "level" is compared to PNG_DEBUG to decide whether to print
3471the message, "message" is the formatted string to be printed,
3472and p1 and p2 are parameters that are to be embedded in the string
3473according to printf-style formatting directives. For example,
3474
3475 png_debug1(2, "foo=%d\n", foo);
3476
3477is expanded to
3478
3479 if(PNG_DEBUG > 2)
3480 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
3481
3482When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3483can still use PNG_DEBUG to control your own debugging:
3484
3485 #ifdef PNG_DEBUG
3486 fprintf(stderr, ...
3487 #endif
3488
3489When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3490having level = 0 will be printed. There aren't any such statements in
3491this version of libpng, but if you insert some they will be printed.
3492
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003493.SH VI. Runtime optimization
3494
3495A new feature in libpng 1.2.0 is the ability to dynamically switch between
3496standard and optimized versions of some routines. Currently these are
3497limited to three computationally intensive tasks when reading PNG files:
3498decoding row filters, expanding interlacing, and combining interlaced or
3499transparent row data with previous row data. Currently the optimized
3500versions are available only for x86 (Intel, AMD, etc.) platforms with
3501MMX support, though this may change in future versions. (For example,
3502the non-MMX assembler optimizations for zlib might become similarly
3503runtime-selectable in future releases, in which case libpng could be
3504extended to support them. Alternatively, the compile-time choice of
3505floating-point versus integer routines for gamma correction might become
3506runtime-selectable.)
3507
3508Because such optimizations tend to be very platform- and compiler-dependent,
3509both in how they are written and in how they perform, the new runtime code
3510in libpng has been written to allow programs to query, enable, and disable
3511either specific optimizations or all such optimizations. For example, to
3512enable all possible optimizations (bearing in mind that some "optimizations"
3513may actually run more slowly in rare cases):
3514
3515 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3516 png_uint_32 mask, flags;
3517
3518 flags = png_get_asm_flags(png_ptr);
3519 mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
3520 png_set_asm_flags(png_ptr, flags | mask);
3521 #endif
3522
3523To enable only optimizations relevant to reading PNGs, use PNG_SELECT_READ
3524by itself when calling png_get_asm_flagmask(); similarly for optimizing
3525only writing. To disable all optimizations:
3526
3527 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3528 flags = png_get_asm_flags(png_ptr);
3529 mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
3530 png_set_asm_flags(png_ptr, flags & ~mask);
3531 #endif
3532
3533To enable or disable only MMX-related features, use png_get_mmx_flagmask()
3534in place of png_get_asm_flagmask(). The mmx version takes one additional
3535parameter:
3536
3537 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3538 int selection = PNG_SELECT_READ | PNG_SELECT_WRITE;
3539 int compilerID;
3540
3541 mask = png_get_mmx_flagmask(selection, &compilerID);
3542 #endif
3543
3544On return, compilerID will indicate which version of the MMX assembler
3545optimizations was compiled. Currently two flavors exist: Microsoft
3546Visual C++ (compilerID == 1) and GNU C (a.k.a. gcc/gas, compilerID == 2).
3547On non-x86 platforms or on systems compiled without MMX optimizations, a
3548value of -1 is used.
3549
3550Note that both png_get_asm_flagmask() and png_get_mmx_flagmask() return
3551all valid, settable optimization bits for the version of the library that's
3552currently in use. In the case of shared (dynamically linked) libraries,
3553this may include optimizations that did not exist at the time the code was
3554written and compiled. It is also possible, of course, to enable only known,
3555specific optimizations; for example:
3556
3557 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3558 flags = PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
3559 | PNG_ASM_FLAG_MMX_READ_INTERLACE \
3560 | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
3561 | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
3562 | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
3563 | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
3564 png_set_asm_flags(png_ptr, flags);
3565 #endif
3566
3567This method would enable only the MMX read-optimizations available at the
3568time of libpng 1.2.0's release, regardless of whether a later version of
3569the DLL were actually being used. (Also note that these functions did not
3570exist in versions older than 1.2.0, so any attempt to run a dynamically
3571linked app on such an older version would fail.)
3572
3573To determine whether the processor supports MMX instructions at all, use
3574the png_mmx_support() function:
3575
3576 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3577 mmxsupport = png_mmx_support();
3578 #endif
3579
3580It returns -1 if MMX support is not compiled into libpng, 0 if MMX code
3581is compiled but MMX is not supported by the processor, or 1 if MMX support
3582is fully available. Note that png_mmx_support(), png_get_mmx_flagmask(),
3583and png_get_asm_flagmask() all may be called without allocating and ini-
3584tializing any PNG structures (for example, as part of a usage screen or
3585"about" box).
3586
3587The following code can be used to prevent an application from using the
3588thread_unsafe features, even if libpng was built with PNG_THREAD_UNSAFE_OK
3589defined:
3590
3591#if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) \
3592 && defined(PNG_THREAD_UNSAFE_OK)
3593 /* Disable thread-unsafe features of pnggccrd */
3594 if (png_access_version() >= 10200)
3595 {
3596 png_uint_32 mmx_disable_mask = 0;
3597 png_uint_32 asm_flags;
3598
3599 mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
3600 | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
3601 | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
3602 | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
3603 asm_flags = png_get_asm_flags(png_ptr);
3604 png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);
3605 }
3606#endif
3607
3608For more extensive examples of runtime querying, enabling and disabling
3609of optimized features, see contrib/gregbook/readpng2.c in the libpng
3610source-code distribution.
3611
3612.SH VII. MNG support
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003613
3614The MNG specification (available at http://www.libpng.org/pub/mng) allows
3615certain extensions to PNG for PNG images that are embedded in MNG datastreams.
3616Libpng can support some of these extensions. To enable them, use the
3617png_permit_mng_features() function:
3618
3619 feature_set = png_permit_mng_features(png_ptr, mask)
3620 mask is a png_uint_32 containing the logical OR of the
3621 features you want to enable. These include
3622 PNG_FLAG_MNG_EMPTY_PLTE
3623 PNG_FLAG_MNG_FILTER_64
3624 PNG_ALL_MNG_FEATURES
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05003625 feature_set is a png_uint_32 that is the logical AND of
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003626 your mask with the set of MNG features that is
3627 supported by the version of libpng that you are using.
3628
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003629It is an error to use this function when reading or writing a standalone
3630PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
Glenn Randers-Pehrsonf05f8032000-12-23 14:27:39 -06003631in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
3632and the MHDR and MEND chunks. Libpng does not provide support for these
3633or any other MNG chunks; your application must provide its own support for
3634them. You may wish to consider using libmng (available at
3635http://www.libmng.com) instead.
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003636
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003637.SH VIII. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003638
3639It should be noted that versions of libpng later than 0.96 are not
3640distributed by the original libpng author, Guy Schalnat, nor by
3641Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3642distributed versions 0.89 through 0.96, but rather by another member
3643of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3644still alive and well, but they have moved on to other things.
3645
3646The old libpng functions png_read_init(), png_write_init(),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05003647png_info_init(), png_read_destroy(), and png_write_destroy() have been
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05003648moved to PNG_INTERNAL in version 0.95 to discourage their use. These
3649functions will be removed from libpng version 2.0.0.
3650
3651The preferred method of creating and initializing the libpng structures is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003652via the png_create_read_struct(), png_create_write_struct(), and
3653png_create_info_struct() because they isolate the size of the structures
3654from the application, allow version error checking, and also allow the
3655use of custom error handling routines during the initialization, which
3656the old functions do not. The functions png_read_destroy() and
3657png_write_destroy() do not actually free the memory that libpng
3658allocated for these structs, but just reset the data structures, so they
3659can be used instead of png_destroy_read_struct() and
3660png_destroy_write_struct() if you feel there is too much system overhead
3661allocating and freeing the png_struct for each image read.
3662
3663Setting the error callbacks via png_set_message_fn() before
3664png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003665because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003666to fail if the png_ptr was not initialized to zero. It is still possible
3667to set the error callbacks AFTER png_read_init(), or to change them with
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05003668png_set_error_fn(), which is essentially the same function, but with a new
3669name to force compilation errors with applications that try to use the old
3670method.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003671
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003672Starting with version 1.0.7, you can find out which version of the library
3673you are using at run-time:
3674
3675 png_uint_32 libpng_vn = png_access_version_number();
3676
3677The number libpng_vn is constructed from the major version, minor
3678version with leading zero, and release number with leading zero,
3679(e.g., libpng_vn for version 1.0.7 is 10007).
3680
3681You can also check which version of png.h you used when compiling your
3682application:
3683
3684 png_uint_32 application_vn = PNG_LIBPNG_VER;
3685
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003686.SH IX. Y2K Compliance in libpng
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003687
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003688February 21, 2006
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003689
3690Since the PNG Development group is an ad-hoc body, we can't make
3691an official declaration.
3692
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003693This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003694upward through 1.2.9beta1 are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003695versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003696
3697Libpng only has three year fields. One is a 2-byte unsigned integer that
3698will hold years up to 65535. The other two hold the date in text
3699format, and will hold years up to 9999.
3700
3701The integer is
3702 "png_uint_16 year" in png_time_struct.
3703
3704The strings are
3705 "png_charp time_buffer" in png_struct and
3706 "near_time_buffer", which is a local character string in png.c.
3707
3708There are seven time-related functions:
3709
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003710 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003711 (formerly png_convert_to_rfc_1152() in error)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003712 png_convert_from_struct_tm() in pngwrite.c, called
3713 in pngwrite.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003714 png_convert_from_time_t() in pngwrite.c
3715 png_get_tIME() in pngget.c
3716 png_handle_tIME() in pngrutil.c, called in pngread.c
3717 png_set_tIME() in pngset.c
3718 png_write_tIME() in pngwutil.c, called in pngwrite.c
3719
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003720All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003721png_convert_from_time_t() function calls gmtime() to convert from system
3722clock time, which returns (year - 1900), which we properly convert to
3723the full 4-digit year. There is a possibility that applications using
3724libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003725function, or that they are incorrectly passing only a 2-digit year
3726instead of "year - 1900" into the png_convert_from_struct_tm() function,
3727but this is not under our control. The libpng documentation has always
3728stated that it works with 4-digit years, and the APIs have been
3729documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003730
3731The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
3732integer to hold the year, and can hold years as large as 65535.
3733
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003734zlib, upon which libpng depends, is also Y2K compliant. It contains
3735no date-related code.
3736
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003737
3738 Glenn Randers-Pehrson
3739 libpng maintainer
3740 PNG Development Group
3741
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003742.SH NOTE
3743
3744Note about libpng version numbers:
3745
3746Due to various miscommunications, unforeseen code incompatibilities
3747and occasional factors outside the authors' control, version numbering
3748on the library has not always been consistent and straightforward.
3749The following table summarizes matters since version 0.89c, which was
3750the first widely used release:
3751
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003752 source png.h png.h shared-lib
3753 version string int version
3754 ------- ------ ----- ----------
3755 0.89c ("beta 3") 0.89 89 1.0.89
3756 0.90 ("beta 4") 0.90 90 0.90
3757 0.95 ("beta 5") 0.95 95 0.95
3758 0.96 ("beta 6") 0.96 96 0.96
3759 0.97b ("beta 7") 1.00.97 97 1.0.1
3760 0.97c 0.97 97 2.0.97
3761 0.98 0.98 98 2.0.98
3762 0.99 0.99 98 2.0.99
3763 0.99a-m 0.99 99 2.0.99
3764 1.00 1.00 100 2.1.0
3765 1.0.0 1.0.0 100 2.1.0
3766 1.0.0 (from here on, the 100 2.1.0
3767 1.0.1 png.h string is 10001 2.1.0
3768 1.0.1a-e identical to the 10002 from here on, the
3769 1.0.2 source version) 10002 shared library is 2.V
3770 1.0.2a-b 10003 where V is the source
3771 1.0.1 10001 code version except as
3772 1.0.1a-e 10002 2.1.0.1a-e noted.
3773 1.0.2 10002 2.1.0.2
3774 1.0.2a-b 10003 2.1.0.2a-b
3775 1.0.3 10003 2.1.0.3
3776 1.0.3a-d 10004 2.1.0.3a-d
3777 1.0.4 10004 2.1.0.4
3778 1.0.4a-f 10005 2.1.0.4a-f
3779 1.0.5 (+ 2 patches) 10005 2.1.0.5
3780 1.0.5a-d 10006 2.1.0.5a-d
3781 1.0.5e-r 10100 2.1.0.5e-r
3782 1.0.5s-v 10006 2.1.0.5s-v
3783 1.0.6 (+ 3 patches) 10006 2.1.0.6
3784 1.0.6d-g 10007 2.1.0.6d-g
3785 1.0.6h 10007 10.6h
3786 1.0.6i 10007 10.6i
3787 1.0.6j 10007 2.1.0.6j
3788 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
3789 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
3790 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
3791 1.0.7 1 10007 2.1.0.7
3792 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
3793 1.0.8rc1 1 10008 2.1.0.8rc1
3794 1.0.8 1 10008 2.1.0.8
3795 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
3796 1.0.9rc1 1 10009 2.1.0.9rc1
3797 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
3798 1.0.9rc2 1 10009 2.1.0.9rc2
3799 1.0.9 1 10009 2.1.0.9
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06003800 1.0.10beta1 1 10010 2.1.0.10beta1
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003801 1.0.10rc1 1 10010 2.1.0.10rc1
Glenn Randers-Pehrson13cfbac2001-03-30 06:42:28 -06003802 1.0.10 1 10010 2.1.0.10
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -05003803 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05003804 1.0.11rc1 1 10011 2.1.0.11rc1
Glenn Randers-Pehrson32835392001-04-27 08:29:32 -05003805 1.0.11 1 10011 2.1.0.11
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05003806 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
3807 1.0.12rc1 2 10012 2.1.0.12rc1
3808 1.0.12 2 10012 2.1.0.12
3809 1.1.0a-f - 10100 2.1.1.0a-f abandoned
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05003810 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
Glenn Randers-Pehrson5a0be342001-10-18 20:55:13 -05003811 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
3812 1.2.0rc1 3 10200 3.1.2.0rc1
3813 1.2.0 3 10200 3.1.2.0
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -06003814 1.2.1beta-4 3 10201 3.1.2.1beta1-4
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -06003815 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
3816 1.2.1 3 10201 3.1.2.1
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -06003817 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
Glenn Randers-Pehrsonfcbd7872002-04-07 16:35:38 -05003818 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
3819 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
3820 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003821 1.0.13 10 10013 10.so.0.1.0.13
3822 1.2.2 12 10202 12.so.0.1.2.2
Glenn Randers-Pehrson22f28962002-05-13 18:17:09 -05003823 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
3824 1.2.3 12 10203 12.so.0.1.2.3
Glenn Randers-Pehrsond020e9d2002-06-28 09:34:00 -05003825 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -05003826 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
Glenn Randers-Pehrson484a8a12002-07-07 19:15:20 -05003827 1.0.14 10 10014 10.so.0.1.0.14
3828 1.2.4 13 10204 12.so.0.1.2.4
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05003829 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
3830 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003831 1.0.15 10 10015 10.so.0.1.0.15
3832 1.2.5 13 10205 12.so.0.1.2.5
3833 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
Glenn Randers-Pehrson37f116a2004-08-15 07:15:39 -05003834 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
3835 1.0.16 10 10016 10.so.0.1.0.16
3836 1.2.6 13 10206 12.so.0.1.2.6
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003837 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05003838 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
3839 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
Glenn Randers-Pehrson250dfe12004-09-11 21:19:54 -05003840 1.0.17 10 10017 12.so.0.1.0.17
3841 1.2.7 13 10207 12.so.0.1.2.7
Glenn Randers-Pehrson40936072004-11-20 11:18:40 -06003842 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
Glenn Randers-Pehrson584b96e2004-11-29 15:08:00 -06003843 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
3844 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06003845 1.0.18 10 10018 12.so.0.1.0.18
3846 1.2.8 13 10208 12.so.0.1.2.8
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003847 1.3.0beta1 14 10300 13.so.0.1.3.0beta1
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003848
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003849Henceforth the source version will match the shared-library minor
3850and patch numbers; the shared-library major version number will be
3851used for changes in backward compatibility, as it is intended. The
3852PNG_PNGLIB_VER macro, which is not used within libpng but is available
3853for applications, is an unsigned integer of the form xyyzz corresponding
3854to the source version x.y.z (leading zeros in y and z). Beta versions
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06003855were given the previous public release number plus a letter, until
3856version 1.0.6j; from then on they were given the upcoming public
3857release number plus "betaNN" or "rcN".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003858
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003859.SH "SEE ALSO"
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003860libpngpf(3), png(5)
3861.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003862.IR libpng :
3863.IP
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05003864http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06003865http://www.libpng.org/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003866
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003867.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003868.IR zlib :
3869.IP
3870(generally) at the same location as
3871.I libpng
3872or at
3873.br
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06003874ftp://ftp.info-zip.org/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003875
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003876.LP
3877.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003878.IP
3879(generally) at the same location as
3880.I libpng
3881or at
3882.br
3883ftp://ds.internic.net/rfc/rfc2083.txt
3884.br
3885or (as a W3C Recommendation) at
3886.br
3887http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003888
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003889.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003890In the case of any inconsistency between the PNG specification
3891and this library, the specification takes precedence.
3892
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003893.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003894This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06003895<glennrp at users.sourceforge.net>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003896
3897The contributing authors would like to thank all those who helped
3898with testing, bug fixes, and patience. This wouldn't have been
3899possible without all of you.
3900
3901Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003902
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003903Libpng version 1.2.9beta1 - February 21, 2006:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003904Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06003905Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003906
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003907Supported by the PNG development group
3908.br
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003909png-mng-implement at lists.sf.net
3910(subscription required; visit
3911png-implement at ccrc.wustl.edu (subscription required; visit
3912https://lists.sourceforge.net/lists/listinfo/png-mng-implement
3913to subscribe).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003914
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003915.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003916
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06003917(This copy of the libpng notices is provided for your convenience. In case of
3918any discrepancy between this copy and the notices in the file png.h that is
3919included in the libpng distribution, the latter shall prevail.)
3920
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003921If you modify libpng you may insert additional notices immediately following
3922this sentence.
3923
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003924libpng versions 1.2.6, August 15, 2004, through 1.2.9beta1, February 21, 2006, are
3925Copyright (c) 2005 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003926distributed according to the same disclaimer and license as libpng-1.2.5
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05003927with the following individual added to the list of Contributing Authors
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003928
3929 Cosmin Truta
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003930
3931libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06003932Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson32fc5ce2000-07-24 06:34:14 -05003933distributed according to the same disclaimer and license as libpng-1.0.6
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003934with the following individuals added to the list of Contributing Authors
3935
3936 Simon-Pierre Cadieux
3937 Eric S. Raymond
3938 Gilles Vollant
3939
3940and with the following additions to the disclaimer:
3941
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003942 There is no warranty against interference with your
3943 enjoyment of the library or against infringement.
3944 There is no warranty that our efforts or the library
3945 will fulfill any of your particular purposes or needs.
3946 This library is provided with all faults, and the entire
3947 risk of satisfactory quality, performance, accuracy, and
3948 effort is with the user.
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003949
3950libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
3951Copyright (c) 1998, 1999 Glenn Randers-Pehrson
3952Distributed according to the same disclaimer and license as libpng-0.96,
3953with the following individuals added to the list of Contributing Authors:
3954
3955 Tom Lane
3956 Glenn Randers-Pehrson
3957 Willem van Schaik
3958
3959libpng versions 0.89, June 1996, through 0.96, May 1997, are
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05003960Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003961Distributed according to the same disclaimer and license as libpng-0.88,
3962with the following individuals added to the list of Contributing Authors:
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003963
3964 John Bowler
3965 Kevin Bracey
3966 Sam Bushell
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003967 Magnus Holmgren
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003968 Greg Roelofs
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003969 Tom Tanner
3970
3971libpng versions 0.5, May 1995, through 0.88, January 1996, are
3972Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
3973
3974For the purposes of this copyright and license, "Contributing Authors"
3975is defined as the following set of individuals:
3976
3977 Andreas Dilger
3978 Dave Martindale
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003979 Guy Eric Schalnat
3980 Paul Schmidt
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003981 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06003982
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003983The PNG Reference Library is supplied "AS IS". The Contributing Authors
3984and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003985including, without limitation, the warranties of merchantability and of
3986fitness for any purpose. The Contributing Authors and Group 42, Inc.
3987assume no liability for direct, indirect, incidental, special, exemplary,
3988or consequential damages, which may result from the use of the PNG
3989Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003990
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003991Permission is hereby granted to use, copy, modify, and distribute this
3992source code, or portions hereof, for any purpose, without fee, subject
3993to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003994
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -050039951. The origin of this source code must not be misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003996
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060039972. Altered versions must be plainly marked as such and
3998 must not be misrepresented as being the original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003999
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060040003. This Copyright notice may not be removed or altered from
4001 any source or altered source distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004002
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004003The Contributing Authors and Group 42, Inc. specifically permit, without
4004fee, and encourage the use of this source code as a component to
4005supporting the PNG file format in commercial products. If you use this
4006source code in a product, acknowledgment is not required but would be
4007appreciated.
4008
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004009
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004010A "png_get_copyright" function is available, for convenient use in "about"
4011boxes and the like:
4012
4013 printf("%s",png_get_copyright(NULL));
4014
4015Also, the PNG logo (in PNG format, of course) is supplied in the
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -05004016files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004017
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004018Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004019certification mark of the Open Source Initiative.
4020
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004021Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06004022glennrp at users.sourceforge.net
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06004023February 21, 2006
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004024
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004025.\" end of man page
4026