blob: e6c7c6fb48cea51837a2df4581a91d6790bb69b8 [file] [log] [blame]
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05001.TH LIBPNG 3 "April 10, 2000"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6e
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-Pehrson4393a9a1999-09-17 12:27:26 -050011\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060012
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050013\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060014
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050015\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 -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_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\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_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 -060024
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050025\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050026
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050027\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 -060028
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050029\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060030
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050031\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 -060032
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050033\fI\fB
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060034
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050035\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060036
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050037\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060038
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050039\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
40
41\fI\fB
42
43\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
44
45\fI\fB
46
47\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
48
49\fI\fB
50
51\fBpng_structp png_create_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
52
53\fI\fB
54
55\fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP
56
57\fI\fB
58
59\fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP
60
61\fI\fB
62
63\fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP
64
65\fI\fB
66
67\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
68
69\fI\fB
70
71\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
72
73\fI\fB
74
75\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
76
77\fI\fB
78
79\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
80
81\fI\fB
82
83\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
84
85\fI\fB
86
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060087\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
88
89\fI\fB
90
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050091\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
92
93\fI\fB
94
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060095\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 -060096
97\fI\fB
98
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050099\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
100
101\fI\fB
102
103\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
104
105\fI\fB
106
107\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
108
109\fI\fB
110
111\fBpng_uint_32 png_get_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
112
113\fI\fB
114
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600115\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
116
117\fI\fB
118
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500119\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
120
121\fI\fB
122
123\fBpng_byte png_get_compression_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_copyright (png_structp \fIpng_ptr\fP\fB);\fP
128
129\fI\fB
130
131\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
132
133\fI\fB
134
135\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
136
137\fI\fB
138
139\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
140
141\fI\fB
142
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600143\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
144
145\fI\fB
146
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600147\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
148
149\fI\fB
150
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500151\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
152
153\fI\fB
154
155\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
156
157\fI\fB
158
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600159\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 -0600160
161\fI\fB
162
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500163\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
164
165\fI\fB
166
167\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
168
169\fI\fB
170
171\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
172
173\fI\fB
174
175\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
176
177\fI\fB
178
179\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
180
181\fI\fB
182
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600183\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
184
185\fI\fB
186
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500187\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
188
189\fI\fB
190
191\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
192
193\fI\fB
194
195\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
196
197\fI\fB
198
199\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
200
201\fI\fB
202
203\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
204
205\fI\fB
206
207\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
208
209\fI\fB
210
211\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
212
213\fI\fB
214
215\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
216
217\fI\fB
218
219\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
220
221\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
222
223\fI\fB
224
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600225\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
226
227\fI\fB
228
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500229\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
230
231\fI\fB
232
233\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
234
235\fI\fB
236
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600237\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fI*splt_ptr\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600238
239\fI\fB
240
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500241\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
242
243\fI\fB
244
245\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
246
247\fI\fB
248
249\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
250
251\fI\fB
252
253\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
254
255\fI\fB
256
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600257\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
258
259\fI\fB
260
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600261\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
262
263\fI\fB
264
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500265\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
266
267\fI\fB
268
269\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
270
271\fI\fB
272
273\fBpng_uint_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
274
275\fI\fB
276
277\fBpng_uint_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
278
279\fI\fB
280
281\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
282
283\fI\fB
284
285\fBpng_uint_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
286
287\fI\fB
288
289\fBpng_uint_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
290
291\fI\fB
292
293\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
294
295\fI\fB
296
297\fBvoid png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP
298
299\fI\fB
300
301\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
302
303\fI\fB
304
305\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
306
307\fI\fB
308
309\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
310
311\fI\fB
312
313\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
314
315\fI\fB
316
317\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
318
319\fI\fB
320
321\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
322
323\fI\fB
324
325\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
326
327\fI\fB
328
329\fBvoid png_permit_empty_plte (png_structp \fP\fIpng_ptr\fP\fB, int \fIempty_plte_permitted\fP\fB);\fP
330
331\fI\fB
332
333\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
334
335\fI\fB
336
337\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
338
339\fI\fB
340
341\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
342
343\fI\fB
344
345\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
346
347\fI\fB
348
349\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
350
351\fI\fB
352
353\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
354
355\fI\fB
356
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600357\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, voidp \fIparams\fP\fB);\fP
358
359\fI\fB
360
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500361\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
362
363\fI\fB
364
365\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
366
367\fI\fB
368
369\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
370
371\fI\fB
372
373\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
374
375\fI\fB
376
377\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
378
379\fI\fB
380
381\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
382
383\fI\fB
384
385\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
386
387\fI\fB
388
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600389\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
390
391\fI\fB
392
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500393\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
394
395\fI\fB
396
397\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
398
399\fI\fB
400
401\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
402
403\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600404
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500405\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 -0600406
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500407\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600408
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500409\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 -0600410
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500411\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500412
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500413\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 -0600414
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500415\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600416
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500417\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 -0600418
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500419\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600420
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500421\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 -0600422
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500423\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600424
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500425\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600426
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500427\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600428
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500429\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 -0600430
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500431\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600432
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500433\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 -0600434
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500435\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600436
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500437\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 -0500438
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500439\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600440
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500441\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600442
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500443\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600444
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500445\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 -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_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 -0600450
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500451\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600452
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600453\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
454
455\fI\fB
456
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500457\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\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_gray_to_rgb (png_structp \fIpng_ptr\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_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 -0600466
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500467\fI\fB
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600468
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600469\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 -0600470
471\fI\fB
472
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500473\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -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_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600478
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_invert_mono (png_structp \fIpng_ptr\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_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 -0600486
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500487\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600488
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600489\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 -0600490
491\fI\fB
492
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500493\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 -0600494
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500495\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600496
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500497\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 -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_packing (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_packswap (png_structp \fIpng_ptr\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-Pehrsona357b991998-02-08 20:56:40 -0600508
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500509\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600510
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500511\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500512
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500513\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 -0600514
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500515\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600516
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500517\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 -0600518
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500519\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600520
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500521\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 -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_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 -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_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 -0600530
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500531\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600532
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500533\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 -0600534
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500535\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600536
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500537\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 -0600538
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500539\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600540
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600541\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
542
543\fI\fB
544
545\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 -0600546
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500547\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600548
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600549\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
550
551\fI\fB
552
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500553\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 -0600554
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500555\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600556
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600557\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
558
559\fI\fB
560
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500561\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 -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_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\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-Pehrsona77ef622000-02-18 13:48:52 -0600569\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 -0600570
571\fI\fB
572
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500573\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 -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_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 -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_strip_16 (png_structp \fIpng_ptr\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-Pehrson4393a9a1999-09-17 12:27:26 -0500585\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600586
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500587\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600588
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500589\fBvoid png_set_swap (png_structp \fIpng_ptr\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-Pehrson4393a9a1999-09-17 12:27:26 -0500593\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600594
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500595\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600596
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500597\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 -0600598
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500599\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600600
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500601\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 -0600602
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500603\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600604
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500605\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 -0500606
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_tRNS_to_alpha(png_structp \fIpng_ptr\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-Pehrson61c32d92000-02-04 23:40:16 -0600613\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
614
615\fI\fB
616
617\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 -0600618
619\fI\fB
620
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500621\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 -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_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 -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_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 -0600630
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500631\fI\fB
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600632
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500633\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 -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\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 -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_start_read_image (png_structp \fIpng_ptr\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_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\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_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 -0600650
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_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 -0600654
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500655\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600656
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500657\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600658
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500659\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600660
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500661\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 -0600662
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500663\fI\fB
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600664
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500665\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600666
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500667\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600668
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500669\fBvoid png_write_destroy_info (png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600670
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500671\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600672
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500673\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 -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_write_flush (png_structp \fIpng_ptr\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_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\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-Pehrsona357b991998-02-08 20:56:40 -0600684
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500685\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 -0600686
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500687\fI\fB
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500688
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600689\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
690
691\fI\fB
692
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600693\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, voidp \fIparams\fP\fB);\fP
694
695\fI\fB
696
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500697\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 -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_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 -0600702
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500703\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600704
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600705.SH DESCRIPTION
706The
707.I libpng
708library supports encoding, decoding, and various manipulations of
709the Portable Network Graphics (PNG) format image files. It uses the
710.IR zlib(3)
711compression library.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600712Following is a copy of the libpng.txt file that accompanies libpng.
713.SH LIBPNG.TXT
714libpng.txt - A description on how to use and modify libpng
715
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -0500716 libpng version 1.0.6e - April 10, 2000
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600717 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500718 <randeg@alum.rpi.edu>
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600719 Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600720 For conditions of distribution and use, see copyright
721 notice in png.h.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600722
723 based on:
724
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600725 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600726 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600727 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600728
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600729 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600730 For conditions of distribution and use, see copyright
731 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600732 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600733
734 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600735 Copyright (c) 1995, 1996 Frank J. T. Wojcik
736 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600737
738.SH I. Introduction
739
740This file describes how to use and modify the PNG reference library
741(known as libpng) for your own use. There are five sections to this
742file: introduction, structures, reading, writing, and modification and
743configuration notes for various special platforms. In addition to this
744file, example.c is a good starting point for using the library, as
745it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600746will need. We assume that libpng is already installed; see the
747INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600748
749Libpng was written as a companion to the PNG specification, as a way
750of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500751file format in application programs.
752
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600753The PNG-1.2 specification is available at <http://www.cdrom.com/pub/png>
754(will be moving to <http://www.libpng.org>)
755and at <ftp://ftp.uu.net/graphics/png/documents/>.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500756
757The PNG-1.0 specification is available
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600758as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
759W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
760additional chunks are described in the special-purpose public chunks
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500761documents at <ftp://ftp.uu.net/graphics/png/documents/>.
762
763Other information
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600764about PNG, and the latest version of libpng, can be found at the PNG home
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600765page, <http://www.cdrom.com/pub/png/> (will be moving to
766<http://www.libpng.org>)
767and at <ftp://ftp.uu.net/graphics/png/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600768
769Most users will not have to modify the library significantly; advanced
770users may want to modify it more. All attempts were made to make it as
771complete as possible, while keeping the code easy to understand.
772Currently, this library only supports C. Support for other languages
773is being considered.
774
775Libpng has been designed to handle multiple sessions at one time,
776to be easily modifiable, to be portable to the vast majority of
777machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
778to use. The ultimate goal of libpng is to promote the acceptance of
779the PNG file format in whatever way possible. While there is still
780work to be done (see the TODO file), libpng should cover the
781majority of the needs of its users.
782
783Libpng uses zlib for its compression and decompression of PNG files.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600784Further information about zlib, and the latest version of zlib, can
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600785be found at the zlib home page, <ftp://ftp.freesoftware.com/pub/infozip/zlib/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600786The zlib compression utility is a general purpose utility that is
787useful for more than PNG files, and can be used without libpng.
788See the documentation delivered with zlib for more details.
789You can usually find the source files for the zlib utility wherever you
790find the libpng source files.
791
792Libpng is thread safe, provided the threads are using different
793instances of the structures. Each thread should have its own
794png_struct and png_info instances, and thus its own image.
795Libpng does not protect itself against two threads using the
796same instance of a structure.
797
798
799.SH II. Structures
800
801There are two main structures that are important to libpng, png_struct
802and png_info. The first, png_struct, is an internal structure that
803will not, for the most part, be used by a user except as the first
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600804variable passed to every libpng function call.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600805
806The png_info structure is designed to provide information about the
807PNG file. At one time, the fields of png_info were intended to be
808directly accessible to the user. However, this tended to cause problems
809with applications using dynamically loaded libraries, and as a result
810a set of interface functions for png_info was developed. The fields
811of png_info are still available for older applications, but it is
812suggested that applications use the new interfaces if at all possible.
813
814The png.h header file is an invaluable reference for programming with libpng.
815And while I'm on the topic, make sure you include the libpng header file:
816
817#include <png.h>
818
819.SH III. Reading
820
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600821We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600822in a PNG file sequentially, briefly explaining the syntax and purpose
823of each one. See example.c and png.h for more detail. While
824progressive reading is covered in the next section, you will still
825need some of the functions discussed in this section to read a PNG
826file.
827
828.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600829
830You will want to do the I/O initialization(*) before you get into libpng,
831so if it doesn't work, you don't have much to undo. Of course, you
832will also want to insure that you are, in fact, dealing with a PNG
833file. Libpng provides a simple check to see if a file is a PNG file.
834To use it, pass in the first 1 to 8 bytes of the file, and it will
835return true or false (1 or 0) depending on whether the bytes could be
836part of a PNG file. Of course, the more bytes you pass in, the
837greater the accuracy of the prediction.
838
839If you are intending to keep the file pointer open for use in libpng,
840you must ensure you don't read more than 8 bytes from the beginning
841of the file, and you also have to make a call to png_set_sig_bytes_read()
842with the number of bytes you read from the beginning. Libpng will
843then only check the bytes (if any) that your program didn't read.
844
845(*): If you are not using the standard I/O functions, you will need
846to replace them with custom functions. See the discussion under
847Customizing libpng.
848
849
850 FILE *fp = fopen(file_name, "rb");
851 if (!fp)
852 {
853 return;
854 }
855 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600856 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600857 if (!is_png)
858 {
859 return;
860 }
861
862
863Next, png_struct and png_info need to be allocated and initialized. In
864order to ensure that the size of these structures is correct even with a
865dynamically linked libpng, there are functions to initialize and
866allocate the structures. We also pass the library version, optional
867pointers to error handling functions, and a pointer to a data struct for
868use by the error functions, if necessary (the pointer and functions can
869be NULL if the default error handlers are to be used). See the section
870on Changes to Libpng below regarding the old initialization functions.
871
872 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500873 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600874 user_error_fn, user_warning_fn);
875 if (!png_ptr)
876 return;
877
878 png_infop info_ptr = png_create_info_struct(png_ptr);
879 if (!info_ptr)
880 {
881 png_destroy_read_struct(&png_ptr,
882 (png_infopp)NULL, (png_infopp)NULL);
883 return;
884 }
885
886 png_infop end_info = png_create_info_struct(png_ptr);
887 if (!end_info)
888 {
889 png_destroy_read_struct(&png_ptr, &info_ptr,
890 (png_infopp)NULL);
891 return;
892 }
893
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500894If you want to use your own memory allocation routines,
895define PNG_USER_MEM_SUPPORTED and use
896png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600897
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500898 png_structp png_ptr = png_create_read_struct_2
899 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
900 user_error_fn, user_warning_fn, (png_voidp)
901 user_mem_ptr, user_malloc_fn, user_free_fn);
902
903The error handling routines passed to png_create_read_struct()
904and the memory alloc/free routines passed to png_create_struct_2()
905are only necessary if you are not using the libpng supplied error
906handling and memory alloc/free functions.
907
908When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600909to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600910your png_jmpbuf(png_ptr). If you read the file from different
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600911routines, you will need to update the jmpbuf field every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600912a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600913
914See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600915information on setjmp/longjmp. See the discussion on libpng error
916handling in the Customizing Libpng section below for more information
917on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600918back to your setjmp, you will want to call png_destroy_read_struct() to
919free any memory.
920
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600921 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600922 {
923 png_destroy_read_struct(&png_ptr, &info_ptr,
924 &end_info);
925 fclose(fp);
926 return;
927 }
928
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600929If you would rather avoid the complexity of setjmp/longjmp issues,
930you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
931errors will result in a call to PNG_ABORT() which defaults to abort().
932
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600933Now you need to set up the input code. The default for libpng is to
934use the C function fread(). If you use this, you will need to pass a
935valid FILE * in the function png_init_io(). Be sure that the file is
936opened in binary mode. If you wish to handle reading data in another
937way, you need not call the png_init_io() function, but you must then
938implement the libpng I/O methods discussed in the Customizing Libpng
939section below.
940
941 png_init_io(png_ptr, fp);
942
943If you had previously opened the file and read any of the signature from
944the beginning in order to see if this was a PNG file, you need to let
945libpng know that there are some bytes missing from the start of the file.
946
947 png_set_sig_bytes(png_ptr, number);
948
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600949.SS Setting up callback code
950
951You can set up a callback function to handle any unknown chunks in the
952input stream. You must supply the function
953
954 read_chunk_callback(png_ptr ptr,
955 png_unknown_chunkp chunk);
956 {
957 /* The unknown chunk structure contains your
958 chunk data: */
959 png_byte name[5];
960 png_byte *data;
961 png_size_t size;
962 /* Note that libpng has already taken care of the
963 CRC handling */
964
965 /* put your code here. Return one of the following: */
966
967 return (-n); /* chunk had an error */
968 return (0); /* did not recognize */
969 return (n); /* success */
970 }
971
972(You can give your function another name that you like instead of
973"read_chunk_callback")
974
975To inform libpng about your function, use
976
977 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
978 read_chunk_callback);
979
980This names not only the callback function, but also a user pointer that
981you can retrieve with
982
983 png_get_user_chunk_ptr(png_ptr);
984
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600985At this point, you can set up a callback function that will be
986called after each row has been read, which you can use to control
987a progress meter or the like. It's demonstrated in pngtest.c.
988You must supply a function
989
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600990 void read_row_callback(png_ptr ptr, png_uint_32 row, int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600991 {
992 /* put your code here */
993 }
994
995(You can give it another name that you like instead of "read_row_callback")
996
997To inform libpng about your function, use
998
999 png_set_read_status_fn(png_ptr, read_row_callback);
1000
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001001.SS Unknown-chunk handling
1002
1003Now you get to set the way the library processes unknown chunks in the
1004input PNG stream. Both known and unknown chunks will be read. Normal
1005behavior is that known chunks will be parsed into information in
1006various info_ptr members; unknown chunks will be discarded. To change
1007this, you can call:
1008
1009 png_set_keep_unknown_chunks(png_ptr, info_ptr, keep,
1010 chunk_list, num_chunks);
1011 keep - 0: do not keep
1012 1: keep only if safe-to-copy
1013 2: keep even if unsafe-to-copy
1014 chunk_list - list of chunks affected (a byte string,
1015 five bytes per chunk, NULL or '\0' if
1016 num_chunks is 0)
1017 num_chunks - number of chunks affected; if 0, all
1018 unknown chunks are affected
1019
1020Unknown chunks declared in this way will be saved as raw data onto a
1021list of png_unknown_chunk structures. If a chunk that is normally
1022known to libpng is named in the list, it will be handled as unknown,
1023according to the "keep" directive. If a chunk is named in successive
1024instances of png_set_keep_unknown_chunks(), the final instance will
1025take precedence.
1026
1027.SS The high-level read interface
1028
1029At this point there are two ways to proceed; through the high-level
1030read interface, or through a sequence of low-level read operations.
1031You can use the high-level interface if (a) you are willing to read
1032the entire image into memory, and (b) the input transformations
1033you want to do are limited to the following set:
1034
1035 PNG_TRANSFORM_IDENTITY No transformation
1036 PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to 8 bits
1037 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
1038 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit samples to bytes
1039 PNG_TRANSFORM_PACKSWAP Change order of packed pixels to LSB first
1040 PNG_TRANSFORM_EXPAND Perform set_expand()
1041 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
1042 PNG_TRANSFORM_SHIFT Normalize pixels to the sBIT depth
1043 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA to BGRA
1044 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA to AG
1045 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency
1046 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
1047
1048(This excludes setting a background color, doing gamma transformation,
1049dithering, and setting filler.) If this is the case, simply do this:
1050
1051 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1052
1053where png_transforms is an integer containing the logical-or of some set of
1054transformation flags. This call is equivalent to png_read_info(),
1055followed the set of transformations indicated by the transform mask,
1056followed by png_update_info(), followed by a read of the image bytes
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05001057to the info_ptr, followed by png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001058
1059(The final parameter of this call is not yet used. Someday it
1060will point to transformation parameters.)
1061
1062.SS The low-level read interface
1063
1064If you are going the low-level route, you are now ready to read all
1065the file information up to the actual image data. You do this with a
1066call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001067
1068 png_read_info(png_ptr, info_ptr);
1069
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001070This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001071
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001072.SS Querying the info structure
1073
1074Functions are used to get the information from the info_ptr once it
1075has been read. Note that these fields may not be completely filled
1076in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001077
1078 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1079 &bit_depth, &color_type, &interlace_type,
1080 &compression_type, &filter_type);
1081
1082 width - holds the width of the image
1083 in pixels (up to 2^31).
1084 height - holds the height of the image
1085 in pixels (up to 2^31).
1086 bit_depth - holds the bit depth of one of the
1087 image channels. (valid values are
1088 1, 2, 4, 8, 16 and depend also on
1089 the color_type. See also
1090 significant bits (sBIT) below).
1091 color_type - describes which color/alpha channels
1092 are present.
1093 PNG_COLOR_TYPE_GRAY
1094 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001095 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001096 (bit depths 8, 16)
1097 PNG_COLOR_TYPE_PALETTE
1098 (bit depths 1, 2, 4, 8)
1099 PNG_COLOR_TYPE_RGB
1100 (bit_depths 8, 16)
1101 PNG_COLOR_TYPE_RGB_ALPHA
1102 (bit_depths 8, 16)
1103
1104 PNG_COLOR_MASK_PALETTE
1105 PNG_COLOR_MASK_COLOR
1106 PNG_COLOR_MASK_ALPHA
1107
1108 filter_type - (must be PNG_FILTER_TYPE_BASE
1109 for PNG 1.0)
1110 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1111 for PNG 1.0)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001112 interlace_type - (PNG_INTERLACE_NONE or
1113 PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001114 Any or all of interlace_type, compression_type, of
1115 filter_type can be
1116 NULL if you are not interested in their values.
1117
1118 channels = png_get_channels(png_ptr, info_ptr);
1119 channels - number of channels of info for the
1120 color type (valid values are 1 (GRAY,
1121 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1122 4 (RGB_ALPHA or RGB + filler byte))
1123 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1124 rowbytes - number of bytes needed to hold a row
1125
1126 signature = png_get_signature(png_ptr, info_ptr);
1127 signature - holds the signature read from the
1128 file (if any). The data is kept in
1129 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001130 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001131 application had already read in 4
1132 bytes of signature before starting
1133 libpng, the remaining 4 bytes would
1134 be in signature[4] through signature[7]
1135 (see png_set_sig_bytes())).
1136
1137
1138 width = png_get_image_width(png_ptr,
1139 info_ptr);
1140 height = png_get_image_height(png_ptr,
1141 info_ptr);
1142 bit_depth = png_get_bit_depth(png_ptr,
1143 info_ptr);
1144 color_type = png_get_color_type(png_ptr,
1145 info_ptr);
1146 filter_type = png_get_filter_type(png_ptr,
1147 info_ptr);
1148 compression_type = png_get_compression_type(png_ptr,
1149 info_ptr);
1150 interlace_type = png_get_interlace_type(png_ptr,
1151 info_ptr);
1152
1153
1154These are also important, but their validity depends on whether the chunk
1155has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1156png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1157data has been read, or zero if it is missing. The parameters to the
1158png_get_<chunk> are set directly if they are simple data types, or a pointer
1159into the info_ptr is returned for any complex types.
1160
1161 png_get_PLTE(png_ptr, info_ptr, &palette,
1162 &num_palette);
1163 palette - the palette for the file
1164 (array of png_color)
1165 num_palette - number of entries in the palette
1166
1167 png_get_gAMA(png_ptr, info_ptr, &gamma);
1168 gamma - the gamma the file is written
1169 at (PNG_INFO_gAMA)
1170
1171 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1172 srgb_intent - the rendering intent (PNG_INFO_sRGB)
1173 The presence of the sRGB chunk
1174 means that the pixel data is in the
1175 sRGB color space. This chunk also
1176 implies specific values of gAMA and
1177 cHRM.
1178
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001179 png_get_iCCP(png_ptr, info_ptr, &name, &compression_type,
1180 &profile, &proflen);
1181 name - The profile name.
1182 compression - The compression type; always PNG_COMPRESSION_TYPE_BASE
1183 for PNG 1.0. You may give NULL to this argument
1184 to ignore it.
1185 profile - International Color Consortium color profile
1186 data. May contain NULs.
1187 proflen - length of profile data in bytes.
1188
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001189 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1190 sig_bit - the number of significant bits for
1191 (PNG_INFO_sBIT) each of the gray,
1192 red, green, and blue channels,
1193 whichever are appropriate for the
1194 given color type (png_color_16)
1195
1196 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
1197 &trans_values);
1198 trans - array of transparent entries for
1199 palette (PNG_INFO_tRNS)
1200 trans_values - transparent pixel for non-paletted
1201 images (PNG_INFO_tRNS)
1202 num_trans - number of transparent entries
1203 (PNG_INFO_tRNS)
1204
1205 png_get_hIST(png_ptr, info_ptr, &hist);
1206 (PNG_INFO_hIST)
1207 hist - histogram of palette (array of
1208 png_color_16)
1209
1210 png_get_tIME(png_ptr, info_ptr, &mod_time);
1211 mod_time - time image was last modified
1212 (PNG_VALID_tIME)
1213
1214 png_get_bKGD(png_ptr, info_ptr, &background);
1215 background - background color (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001216 valid 16-bit red, green and blue
1217 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001218
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001219 num_comments = png_get_text(png_ptr, info_ptr,
1220 &text_ptr, &num_text);
1221 num_comments - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001222 text_ptr - array of png_text holding image
1223 comments
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001224 text_ptr[i]->compression - type of compression used
1225 on "text" PNG_TEXT_COMPRESSION_NONE
1226 PNG_TEXT_COMPRESSION_zTXt
1227 PNG_ITXT_COMPRESSION_NONE
1228 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001229 text_ptr[i]->key - keyword for comment.
1230 text_ptr[i]->text - text comments for current
1231 keyword.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001232 text_ptr[i]->text_length - length of text string,
1233 after decompression, 0 for iTXt
1234 text_ptr[i]->itxt_length - length of itxt string,
1235 after decompression, 0 for tEXt/zTXt
1236 text_ptr[i]->lang - language of comment (NULL for unknown).
1237 text_ptr[i]->translated_keyword - keyword in UTF-8 (NULL
1238 for unknown).
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001239 num_text - number of comments (same as num_comments;
1240 you can put NULL here to avoid the duplication)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001241 num_spalettes = png_get_spalettes(png_ptr, info_ptr, &palette_ptr);
1242 palette_ptr - array of png_spalette structures holding contents
1243 of one or more sPLT chunks read.
1244 num_spalettes - number of sPLT chunks read.
1245
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001246 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
1247 &unit_type);
1248 offset_x - positive offset from the left edge
1249 of the screen
1250 offset_y - positive offset from the top edge
1251 of the screen
1252 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1253
1254 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
1255 &unit_type);
1256 res_x - pixels/unit physical resolution in
1257 x direction
1258 res_y - pixels/unit physical resolution in
1259 x direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001260 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001261 PNG_RESOLUTION_METER
1262
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001263 png_get_sCAL(png_ptr, info_ptr, &unit, &width, &height)
1264 unit - physical scale units (a string)
1265 width - width of a pixel in physical scale units
1266 height - height of a pixel in physical scale units
1267
1268 num_unknown_chunks = png_get_unknown_chunks(png_ptr, info_ptr,
1269 &unknowns)
1270 unknowns - array of png_unknown_chunk structures holding
1271 unknown chunks
1272 unknowns[i].name - name of unknown chunk
1273 unknowns[i].data - data of unknown chunk
1274 unknowns[i].size - size of unknown chunk
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001275 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001276
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001277The data from the pHYs chunk can be retrieved in several convenient
1278forms:
1279
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001280 res_x = png_get_x_pixels_per_meter(png_ptr,
1281 info_ptr)
1282 res_y = png_get_y_pixels_per_meter(png_ptr,
1283 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001284 res_x_and_y = png_get_pixels_per_meter(png_ptr,
1285 info_ptr)
1286 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
1287 info_ptr)
1288
1289 (Each of these returns 0 [signifying "unknown"] if
1290 the data is not present or if res_x is 0;
1291 res_x_and_y is 0 if res_x != res_y)
1292
1293For more information, see the png_info definition in png.h and the
1294PNG specification for chunk contents. Be careful with trusting
1295rowbytes, as some of the transformations could increase the space
1296needed to hold a row (expand, filler, gray_to_rgb, etc.).
1297See png_read_update_info(), below.
1298
1299A quick word about text_ptr and num_text. PNG stores comments in
1300keyword/text pairs, one pair per chunk, with no limit on the number
1301of text chunks, and a 2^31 byte limit on their size. While there are
1302suggested keywords, there is no requirement to restrict the use to these
1303strings. It is strongly suggested that keywords and text be sensible
1304to humans (that's the point), so don't use abbreviations. Non-printing
1305symbols are not allowed. See the PNG specification for more details.
1306There is also no requirement to have text after the keyword.
1307
1308Keywords should be limited to 79 Latin-1 characters without leading or
1309trailing spaces, but non-consecutive spaces are allowed within the
1310keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001311The text_ptr is an array of png_text structures, each holding a
1312pointer to a language string, a pointer to a keyword and a pointer to
1313a text string. Only the text string may be null. The keyword/text
1314pairs are put into the array in the order that they are received.
1315However, some or all of the text chunks may be after the image, so, to
1316make sure you have read all the text chunks, don't mess with these
1317until after you read the stuff after the image. This will be
1318mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001319
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001320.SS Input transformations
1321
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001322After you've read the header information, you can set up the library
1323to handle any special transformations of the image data. The various
1324ways to transform the data will be described in the order that they
1325should occur. This is important, as some of these change the color
1326type and/or bit depth of the data, and some others only work on
1327certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001328checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001329make sure to only enable a transformation if it will be valid for the
1330data. For example, don't swap red and blue on grayscale data.
1331
1332The colors used for the background and transparency values should be
1333supplied in the same format/depth as the current image data. They
1334are stored in the same format/depth as the image data in a bKGD or tRNS
1335chunk, so this is what libpng expects for this data. The colors are
1336transformed to keep in sync with the image data when an application
1337calls the png_read_update_info() routine (see below).
1338
1339Data will be decoded into the supplied row buffers packed into bytes
1340unless the library has been told to transform it into another format.
1341For example, 4 bit/pixel paletted or grayscale data will be returned
13422 pixels/byte with the leftmost pixel in the high-order bits of the
1343byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001344in RGB RGB RGB format unless png_set_filler() is called to insert filler
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001345bytes, either before or after each RGB triplet. 16-bit RGB data will
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001346be returned RRGGBB RRGGBB, with the most significant byte of the color
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001347value first, unless png_set_strip_16() is called to transform it to
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001348regular RGB RGB triplets, or png_set_filler() is called to insert
1349filler bytes, either before or after each RRGGBB triplet. Similarly,
13508-bit or 16-bit grayscale data can be modified with png_set_filler()
1351or png_set_strip_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001352
1353The following code transforms grayscale images of less than 8 to 8 bits,
1354changes paletted images to RGB, and adds a full alpha channel if there is
1355transparency information in a tRNS chunk. This is most useful on
1356grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1357viewing application that wishes to treat all images in the same way.
1358
1359 if (color_type == PNG_COLOR_TYPE_PALETTE &&
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001360 bit_depth <= 8) png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001361
1362 if (color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001363 bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001364
1365 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001366 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1367
1368These three functions are actually aliases for png_set_expand(), added
1369in libpng version 1.0.4, with the function names expanded to improve code
1370readability. In some future version they may actually do different
1371things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001372
1373PNG can have files with 16 bits per channel. If you only can handle
13748 bits per channel, this will strip the pixels down to 8 bit.
1375
1376 if (bit_depth == 16)
1377 png_set_strip_16(png_ptr);
1378
1379The png_set_background() function tells libpng to composite images
1380with alpha or simple transparency against the supplied background
1381color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1382you may use this color, or supply another color more suitable for
1383the current display (e.g., the background color from a web page). You
1384need to tell libpng whether the color is in the gamma space of the
1385display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
1386(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
1387that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
1388know why anyone would use this, but it's here).
1389
1390If, for some reason, you don't need the alpha channel on an image,
1391and you want to remove it rather than combining it with the background
1392(but the image author certainly had in mind that you *would* combine
1393it with the background, so that's what you should probably do):
1394
1395 if (color_type & PNG_COLOR_MASK_ALPHA)
1396 png_set_strip_alpha(png_ptr);
1397
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001398In PNG files, the alpha channel in an image
1399is the level of opacity. If you need the alpha channel in an image to
1400be the level of transparency instead of opacity, you can invert the
1401alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1402fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1403images) is fully transparent, with
1404
1405 png_set_invert_alpha(png_ptr);
1406
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001407PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1408they can, resulting in, for example, 8 pixels per byte for 1 bit
1409files. This code expands to 1 pixel per byte without changing the
1410values of the pixels:
1411
1412 if (bit_depth < 8)
1413 png_set_packing(png_ptr);
1414
1415PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1416stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001417higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060014188 bits/sample in the range [0, 255]). However, it is also possible to
1419convert the PNG pixel data back to the original bit depth of the image.
1420This call reduces the pixels back down to the original bit depth:
1421
1422 png_color_16p sig_bit;
1423
1424 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1425 png_set_shift(png_ptr, sig_bit);
1426
1427PNG files store 3-color pixels in red, green, blue order. This code
1428changes the storage of the pixels to blue, green, red:
1429
1430 if (color_type == PNG_COLOR_TYPE_RGB ||
1431 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1432 png_set_bgr(png_ptr);
1433
1434PNG files store RGB pixels packed into 3 bytes. This code expands them
1435into 4 bytes for windowing systems that need them in this format:
1436
1437 if (bit_depth == 8 && color_type ==
1438 PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
1439 filler, PNG_FILLER_BEFORE);
1440
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001441where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001442either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1443you want the filler before the RGB or after. This transformation
1444does not affect images that already have full alpha channels.
1445
1446If you are reading an image with an alpha channel, and you need the
1447data as ARGB instead of the normal PNG format RGBA:
1448
1449 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1450 png_set_swap_alpha(png_ptr);
1451
1452For some uses, you may want a grayscale image to be represented as
1453RGB. This code will do that conversion:
1454
1455 if (color_type == PNG_COLOR_TYPE_GRAY ||
1456 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1457 png_set_gray_to_rgb(png_ptr);
1458
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001459Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001460with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001461
1462 if (color_type == PNG_COLOR_TYPE_RGB ||
1463 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001464 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1465 int red_weight, int green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001466
1467 error_action = 1: silently do the conversion
1468 error_action = 2: issue a warning if the original
1469 image has any pixel where
1470 red != green or red != blue
1471 error_action = 3: issue an error and abort the
1472 conversion if the original
1473 image has any pixel where
1474 red != green or red != blue
1475
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001476 red_weight: weight of red component times 100000
1477 green_weight: weight of green component times 100000
1478 If either weight is negative, default
1479 weights (21268, 71514) are used.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001480
1481If you have set error_action = 1 or 2, you can
1482later check whether the image really was gray, after processing
1483the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1484It will return a png_byte that is zero if the image was gray or
14851 if there were any non-gray pixels. bKGD and sBIT data
1486will be silently converted to grayscale, using the green channel
1487data, regardless of the error_action setting.
1488
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001489With red_weight+green_weight<=100000,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001490the normalized graylevel is computed:
1491
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001492 int rw = red_weight * 65536;
1493 int gw = green_weight * 65536;
1494 int bw = 65536 - (rw + gw);
1495 gray = (rw*red + gw*green + bw*blue)/65536;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001496
1497The default values approximate those recommended in the Charles
1498Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
1499Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
1500
1501 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1502
1503Libpng approximates this with
1504
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001505 Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001506
1507which can be expressed with integers as
1508
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001509 Y = (6969 * R + 23434 * G + 2365 * B)/32768
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001510
1511The calculation is done in a linear colorspace, if the image gamma
1512is known.
1513
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001514If you have a grayscale and you are using png_set_expand_depth() or
1515png_set_expand() to change to
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001516a higher bit-depth, you must either supply the background color as a gray
1517value at the original file bit-depth (need_expand = 1) or else supply the
1518background color as an RGB triplet at the final, expanded bit depth
1519(need_expand = 0). Similarly, if you are reading a paletted image, you
1520must either supply the background color as a palette index (need_expand = 1)
1521or as an RGB triplet that may or may not be in the palette (need_expand = 0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001522
1523 png_color_16 my_background;
1524 png_color_16p image_background;
1525
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001526 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1527 png_set_background(png_ptr, image_background,
1528 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001529 else
1530 png_set_background(png_ptr, &my_background,
1531 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1532
1533To properly display PNG images on any kind of system, the application needs
1534to know what the display gamma is. Ideally, the user will know this, and
1535the application will allow them to set it. One method of allowing the user
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001536to set the display gamma separately for each system is to check for a
1537SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
1538correctly set.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001539
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001540Note that display_gamma is the overall gamma correction required to produce
1541pleasing results, which depends on the lighting conditions in the surrounding
1542environment. In a dim or brightly lit room, no compensation other than
1543the physical gamma exponent of the monitor is needed, while in a dark room
1544a slightly smaller exponent is better.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001545
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001546 double gamma, screen_gamma;
1547
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001548 if (/* We have a user-defined screen
1549 gamma value */)
1550 {
1551 screen_gamma = user_defined_screen_gamma;
1552 }
1553 /* One way that applications can share the same
1554 screen gamma value */
1555 else if ((gamma_str = getenv("SCREEN_GAMMA"))
1556 != NULL)
1557 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001558 screen_gamma = (double)atof(gamma_str);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001559 }
1560 /* If we don't have another value */
1561 else
1562 {
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001563 screen_gamma = 2.2; /* A good guess for a
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001564 PC monitor in a bright office or a dim room */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001565 screen_gamma = 2.0; /* A good guess for a
1566 PC monitor in a dark room */
1567 screen_gamma = 1.7 or 1.0; /* A good
1568 guess for Mac systems */
1569 }
1570
1571The png_set_gamma() function handles gamma transformations of the data.
1572Pass both the file gamma and the current screen_gamma. If the file does
1573not have a gamma value, you can pass one anyway if you have an idea what
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001574it is (usually 0.45455 is a good guess for GIF images on PCs). Note
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001575that file gammas are inverted from screen gammas. See the discussions
1576on gamma in the PNG specification for an excellent description of what
1577gamma is, and why all applications should support it. It is strongly
1578recommended that PNG viewers support gamma correction.
1579
1580 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
1581 png_set_gamma(png_ptr, screen_gamma, gamma);
1582 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001583 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001584
1585If you need to reduce an RGB file to a paletted file, or if a paletted
1586file has more entries then will fit on your screen, png_set_dither()
1587will do that. Note that this is a simple match dither that merely
1588finds the closest color available. This should work fairly well with
1589optimized palettes, and fairly badly with linear color cubes. If you
1590pass a palette that is larger then maximum_colors, the file will
1591reduce the number of colors in the palette so it will fit into
1592maximum_colors. If there is a histogram, it will use it to make
1593more intelligent choices when reducing the palette. If there is no
1594histogram, it may not do as good a job.
1595
1596 if (color_type & PNG_COLOR_MASK_COLOR)
1597 {
1598 if (png_get_valid(png_ptr, info_ptr,
1599 PNG_INFO_PLTE))
1600 {
1601 png_color_16p histogram;
1602
1603 png_get_hIST(png_ptr, info_ptr,
1604 &histogram);
1605 png_set_dither(png_ptr, palette, num_palette,
1606 max_screen_colors, histogram, 1);
1607 }
1608 else
1609 {
1610 png_color std_color_cube[MAX_SCREEN_COLORS] =
1611 { ... colors ... };
1612
1613 png_set_dither(png_ptr, std_color_cube,
1614 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
1615 NULL,0);
1616 }
1617 }
1618
1619PNG files describe monochrome as black being zero and white being one.
1620The following code will reverse this (make black be one and white be
1621zero):
1622
1623 if (bit_depth == 1 && color_type == PNG_COLOR_GRAY)
1624 png_set_invert_mono(png_ptr);
1625
1626PNG files store 16 bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001627ie. most significant bits first). This code changes the storage to the
1628other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001629way PCs store them):
1630
1631 if (bit_depth == 16)
1632 png_set_swap(png_ptr);
1633
1634If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
1635need to change the order the pixels are packed into bytes, you can use:
1636
1637 if (bit_depth < 8)
1638 png_set_packswap(png_ptr);
1639
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001640Finally, you can write your own transformation function if none of
1641the existing ones meets your needs. This is done by setting a callback
1642with
1643
1644 png_set_read_user_transform_fn(png_ptr,
1645 read_transform_fn);
1646
1647You must supply the function
1648
1649 void read_transform_fn(png_ptr ptr, row_info_ptr
1650 row_info, png_bytep data)
1651
1652See pngtest.c for a working example. Your function will be called
1653after all of the other transformations have been processed.
1654
1655You can also set up a pointer to a user structure for use by your
1656callback function, and you can inform libpng that your transform
1657function will change the number of channels or bit depth with the
1658function
1659
1660 png_set_user_transform_info(png_ptr, user_ptr,
1661 user_depth, user_channels);
1662
1663The user's application, not libpng, is responsible for allocating and
1664freeing any memory required for the user structure.
1665
1666You can retrieve the pointer via the function
1667png_get_user_transform_ptr(). For example:
1668
1669 voidp read_user_transform_ptr =
1670 png_get_user_transform_ptr(png_ptr);
1671
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001672The last thing to handle is interlacing; this is covered in detail below,
1673but you must call the function here if you want libpng to handle expansion
1674of the interlaced image.
1675
1676 number_of_passes = png_set_interlace_handling(png_ptr);
1677
1678After setting the transformations, libpng can update your png_info
1679structure to reflect any transformations you've requested with this
1680call. This is most useful to update the info structure's rowbytes
1681field so you can use it to allocate your image memory. This function
1682will also update your palette with the correct screen_gamma and
1683background if these have been given with the calls above.
1684
1685 png_read_update_info(png_ptr, info_ptr);
1686
1687After you call png_read_update_info(), you can allocate any
1688memory you need to hold the image. The row data is simply
1689raw byte data for all forms of images. As the actual allocation
1690varies among applications, no example will be given. If you
1691are allocating one large chunk, you will need to build an
1692array of pointers to each row, as it will be needed for some
1693of the functions below.
1694
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001695.SS Reading image data
1696
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001697After you've allocated memory, you can read the image data.
1698The simplest way to do this is in one function call. If you are
1699allocating enough memory to hold the whole image, you can just
1700call png_read_image() and libpng will read in all the image data
1701and put it in the memory area supplied. You will need to pass in
1702an array of pointers to each row.
1703
1704This function automatically handles interlacing, so you don't need
1705to call png_set_interlace_handling() or call this function multiple
1706times, or any of that other stuff necessary with png_read_rows().
1707
1708 png_read_image(png_ptr, row_pointers);
1709
1710where row_pointers is:
1711
1712 png_bytep row_pointers[height];
1713
1714You can point to void or char or whatever you use for pixels.
1715
1716If you don't want to read in the whole image at once, you can
1717use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001718interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001719
1720 png_read_rows(png_ptr, row_pointers, NULL,
1721 number_of_rows);
1722
1723where row_pointers is the same as in the png_read_image() call.
1724
1725If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001726a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001727
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001728 png_bytep row_pointer = row;
1729 png_read_row(png_ptr, row_pointers, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001730
1731If the file is interlaced (info_ptr->interlace_type != 0), things get
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001732somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001733interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001734is a somewhat complicated 2D interlace scheme, known as Adam7, that
1735breaks down an image into seven smaller images of varying size, based
1736on an 8x8 grid.
1737
1738libpng can fill out those images or it can give them to you "as is".
1739If you want them filled out, there are two ways to do that. The one
1740mentioned in the PNG specification is to expand each pixel to cover
1741those pixels that have not been read yet (the "rectangle" method).
1742This results in a blocky image for the first pass, which gradually
1743smooths out as more pixels are read. The other method is the "sparkle"
1744method, where pixels are drawn only in their final locations, with the
1745rest of the image remaining whatever colors they were initialized to
1746before the start of the read. The first method usually looks better,
1747but tends to be slower, as there are more pixels to put in the rows.
1748
1749If you don't want libpng to handle the interlacing details, just call
1750png_read_rows() seven times to read in all seven images. Each of the
1751images is a valid image by itself, or they can all be combined on an
17528x8 grid to form a single image (although if you intend to combine them
1753you would be far better off using the libpng interlace handling).
1754
1755The first pass will return an image 1/8 as wide as the entire image
1756(every 8th column starting in column 0) and 1/8 as high as the original
1757(every 8th row starting in row 0), the second will be 1/8 as wide
1758(starting in column 4) and 1/8 as high (also starting in row 0). The
1759third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
17601/8 as high (every 8th row starting in row 4), and the fourth pass will
1761be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
1762and every 4th row starting in row 0). The fifth pass will return an
1763image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
1764while the sixth pass will be 1/2 as wide and 1/2 as high as the original
1765(starting in column 1 and row 0). The seventh and final pass will be as
1766wide as the original, and 1/2 as high, containing all of the odd
1767numbered scanlines. Phew!
1768
1769If you want libpng to expand the images, call this before calling
1770png_start_read_image() or png_read_update_info():
1771
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001772 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001773 number_of_passes
1774 = png_set_interlace_handling(png_ptr);
1775
1776This will return the number of passes needed. Currently, this
1777is seven, but may change if another interlace type is added.
1778This function can be called even if the file is not interlaced,
1779where it will return one pass.
1780
1781If you are not going to display the image after each pass, but are
1782going to wait until the entire image is read in, use the sparkle
1783effect. This effect is faster and the end result of either method
1784is exactly the same. If you are planning on displaying the image
1785after each pass, the "rectangle" effect is generally considered the
1786better looking one.
1787
1788If you only want the "sparkle" effect, just call png_read_rows() as
1789normal, with the third parameter NULL. Make sure you make pass over
1790the image number_of_passes times, and you don't change the data in the
1791rows between calls. You can change the locations of the data, just
1792not the data. Each pass only writes the pixels appropriate for that
1793pass, and assumes the data from previous passes is still valid.
1794
1795 png_read_rows(png_ptr, row_pointers, NULL,
1796 number_of_rows);
1797
1798If you only want the first effect (the rectangles), do the same as
1799before except pass the row buffer in the third parameter, and leave
1800the second parameter NULL.
1801
1802 png_read_rows(png_ptr, NULL, row_pointers,
1803 number_of_rows);
1804
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001805.SS Finishing a sequential read
1806
1807After you are finished reading the image through either the high- or
1808low-level interfaces, you can finish reading the file. If you are
1809interested in comments or time, which may be stored either before or
1810after the image data, you should pass the separate png_info struct if
1811you want to keep the comments from before and after the image
1812separate. If you are not interested, you can pass NULL.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001813
1814 png_read_end(png_ptr, end_info);
1815
1816When you are done, you can free all memory allocated by libpng like this:
1817
1818 png_destroy_read_struct(&png_ptr, &info_ptr,
1819 &end_info);
1820
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001821It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001822point to libpng-allocated storage with the following functions:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001823
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001824 png_free_data(png_ptr, info_ptr, mask, n)
1825 mask - identifies data to be freed, a mask
1826 made up by the OR one or more of
1827 PNG_FREE_PLTE, PNG_FREE_TRNS,
1828 PNG_FREE_HIST, PNG_FREE_ICCP,
1829 PNG_FREE_SPLT, PNG_FREE_ROWS,
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001830 PNG_FREE_TEXT, PNG_FREE_UNKN,
1831 or simply PNG_FREE_ALL
1832 n - sequence number of item to be freed
1833 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001834
1835These functions may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06001836already been freed, or has not yet been allocated, or was allocated
1837by the user and not by libpng, and will in those
1838cases do nothing. The "n" parameter is ignored if only one item
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001839of the selected data type, such as PLTE, is allowed. If "n" is not
1840-1, and multiple items are allowed for the data type identified in
1841the mask, such as text or splt, only the n'th item is freed.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001842
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05001843The default behavior is only to free data that was allocated internally
1844by libpng. This can be changed, so that libpng will not free the data,
1845or so that it will also free data that was passed in via a png_set_*()
1846function, with
1847
1848 png_data_freer(png_ptr, info_ptr, freer, mask)
1849 mask - which data elements are affected
1850 same choices as in png_free_data()
1851 freer - one of
1852 PNG_DESTROY_WILL_FREE_DATA
1853 PNG_SET_WILL_FREE_DATA
1854 PNG_USER_WILL_FREE_DATA
1855
1856This function only affects data that has already been allocated.
1857You can call this function after reading the PNG data but before calling
1858any png_set_*() functions, to control whether the user or the png_set_*()
1859function is responsible for freeing any existing data that might be present,
1860and again after the png_set_*() functions to control whether the user
1861or png_destroy_*() is supposed to free the data..
1862
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001863For a more compact example of reading a PNG image, see the file example.c.
1864
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001865.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001866
1867The progressive reader is slightly different then the non-progressive
1868reader. Instead of calling png_read_info(), png_read_rows(), and
1869png_read_end(), you make one call to png_process_data(), which calls
1870callbacks when it has the info, a row, or the end of the image. You
1871set up these callbacks with png_set_progressive_read_fn(). You don't
1872have to worry about the input/output functions of libpng, as you are
1873giving the library the data directly in png_process_data(). I will
1874assume that you have read the section on reading PNG files above,
1875so I will only highlight the differences (although I will show
1876all of the code).
1877
1878png_structp png_ptr;
1879png_infop info_ptr;
1880
1881 /* An example code fragment of how you would
1882 initialize the progressive reader in your
1883 application. */
1884 int
1885 initialize_png_reader()
1886 {
1887 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001888 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001889 user_error_fn, user_warning_fn);
1890 if (!png_ptr)
1891 return -1;
1892 info_ptr = png_create_info_struct(png_ptr);
1893 if (!info_ptr)
1894 {
1895 png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
1896 (png_infopp)NULL);
1897 return -1;
1898 }
1899
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001900 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001901 {
1902 png_destroy_read_struct(&png_ptr, &info_ptr,
1903 (png_infopp)NULL);
1904 return -1;
1905 }
1906
1907 /* This one's new. You can provide functions
1908 to be called when the header info is valid,
1909 when each row is completed, and when the image
1910 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001911 you can specify NULL parameters. Even when all
1912 three functions are NULL, you need to call
1913 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001914 any struct as the user_ptr (cast to a void pointer
1915 for the function call), and retrieve the pointer
1916 from inside the callbacks using the function
1917
1918 png_get_progressive_ptr(png_ptr);
1919
1920 which will return a void pointer, which you have
1921 to cast appropriately.
1922 */
1923 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
1924 info_callback, row_callback, end_callback);
1925
1926 return 0;
1927 }
1928
1929 /* A code fragment that you call as you receive blocks
1930 of data */
1931 int
1932 process_data(png_bytep buffer, png_uint_32 length)
1933 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001934 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001935 {
1936 png_destroy_read_struct(&png_ptr, &info_ptr,
1937 (png_infopp)NULL);
1938 return -1;
1939 }
1940
1941 /* This one's new also. Simply give it a chunk
1942 of data from the file stream (in order, of
1943 course). On machines with segmented memory
1944 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001945 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001946 of 4K. Although you can give it much less if
1947 necessary (I assume you can give it chunks of
1948 1 byte, I haven't tried less then 256 bytes
1949 yet). When this function returns, you may
1950 want to display any rows that were generated
1951 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001952 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001953 */
1954 png_process_data(png_ptr, info_ptr, buffer, length);
1955 return 0;
1956 }
1957
1958 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001959 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001960 has been supplied so all of the header has been
1961 read.
1962 */
1963 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001964 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001965 {
1966 /* Do any setup here, including setting any of
1967 the transformations mentioned in the Reading
1968 PNG files section. For now, you _must_ call
1969 either png_start_read_image() or
1970 png_read_update_info() after all the
1971 transformations are set (even if you don't set
1972 any). You may start getting rows before
1973 png_process_data() returns, so this is your
1974 last chance to prepare for that.
1975 */
1976 }
1977
1978 /* This function is called when each row of image
1979 data is complete */
1980 void
1981 row_callback(png_structp png_ptr, png_bytep new_row,
1982 png_uint_32 row_num, int pass)
1983 {
1984 /* If the image is interlaced, and you turned
1985 on the interlace handler, this function will
1986 be called for every row in every pass. Some
1987 of these rows will not be changed from the
1988 previous pass. When the row is not changed,
1989 the new_row variable will be NULL. The rows
1990 and passes are called in order, so you don't
1991 really need the row_num and pass, but I'm
1992 supplying them because it may make your life
1993 easier.
1994
1995 For the non-NULL rows of interlaced images,
1996 you must call png_progressive_combine_row()
1997 passing in the row and the old row. You can
1998 call this function for NULL rows (it will just
1999 return) and for non-interlaced images (it just
2000 does the memcpy for you) if it will make the
2001 code easier. Thus, you can just do this for
2002 all cases:
2003 */
2004
2005 png_progressive_combine_row(png_ptr, old_row,
2006 new_row);
2007
2008 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05002009 previously for the row. Note that the first
2010 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002011 the old row, so the rows do not have to be
2012 initialized. After the first pass (and only
2013 for interlaced images), you will have to pass
2014 the current row, and the function will combine
2015 the old row and the new row.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002016 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002017 }
2018
2019 void
2020 end_callback(png_structp png_ptr, png_infop info)
2021 {
2022 /* This function is called after the whole image
2023 has been read, including any chunks after the
2024 image (up to and including the IEND). You
2025 will usually have the same info chunk as you
2026 had in the header, although some data may have
2027 been added to the comments and time fields.
2028
2029 Most people won't do much here, perhaps setting
2030 a flag that marks the image as finished.
2031 */
2032 }
2033
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002034
2035
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002036.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002037
2038Much of this is very similar to reading. However, everything of
2039importance is repeated here, so you won't have to constantly look
2040back up in the reading section to understand writing.
2041
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002042.SS Setup
2043
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002044You will want to do the I/O initialization before you get into libpng,
2045so if it doesn't work, you don't have anything to undo. If you are not
2046using the standard I/O functions, you will need to replace them with
2047custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002048
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002049 FILE *fp = fopen(file_name, "wb");
2050 if (!fp)
2051 {
2052 return;
2053 }
2054
2055Next, png_struct and png_info need to be allocated and initialized.
2056As these can be both relatively large, you may not want to store these
2057on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002058will want to check if they return NULL. If you are also reading,
2059you won't want to name your read structure and your write structure
2060both "png_ptr"; you can call them anything you like, such as
2061"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002062
2063 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002064 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002065 user_error_fn, user_warning_fn);
2066 if (!png_ptr)
2067 return;
2068
2069 png_infop info_ptr = png_create_info_struct(png_ptr);
2070 if (!info_ptr)
2071 {
2072 png_destroy_write_struct(&png_ptr,
2073 (png_infopp)NULL);
2074 return;
2075 }
2076
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002077If you want to use your own memory allocation routines,
2078define PNG_USER_MEM_SUPPORTED and use
2079png_create_write_struct_2() instead of png_create_read_struct():
2080
2081 png_structp png_ptr = png_create_write_struct_2
2082 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2083 user_error_fn, user_warning_fn, (png_voidp)
2084 user_mem_ptr, user_malloc_fn, user_free_fn);
2085
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002086After you have these structures, you will need to set up the
2087error handling. When libpng encounters an error, it expects to
2088longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002089setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002090write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002091the png_jmpbuf(png_ptr) every time you enter a new routine that will
2092call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002093for your compiler for more information on setjmp/longjmp. See
2094the discussion on libpng error handling in the Customizing Libpng
2095section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002096
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002097 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002098 {
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002099 png_destroy_write_struct(&png_ptr, &info_ptr);
2100 fclose(fp);
2101 return;
2102 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002103 ...
2104 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002105
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002106If you would rather avoid the complexity of setjmp/longjmp issues,
2107you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
2108errors will result in a call to PNG_ABORT() which defaults to abort().
2109
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002110Now you need to set up the output code. The default for libpng is to
2111use the C function fwrite(). If you use this, you will need to pass a
2112valid FILE * in the function png_init_io(). Be sure that the file is
2113opened in binary mode. Again, if you wish to handle writing data in
2114another way, see the discussion on libpng I/O handling in the Customizing
2115Libpng section below.
2116
2117 png_init_io(png_ptr, fp);
2118
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002119.SS Write callbacks
2120
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002121At this point, you can set up a callback function that will be
2122called after each row has been written, which you can use to control
2123a progress meter or the like. It's demonstrated in pngtest.c.
2124You must supply a function
2125
2126 void write_row_callback(png_ptr, png_uint_32 row, int pass);
2127 {
2128 /* put your code here */
2129 }
2130
2131(You can give it another name that you like instead of "write_row_callback")
2132
2133To inform libpng about your function, use
2134
2135 png_set_write_status_fn(png_ptr, write_row_callback);
2136
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002137You now have the option of modifying how the compression library will
2138run. The following functions are mainly for testing, but may be useful
2139in some cases, like if you need to write PNG files extremely fast and
2140are willing to give up some compression, or if you want to get the
2141maximum possible compression at the expense of slower writing. If you
2142have no special needs in this area, let the library do what it wants by
2143not calling this function at all, as it has been tuned to deliver a good
2144speed/compression ratio. The second parameter to png_set_filter() is
2145the filter method, for which the only valid value is '0' (as of the
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002146July 1999 PNG specification, version 1.2). The third parameter is a
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002147flag that indicates which filter type(s) are to be tested for each
2148scanline. See the Compression Library for details on the specific filter
2149types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002150
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002151
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002152 /* turn on or off filtering, and/or choose
2153 specific filters */
2154 png_set_filter(png_ptr, 0,
2155 PNG_FILTER_NONE | PNG_FILTER_SUB |
2156 PNG_FILTER_PAETH);
2157
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002158The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002159library, and should mostly be ignored unless you really know what you are
2160doing. The only generally useful call is png_set_compression_level()
2161which changes how much time zlib spends on trying to compress the image
2162data. See the Compression Library for details on the compression levels.
2163
2164 /* set the zlib compression level */
2165 png_set_compression_level(png_ptr,
2166 Z_BEST_COMPRESSION);
2167
2168 /* set other zlib parameters */
2169 png_set_compression_mem_level(png_ptr, 8);
2170 png_set_compression_strategy(png_ptr,
2171 Z_DEFAULT_STRATEGY);
2172 png_set_compression_window_bits(png_ptr, 15);
2173 png_set_compression_method(png_ptr, 8);
2174
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002175.SS Setting the contents of info for output
2176
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002177You now need to fill in the png_info structure with all the data you
2178wish to write before the actual image. Note that the only thing you
2179are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002180chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002181the latest PNG specification for more information on that. If you
2182wish to write them before the image, fill them in now, and flag that
2183data as being valid. If you want to wait until after the data, don't
2184fill them until png_write_end(). For all the fields in png_info and
2185their data types, see png.h. For explanations of what the fields
2186contain, see the PNG specification.
2187
2188Some of the more important parts of the png_info are:
2189
2190 png_set_IHDR(png_ptr, info_ptr, width, height,
2191 bit_depth, color_type, interlace_type,
2192 compression_type, filter_type)
2193 width - holds the width of the image
2194 in pixels (up to 2^31).
2195 height - holds the height of the image
2196 in pixels (up to 2^31).
2197 bit_depth - holds the bit depth of one of the
2198 image channels.
2199 (valid values are 1, 2, 4, 8, 16
2200 and depend also on the
2201 color_type. See also significant
2202 bits (sBIT) below).
2203 color_type - describes which color/alpha
2204 channels are present.
2205 PNG_COLOR_TYPE_GRAY
2206 (bit depths 1, 2, 4, 8, 16)
2207 PNG_COLOR_TYPE_GRAY_ALPHA
2208 (bit depths 8, 16)
2209 PNG_COLOR_TYPE_PALETTE
2210 (bit depths 1, 2, 4, 8)
2211 PNG_COLOR_TYPE_RGB
2212 (bit_depths 8, 16)
2213 PNG_COLOR_TYPE_RGB_ALPHA
2214 (bit_depths 8, 16)
2215
2216 PNG_COLOR_MASK_PALETTE
2217 PNG_COLOR_MASK_COLOR
2218 PNG_COLOR_MASK_ALPHA
2219
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002220 interlace_type - PNG_INTERLACE_NONE or
2221 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002222 compression_type - (must be
2223 PNG_COMPRESSION_TYPE_DEFAULT)
2224 filter_type - (must be PNG_FILTER_TYPE_DEFAULT)
2225
2226 png_set_PLTE(png_ptr, info_ptr, palette,
2227 num_palette);
2228 palette - the palette for the file
2229 (array of png_color)
2230 num_palette - number of entries in the palette
2231
2232 png_set_gAMA(png_ptr, info_ptr, gamma);
2233 gamma - the gamma the image was created
2234 at (PNG_INFO_gAMA)
2235
2236 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2237 srgb_intent - the rendering intent
2238 (PNG_INFO_sRGB) The presence of
2239 the sRGB chunk means that the pixel
2240 data is in the sRGB color space.
2241 This chunk also implies specific
2242 values of gAMA and cHRM. Rendering
2243 intent is the CSS-1 property that
2244 has been defined by the International
2245 Color Consortium
2246 (http://www.color.org).
2247 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002248 PNG_sRGB_INTENT_SATURATION,
2249 PNG_sRGB_INTENT_PERCEPTUAL,
2250 PNG_sRGB_INTENT_ABSOLUTE, or
2251 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002252
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002253
2254 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2255 srgb_intent);
2256 srgb_intent - the rendering intent
2257 (PNG_INFO_sRGB) The presence of the
2258 sRGB chunk means that the pixel
2259 data is in the sRGB color space.
2260 This function also causes gAMA and
2261 cHRM chunks with the specific values
2262 that are consistent with sRGB to be
2263 written.
2264
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002265 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2266 profile, proflen);
2267 name - The profile name.
2268 compression - The compression type; always PNG_COMPRESSION_TYPE_BASE
2269 for PNG 1.0. You may give NULL to this argument
2270 to ignore it.
2271 profile - International Color Consortium color profile
2272 data. May contain NULs.
2273 proflen - length of profile data in bytes.
2274
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002275 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2276 sig_bit - the number of significant bits for
2277 (PNG_INFO_sBIT) each of the gray, red,
2278 green, and blue channels, whichever are
2279 appropriate for the given color type
2280 (png_color_16)
2281
2282 png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
2283 trans_values);
2284 trans - array of transparent entries for
2285 palette (PNG_INFO_tRNS)
2286 trans_values - transparent pixel for non-paletted
2287 images (PNG_INFO_tRNS)
2288 num_trans - number of transparent entries
2289 (PNG_INFO_tRNS)
2290
2291 png_set_hIST(png_ptr, info_ptr, hist);
2292 (PNG_INFO_hIST)
2293 hist - histogram of palette (array of
2294 png_color_16)
2295
2296 png_set_tIME(png_ptr, info_ptr, mod_time);
2297 mod_time - time image was last modified
2298 (PNG_VALID_tIME)
2299
2300 png_set_bKGD(png_ptr, info_ptr, background);
2301 background - background color (PNG_VALID_bKGD)
2302
2303 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2304 text_ptr - array of png_text holding image
2305 comments
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002306 text_ptr[i]->compression - type of compression used
2307 on "text" PNG_TEXT_COMPRESSION_NONE
2308 PNG_TEXT_COMPRESSION_zTXt
2309 PNG_ITXT_COMPRESSION_NONE
2310 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002311 text_ptr[i]->key - keyword for comment.
2312 text_ptr[i]->text - text comments for current
2313 keyword.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002314 text_ptr[i]->text_length - length of text string,
2315 after decompression, 0 for iTXt
2316 text_ptr[i]->itxt_length - length of itxt string,
2317 after decompression, 0 for tEXt/zTXt
2318 text_ptr[i]->lang - language of comment (NULL for unknown).
2319 text_ptr[i]->translated_keyword - keyword in UTF-8 (NULL
2320 for unknown).
2321 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002322
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002323 png_set_spalettes(png_ptr, info_ptr, &palette_ptr, num_spalettes);
2324 palette_ptr - array of png_spalette structures to be added to
2325 the list of palettes in the info structure.
2326 num_spalettes - number of palette structures to be added.
2327
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002328 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2329 unit_type);
2330 offset_x - positive offset from the left
2331 edge of the screen
2332 offset_y - positive offset from the top
2333 edge of the screen
2334 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2335
2336 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2337 unit_type);
2338 res_x - pixels/unit physical resolution
2339 in x direction
2340 res_y - pixels/unit physical resolution
2341 in y direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002342 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002343 PNG_RESOLUTION_METER
2344
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002345 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
2346 unit - physical scale units (a string)
2347 width - width of a pixel in physical scale units
2348 height - height of a pixel in physical scale units
2349
2350 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, num_unknowns)
2351 unknowns - array of png_unknown_chunk structures holding
2352 unknown chunks
2353 unknowns[i].name - name of unknown chunk
2354 unknowns[i].data - data of unknown chunk
2355 unknowns[i].size - size of unknown chunk
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002356 unknowns[i].location - position to write chunk in file
2357 0: do not write chunk
2358 PNG_HAVE_IHDR: before PLTE
2359 PNG_HAVE_PLTE: before IDAT
2360 PNG_AFTER_IDAT: after IDAT
2361 The "location" member is set automatically according to
2362 what part of the output file has already been written.
2363 You can change its value after calling png_set_unknown_chunks()
2364 as demonstrated in pngtest.c.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002365
2366A quick word about text and num_text. text is an array of png_text
2367structures. num_text is the number of valid structures in the array.
2368If you want, you can use max_text to hold the size of the array, but
2369libpng ignores it for writing (it does use it for reading). Each
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002370png_text structure holds a language code, a keyword, a text value, and
2371a compression type.
2372
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002373The compression types have the same valid numbers as the compression
2374types of the image data. Currently, the only valid number is zero.
2375However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002376images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002377text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002378Because compressed-text chunks don't have a language field, if you
2379specify compression any language code will not be written out.
2380
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002381Until text gets around 1000 bytes, it is not worth compressing it.
2382After the text has been written out to the file, the compression type
2383is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2384so that it isn't written out again at the end (in case you are calling
2385png_write_end() with the same struct.
2386
2387The keywords that are given in the PNG Specification are:
2388
2389 Title Short (one line) title or
2390 caption for image
2391 Author Name of image's creator
2392 Description Description of image (possibly long)
2393 Copyright Copyright notice
2394 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002395 (usually RFC 1123 format, see below)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002396 Software Software used to create the image
2397 Disclaimer Legal disclaimer
2398 Warning Warning of nature of content
2399 Source Device used to create the image
2400 Comment Miscellaneous comment; conversion
2401 from other image format
2402
2403The keyword-text pairs work like this. Keywords should be short
2404simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002405keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002406on keywords. You can repeat keywords in a file. You can even write
2407some text before the image and some after. For example, you may want
2408to put a description of the image before the image, but leave the
2409disclaimer until after, so viewers working over modem connections
2410don't have to wait for the disclaimer to go over the modem before
2411they start seeing the image. Finally, keywords should be full
2412words, not abbreviations. Keywords and text are in the ISO 8859-1
2413(Latin-1) character set (a superset of regular ASCII) and can not
2414contain NUL characters, and should not contain control or other
2415unprintable characters. To make the comments widely readable, stick
2416with basic ASCII, and avoid machine specific character set extensions
2417like the IBM-PC character set. The keyword must be present, but
2418you can leave off the text string on non-compressed pairs.
2419Compressed pairs must have a text string, as only the text string
2420is compressed anyway, so the compression would be meaningless.
2421
2422PNG supports modification time via the png_time structure. Two
2423conversion routines are proved, png_convert_from_time_t() for
2424time_t and png_convert_from_struct_tm() for struct tm. The
2425time_t routine uses gmtime(). You don't have to use either of
2426these, but if you wish to fill in the png_time structure directly,
2427you should provide the time in universal time (GMT) if possible
2428instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002429year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002430that months start with 1.
2431
2432If you want to store the time of the original image creation, you should
2433use a plain tEXt chunk with the "Creation Time" keyword. This is
2434necessary because the "creation time" of a PNG image is somewhat vague,
2435depending on whether you mean the PNG file, the time the image was
2436created in a non-PNG format, a still photo from which the image was
2437scanned, or possibly the subject matter itself. In order to facilitate
2438machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002439tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002440although this isn't a requirement. Unlike the tIME chunk, the
2441"Creation Time" tEXt chunk is not expected to be automatically changed
2442by the software. To facilitate the use of RFC 1123 dates, a function
2443png_convert_to_rfc1123(png_timep) is provided to convert from PNG
2444time to an RFC 1123 format string.
2445
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002446.SS Writing unknown chunks
2447
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002448You can use the png_set_unknown_chunks function to queue up chunks
2449for writing. You give it a chunk name, raw data, and a size; that's
2450all there is to it. The chunks will be written by the next following
2451png_write_info_before_PLTE, png_write_info, or png_write_end function.
2452Any chunks previously read into the info structure's unknown-chunk
2453list will also be written out in a sequence that satisfies the PNG
2454specification's ordering rules.
2455
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002456.SS The high-level write interface
2457
2458At this point there are two ways to proceed; through the high-level
2459write interface, or through a sequence of low-level write operations.
2460You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002461in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002462transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002463
2464 PNG_TRANSFORM_IDENTITY No transformation
2465 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
2466 PNG_TRANSFORM_PACKSWAP Change order of packed pixels to LSB first
2467 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
2468 PNG_TRANSFORM_SHIFT Normalize pixels to the sBIT depth
2469 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA to BGRA
2470 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA to AG
2471 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency
2472 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
2473 PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
2474
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002475If you have valid image data in the info structure, simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002476
2477 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
2478
2479where png_transforms is an integer containing the logical-or of some set of
2480transformation flags. This call is equivalent to png_write_info(),
2481followed by the set of transformations indicated by the transform
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002482mask, followed by followed by a write of the image bytes from the
2483info_ptr, followed by png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002484
2485(The final parameter of this call is not yet used. Someday it
2486may point to output transformation parameters.)
2487
2488.SS The low-level write interface
2489
2490If you are going the low-level route instead, you are now ready to
2491write all the file information up to the actual image data. You do
2492this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002493
2494 png_write_info(png_ptr, info_ptr);
2495
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002496Note that there is one transformation you may need to do before
2497png_write_info(). In PNG files, the alpha channel in an image is the
2498level of opacity. If your data is supplied as a level of
2499transparency, you can invert the alpha channel before you write it, so
2500that 0 is fully transparent and 255 (in 8-bit or paletted images) or
250165535 (in 16-bit images) is fully opaque, with
2502
2503 png_set_invert_alpha(png_ptr);
2504
2505This must appear before png_write_info() instead of later with the
2506other transformations because in the case of paletted images the tRNS
2507chunk data has to be inverted before the tRNS chunk is written. If
2508your image is not a paletted image, the tRNS data (which in such cases
2509represents a single color to be rendered as transparent) won't need to
2510be changed, and you can safely do this transformation after your
2511png_write_info() call.
2512
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002513If you need to write a private chunk that you want to appear before
2514the PLTE chunk when PLTE is present, you can write the PNG info in
2515two steps, and insert code to write your own chunk between them:
2516
2517 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002518 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002519 png_write_info(png_ptr, info_ptr);
2520
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002521After you've written the file information, you can set up the library
2522to handle any special transformations of the image data. The various
2523ways to transform the data will be described in the order that they
2524should occur. This is important, as some of these change the color
2525type and/or bit depth of the data, and some others only work on
2526certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002527checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002528make sure to only enable a transformation if it will be valid for the
2529data. For example, don't swap red and blue on grayscale data.
2530
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002531PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002532the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002533to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
2534bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002535
2536 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
2537
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002538where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
2539PNG_FILLER_AFTER, depending upon whether the filler byte in the is stored
2540XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002541
2542PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2543they can, resulting in, for example, 8 pixels per byte for 1 bit files.
2544If the data is supplied at 1 pixel per byte, use this code, which will
2545correctly pack the pixels into a single byte:
2546
2547 png_set_packing(png_ptr);
2548
2549PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
2550data is of another bit depth, you can write an sBIT chunk into the
2551file so that decoders can get the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002552
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002553 /* Set the true bit depth of the image data */
2554 if (color_type & PNG_COLOR_MASK_COLOR)
2555 {
2556 sig_bit.red = true_bit_depth;
2557 sig_bit.green = true_bit_depth;
2558 sig_bit.blue = true_bit_depth;
2559 }
2560 else
2561 {
2562 sig_bit.gray = true_bit_depth;
2563 }
2564 if (color_type & PNG_COLOR_MASK_ALPHA)
2565 {
2566 sig_bit.alpha = true_bit_depth;
2567 }
2568
2569 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
2570
2571If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002572one 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 -06002573this will scale the values to appear to be the correct bit depth as
2574is required by PNG.
2575
2576 png_set_shift(png_ptr, &sig_bit);
2577
2578PNG files store 16 bit pixels in network byte order (big-endian,
2579ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002580supplied the other way (little-endian, i.e. least significant bits
2581first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002582
2583 if (bit_depth > 8)
2584 png_set_swap(png_ptr);
2585
2586If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2587need to change the order the pixels are packed into bytes, you can use:
2588
2589 if (bit_depth < 8)
2590 png_set_packswap(png_ptr);
2591
2592PNG files store 3 color pixels in red, green, blue order. This code
2593would be used if they are supplied as blue, green, red:
2594
2595 png_set_bgr(png_ptr);
2596
2597PNG files describe monochrome as black being zero and white being
2598one. This code would be used if the pixels are supplied with this reversed
2599(black being one and white being zero):
2600
2601 png_set_invert_mono(png_ptr);
2602
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002603Finally, you can write your own transformation function if none of
2604the existing ones meets your needs. This is done by setting a callback
2605with
2606
2607 png_set_write_user_transform_fn(png_ptr,
2608 write_transform_fn);
2609
2610You must supply the function
2611
2612 void write_transform_fn(png_ptr ptr, row_info_ptr
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002613 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002614
2615See pngtest.c for a working example. Your function will be called
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002616before any of the other transformations are processed.
2617
2618You can also set up a pointer to a user structure for use by your
2619callback function.
2620
2621 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
2622
2623The user_channels and user_depth parameters of this function are ignored
2624when writing; you can set them to zero as shown.
2625
2626You can retrieve the pointer via the function
2627png_get_user_transform_ptr(). For example:
2628
2629 voidp write_user_transform_ptr =
2630 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002631
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002632It is possible to have libpng flush any pending output, either manually,
2633or automatically after a certain number of lines have been written. To
2634flush the output stream a single time call:
2635
2636 png_write_flush(png_ptr);
2637
2638and to have libpng flush the output stream periodically after a certain
2639number of scanlines have been written, call:
2640
2641 png_set_flush(png_ptr, nrows);
2642
2643Note that the distance between rows is from the last time png_write_flush()
2644was called, or the first row of the image if it has never been called.
2645So if you write 50 lines, and then png_set_flush 25, it will flush the
2646output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002647png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002648If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002649RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002650may be acceptable for real-time applications). Infrequent flushing will
2651only degrade the compression performance by a few percent over images
2652that do not use flushing.
2653
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002654.SS Writing the image data
2655
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002656That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002657The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002658whole image in memory, you can just call png_write_image() and libpng
2659will write the image. You will need to pass in an array of pointers to
2660each row. This function automatically handles interlacing, so you don't
2661need to call png_set_interlace_handling() or call this function multiple
2662times, or any of that other stuff necessary with png_write_rows().
2663
2664 png_write_image(png_ptr, row_pointers);
2665
2666where row_pointers is:
2667
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002668 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002669
2670You can point to void or char or whatever you use for pixels.
2671
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002672If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002673use png_write_rows() instead. If the file is not interlaced,
2674this is simple:
2675
2676 png_write_rows(png_ptr, row_pointers,
2677 number_of_rows);
2678
2679row_pointers is the same as in the png_write_image() call.
2680
2681If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002682a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002683
2684 png_bytep row_pointer = row;
2685
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002686 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002687
2688When the file is interlaced, things can get a good deal more
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002689complicated. The only currently (as of January 2000 -- PNG Specification
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002690version 1.2, dated July 1999) defined interlacing scheme for PNG files
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002691is the "Adam7" interlace scheme, that breaks down an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002692image into seven smaller images of varying size. libpng will build
2693these images for you, or you can do them yourself. If you want to
2694build them yourself, see the PNG specification for details of which
2695pixels to write when.
2696
2697If you don't want libpng to handle the interlacing details, just
2698use png_set_interlace_handling() and call png_write_rows() the
2699correct number of times to write all seven sub-images.
2700
2701If you want libpng to build the sub-images, call this before you start
2702writing any rows:
2703
2704 number_of_passes =
2705 png_set_interlace_handling(png_ptr);
2706
2707This will return the number of passes needed. Currently, this
2708is seven, but may change if another interlace type is added.
2709
2710Then write the complete image number_of_passes times.
2711
2712 png_write_rows(png_ptr, row_pointers,
2713 number_of_rows);
2714
2715As some of these rows are not used, and thus return immediately,
2716you may want to read about interlacing in the PNG specification,
2717and only update the rows that are actually used.
2718
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002719.SS Finishing a sequential write
2720
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002721After you are finished writing the image, you should finish writing
2722the file. If you are interested in writing comments or time, you should
2723pass an appropriately filled png_info pointer. If you are not interested,
2724you can pass NULL.
2725
2726 png_write_end(png_ptr, info_ptr);
2727
2728When you are done, you can free all memory used by libpng like this:
2729
2730 png_destroy_write_struct(&png_ptr, &info_ptr);
2731
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002732It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002733point to libpng-allocated storage with the following functions:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002734
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002735 png_free_data(png_ptr, info_ptr, mask, n)
2736 mask - identifies data to be freed, a mask
2737 made up by the OR one or more of
2738 PNG_FREE_PLTE, PNG_FREE_TRNS,
2739 PNG_FREE_HIST, PNG_FREE_ICCP,
2740 PNG_FREE_SPLT, PNG_FREE_ROWS,
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002741 PNG_FREE_TEXT, PNG_FREE_UNKN,
2742 or simply PNG_FREE_ALL
2743 n - sequence number of item to be freed
2744 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002745
2746These functions may be safely called when the relevant storage has
2747already been freed, or has not yet been allocated, and will in that
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002748case do nothing. The "n" parameter is ignored if only one item
2749of the selected data type, such as PLTE, is allowed. If "n" is not
2750-1, and multiple items are allowed for the data type identified in
2751the mask, such as text or splt, only the n'th item is freed.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002752
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002753If you allocated data such as a palette that you passed in to libpng with
2754png_set_*, you must not free it until just before the call to
2755png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002756
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002757The default behavior is only to free data that was allocated internally
2758by libpng. This can be changed, so that libpng will not free the data,
2759or so that it will free data that was passed in via a png_set_*() function,
2760with
2761
2762 png_data_freer(png_ptr, info_ptr, freer, mask)
2763 mask - which data elements are affected
2764 same choices as in png_free_data()
2765 freer - one of
2766 PNG_DESTROY_WILL_FREE_DATA
2767 PNG_SET_WILL_FREE_DATA
2768 PNG_USER_WILL_FREE_DATA
2769
2770For example, to transfer responsibility for some data from a read structure
2771to a write structure, you could use
2772
2773 png_data_freer(read_ptr, read_info_ptr,
2774 PNG_USER_WILL_FREE_DATA,
2775 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
2776 png_data_freer(write_ptr, write_info_ptr,
2777 PNG_DESTROY_WILL_FREE_DATA,
2778 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
2779
2780Thereby briefly reassigning responsibility for freeing to the user but
2781immediately afterwards reassigning it once more to the write_destroy
2782function. Having done this, it would then be safe to destroy the read
2783structure and continue to use the PLTE, tRNS, and hIST data in the write
2784structure.
2785
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002786For a more compact example of writing a PNG image, see the file example.c.
2787
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002788.SH V. Modifying/Customizing libpng:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002789
2790There are two issues here. The first is changing how libpng does
2791standard things like memory allocation, input/output, and error handling.
2792The second deals with more complicated things like adding new chunks,
2793adding new transformations, and generally changing how libpng works.
2794
2795All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002796goes through callbacks that are user settable. The default routines are
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002797in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002798these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002799
2800Memory allocation is done through the functions png_large_malloc(),
2801png_malloc(), png_realloc(), png_large_free(), and png_free(). These
2802currently just call the standard C functions. The large functions must
2803handle exactly 64K, but they don't have to handle more than that. If
2804your pointers can't access more then 64K at a time, you will want to set
2805MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
2806memory allocation on a platform will change between applications, these
2807functions must be modified in the library at compile time.
2808
2809Input/Output in libpng is done through png_read() and png_write(),
2810which currently just call fread() and fwrite(). The FILE * is stored in
2811png_struct and is initialized via png_init_io(). If you wish to change
2812the method of I/O, the library supplies callbacks that you can set
2813through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002814time, instead of calling the png_init_io() function.
2815These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002816also provide a void pointer that can be retrieved via the function
2817png_get_io_ptr(). For example:
2818
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002819 png_set_read_fn(png_structp read_ptr,
2820 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002821
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002822 png_set_write_fn(png_structp write_ptr,
2823 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002824 png_flush_ptr output_flush_fn);
2825
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002826 voidp read_io_ptr = png_get_io_ptr(read_ptr);
2827 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002828
2829The replacement I/O functions should have prototypes as follows:
2830
2831 void user_read_data(png_structp png_ptr,
2832 png_bytep data, png_uint_32 length);
2833 void user_write_data(png_structp png_ptr,
2834 png_bytep data, png_uint_32 length);
2835 void user_flush_data(png_structp png_ptr);
2836
2837Supplying NULL for the read, write, or flush functions sets them back
2838to using the default C stream functions. It is an error to read from
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002839a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002840
2841Error handling in libpng is done through png_error() and png_warning().
2842Errors handled through png_error() are fatal, meaning that png_error()
2843should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002844setjmp() and longjmp() (unless you have compiled libpng with
2845PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
2846but you could change this to do things like exit() if you should wish.
2847
2848On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002849to print a warning message, and then control returns to the calling code.
2850By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002851fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
2852(because you don't want the messages) or PNG_NO_STDIO defined (because
2853fprintf() isn't available). If you wish to change the behavior of the error
2854functions, you will need to set up your own message callbacks. These
2855functions are normally supplied at the time that the png_struct is created.
2856It is also possible to change these functions after png_create_*_struct()
2857has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002858
2859 png_set_error_fn(png_structp png_ptr,
2860 png_voidp error_ptr, png_error_ptr error_fn,
2861 png_error_ptr warning_fn);
2862
2863 png_voidp error_ptr = png_get_error_ptr(png_ptr);
2864
2865If NULL is supplied for either error_fn or warning_fn, then the libpng
2866default function will be used, calling fprintf() and/or longjmp() if a
2867problem is encountered. The replacement error functions should have
2868parameters as follows:
2869
2870 void user_error_fn(png_structp png_ptr,
2871 png_const_charp error_msg);
2872 void user_warning_fn(png_structp png_ptr,
2873 png_const_charp warning_msg);
2874
2875The motivation behind using setjmp() and longjmp() is the C++ throw and
2876catch exception handling methods. This makes the code much easier to write,
2877as there is no need to check every return code of every function call.
2878However, there are some uncertainties about the status of local variables
2879after a longjmp, so the user may want to be careful about doing anything after
2880setjmp returns non-zero besides returning itself. Consult your compiler
2881documentation for more details.
2882
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002883.SS Custom chunks
2884
2885If you need to read or write custom chunks, you may need to get deeper
2886into the libpng code. The library now has mechanisms for storing
2887and writing chunks of unknown type; you can even declare callbacks
2888for custom chunks. Hoewver, this may not be good enough if the
2889library code itself needs to know about interactions between your
2890chunk and existing `intrinsic' chunks.
2891
2892If you need to write a new intrinsic chunk, first read the PNG
2893specification. Acquire a first level of
2894understanding of how it works. Pay particular attention to the
2895sections that describe chunk names, and look at how other chunks were
2896designed, so you can do things similarly. Second, check out the
2897sections of libpng that read and write chunks. Try to find a chunk
2898that is similar to yours and use it as a template. More details can
2899be found in the comments inside the code. It is best to handle unknown
2900chunks in a generic method, via callback functions, instead of by
2901modifying libpng functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002902
2903If you wish to write your own transformation for the data, look through
2904the part of the code that does the transformations, and check out some of
2905the simpler ones to get an idea of how they work. Try to find a similar
2906transformation to the one you want to add and copy off of it. More details
2907can be found in the comments inside the code itself.
2908
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002909.SS Configuring for 16 bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002910
2911You may need to change the png_large_malloc() and png_large_free()
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002912routines in pngmem.c, as these are required to allocate 64K, although
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002913there is already support for many of the common DOS compilers. Also,
2914you will want to look into zconf.h to tell zlib (and thus libpng) that
2915it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002916won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002917
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002918.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002919
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002920For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002921have to limit zlib's memory usage via a png_set_compression_mem_level()
2922call. See zlib.h or zconf.h in the zlib library for more information.
2923
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002924.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002925
2926Libpng's support for medium model has been tested on most of the popular
2927compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
2928defined, and FAR gets defined to far in pngconf.h, and you should be
2929all set. Everything in the library (except for zlib's structure) is
2930expecting far data. You must use the typedefs with the p or pp on
2931the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002932note that the rows of data are defined as png_bytepp, which is an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002933unsigned char far * far *.
2934
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002935.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002936
2937You will need to write new error and warning functions that use the GUI
2938interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002939warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002940in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002941They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002942you may also have to change the memory allocators (png_malloc, etc.).
2943
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002944.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002945
2946All includes for libpng are in pngconf.h. If you need to add/change/delete
2947an include, this is the place to do it. The includes that are not
2948needed outside libpng are protected by the PNG_INTERNAL definition,
2949which is only defined for those routines inside libpng itself. The
2950files in libpng proper only include png.h, which includes pngconf.h.
2951
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002952.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002953
2954There are special functions to configure the compression. Perhaps the
2955most useful one changes the compression level, which currently uses
2956input compression values in the range 0 - 9. The library normally
2957uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
2958have shown that for a large majority of images, compression values in
2959the range 3-6 compress nearly as well as higher levels, and do so much
2960faster. For online applications it may be desirable to have maximum speed
2961(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
2962specify no compression (Z_NO_COMPRESSION = 0), but this would create
2963files larger than just storing the raw bitmap. You can specify the
2964compression level by calling:
2965
2966 png_set_compression_level(png_ptr, level);
2967
2968Another useful one is to reduce the memory level used by the library.
2969The memory level defaults to 8, but it can be lowered if you are
2970short on memory (running DOS, for example, where you only have 640K).
2971
2972 png_set_compression_mem_level(png_ptr, level);
2973
2974The other functions are for configuring zlib. They are not recommended
2975for normal use and may result in writing an invalid PNG file. See
2976zlib.h for more information on what these mean.
2977
2978 png_set_compression_strategy(png_ptr,
2979 strategy);
2980 png_set_compression_window_bits(png_ptr,
2981 window_bits);
2982 png_set_compression_method(png_ptr, method);
2983
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002984.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002985
2986If you want to control whether libpng uses filtering or not, which
2987filters are used, and how it goes about picking row filters, you
2988can call one of these functions. The selection and configuration
2989of row filters can have a significant impact on the size and
2990encoding speed and a somewhat lesser impact on the decoding speed
2991of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002992images (with and without alpha), but not for paletted images nor
2993for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002994
2995The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002996currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002997parameter sets which filter(s), if any, should be used for each
2998scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
2999to turn filtering on and off, respectively.
3000
3001Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3002PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
3003ORed together '|' to specify one or more filters to use. These
3004filters are described in more detail in the PNG specification. If
3005you intend to change the filter type during the course of writing
3006the image, you should start with flags set for all of the filters
3007you intend to use so that libpng can initialize its internal
3008structures appropriately for all of the filter types.
3009
3010 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
3011 | PNG_FILTER_UP;
3012 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3013 filters);
3014
3015It is also possible to influence how libpng chooses from among the
3016available filters. This is done in two ways - by telling it how
3017important it is to keep the same filter for successive rows, and
3018by telling it the relative computational costs of the filters.
3019
3020 double weights[3] = {1.5, 1.3, 1.1},
3021 costs[PNG_FILTER_VALUE_LAST] =
3022 {1.0, 1.3, 1.3, 1.5, 1.7};
3023
3024 png_set_filter_selection(png_ptr,
3025 PNG_FILTER_SELECTION_WEIGHTED, 3,
3026 weights, costs);
3027
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003028The weights are multiplying factors that indicate to libpng that the
3029row filter should be the same for successive rows unless another row filter
3030is that many times better than the previous filter. In the above example,
3031if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003032"sum of absolute differences" 1.5 x 1.3 times higher than other filters
3033and still be chosen, while the NONE filter could have a sum 1.1 times
3034higher than other filters and still be chosen. Unspecified weights are
3035taken to be 1.0, and the specified weights should probably be declining
3036like those above in order to emphasize recent filters over older filters.
3037
3038The filter costs specify for each filter type a relative decoding cost
3039to be considered when selecting row filters. This means that filters
3040with higher costs are less likely to be chosen over filters with lower
3041costs, unless their "sum of absolute differences" is that much smaller.
3042The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003043the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003044size.
3045
3046Note that the numbers above were invented purely for this example and
3047are given only to help explain the function usage. Little testing has
3048been done to find optimum values for either the costs or the weights.
3049
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003050.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003051
3052There are a bunch of #define's in pngconf.h that control what parts of
3053libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003054never going to use a capability, you can change the #define to #undef
3055before recompiling libpng and save yourself code and data space, or
3056you can turn off individual capabilities with defines that begin with
3057PNG_NO_.
3058
3059You can also turn all of the transforms and ancillary chunk capabilities
3060off en masse with compiler directives that define
3061PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3062or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003063along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003064want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003065the extra transformations but still leave the library fully capable of reading
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003066and writing PNG files with all known public chunks
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003067Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003068produces a library that is incapable of reading or writing ancillary chunks.
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003069If you are not using the progressive reading capability, you can
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003070turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003071this with the INTERLACING capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003072
3073All the reading and writing specific code are in separate files, so the
3074linker should only grab the files it needs. However, if you want to
3075make sure, or if you are building a stand alone library, all the
3076reading files start with pngr and all the writing files start with
3077pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
3078are used for both reading and writing, and always need to be included.
3079The progressive reader is in pngpread.c
3080
3081If you are creating or distributing a dynamically linked library (a .so
3082or DLL file), you should not remove or disable any parts of the library,
3083as this will cause applications linked with different versions of the
3084library to fail if they call functions not available in your library.
3085The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003086those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003087
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003088.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003089
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003090The macro definition PNG_DEBUG can be used to request debugging
3091printout. Set it to an integer value in the range 0 to 3. Higher
3092numbers result in increasing amounts of debugging information. The
3093information is printed to the "stderr" file, unless another file
3094name is specified in the PNG_DEBUG_FILE macro definition.
3095
3096When PNG_DEBUG > 0, the following functions (macros) become available:
3097
3098 png_debug(level, message)
3099 png_debug1(level, message, p1)
3100 png_debug2(level, message, p1, p2)
3101
3102in which "level" is compared to PNG_DEBUG to decide whether to print
3103the message, "message" is the formatted string to be printed,
3104and p1 and p2 are parameters that are to be embedded in the string
3105according to printf-style formatting directives. For example,
3106
3107 png_debug1(2, "foo=%d\n", foo);
3108
3109is expanded to
3110
3111 if(PNG_DEBUG > 2)
3112 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
3113
3114When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3115can still use PNG_DEBUG to control your own debugging:
3116
3117 #ifdef PNG_DEBUG
3118 fprintf(stderr, ...
3119 #endif
3120
3121When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3122having level = 0 will be printed. There aren't any such statements in
3123this version of libpng, but if you insert some they will be printed.
3124
3125.SH VI. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003126
3127It should be noted that versions of libpng later than 0.96 are not
3128distributed by the original libpng author, Guy Schalnat, nor by
3129Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3130distributed versions 0.89 through 0.96, but rather by another member
3131of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3132still alive and well, but they have moved on to other things.
3133
3134The old libpng functions png_read_init(), png_write_init(),
3135png_info_init(), png_read_destroy(), and png_write_destory() have been
3136moved to PNG_INTERNAL in version 0.95 to discourage their use. The
3137preferred method of creating and initializing the libpng structures is
3138via the png_create_read_struct(), png_create_write_struct(), and
3139png_create_info_struct() because they isolate the size of the structures
3140from the application, allow version error checking, and also allow the
3141use of custom error handling routines during the initialization, which
3142the old functions do not. The functions png_read_destroy() and
3143png_write_destroy() do not actually free the memory that libpng
3144allocated for these structs, but just reset the data structures, so they
3145can be used instead of png_destroy_read_struct() and
3146png_destroy_write_struct() if you feel there is too much system overhead
3147allocating and freeing the png_struct for each image read.
3148
3149Setting the error callbacks via png_set_message_fn() before
3150png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003151because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003152to fail if the png_ptr was not initialized to zero. It is still possible
3153to set the error callbacks AFTER png_read_init(), or to change them with
3154png_set_error_fn(), which is essentially the same function, but with a
3155new name to force compilation errors with applications that try to use
3156the old method.
3157
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003158.SH VII. Y2K Compliance in libpng
3159
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003160April 10, 2000
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003161
3162Since the PNG Development group is an ad-hoc body, we can't make
3163an official declaration.
3164
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003165This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003166upward through 1.0.6e are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003167versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003168
3169Libpng only has three year fields. One is a 2-byte unsigned integer that
3170will hold years up to 65535. The other two hold the date in text
3171format, and will hold years up to 9999.
3172
3173The integer is
3174 "png_uint_16 year" in png_time_struct.
3175
3176The strings are
3177 "png_charp time_buffer" in png_struct and
3178 "near_time_buffer", which is a local character string in png.c.
3179
3180There are seven time-related functions:
3181
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003182 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003183 (formerly png_convert_to_rfc_1152() in error)
3184 png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
3185 png_convert_from_time_t() in pngwrite.c
3186 png_get_tIME() in pngget.c
3187 png_handle_tIME() in pngrutil.c, called in pngread.c
3188 png_set_tIME() in pngset.c
3189 png_write_tIME() in pngwutil.c, called in pngwrite.c
3190
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003191All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003192png_convert_from_time_t() function calls gmtime() to convert from system
3193clock time, which returns (year - 1900), which we properly convert to
3194the full 4-digit year. There is a possibility that applications using
3195libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003196function, or that they are incorrectly passing only a 2-digit year
3197instead of "year - 1900" into the png_convert_from_struct_tm() function,
3198but this is not under our control. The libpng documentation has always
3199stated that it works with 4-digit years, and the APIs have been
3200documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003201
3202The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
3203integer to hold the year, and can hold years as large as 65535.
3204
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003205zlib, upon which libpng depends, is also Y2K compliant. It contains
3206no date-related code.
3207
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003208
3209 Glenn Randers-Pehrson
3210 libpng maintainer
3211 PNG Development Group
3212
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003213.SH NOTE
3214
3215Note about libpng version numbers:
3216
3217Due to various miscommunications, unforeseen code incompatibilities
3218and occasional factors outside the authors' control, version numbering
3219on the library has not always been consistent and straightforward.
3220The following table summarizes matters since version 0.89c, which was
3221the first widely used release:
3222
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003223 source png.h png.h shared-lib
3224 version string int version
3225 ------- ------ ----- ----------
3226 0.89c ("1.0 beta 3") 0.89 89 1.0.89
3227 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
3228 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
3229 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
3230 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
3231 0.97c 0.97 97 2.0.97
3232 0.98 0.98 98 2.0.98
3233 0.99 0.99 98 2.0.99
3234 0.99a-m 0.99 99 2.0.99
3235 1.00 1.00 100 2.1.0 [100 should be 10000]
3236 1.0.0 1.0.0 100 2.1.0 [100 should be 10000]
3237 1.0.1 1.0.1 10001 2.1.0
3238 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
3239 1.0.2 1.0.2 10002 2.1.0.2
3240 1.0.2a-b 1.0.2a-b 10003 2.1.0.2a-b
3241 1.0.3 1.0.3 10003 2.1.0.3
3242 1.0.3a-d 1.0.3a-d 10004 2.1.0.3a-d
3243 1.0.4 1.0.4 10004 2.1.0.4
3244 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -05003245 1.0.5 (+ 2 patches) 1.0.5 10005 2.1.0.5
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003246 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
3247 1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not compatible)
3248 1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (compatible)
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -05003249 1.0.6 (+ 3 patches) 1.0.6 10006 2.1.0.6
3250 1.0.6d 1.0.6d 10007 2.1.0.6d
3251 1.0.7 1.0.7 10007 2.1.0.7 (still compatible)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003252
Glenn Randers-Pehrson81fdf8a2000-04-07 10:34:56 -05003253 Henceforth the source version will match the shared-library minor
3254 and patch numbers; the shared-library major version number will be
3255 used for changes in backward compatibility, as it is intended. The
3256 PNG_PNGLIB_VER macro, which is not used within libpng but is available
3257 for applications, is an unsigned integer of the form xyyzz corresponding
3258 to the source version x.y.z (leading zeros in y and z). Beta versions
3259 are given the previous public release number plus a letter or two.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003260
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003261.SH "SEE ALSO"
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003262libpngpf(3), png(5)
3263.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003264.IR libpng :
3265.IP
3266ftp://ftp.uu.net/graphics/png
3267http://www.cdrom.com/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003268
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003269.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003270.IR zlib :
3271.IP
3272(generally) at the same location as
3273.I libpng
3274or at
3275.br
3276ftp://ftp.uu.net/pub/archiving/zip/zlib
3277.br
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003278ftp://ftp.freesoftware.com/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003279
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003280.LP
3281.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003282.IP
3283(generally) at the same location as
3284.I libpng
3285or at
3286.br
3287ftp://ds.internic.net/rfc/rfc2083.txt
3288.br
3289or (as a W3C Recommendation) at
3290.br
3291http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003292
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003293.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003294In the case of any inconsistency between the PNG specification
3295and this library, the specification takes precedence.
3296
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003297.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003298This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003299<randeg@alum.rpi.edu>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003300
3301The contributing authors would like to thank all those who helped
3302with testing, bug fixes, and patience. This wouldn't have been
3303possible without all of you.
3304
3305Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003306
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003307Libpng version 1.0.6e - April 10, 2000:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003308Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003309Currently maintained by Glenn Randers-Pehrson (randeg@alum.rpi.edu).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003310
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003311Supported by the PNG development group
3312.br
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003313(png-implement@ccrc.wustl.edu).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003314
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003315.SH COPYRIGHT NOTICE:
3316
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003317Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003318(libpng versions 0.5, May 1995, through 0.88, January 1996)
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05003319Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003320(libpng versions 0.89c, May 1996, through 0.96, May 1997)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003321Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003322(libpng versions 0.97, January 1998, through 1.0.6e, April 10, 2000)
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003323
3324For the purposes of this copyright and license, "Contributing Authors"
3325is defined as the following set of individuals:
3326
3327 John Bowler
3328 Kevin Bracey
3329 Sam Bushell
3330 Andreas Dilger
3331 Magnus Holmgren
3332 Tom Lane
3333 Dave Martindale
3334 Glenn Randers-Pehrson
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003335 Eric S. Raymond
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003336 Greg Roelofs
3337 Guy Eric Schalnat
3338 Paul Schmidt
3339 Tom Tanner
3340 Willem van Schaik
3341 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06003342
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003343The PNG Reference Library (libpng) is supplied "AS IS". The Contributing
3344Authors and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003345including, without limitation, the warranties of merchantability and of
3346fitness for any purpose. The Contributing Authors and Group 42, Inc.
3347assume no liability for direct, indirect, incidental, special, exemplary,
3348or consequential damages, which may result from the use of the PNG
3349Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003350
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003351Permission is hereby granted to use, copy, modify, and distribute this
3352source code, or portions hereof, for any purpose, without fee, subject
3353to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003354
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003355 1. The origin of this source code must not be
3356 misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003357
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003358 2. Altered versions must be plainly marked as such
3359 and must not be misrepresented as being the
3360 original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003361
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003362 3. This Copyright notice may not be removed or
3363 altered from any source or altered source
3364 distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003365
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003366The Contributing Authors and Group 42, Inc. specifically permit, without
3367fee, and encourage the use of this source code as a component to
3368supporting the PNG file format in commercial products. If you use this
3369source code in a product, acknowledgment is not required but would be
3370appreciated.
3371
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003372A "png_get_copyright" function is available, for convenient use in "about"
3373boxes and the like:
3374
3375 printf("%s",png_get_copyright(NULL));
3376
3377Also, the PNG logo (in PNG format, of course) is supplied in the
3378file "pngnow.png".
3379
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05003380Libpng is OSI Certified Open Source Software. OSI Certified is a
3381certification mark of the Open Source Initiative.
3382
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003383.\" end of man page
3384