blob: ac6361bcdf04ea60470382535e667f0606f2d7f5 [file] [log] [blame]
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05001.TH LIBPNG 3 "July 30, 2008"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05003libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta25
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004.SH SYNOPSIS
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05005\fI\fB
6
7\fB#include <png.h>\fP
8
9\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060010
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -050011\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
12
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050013\fI\fB
14
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -050015\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
16
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050017\fI\fB
18
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -050019\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
20
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050021\fI\fB
22
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050023\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060024
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050025\fI\fB
26
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050027\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 -060028
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050029\fI\fB
30
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050031\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 -060032
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050033\fI\fB
34
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050035\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 -060036
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050037\fI\fB
38
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050039\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 -060040
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050041\fI\fB
42
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050043\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 -060044
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050045\fI\fB
46
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050047\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060048
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050049\fI\fB
50
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060051\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050052
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050053\fI\fB
54
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050055\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
56
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050057\fI\fB
58
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060059\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050060
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050061\fI\fB
62
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050063\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
64
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050065\fI\fB
66
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050067\fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP
68
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050069\fI\fB
70
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050071\fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP
72
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050073\fI\fB
74
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050075\fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP
76
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050077\fI\fB
78
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050079\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
80
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050081\fI\fB
82
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050083\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
84
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050085\fI\fB
86
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050087\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
88
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050089\fI\fB
90
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050091\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
92
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050093\fI\fB
94
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050095\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
96
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050097\fI\fB
98
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060099\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
100
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500101\fI\fB
102
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500103\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
104
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500105\fI\fB
106
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600107\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 -0600108
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500109\fI\fB
110
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500111\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
112
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500113\fI\fB
114
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500115\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
116
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500117\fI\fB
118
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500119\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
120
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500121\fI\fB
122
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500123\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
124
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500125\fI\fB
126
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600127\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
128
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500129\fI\fB
130
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500131\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
132
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500133\fI\fB
134
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500135\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
136
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500137\fI\fB
138
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500139\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
140
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500141\fI\fB
142
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500143\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
144
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500145\fI\fB
146
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500147\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
148
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500149\fI\fB
150
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500151\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
152
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500153\fI\fB
154
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600155\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
156
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500157\fI\fB
158
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600159\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
160
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500161\fI\fB
162
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500163\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
164
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500165\fI\fB
166
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500167\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
168
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500169\fI\fB
170
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600171\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 -0600172
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500173\fI\fB
174
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500175\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
176
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500177\fI\fB
178
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500179\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
180
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500181\fI\fB
182
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500183\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
184
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500185\fI\fB
186
187\fB#if \fI!defined(PNG_1_0_X)
188
189\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
190
191\fI\fB#endif
192
193\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600194
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500195\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
196
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500197\fI\fB
198
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500199\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
200
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500201\fI\fB
202
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600203\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
204
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500205\fI\fB
206
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500207\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
208
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500209\fI\fB
210
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500211\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
212
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500213\fI\fB
214
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500215\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
216
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500217\fI\fB
218
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500219\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
220
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500221\fI\fB
222
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500223\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
224
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500225\fI\fB
226
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500227\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
228
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500229\fI\fB
230
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500231\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
232
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500233\fI\fB
234
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500235\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
236
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500237\fI\fB
238
239\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
240
241\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
242
243\fI\fB
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500244
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600245\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
246
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500247\fI\fB
248
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500249\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
250
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500251\fI\fB
252
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500253\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
254
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500255\fI\fB
256
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500257\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600258
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500259\fI\fB
260
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500261\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
262
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500263\fI\fB
264
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500265\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
266
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500267\fI\fB
268
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500269\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
270
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500271\fI\fB
272
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500273\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP
274
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500275\fI\fB
276
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -0500277\fB/* This function is really an inline macro. \fI*/
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500278
279\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
280
281\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600282
283\fBpng_uint_32 png_get_uint_31 (png_bytep \fIbuf\fP\fB);\fP
284
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500285\fI\fB
286
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -0500287\fB/* This function is really an inline macro. \fI*/
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500288
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -0500289\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500290
291\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600292
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600293\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
294
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500295\fI\fB
296
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600297\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
298
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500299\fI\fB
300
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500301\fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP
302
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500303\fI\fB
304
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500305\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
306
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500307\fI\fB
308
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500309\fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP
310
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500311\fI\fB
312
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500313\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
314
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500315\fI\fB
316
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500317\fBpng_int_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500318
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500319\fI\fB
320
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500321\fBpng_int_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500322
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500323\fI\fB
324
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500325\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
326
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500327\fI\fB
328
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500329\fBpng_int_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500330
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500331\fI\fB
332
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500333\fBpng_int_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500334
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500335\fI\fB
336
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500337\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
338
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500339\fI\fB
340
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500341\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
342
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500343\fI\fB
344
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600345\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
346
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500347\fI\fB
348
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500349\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500350
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500351\fI\fB
352
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500353\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500354
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500355\fI\fB
356
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500357\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500358
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500359\fI\fB
360
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500361\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
362
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500363\fI\fB
364
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500365\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
366
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500367\fI\fB
368
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500369\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
370
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500371\fI\fB
372
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500373\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
374
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500375\fI\fB
376
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500377\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
378
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500379\fI\fB
380
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500381\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
382
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500383\fI\fB
384
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500385\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
386
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500387\fI\fB
388
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500389\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
390
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500391\fI\fB
392
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600393\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600394
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500395\fI\fB
396
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500397\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
398
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500399\fI\fB
400
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500401\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
402
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500403\fI\fB
404
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500405\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
406
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500407\fI\fB
408
409\fB#if \fI!defined(PNG_1_0_X)
410
411\fBpng_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
412
413\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600414
415\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
416
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500417\fI\fB
418
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600419\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
420
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500421\fI\fB
422
423\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
424
425\fI\fB#endif
426
427\fI\fB
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -0500428
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500429\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
430
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500431\fI\fB
432
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500433\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
434
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500435\fI\fB
436
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500437\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
438
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500439\fI\fB
440
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500441\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
442
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500443\fI\fB
444
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600445\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
446
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500447\fI\fB
448
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500449\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
450
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500451\fI\fB
452
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500453\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
454
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500455\fI\fB
456
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500457\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
458
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500459\fI\fB
460
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500461\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 -0600462
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500463\fI\fB
464
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500465\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 -0600466
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500467\fI\fB
468
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500469\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 -0600470
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500471\fI\fB
472
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500473\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 -0600474
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500475\fI\fB
476
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500477\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 -0600478
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500479\fI\fB
480
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500481\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600482
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500483\fI\fB
484
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -0600485\fBvoid png_set_expand_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
486
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500487\fI\fB
488
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500489\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 -0600490
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500491\fI\fB
492
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500493\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 -0600494
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500495\fI\fB
496
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500497\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 -0500498
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500499\fI\fB
500
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500501\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600502
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500503\fI\fB
504
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500505\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 -0600506
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500507\fI\fB
508
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500509\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 -0600510
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500511\fI\fB
512
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600513\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
514
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500515\fI\fB
516
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500517\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600518
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500519\fI\fB
520
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500521\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600522
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500523\fI\fB
524
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500525\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 -0600526
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500527\fI\fB
528
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600529\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 -0600530
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500531\fI\fB
532
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500533\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600534
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500535\fI\fB
536
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500537\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
538
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500539\fI\fB
540
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500541\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600542
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500543\fI\fB
544
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500545\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600546
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500547\fI\fB
548
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500549\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 -0600550
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500551\fI\fB
552
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600553\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 -0600554
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500555\fI\fB
556
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500557\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 -0600558
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500559\fI\fB
560
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500561\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 -0600562
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500563\fI\fB
564
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500565\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600566
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500567\fI\fB
568
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500569\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600570
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500571\fI\fB
572
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500573\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600574
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500575\fI\fB
576
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500577\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 -0600578
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500579\fI\fB
580
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500581\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 -0600582
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500583\fI\fB
584
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500585\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 -0600586
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500587\fI\fB
588
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500589\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 -0600590
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500591\fI\fB
592
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500593\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 -0600594
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500595\fI\fB
596
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500597\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 -0600598
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500599\fI\fB
600
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500601\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 -0600602
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500603\fI\fB
604
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600605\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
606
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500607\fI\fB
608
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600609\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 -0600610
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500611\fI\fB
612
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600613\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
614
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500615\fI\fB
616
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500617\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 -0600618
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500619\fI\fB
620
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600621\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
622
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500623\fI\fB
624
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500625\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 -0600626
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500627\fI\fB
628
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500629\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 -0600630
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500631\fI\fB
632
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600633\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 -0600634
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500635\fI\fB
636
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500637\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 -0600638
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500639\fI\fB
640
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500641\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 -0600642
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500643\fI\fB
644
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500645\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600646
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500647\fI\fB
648
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500649\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600650
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500651\fI\fB
652
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500653\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600654
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500655\fI\fB
656
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500657\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600658
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500659\fI\fB
660
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500661\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 -0600662
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500663\fI\fB
664
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500665\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 -0600666
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500667\fI\fB
668
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500669\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 -0500670
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500671\fI\fB
672
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500673\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600674
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500675\fI\fB
676
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600677\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
678
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500679\fI\fB
680
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500681\fBvoid png_set_unknown_chunk_location(png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP
682
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500683\fI\fB
684
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600685\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 -0600686
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500687\fI\fB
688
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500689\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
690
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500691\fI\fB
692
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500693\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 -0600694
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500695\fI\fB
696
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500697\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 -0600698
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500699\fI\fB
700
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500701\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 -0600702
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500703\fI\fB
704
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500705\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 -0600706
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500707\fI\fB
708
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500709\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
710
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500711\fI\fB
712
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500713\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 -0600714
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500715\fI\fB
716
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500717\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600718
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500719\fI\fB
720
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500721\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 -0600722
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500723\fI\fB
724
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500725\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 -0600726
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500727\fI\fB
728
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500729\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 -0600730
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500731\fI\fB
732
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500733\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600734
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500735\fI\fB
736
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500737\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 -0600738
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500739\fI\fB
740
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500741\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600742
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500743\fI\fB
744
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500745\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 -0600746
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500747\fI\fB
748
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500749\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600750
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500751\fI\fB
752
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500753\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 -0600754
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500755\fI\fB
756
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500757\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 -0600758
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500759\fI\fB
760
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600761\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
762
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500763\fI\fB
764
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600765\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600766
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500767\fI\fB
768
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500769\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 -0600770
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500771\fI\fB
772
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500773\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 -0600774
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500775\fI\fB
776
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500777\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
778
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500779\fI\fB
780
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500781\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
782
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500783\fI\fB
784
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500785\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
786
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500787\fI\fB
788
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600789.SH DESCRIPTION
790The
791.I libpng
792library supports encoding, decoding, and various manipulations of
793the Portable Network Graphics (PNG) format image files. It uses the
794.IR zlib(3)
795compression library.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600796Following is a copy of the libpng.txt file that accompanies libpng.
797.SH LIBPNG.TXT
798libpng.txt - A description on how to use and modify libpng
799
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -0500800 libpng version 1.4.0beta25 - July 30, 2008
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600801 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -0600802 <glennrp at users.sourceforge.net>
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600803 Copyright (c) 1998-2005 Glenn Randers-Pehrson
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600804 For conditions of distribution and use, see copyright
805 notice in png.h.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600806
807 based on:
808
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600809 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600810 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600811 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600812
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600813 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600814 For conditions of distribution and use, see copyright
815 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600816 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600817
818 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600819 Copyright (c) 1995, 1996 Frank J. T. Wojcik
820 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600821
822.SH I. Introduction
823
824This file describes how to use and modify the PNG reference library
825(known as libpng) for your own use. There are five sections to this
826file: introduction, structures, reading, writing, and modification and
827configuration notes for various special platforms. In addition to this
828file, example.c is a good starting point for using the library, as
829it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600830will need. We assume that libpng is already installed; see the
831INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600832
833Libpng was written as a companion to the PNG specification, as a way
834of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500835file format in application programs.
836
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500837The PNG specification (second edition), November 2003, is available as
838a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
839<http://www.w3.org/TR/2003/REC-PNG-20031110/
840The W3C and ISO documents have identical technical content.
841
842The PNG-1.2 specification is available at
843<http://www.libpng.org/pub/png/documents/>
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500844
845The PNG-1.0 specification is available
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500846as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600847W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
848additional chunks are described in the special-purpose public chunks
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500849documents at <http://www.libpng.org/pub/png/documents/>.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500850
851Other information
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600852about PNG, and the latest version of libpng, can be found at the PNG home
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500853page, <http://www.libpng.org/pub/png/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600854
855Most users will not have to modify the library significantly; advanced
856users may want to modify it more. All attempts were made to make it as
857complete as possible, while keeping the code easy to understand.
858Currently, this library only supports C. Support for other languages
859is being considered.
860
861Libpng has been designed to handle multiple sessions at one time,
862to be easily modifiable, to be portable to the vast majority of
863machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
864to use. The ultimate goal of libpng is to promote the acceptance of
865the PNG file format in whatever way possible. While there is still
866work to be done (see the TODO file), libpng should cover the
867majority of the needs of its users.
868
869Libpng uses zlib for its compression and decompression of PNG files.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600870Further information about zlib, and the latest version of zlib, can
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -0600871be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600872The zlib compression utility is a general purpose utility that is
873useful for more than PNG files, and can be used without libpng.
874See the documentation delivered with zlib for more details.
875You can usually find the source files for the zlib utility wherever you
876find the libpng source files.
877
878Libpng is thread safe, provided the threads are using different
879instances of the structures. Each thread should have its own
880png_struct and png_info instances, and thus its own image.
881Libpng does not protect itself against two threads using the
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -0500882same instance of a structure. Note: thread safety may be defeated
883by use of some of the MMX assembler code in pnggccrd.c, which is only
884compiled when the user defines PNG_THREAD_UNSAFE_OK.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600885
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600886.SH II. Structures
887
888There are two main structures that are important to libpng, png_struct
889and png_info. The first, png_struct, is an internal structure that
890will not, for the most part, be used by a user except as the first
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600891variable passed to every libpng function call.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600892
893The png_info structure is designed to provide information about the
894PNG file. At one time, the fields of png_info were intended to be
895directly accessible to the user. However, this tended to cause problems
896with applications using dynamically loaded libraries, and as a result
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500897a set of interface functions for png_info (the png_get_*() and png_set_*()
898functions) was developed. The fields of png_info are still available for
899older applications, but it is suggested that applications use the new
900interfaces if at all possible.
901
902Applications that do make direct access to the members of png_struct (except
903for png_ptr->jmpbuf) must be recompiled whenever the library is updated,
904and applications that make direct access to the members of png_info must
905be recompiled if they were compiled or loaded with libpng version 1.0.6,
906in which the members were in a different order. In version 1.0.7, the
907members of the png_info structure reverted to the old order, as they were
908in versions 0.97c through 1.0.5. Starting with version 2.0.0, both
909structures are going to be hidden, and the contents of the structures will
910only be accessible through the png_get/png_set functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600911
912The png.h header file is an invaluable reference for programming with libpng.
913And while I'm on the topic, make sure you include the libpng header file:
914
915#include <png.h>
916
917.SH III. Reading
918
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600919We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600920in a PNG file sequentially, briefly explaining the syntax and purpose
921of each one. See example.c and png.h for more detail. While
922progressive reading is covered in the next section, you will still
923need some of the functions discussed in this section to read a PNG
924file.
925
926.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600927
928You will want to do the I/O initialization(*) before you get into libpng,
929so if it doesn't work, you don't have much to undo. Of course, you
930will also want to insure that you are, in fact, dealing with a PNG
931file. Libpng provides a simple check to see if a file is a PNG file.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500932To use it, pass in the first 1 to 8 bytes of the file to the function
933png_sig_cmp(), and it will return 0 if the bytes match the corresponding
934bytes of the PNG signature, or nonzero otherwise. Of course, the more bytes
935you pass in, the greater the accuracy of the prediction.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600936
937If you are intending to keep the file pointer open for use in libpng,
938you must ensure you don't read more than 8 bytes from the beginning
939of the file, and you also have to make a call to png_set_sig_bytes_read()
940with the number of bytes you read from the beginning. Libpng will
941then only check the bytes (if any) that your program didn't read.
942
943(*): If you are not using the standard I/O functions, you will need
944to replace them with custom functions. See the discussion under
945Customizing libpng.
946
947
948 FILE *fp = fopen(file_name, "rb");
949 if (!fp)
950 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500951 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600952 }
953 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600954 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600955 if (!is_png)
956 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500957 return (NOT_PNG);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600958 }
959
960
961Next, png_struct and png_info need to be allocated and initialized. In
962order to ensure that the size of these structures is correct even with a
963dynamically linked libpng, there are functions to initialize and
964allocate the structures. We also pass the library version, optional
965pointers to error handling functions, and a pointer to a data struct for
966use by the error functions, if necessary (the pointer and functions can
967be NULL if the default error handlers are to be used). See the section
968on Changes to Libpng below regarding the old initialization functions.
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500969The structure allocation functions quietly return NULL if they fail to
970create the structure, so your application should check for that.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600971
972 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500973 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600974 user_error_fn, user_warning_fn);
975 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500976 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600977
978 png_infop info_ptr = png_create_info_struct(png_ptr);
979 if (!info_ptr)
980 {
981 png_destroy_read_struct(&png_ptr,
982 (png_infopp)NULL, (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500983 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600984 }
985
986 png_infop end_info = png_create_info_struct(png_ptr);
987 if (!end_info)
988 {
989 png_destroy_read_struct(&png_ptr, &info_ptr,
990 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500991 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600992 }
993
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500994If you want to use your own memory allocation routines,
995define PNG_USER_MEM_SUPPORTED and use
996png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600997
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500998 png_structp png_ptr = png_create_read_struct_2
999 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1000 user_error_fn, user_warning_fn, (png_voidp)
1001 user_mem_ptr, user_malloc_fn, user_free_fn);
1002
1003The error handling routines passed to png_create_read_struct()
1004and the memory alloc/free routines passed to png_create_struct_2()
1005are only necessary if you are not using the libpng supplied error
1006handling and memory alloc/free functions.
1007
1008When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001009to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001010your png_jmpbuf(png_ptr). If you read the file from different
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001011routines, you will need to update the jmpbuf field every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001012a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001013
1014See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001015information on setjmp/longjmp. See the discussion on libpng error
1016handling in the Customizing Libpng section below for more information
1017on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001018back to your setjmp, you will want to call png_destroy_read_struct() to
1019free any memory.
1020
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001021 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001022 {
1023 png_destroy_read_struct(&png_ptr, &info_ptr,
1024 &end_info);
1025 fclose(fp);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001026 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001027 }
1028
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001029If you would rather avoid the complexity of setjmp/longjmp issues,
1030you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
1031errors will result in a call to PNG_ABORT() which defaults to abort().
1032
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001033Now you need to set up the input code. The default for libpng is to
1034use the C function fread(). If you use this, you will need to pass a
1035valid FILE * in the function png_init_io(). Be sure that the file is
1036opened in binary mode. If you wish to handle reading data in another
1037way, you need not call the png_init_io() function, but you must then
1038implement the libpng I/O methods discussed in the Customizing Libpng
1039section below.
1040
1041 png_init_io(png_ptr, fp);
1042
1043If you had previously opened the file and read any of the signature from
1044the beginning in order to see if this was a PNG file, you need to let
1045libpng know that there are some bytes missing from the start of the file.
1046
1047 png_set_sig_bytes(png_ptr, number);
1048
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001049.SS Setting up callback code
1050
1051You can set up a callback function to handle any unknown chunks in the
1052input stream. You must supply the function
1053
1054 read_chunk_callback(png_ptr ptr,
1055 png_unknown_chunkp chunk);
1056 {
1057 /* The unknown chunk structure contains your
1058 chunk data: */
1059 png_byte name[5];
1060 png_byte *data;
1061 png_size_t size;
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001062 /* Note that libpng has already taken care of
1063 the CRC handling */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001064
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001065 /* put your code here. Return one of the
1066 following: */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001067
1068 return (-n); /* chunk had an error */
1069 return (0); /* did not recognize */
1070 return (n); /* success */
1071 }
1072
1073(You can give your function another name that you like instead of
1074"read_chunk_callback")
1075
1076To inform libpng about your function, use
1077
1078 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1079 read_chunk_callback);
1080
1081This names not only the callback function, but also a user pointer that
1082you can retrieve with
1083
1084 png_get_user_chunk_ptr(png_ptr);
1085
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001086At this point, you can set up a callback function that will be
1087called after each row has been read, which you can use to control
1088a progress meter or the like. It's demonstrated in pngtest.c.
1089You must supply a function
1090
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001091 void read_row_callback(png_ptr ptr, png_uint_32 row,
1092 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001093 {
1094 /* put your code here */
1095 }
1096
1097(You can give it another name that you like instead of "read_row_callback")
1098
1099To inform libpng about your function, use
1100
1101 png_set_read_status_fn(png_ptr, read_row_callback);
1102
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05001103.SS Width and height limits
1104
1105The PNG specification allows the width and height of an image to be as
1106large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1107Since very few applications really need to process such large images,
1108we have imposed an arbitrary 1-million limit on rows and columns.
1109Larger images will be rejected immediately with a png_error() call. If
1110you wish to override this limit, you can use
1111
1112 png_set_user_limits(png_ptr, width_max, height_max);
1113
1114to set your own limits, or use width_max = height_max = 0x7fffffffL
1115to allow all valid dimensions (libpng may reject some very large images
1116anyway because of potential buffer overflow conditions).
1117
1118You should put this statement after you create the PNG structure and
1119before calling png_read_info(), png_read_png(), or png_process_data().
1120If you need to retrieve the limits that are being applied, use
1121
1122 width_max = png_get_user_width_max(png_ptr);
1123 height_max = png_get_user_height_max(png_ptr);
1124
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001125.SS Unknown-chunk handling
1126
1127Now you get to set the way the library processes unknown chunks in the
1128input PNG stream. Both known and unknown chunks will be read. Normal
1129behavior is that known chunks will be parsed into information in
1130various info_ptr members; unknown chunks will be discarded. To change
1131this, you can call:
1132
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001133 png_set_keep_unknown_chunks(png_ptr, keep,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001134 chunk_list, num_chunks);
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001135 keep - 0: do not handle as unknown
1136 1: do not keep
1137 2: keep only if safe-to-copy
1138 3: keep even if unsafe-to-copy
1139 You can use these definitions:
1140 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1141 PNG_HANDLE_CHUNK_NEVER 1
1142 PNG_HANDLE_CHUNK_IF_SAFE 2
1143 PNG_HANDLE_CHUNK_ALWAYS 3
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001144 chunk_list - list of chunks affected (a byte string,
1145 five bytes per chunk, NULL or '\0' if
1146 num_chunks is 0)
1147 num_chunks - number of chunks affected; if 0, all
Glenn Randers-Pehrsondff799e2004-08-07 21:42:49 -05001148 unknown chunks are affected. If nonzero,
1149 only the chunks in the list are affected
1150
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001151Unknown chunks declared in this way will be saved as raw data onto a
1152list of png_unknown_chunk structures. If a chunk that is normally
1153known to libpng is named in the list, it will be handled as unknown,
1154according to the "keep" directive. If a chunk is named in successive
1155instances of png_set_keep_unknown_chunks(), the final instance will
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001156take precedence. The IHDR and IEND chunks should not be named in
1157chunk_list; if they are, libpng will process them normally anyway.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001158
1159.SS The high-level read interface
1160
1161At this point there are two ways to proceed; through the high-level
1162read interface, or through a sequence of low-level read operations.
1163You can use the high-level interface if (a) you are willing to read
1164the entire image into memory, and (b) the input transformations
1165you want to do are limited to the following set:
1166
1167 PNG_TRANSFORM_IDENTITY No transformation
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001168 PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
1169 8 bits
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001170 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001171 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1172 samples to bytes
1173 PNG_TRANSFORM_PACKSWAP Change order of packed
1174 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001175 PNG_TRANSFORM_EXPAND Perform set_expand()
1176 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001177 PNG_TRANSFORM_SHIFT Normalize pixels to the
1178 sBIT depth
1179 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1180 to BGRA
1181 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1182 to AG
1183 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1184 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001185 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
1186
1187(This excludes setting a background color, doing gamma transformation,
1188dithering, and setting filler.) If this is the case, simply do this:
1189
1190 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1191
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05001192where png_transforms is an integer containing the bitwise OR of
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001193some set of transformation flags. This call is equivalent to png_read_info(),
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001194followed the set of transformations indicated by the transform mask,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001195then png_read_image(), and finally png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001196
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001197(The final parameter of this call is not yet used. Someday it might point
1198to transformation parameters required by some future input transform.)
1199
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001200You must use png_transforms and not call any png_set_transform() functions
1201when you use png_read_png().
1202
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001203After you have called png_read_png(), you can retrieve the image data
1204with
1205
1206 row_pointers = png_get_rows(png_ptr, info_ptr);
1207
1208where row_pointers is an array of pointers to the pixel data for each row:
1209
1210 png_bytep row_pointers[height];
1211
1212If you know your image size and pixel size ahead of time, you can allocate
1213row_pointers prior to calling png_read_png() with
1214
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001215 if (height > PNG_UINT_32_MAX/sizeof(png_bytep))
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001216 png_error (png_ptr,
1217 "Image is too tall to process in memory");
1218 if (width > PNG_UINT_32_MAX/pixel_size)
1219 png_error (png_ptr,
1220 "Image is too wide to process in memory");
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001221 row_pointers = png_malloc(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001222 height*sizeof(png_bytep));
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001223 for (int i=0; i<height, i++)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001224 row_pointers[i]=png_malloc(png_ptr,
1225 width*pixel_size);
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001226 png_set_rows(png_ptr, info_ptr, &row_pointers);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001227
1228Alternatively you could allocate your image in one big block and define
1229row_pointers[i] to point into the proper places in your block.
1230
1231If you use png_set_rows(), the application is responsible for freeing
1232row_pointers (and row_pointers[i], if they were separately allocated).
1233
1234If you don't allocate row_pointers ahead of time, png_read_png() will
1235do it, and it'll be free'ed when you call png_destroy_*().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001236
1237.SS The low-level read interface
1238
1239If you are going the low-level route, you are now ready to read all
1240the file information up to the actual image data. You do this with a
1241call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001242
1243 png_read_info(png_ptr, info_ptr);
1244
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001245This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001246
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001247.SS Querying the info structure
1248
1249Functions are used to get the information from the info_ptr once it
1250has been read. Note that these fields may not be completely filled
1251in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001252
1253 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1254 &bit_depth, &color_type, &interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001255 &compression_type, &filter_method);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001256
1257 width - holds the width of the image
1258 in pixels (up to 2^31).
1259 height - holds the height of the image
1260 in pixels (up to 2^31).
1261 bit_depth - holds the bit depth of one of the
1262 image channels. (valid values are
1263 1, 2, 4, 8, 16 and depend also on
1264 the color_type. See also
1265 significant bits (sBIT) below).
1266 color_type - describes which color/alpha channels
1267 are present.
1268 PNG_COLOR_TYPE_GRAY
1269 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001270 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001271 (bit depths 8, 16)
1272 PNG_COLOR_TYPE_PALETTE
1273 (bit depths 1, 2, 4, 8)
1274 PNG_COLOR_TYPE_RGB
1275 (bit_depths 8, 16)
1276 PNG_COLOR_TYPE_RGB_ALPHA
1277 (bit_depths 8, 16)
1278
1279 PNG_COLOR_MASK_PALETTE
1280 PNG_COLOR_MASK_COLOR
1281 PNG_COLOR_MASK_ALPHA
1282
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001283 filter_method - (must be PNG_FILTER_TYPE_BASE
1284 for PNG 1.0, and can also be
1285 PNG_INTRAPIXEL_DIFFERENCING if
1286 the PNG datastream is embedded in
1287 a MNG-1.0 datastream)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001288 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1289 for PNG 1.0)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001290 interlace_type - (PNG_INTERLACE_NONE or
1291 PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001292 Any or all of interlace_type, compression_type, of
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001293 filter_method can be NULL if you are
1294 not interested in their values.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001295
1296 channels = png_get_channels(png_ptr, info_ptr);
1297 channels - number of channels of info for the
1298 color type (valid values are 1 (GRAY,
1299 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1300 4 (RGB_ALPHA or RGB + filler byte))
1301 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1302 rowbytes - number of bytes needed to hold a row
1303
1304 signature = png_get_signature(png_ptr, info_ptr);
1305 signature - holds the signature read from the
1306 file (if any). The data is kept in
1307 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001308 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001309 application had already read in 4
1310 bytes of signature before starting
1311 libpng, the remaining 4 bytes would
1312 be in signature[4] through signature[7]
1313 (see png_set_sig_bytes())).
1314
1315
1316 width = png_get_image_width(png_ptr,
1317 info_ptr);
1318 height = png_get_image_height(png_ptr,
1319 info_ptr);
1320 bit_depth = png_get_bit_depth(png_ptr,
1321 info_ptr);
1322 color_type = png_get_color_type(png_ptr,
1323 info_ptr);
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001324 filter_method = png_get_filter_type(png_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001325 info_ptr);
1326 compression_type = png_get_compression_type(png_ptr,
1327 info_ptr);
1328 interlace_type = png_get_interlace_type(png_ptr,
1329 info_ptr);
1330
1331
1332These are also important, but their validity depends on whether the chunk
1333has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1334png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1335data has been read, or zero if it is missing. The parameters to the
1336png_get_<chunk> are set directly if they are simple data types, or a pointer
1337into the info_ptr is returned for any complex types.
1338
1339 png_get_PLTE(png_ptr, info_ptr, &palette,
1340 &num_palette);
1341 palette - the palette for the file
1342 (array of png_color)
1343 num_palette - number of entries in the palette
1344
1345 png_get_gAMA(png_ptr, info_ptr, &gamma);
1346 gamma - the gamma the file is written
1347 at (PNG_INFO_gAMA)
1348
1349 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1350 srgb_intent - the rendering intent (PNG_INFO_sRGB)
1351 The presence of the sRGB chunk
1352 means that the pixel data is in the
1353 sRGB color space. This chunk also
1354 implies specific values of gAMA and
1355 cHRM.
1356
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001357 png_get_iCCP(png_ptr, info_ptr, &name,
1358 &compression_type, &profile, &proflen);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001359 name - The profile name.
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001360 compression - The compression type; always
1361 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1362 You may give NULL to this argument to
1363 ignore it.
1364 profile - International Color Consortium color
1365 profile data. May contain NULs.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001366 proflen - length of profile data in bytes.
1367
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001368 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1369 sig_bit - the number of significant bits for
1370 (PNG_INFO_sBIT) each of the gray,
1371 red, green, and blue channels,
1372 whichever are appropriate for the
1373 given color type (png_color_16)
1374
1375 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
1376 &trans_values);
1377 trans - array of transparent entries for
1378 palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05001379 trans_values - graylevel or color sample values of
1380 the single transparent color for
1381 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001382 num_trans - number of transparent entries
1383 (PNG_INFO_tRNS)
1384
1385 png_get_hIST(png_ptr, info_ptr, &hist);
1386 (PNG_INFO_hIST)
1387 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001388 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001389
1390 png_get_tIME(png_ptr, info_ptr, &mod_time);
1391 mod_time - time image was last modified
1392 (PNG_VALID_tIME)
1393
1394 png_get_bKGD(png_ptr, info_ptr, &background);
1395 background - background color (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001396 valid 16-bit red, green and blue
1397 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001398
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001399 num_comments = png_get_text(png_ptr, info_ptr,
1400 &text_ptr, &num_text);
1401 num_comments - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001402 text_ptr - array of png_text holding image
1403 comments
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001404 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001405 on "text" PNG_TEXT_COMPRESSION_NONE
1406 PNG_TEXT_COMPRESSION_zTXt
1407 PNG_ITXT_COMPRESSION_NONE
1408 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001409 text_ptr[i].key - keyword for comment. Must contain
1410 1-79 characters.
1411 text_ptr[i].text - text comments for current
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001412 keyword. Can be empty.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001413 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001414 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001415 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001416 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001417 text_ptr[i].lang - language of comment (empty
1418 string for unknown).
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06001419 text_ptr[i].lang_key - keyword in UTF-8
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001420 (empty string for unknown).
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001421 num_text - number of comments (same as
1422 num_comments; you can put NULL here
1423 to avoid the duplication)
1424 Note while png_set_text() will accept text, language,
1425 and translated keywords that can be NULL pointers, the
1426 structure returned by png_get_text will always contain
1427 regular zero-terminated C strings. They might be
1428 empty strings but they will never be NULL pointers.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001429
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001430 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1431 &palette_ptr);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001432 palette_ptr - array of palette structures holding
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001433 contents of one or more sPLT chunks
1434 read.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001435 num_spalettes - number of sPLT chunks read.
1436
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001437 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001438 &unit_type);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001439 offset_x - positive offset from the left edge
1440 of the screen
1441 offset_y - positive offset from the top edge
1442 of the screen
1443 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1444
1445 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001446 &unit_type);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001447 res_x - pixels/unit physical resolution in
1448 x direction
1449 res_y - pixels/unit physical resolution in
1450 x direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001451 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001452 PNG_RESOLUTION_METER
1453
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001454 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1455 &height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001456 unit - physical scale units (an integer)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001457 width - width of a pixel in physical scale units
1458 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001459 (width and height are doubles)
1460
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001461 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1462 &height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001463 unit - physical scale units (an integer)
1464 width - width of a pixel in physical scale units
1465 height - height of a pixel in physical scale units
1466 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001467
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001468 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1469 info_ptr, &unknowns)
1470 unknowns - array of png_unknown_chunk
1471 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001472 unknowns[i].name - name of unknown chunk
1473 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001474 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001475 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001476
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001477 The value of "i" corresponds to the order in which the
1478 chunks were read from the PNG file or inserted with the
1479 png_set_unknown_chunks() function.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001480
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001481The data from the pHYs chunk can be retrieved in several convenient
1482forms:
1483
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001484 res_x = png_get_x_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001485 info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001486 res_y = png_get_y_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001487 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001488 res_x_and_y = png_get_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001489 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001490 res_x = png_get_x_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001491 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001492 res_y = png_get_y_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001493 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001494 res_x_and_y = png_get_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001495 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001496 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001497 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001498
1499 (Each of these returns 0 [signifying "unknown"] if
1500 the data is not present or if res_x is 0;
1501 res_x_and_y is 0 if res_x != res_y)
1502
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001503The data from the oFFs chunk can be retrieved in several convenient
1504forms:
1505
1506 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1507 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1508 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1509 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1510
1511 (Each of these returns 0 [signifying "unknown" if both
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001512 x and y are 0] if the data is not present or if the
1513 chunk is present but the unit is the pixel)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001514
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001515For more information, see the png_info definition in png.h and the
1516PNG specification for chunk contents. Be careful with trusting
1517rowbytes, as some of the transformations could increase the space
1518needed to hold a row (expand, filler, gray_to_rgb, etc.).
1519See png_read_update_info(), below.
1520
1521A quick word about text_ptr and num_text. PNG stores comments in
1522keyword/text pairs, one pair per chunk, with no limit on the number
1523of text chunks, and a 2^31 byte limit on their size. While there are
1524suggested keywords, there is no requirement to restrict the use to these
1525strings. It is strongly suggested that keywords and text be sensible
1526to humans (that's the point), so don't use abbreviations. Non-printing
1527symbols are not allowed. See the PNG specification for more details.
1528There is also no requirement to have text after the keyword.
1529
1530Keywords should be limited to 79 Latin-1 characters without leading or
1531trailing spaces, but non-consecutive spaces are allowed within the
1532keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001533The text_ptr is an array of png_text structures, each holding a
1534pointer to a language string, a pointer to a keyword and a pointer to
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001535a text string. The text string, language code, and translated
1536keyword may be empty or NULL pointers. The keyword/text
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001537pairs are put into the array in the order that they are received.
1538However, some or all of the text chunks may be after the image, so, to
1539make sure you have read all the text chunks, don't mess with these
1540until after you read the stuff after the image. This will be
1541mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001542
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001543.SS Input transformations
1544
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001545After you've read the header information, you can set up the library
1546to handle any special transformations of the image data. The various
1547ways to transform the data will be described in the order that they
1548should occur. This is important, as some of these change the color
1549type and/or bit depth of the data, and some others only work on
1550certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001551checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001552make sure to only enable a transformation if it will be valid for the
1553data. For example, don't swap red and blue on grayscale data.
1554
1555The colors used for the background and transparency values should be
1556supplied in the same format/depth as the current image data. They
1557are stored in the same format/depth as the image data in a bKGD or tRNS
1558chunk, so this is what libpng expects for this data. The colors are
1559transformed to keep in sync with the image data when an application
1560calls the png_read_update_info() routine (see below).
1561
1562Data will be decoded into the supplied row buffers packed into bytes
1563unless the library has been told to transform it into another format.
1564For example, 4 bit/pixel paletted or grayscale data will be returned
15652 pixels/byte with the leftmost pixel in the high-order bits of the
1566byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001567in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
1568is called to insert filler bytes, either before or after each RGB triplet.
156916-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
1570byte of the color value first, unless png_set_strip_16() is called to
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06001571transform it to regular RGB RGB triplets, or png_set_filler() or
1572png_set_add alpha() is called to insert filler bytes, either before or
1573after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
1574be modified with
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001575png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001576
1577The following code transforms grayscale images of less than 8 to 8 bits,
1578changes paletted images to RGB, and adds a full alpha channel if there is
1579transparency information in a tRNS chunk. This is most useful on
1580grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1581viewing application that wishes to treat all images in the same way.
1582
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001583 if (color_type == PNG_COLOR_TYPE_PALETTE)
1584 png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001585
1586 if (color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06001587 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001588
1589 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001590 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1591
1592These three functions are actually aliases for png_set_expand(), added
1593in libpng version 1.0.4, with the function names expanded to improve code
1594readability. In some future version they may actually do different
1595things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001596
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06001597As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
1598added. It expands the sample depth without changing tRNS to alpha.
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05001599%12%At the same time, png_set_gray_1_2_4_to_8() was deprecated, and it
1600%12%will be removed from a future version.
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06001601
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001602PNG can have files with 16 bits per channel. If you only can handle
16038 bits per channel, this will strip the pixels down to 8 bit.
1604
1605 if (bit_depth == 16)
1606 png_set_strip_16(png_ptr);
1607
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001608If, for some reason, you don't need the alpha channel on an image,
1609and you want to remove it rather than combining it with the background
1610(but the image author certainly had in mind that you *would* combine
1611it with the background, so that's what you should probably do):
1612
1613 if (color_type & PNG_COLOR_MASK_ALPHA)
1614 png_set_strip_alpha(png_ptr);
1615
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001616In PNG files, the alpha channel in an image
1617is the level of opacity. If you need the alpha channel in an image to
1618be the level of transparency instead of opacity, you can invert the
1619alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1620fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1621images) is fully transparent, with
1622
1623 png_set_invert_alpha(png_ptr);
1624
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001625PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1626they can, resulting in, for example, 8 pixels per byte for 1 bit
1627files. This code expands to 1 pixel per byte without changing the
1628values of the pixels:
1629
1630 if (bit_depth < 8)
1631 png_set_packing(png_ptr);
1632
1633PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1634stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001635higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060016368 bits/sample in the range [0, 255]). However, it is also possible to
1637convert the PNG pixel data back to the original bit depth of the image.
1638This call reduces the pixels back down to the original bit depth:
1639
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05001640 png_color_8p sig_bit;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001641
1642 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1643 png_set_shift(png_ptr, sig_bit);
1644
1645PNG files store 3-color pixels in red, green, blue order. This code
1646changes the storage of the pixels to blue, green, red:
1647
1648 if (color_type == PNG_COLOR_TYPE_RGB ||
1649 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1650 png_set_bgr(png_ptr);
1651
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001652PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
1653into 4 or 8 bytes for windowing systems that need them in this format:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001654
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001655 if (color_type == PNG_COLOR_TYPE_RGB)
1656 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001657
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001658where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001659either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1660you want the filler before the RGB or after. This transformation
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001661does not affect images that already have full alpha channels. To add an
1662opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
1663will generate RGBA pixels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001664
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001665Note that png_set_filler() does not change the color type. If you want
1666to do that, you can add a true alpha channel with
1667
1668 if (color_type == PNG_COLOR_TYPE_RGB ||
1669 color_type == PNG_COLOR_TYPE_GRAY)
1670 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
1671
1672where "filler" contains the alpha value to assign to each pixel.
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06001673This function was added in libpng-1.2.7.
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001674
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001675If you are reading an image with an alpha channel, and you need the
1676data as ARGB instead of the normal PNG format RGBA:
1677
1678 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1679 png_set_swap_alpha(png_ptr);
1680
1681For some uses, you may want a grayscale image to be represented as
1682RGB. This code will do that conversion:
1683
1684 if (color_type == PNG_COLOR_TYPE_GRAY ||
1685 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1686 png_set_gray_to_rgb(png_ptr);
1687
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001688Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001689with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001690
1691 if (color_type == PNG_COLOR_TYPE_RGB ||
1692 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001693 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1694 int red_weight, int green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001695
1696 error_action = 1: silently do the conversion
1697 error_action = 2: issue a warning if the original
1698 image has any pixel where
1699 red != green or red != blue
1700 error_action = 3: issue an error and abort the
1701 conversion if the original
1702 image has any pixel where
1703 red != green or red != blue
1704
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001705 red_weight: weight of red component times 100000
1706 green_weight: weight of green component times 100000
1707 If either weight is negative, default
1708 weights (21268, 71514) are used.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001709
1710If you have set error_action = 1 or 2, you can
1711later check whether the image really was gray, after processing
1712the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1713It will return a png_byte that is zero if the image was gray or
17141 if there were any non-gray pixels. bKGD and sBIT data
1715will be silently converted to grayscale, using the green channel
1716data, regardless of the error_action setting.
1717
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001718With red_weight+green_weight<=100000,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001719the normalized graylevel is computed:
1720
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001721 int rw = red_weight * 65536;
1722 int gw = green_weight * 65536;
1723 int bw = 65536 - (rw + gw);
1724 gray = (rw*red + gw*green + bw*blue)/65536;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001725
1726The default values approximate those recommended in the Charles
1727Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06001728Copyright (c) 1998-01-04 Charles Poynton <poynton at inforamp.net>
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001729
1730 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1731
1732Libpng approximates this with
1733
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001734 Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001735
1736which can be expressed with integers as
1737
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001738 Y = (6969 * R + 23434 * G + 2365 * B)/32768
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001739
1740The calculation is done in a linear colorspace, if the image gamma
1741is known.
1742
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06001743If you have a grayscale and you are using png_set_expand_depth(),
1744png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001745a higher bit-depth, you must either supply the background color as a gray
1746value at the original file bit-depth (need_expand = 1) or else supply the
1747background color as an RGB triplet at the final, expanded bit depth
1748(need_expand = 0). Similarly, if you are reading a paletted image, you
1749must either supply the background color as a palette index (need_expand = 1)
1750or as an RGB triplet that may or may not be in the palette (need_expand = 0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001751
1752 png_color_16 my_background;
1753 png_color_16p image_background;
1754
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001755 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1756 png_set_background(png_ptr, image_background,
1757 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001758 else
1759 png_set_background(png_ptr, &my_background,
1760 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1761
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001762The png_set_background() function tells libpng to composite images
1763with alpha or simple transparency against the supplied background
1764color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1765you may use this color, or supply another color more suitable for
1766the current display (e.g., the background color from a web page). You
1767need to tell libpng whether the color is in the gamma space of the
1768display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
1769(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
1770that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
1771know why anyone would use this, but it's here).
1772
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001773To properly display PNG images on any kind of system, the application needs
1774to know what the display gamma is. Ideally, the user will know this, and
1775the application will allow them to set it. One method of allowing the user
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001776to set the display gamma separately for each system is to check for a
1777SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
1778correctly set.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001779
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001780Note that display_gamma is the overall gamma correction required to produce
1781pleasing results, which depends on the lighting conditions in the surrounding
1782environment. In a dim or brightly lit room, no compensation other than
1783the physical gamma exponent of the monitor is needed, while in a dark room
1784a slightly smaller exponent is better.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001785
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001786 double gamma, screen_gamma;
1787
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001788 if (/* We have a user-defined screen
1789 gamma value */)
1790 {
1791 screen_gamma = user_defined_screen_gamma;
1792 }
1793 /* One way that applications can share the same
1794 screen gamma value */
1795 else if ((gamma_str = getenv("SCREEN_GAMMA"))
1796 != NULL)
1797 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001798 screen_gamma = (double)atof(gamma_str);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001799 }
1800 /* If we don't have another value */
1801 else
1802 {
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001803 screen_gamma = 2.2; /* A good guess for a
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001804 PC monitor in a bright office or a dim room */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001805 screen_gamma = 2.0; /* A good guess for a
1806 PC monitor in a dark room */
1807 screen_gamma = 1.7 or 1.0; /* A good
1808 guess for Mac systems */
1809 }
1810
1811The png_set_gamma() function handles gamma transformations of the data.
1812Pass both the file gamma and the current screen_gamma. If the file does
1813not have a gamma value, you can pass one anyway if you have an idea what
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001814it is (usually 0.45455 is a good guess for GIF images on PCs). Note
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001815that file gammas are inverted from screen gammas. See the discussions
1816on gamma in the PNG specification for an excellent description of what
1817gamma is, and why all applications should support it. It is strongly
1818recommended that PNG viewers support gamma correction.
1819
1820 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
1821 png_set_gamma(png_ptr, screen_gamma, gamma);
1822 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001823 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001824
1825If you need to reduce an RGB file to a paletted file, or if a paletted
1826file has more entries then will fit on your screen, png_set_dither()
1827will do that. Note that this is a simple match dither that merely
1828finds the closest color available. This should work fairly well with
1829optimized palettes, and fairly badly with linear color cubes. If you
1830pass a palette that is larger then maximum_colors, the file will
1831reduce the number of colors in the palette so it will fit into
1832maximum_colors. If there is a histogram, it will use it to make
1833more intelligent choices when reducing the palette. If there is no
1834histogram, it may not do as good a job.
1835
1836 if (color_type & PNG_COLOR_MASK_COLOR)
1837 {
1838 if (png_get_valid(png_ptr, info_ptr,
1839 PNG_INFO_PLTE))
1840 {
Glenn Randers-Pehrson865f4f02002-09-15 20:30:38 -05001841 png_uint_16p histogram = NULL;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001842
1843 png_get_hIST(png_ptr, info_ptr,
1844 &histogram);
1845 png_set_dither(png_ptr, palette, num_palette,
1846 max_screen_colors, histogram, 1);
1847 }
1848 else
1849 {
1850 png_color std_color_cube[MAX_SCREEN_COLORS] =
1851 { ... colors ... };
1852
1853 png_set_dither(png_ptr, std_color_cube,
1854 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
1855 NULL,0);
1856 }
1857 }
1858
1859PNG files describe monochrome as black being zero and white being one.
1860The following code will reverse this (make black be one and white be
1861zero):
1862
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05001863 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
1864 png_set_invert_mono(png_ptr);
1865
1866This function can also be used to invert grayscale and gray-alpha images:
1867
1868 if (color_type == PNG_COLOR_TYPE_GRAY ||
1869 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001870 png_set_invert_mono(png_ptr);
1871
1872PNG files store 16 bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001873ie. most significant bits first). This code changes the storage to the
1874other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001875way PCs store them):
1876
1877 if (bit_depth == 16)
1878 png_set_swap(png_ptr);
1879
1880If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
1881need to change the order the pixels are packed into bytes, you can use:
1882
1883 if (bit_depth < 8)
1884 png_set_packswap(png_ptr);
1885
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001886Finally, you can write your own transformation function if none of
1887the existing ones meets your needs. This is done by setting a callback
1888with
1889
1890 png_set_read_user_transform_fn(png_ptr,
1891 read_transform_fn);
1892
1893You must supply the function
1894
1895 void read_transform_fn(png_ptr ptr, row_info_ptr
1896 row_info, png_bytep data)
1897
1898See pngtest.c for a working example. Your function will be called
1899after all of the other transformations have been processed.
1900
1901You can also set up a pointer to a user structure for use by your
1902callback function, and you can inform libpng that your transform
1903function will change the number of channels or bit depth with the
1904function
1905
1906 png_set_user_transform_info(png_ptr, user_ptr,
1907 user_depth, user_channels);
1908
1909The user's application, not libpng, is responsible for allocating and
1910freeing any memory required for the user structure.
1911
1912You can retrieve the pointer via the function
1913png_get_user_transform_ptr(). For example:
1914
1915 voidp read_user_transform_ptr =
1916 png_get_user_transform_ptr(png_ptr);
1917
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001918The last thing to handle is interlacing; this is covered in detail below,
1919but you must call the function here if you want libpng to handle expansion
1920of the interlaced image.
1921
1922 number_of_passes = png_set_interlace_handling(png_ptr);
1923
1924After setting the transformations, libpng can update your png_info
1925structure to reflect any transformations you've requested with this
1926call. This is most useful to update the info structure's rowbytes
1927field so you can use it to allocate your image memory. This function
1928will also update your palette with the correct screen_gamma and
1929background if these have been given with the calls above.
1930
1931 png_read_update_info(png_ptr, info_ptr);
1932
1933After you call png_read_update_info(), you can allocate any
1934memory you need to hold the image. The row data is simply
1935raw byte data for all forms of images. As the actual allocation
1936varies among applications, no example will be given. If you
1937are allocating one large chunk, you will need to build an
1938array of pointers to each row, as it will be needed for some
1939of the functions below.
1940
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001941.SS Reading image data
1942
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001943After you've allocated memory, you can read the image data.
1944The simplest way to do this is in one function call. If you are
1945allocating enough memory to hold the whole image, you can just
1946call png_read_image() and libpng will read in all the image data
1947and put it in the memory area supplied. You will need to pass in
1948an array of pointers to each row.
1949
1950This function automatically handles interlacing, so you don't need
1951to call png_set_interlace_handling() or call this function multiple
1952times, or any of that other stuff necessary with png_read_rows().
1953
1954 png_read_image(png_ptr, row_pointers);
1955
1956where row_pointers is:
1957
1958 png_bytep row_pointers[height];
1959
1960You can point to void or char or whatever you use for pixels.
1961
1962If you don't want to read in the whole image at once, you can
1963use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001964interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001965
1966 png_read_rows(png_ptr, row_pointers, NULL,
1967 number_of_rows);
1968
1969where row_pointers is the same as in the png_read_image() call.
1970
1971If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001972a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001973
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001974 png_bytep row_pointer = row;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001975 png_read_row(png_ptr, row_pointer, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001976
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001977If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
1978get somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001979interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001980is a somewhat complicated 2D interlace scheme, known as Adam7, that
1981breaks down an image into seven smaller images of varying size, based
1982on an 8x8 grid.
1983
1984libpng can fill out those images or it can give them to you "as is".
1985If you want them filled out, there are two ways to do that. The one
1986mentioned in the PNG specification is to expand each pixel to cover
1987those pixels that have not been read yet (the "rectangle" method).
1988This results in a blocky image for the first pass, which gradually
1989smooths out as more pixels are read. The other method is the "sparkle"
1990method, where pixels are drawn only in their final locations, with the
1991rest of the image remaining whatever colors they were initialized to
1992before the start of the read. The first method usually looks better,
1993but tends to be slower, as there are more pixels to put in the rows.
1994
1995If you don't want libpng to handle the interlacing details, just call
1996png_read_rows() seven times to read in all seven images. Each of the
1997images is a valid image by itself, or they can all be combined on an
19988x8 grid to form a single image (although if you intend to combine them
1999you would be far better off using the libpng interlace handling).
2000
2001The first pass will return an image 1/8 as wide as the entire image
2002(every 8th column starting in column 0) and 1/8 as high as the original
2003(every 8th row starting in row 0), the second will be 1/8 as wide
2004(starting in column 4) and 1/8 as high (also starting in row 0). The
2005third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
20061/8 as high (every 8th row starting in row 4), and the fourth pass will
2007be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
2008and every 4th row starting in row 0). The fifth pass will return an
2009image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
2010while the sixth pass will be 1/2 as wide and 1/2 as high as the original
2011(starting in column 1 and row 0). The seventh and final pass will be as
2012wide as the original, and 1/2 as high, containing all of the odd
2013numbered scanlines. Phew!
2014
2015If you want libpng to expand the images, call this before calling
2016png_start_read_image() or png_read_update_info():
2017
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002018 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002019 number_of_passes
2020 = png_set_interlace_handling(png_ptr);
2021
2022This will return the number of passes needed. Currently, this
2023is seven, but may change if another interlace type is added.
2024This function can be called even if the file is not interlaced,
2025where it will return one pass.
2026
2027If you are not going to display the image after each pass, but are
2028going to wait until the entire image is read in, use the sparkle
2029effect. This effect is faster and the end result of either method
2030is exactly the same. If you are planning on displaying the image
2031after each pass, the "rectangle" effect is generally considered the
2032better looking one.
2033
2034If you only want the "sparkle" effect, just call png_read_rows() as
2035normal, with the third parameter NULL. Make sure you make pass over
2036the image number_of_passes times, and you don't change the data in the
2037rows between calls. You can change the locations of the data, just
2038not the data. Each pass only writes the pixels appropriate for that
2039pass, and assumes the data from previous passes is still valid.
2040
2041 png_read_rows(png_ptr, row_pointers, NULL,
2042 number_of_rows);
2043
2044If you only want the first effect (the rectangles), do the same as
2045before except pass the row buffer in the third parameter, and leave
2046the second parameter NULL.
2047
2048 png_read_rows(png_ptr, NULL, row_pointers,
2049 number_of_rows);
2050
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002051.SS Finishing a sequential read
2052
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06002053After you are finished reading the image through the
2054low-level interface, you can finish reading the file. If you are
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002055interested in comments or time, which may be stored either before or
2056after the image data, you should pass the separate png_info struct if
2057you want to keep the comments from before and after the image
2058separate. If you are not interested, you can pass NULL.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002059
2060 png_read_end(png_ptr, end_info);
2061
2062When you are done, you can free all memory allocated by libpng like this:
2063
2064 png_destroy_read_struct(&png_ptr, &info_ptr,
2065 &end_info);
2066
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002067It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002068point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002069
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002070 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002071 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002072 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002073 more of
2074 PNG_FREE_PLTE, PNG_FREE_TRNS,
2075 PNG_FREE_HIST, PNG_FREE_ICCP,
2076 PNG_FREE_PCAL, PNG_FREE_ROWS,
2077 PNG_FREE_SCAL, PNG_FREE_SPLT,
2078 PNG_FREE_TEXT, PNG_FREE_UNKN,
2079 or simply PNG_FREE_ALL
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002080 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002081 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002082
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002083This function may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002084already been freed, or has not yet been allocated, or was allocated
2085by the user and not by libpng, and will in those
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002086cases do nothing. The "seq" parameter is ignored if only one item
2087of the selected data type, such as PLTE, is allowed. If "seq" is not
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002088-1, and multiple items are allowed for the data type identified in
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002089the mask, such as text or sPLT, only the n'th item in the structure
2090is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002091
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002092The default behavior is only to free data that was allocated internally
2093by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002094or so that it will free data that was allocated by the user with png_malloc()
2095or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002096
2097 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002098 mask - which data elements are affected
2099 same choices as in png_free_data()
2100 freer - one of
2101 PNG_DESTROY_WILL_FREE_DATA
2102 PNG_SET_WILL_FREE_DATA
2103 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002104
2105This function only affects data that has already been allocated.
2106You can call this function after reading the PNG data but before calling
2107any png_set_*() functions, to control whether the user or the png_set_*()
2108function is responsible for freeing any existing data that might be present,
2109and again after the png_set_*() functions to control whether the user
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002110or png_destroy_*() is supposed to free the data. When the user assumes
2111responsibility for libpng-allocated data, the application must use
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002112png_free() to free it, and when the user transfers responsibility to libpng
2113for data that the user has allocated, the user must have used png_malloc()
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05002114or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002115
2116If you allocated your row_pointers in a single block, as suggested above in
2117the description of the high level read interface, you must not transfer
2118responsibility for freeing it to the png_set_rows or png_read_destroy function,
2119because they would also try to free the individual row_pointers[i].
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002120
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002121If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2122separately, do not transfer responsibility for freeing text_ptr to libpng,
2123because when libpng fills a png_text structure it combines these members with
2124the key member, and png_free_data() will free only text_ptr.key. Similarly,
2125if you transfer responsibility for free'ing text_ptr from libpng to your
2126application, your application must not separately free those members.
2127
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002128The png_free_data() function will turn off the "valid" flag for anything
2129it frees. If you need to turn the flag off for a chunk that was freed by your
2130application instead of by libpng, you can use
2131
2132 png_set_invalid(png_ptr, info_ptr, mask);
2133 mask - identifies the chunks to be made invalid,
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002134 containing the bitwise OR of one or
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06002135 more of
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002136 PNG_INFO_gAMA, PNG_INFO_sBIT,
2137 PNG_INFO_cHRM, PNG_INFO_PLTE,
2138 PNG_INFO_tRNS, PNG_INFO_bKGD,
2139 PNG_INFO_hIST, PNG_INFO_pHYs,
2140 PNG_INFO_oFFs, PNG_INFO_tIME,
2141 PNG_INFO_pCAL, PNG_INFO_sRGB,
2142 PNG_INFO_iCCP, PNG_INFO_sPLT,
2143 PNG_INFO_sCAL, PNG_INFO_IDAT
2144
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002145For a more compact example of reading a PNG image, see the file example.c.
2146
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002147.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002148
2149The progressive reader is slightly different then the non-progressive
2150reader. Instead of calling png_read_info(), png_read_rows(), and
2151png_read_end(), you make one call to png_process_data(), which calls
2152callbacks when it has the info, a row, or the end of the image. You
2153set up these callbacks with png_set_progressive_read_fn(). You don't
2154have to worry about the input/output functions of libpng, as you are
2155giving the library the data directly in png_process_data(). I will
2156assume that you have read the section on reading PNG files above,
2157so I will only highlight the differences (although I will show
2158all of the code).
2159
2160png_structp png_ptr;
2161png_infop info_ptr;
2162
2163 /* An example code fragment of how you would
2164 initialize the progressive reader in your
2165 application. */
2166 int
2167 initialize_png_reader()
2168 {
2169 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002170 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002171 user_error_fn, user_warning_fn);
2172 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002173 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002174 info_ptr = png_create_info_struct(png_ptr);
2175 if (!info_ptr)
2176 {
2177 png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
2178 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002179 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002180 }
2181
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002182 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002183 {
2184 png_destroy_read_struct(&png_ptr, &info_ptr,
2185 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002186 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002187 }
2188
2189 /* This one's new. You can provide functions
2190 to be called when the header info is valid,
2191 when each row is completed, and when the image
2192 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002193 you can specify NULL parameters. Even when all
2194 three functions are NULL, you need to call
2195 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002196 any struct as the user_ptr (cast to a void pointer
2197 for the function call), and retrieve the pointer
2198 from inside the callbacks using the function
2199
2200 png_get_progressive_ptr(png_ptr);
2201
2202 which will return a void pointer, which you have
2203 to cast appropriately.
2204 */
2205 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
2206 info_callback, row_callback, end_callback);
2207
2208 return 0;
2209 }
2210
2211 /* A code fragment that you call as you receive blocks
2212 of data */
2213 int
2214 process_data(png_bytep buffer, png_uint_32 length)
2215 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002216 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002217 {
2218 png_destroy_read_struct(&png_ptr, &info_ptr,
2219 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002220 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002221 }
2222
2223 /* This one's new also. Simply give it a chunk
2224 of data from the file stream (in order, of
2225 course). On machines with segmented memory
2226 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002227 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002228 of 4K. Although you can give it much less if
2229 necessary (I assume you can give it chunks of
2230 1 byte, I haven't tried less then 256 bytes
2231 yet). When this function returns, you may
2232 want to display any rows that were generated
2233 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002234 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002235 */
2236 png_process_data(png_ptr, info_ptr, buffer, length);
2237 return 0;
2238 }
2239
2240 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002241 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002242 has been supplied so all of the header has been
2243 read.
2244 */
2245 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002246 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002247 {
2248 /* Do any setup here, including setting any of
2249 the transformations mentioned in the Reading
2250 PNG files section. For now, you _must_ call
2251 either png_start_read_image() or
2252 png_read_update_info() after all the
2253 transformations are set (even if you don't set
2254 any). You may start getting rows before
2255 png_process_data() returns, so this is your
2256 last chance to prepare for that.
2257 */
2258 }
2259
2260 /* This function is called when each row of image
2261 data is complete */
2262 void
2263 row_callback(png_structp png_ptr, png_bytep new_row,
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05002264 png_uint_32 row_num, int pass)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002265 {
2266 /* If the image is interlaced, and you turned
2267 on the interlace handler, this function will
2268 be called for every row in every pass. Some
2269 of these rows will not be changed from the
2270 previous pass. When the row is not changed,
2271 the new_row variable will be NULL. The rows
2272 and passes are called in order, so you don't
2273 really need the row_num and pass, but I'm
2274 supplying them because it may make your life
2275 easier.
2276
2277 For the non-NULL rows of interlaced images,
2278 you must call png_progressive_combine_row()
2279 passing in the row and the old row. You can
2280 call this function for NULL rows (it will just
2281 return) and for non-interlaced images (it just
2282 does the memcpy for you) if it will make the
2283 code easier. Thus, you can just do this for
2284 all cases:
2285 */
2286
2287 png_progressive_combine_row(png_ptr, old_row,
2288 new_row);
2289
2290 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05002291 previously for the row. Note that the first
2292 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002293 the old row, so the rows do not have to be
2294 initialized. After the first pass (and only
2295 for interlaced images), you will have to pass
2296 the current row, and the function will combine
2297 the old row and the new row.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002298 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002299 }
2300
2301 void
2302 end_callback(png_structp png_ptr, png_infop info)
2303 {
2304 /* This function is called after the whole image
2305 has been read, including any chunks after the
2306 image (up to and including the IEND). You
2307 will usually have the same info chunk as you
2308 had in the header, although some data may have
2309 been added to the comments and time fields.
2310
2311 Most people won't do much here, perhaps setting
2312 a flag that marks the image as finished.
2313 */
2314 }
2315
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002316
2317
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002318.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002319
2320Much of this is very similar to reading. However, everything of
2321importance is repeated here, so you won't have to constantly look
2322back up in the reading section to understand writing.
2323
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002324.SS Setup
2325
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002326You will want to do the I/O initialization before you get into libpng,
2327so if it doesn't work, you don't have anything to undo. If you are not
2328using the standard I/O functions, you will need to replace them with
2329custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002330
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002331 FILE *fp = fopen(file_name, "wb");
2332 if (!fp)
2333 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002334 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002335 }
2336
2337Next, png_struct and png_info need to be allocated and initialized.
2338As these can be both relatively large, you may not want to store these
2339on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002340will want to check if they return NULL. If you are also reading,
2341you won't want to name your read structure and your write structure
2342both "png_ptr"; you can call them anything you like, such as
2343"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002344
2345 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002346 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002347 user_error_fn, user_warning_fn);
2348 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002349 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002350
2351 png_infop info_ptr = png_create_info_struct(png_ptr);
2352 if (!info_ptr)
2353 {
2354 png_destroy_write_struct(&png_ptr,
2355 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002356 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002357 }
2358
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002359If you want to use your own memory allocation routines,
2360define PNG_USER_MEM_SUPPORTED and use
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002361png_create_write_struct_2() instead of png_create_write_struct():
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002362
2363 png_structp png_ptr = png_create_write_struct_2
2364 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2365 user_error_fn, user_warning_fn, (png_voidp)
2366 user_mem_ptr, user_malloc_fn, user_free_fn);
2367
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002368After you have these structures, you will need to set up the
2369error handling. When libpng encounters an error, it expects to
2370longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002371setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002372write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002373the png_jmpbuf(png_ptr) every time you enter a new routine that will
2374call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002375for your compiler for more information on setjmp/longjmp. See
2376the discussion on libpng error handling in the Customizing Libpng
2377section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002378
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002379 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002380 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002381 png_destroy_write_struct(&png_ptr, &info_ptr);
2382 fclose(fp);
2383 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002384 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002385 ...
2386 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002387
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002388If you would rather avoid the complexity of setjmp/longjmp issues,
2389you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
2390errors will result in a call to PNG_ABORT() which defaults to abort().
2391
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002392Now you need to set up the output code. The default for libpng is to
2393use the C function fwrite(). If you use this, you will need to pass a
2394valid FILE * in the function png_init_io(). Be sure that the file is
2395opened in binary mode. Again, if you wish to handle writing data in
2396another way, see the discussion on libpng I/O handling in the Customizing
2397Libpng section below.
2398
2399 png_init_io(png_ptr, fp);
2400
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05002401If you are embedding your PNG into a datastream such as MNG, and don't
2402want libpng to write the 8-byte signature, or if you have already
2403written the signature in your application, use
2404
2405 png_set_sig_bytes(png_ptr, 8);
2406
2407to inform libpng that it should not write a signature.
2408
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002409.SS Write callbacks
2410
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002411At this point, you can set up a callback function that will be
2412called after each row has been written, which you can use to control
2413a progress meter or the like. It's demonstrated in pngtest.c.
2414You must supply a function
2415
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002416 void write_row_callback(png_ptr, png_uint_32 row,
2417 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002418 {
2419 /* put your code here */
2420 }
2421
2422(You can give it another name that you like instead of "write_row_callback")
2423
2424To inform libpng about your function, use
2425
2426 png_set_write_status_fn(png_ptr, write_row_callback);
2427
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002428You now have the option of modifying how the compression library will
2429run. The following functions are mainly for testing, but may be useful
2430in some cases, like if you need to write PNG files extremely fast and
2431are willing to give up some compression, or if you want to get the
2432maximum possible compression at the expense of slower writing. If you
2433have no special needs in this area, let the library do what it wants by
2434not calling this function at all, as it has been tuned to deliver a good
2435speed/compression ratio. The second parameter to png_set_filter() is
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002436the filter method, for which the only valid values are 0 (as of the
2437July 1999 PNG specification, version 1.2) or 64 (if you are writing
2438a PNG datastream that is to be embedded in a MNG datastream). The third
2439parameter is a flag that indicates which filter type(s) are to be tested
2440for each scanline. See the PNG specification for details on the specific filter
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002441types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002442
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002443
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002444 /* turn on or off filtering, and/or choose
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002445 specific filters. You can use either a single
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002446 PNG_FILTER_VALUE_NAME or the bitwise OR of one
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002447 or more PNG_FILTER_NAME masks. */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002448 png_set_filter(png_ptr, 0,
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002449 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
2450 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
2451 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
2452 PNG_FILTER_AVE | PNG_FILTER_VALUE_AVE |
2453 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
2454 PNG_ALL_FILTERS);
2455
2456If an application
2457wants to start and stop using particular filters during compression,
2458it should start out with all of the filters (to ensure that the previous
2459row of pixels will be stored in case it's needed later), and then add
2460and remove them after the start of compression.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002461
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002462If you are writing a PNG datastream that is to be embedded in a MNG
2463datastream, the second parameter can be either 0 or 64.
2464
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002465The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002466library, and should mostly be ignored unless you really know what you are
2467doing. The only generally useful call is png_set_compression_level()
2468which changes how much time zlib spends on trying to compress the image
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002469data. See the Compression Library (zlib.h and algorithm.txt, distributed
2470with zlib) for details on the compression levels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002471
2472 /* set the zlib compression level */
2473 png_set_compression_level(png_ptr,
2474 Z_BEST_COMPRESSION);
2475
2476 /* set other zlib parameters */
2477 png_set_compression_mem_level(png_ptr, 8);
2478 png_set_compression_strategy(png_ptr,
2479 Z_DEFAULT_STRATEGY);
2480 png_set_compression_window_bits(png_ptr, 15);
2481 png_set_compression_method(png_ptr, 8);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002482 png_set_compression_buffer_size(png_ptr, 8192)
2483
2484extern PNG_EXPORT(void,png_set_zbuf_size)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002485
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002486.SS Setting the contents of info for output
2487
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002488You now need to fill in the png_info structure with all the data you
2489wish to write before the actual image. Note that the only thing you
2490are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002491chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002492the latest PNG specification for more information on that. If you
2493wish to write them before the image, fill them in now, and flag that
2494data as being valid. If you want to wait until after the data, don't
2495fill them until png_write_end(). For all the fields in png_info and
2496their data types, see png.h. For explanations of what the fields
2497contain, see the PNG specification.
2498
2499Some of the more important parts of the png_info are:
2500
2501 png_set_IHDR(png_ptr, info_ptr, width, height,
2502 bit_depth, color_type, interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002503 compression_type, filter_method)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002504 width - holds the width of the image
2505 in pixels (up to 2^31).
2506 height - holds the height of the image
2507 in pixels (up to 2^31).
2508 bit_depth - holds the bit depth of one of the
2509 image channels.
2510 (valid values are 1, 2, 4, 8, 16
2511 and depend also on the
2512 color_type. See also significant
2513 bits (sBIT) below).
2514 color_type - describes which color/alpha
2515 channels are present.
2516 PNG_COLOR_TYPE_GRAY
2517 (bit depths 1, 2, 4, 8, 16)
2518 PNG_COLOR_TYPE_GRAY_ALPHA
2519 (bit depths 8, 16)
2520 PNG_COLOR_TYPE_PALETTE
2521 (bit depths 1, 2, 4, 8)
2522 PNG_COLOR_TYPE_RGB
2523 (bit_depths 8, 16)
2524 PNG_COLOR_TYPE_RGB_ALPHA
2525 (bit_depths 8, 16)
2526
2527 PNG_COLOR_MASK_PALETTE
2528 PNG_COLOR_MASK_COLOR
2529 PNG_COLOR_MASK_ALPHA
2530
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002531 interlace_type - PNG_INTERLACE_NONE or
2532 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002533 compression_type - (must be
2534 PNG_COMPRESSION_TYPE_DEFAULT)
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002535 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
2536 or, if you are writing a PNG to
2537 be embedded in a MNG datastream,
2538 can also be
2539 PNG_INTRAPIXEL_DIFFERENCING)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002540
2541 png_set_PLTE(png_ptr, info_ptr, palette,
2542 num_palette);
2543 palette - the palette for the file
2544 (array of png_color)
2545 num_palette - number of entries in the palette
2546
2547 png_set_gAMA(png_ptr, info_ptr, gamma);
2548 gamma - the gamma the image was created
2549 at (PNG_INFO_gAMA)
2550
2551 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2552 srgb_intent - the rendering intent
2553 (PNG_INFO_sRGB) The presence of
2554 the sRGB chunk means that the pixel
2555 data is in the sRGB color space.
2556 This chunk also implies specific
2557 values of gAMA and cHRM. Rendering
2558 intent is the CSS-1 property that
2559 has been defined by the International
2560 Color Consortium
2561 (http://www.color.org).
2562 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002563 PNG_sRGB_INTENT_SATURATION,
2564 PNG_sRGB_INTENT_PERCEPTUAL,
2565 PNG_sRGB_INTENT_ABSOLUTE, or
2566 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002567
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002568
2569 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2570 srgb_intent);
2571 srgb_intent - the rendering intent
2572 (PNG_INFO_sRGB) The presence of the
2573 sRGB chunk means that the pixel
2574 data is in the sRGB color space.
2575 This function also causes gAMA and
2576 cHRM chunks with the specific values
2577 that are consistent with sRGB to be
2578 written.
2579
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002580 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2581 profile, proflen);
2582 name - The profile name.
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002583 compression - The compression type; always
2584 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2585 You may give NULL to this argument to
2586 ignore it.
2587 profile - International Color Consortium color
2588 profile data. May contain NULs.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002589 proflen - length of profile data in bytes.
2590
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002591 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2592 sig_bit - the number of significant bits for
2593 (PNG_INFO_sBIT) each of the gray, red,
2594 green, and blue channels, whichever are
2595 appropriate for the given color type
2596 (png_color_16)
2597
2598 png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
2599 trans_values);
2600 trans - array of transparent entries for
2601 palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05002602 trans_values - graylevel or color sample values of
2603 the single transparent color for
2604 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002605 num_trans - number of transparent entries
2606 (PNG_INFO_tRNS)
2607
2608 png_set_hIST(png_ptr, info_ptr, hist);
2609 (PNG_INFO_hIST)
2610 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002611 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002612
2613 png_set_tIME(png_ptr, info_ptr, mod_time);
2614 mod_time - time image was last modified
2615 (PNG_VALID_tIME)
2616
2617 png_set_bKGD(png_ptr, info_ptr, background);
2618 background - background color (PNG_VALID_bKGD)
2619
2620 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2621 text_ptr - array of png_text holding image
2622 comments
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002623 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002624 on "text" PNG_TEXT_COMPRESSION_NONE
2625 PNG_TEXT_COMPRESSION_zTXt
2626 PNG_ITXT_COMPRESSION_NONE
2627 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002628 text_ptr[i].key - keyword for comment. Must contain
2629 1-79 characters.
2630 text_ptr[i].text - text comments for current
2631 keyword. Can be NULL or empty.
2632 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002633 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002634 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002635 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002636 text_ptr[i].lang - language of comment (NULL or
2637 empty for unknown).
2638 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
2639 or empty for unknown).
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002640 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002641
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002642 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
2643 num_spalettes);
2644 palette_ptr - array of png_sPLT_struct structures
2645 to be added to the list of palettes
2646 in the info structure.
2647 num_spalettes - number of palette structures to be
2648 added.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002649
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002650 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2651 unit_type);
2652 offset_x - positive offset from the left
2653 edge of the screen
2654 offset_y - positive offset from the top
2655 edge of the screen
2656 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2657
2658 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2659 unit_type);
2660 res_x - pixels/unit physical resolution
2661 in x direction
2662 res_y - pixels/unit physical resolution
2663 in y direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002664 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002665 PNG_RESOLUTION_METER
2666
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002667 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002668 unit - physical scale units (an integer)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002669 width - width of a pixel in physical scale units
2670 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002671 (width and height are doubles)
2672
2673 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
2674 unit - physical scale units (an integer)
2675 width - width of a pixel in physical scale units
2676 height - height of a pixel in physical scale units
2677 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002678
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002679 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
2680 num_unknowns)
2681 unknowns - array of png_unknown_chunk
2682 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002683 unknowns[i].name - name of unknown chunk
2684 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002685 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002686 unknowns[i].location - position to write chunk in file
2687 0: do not write chunk
2688 PNG_HAVE_IHDR: before PLTE
2689 PNG_HAVE_PLTE: before IDAT
2690 PNG_AFTER_IDAT: after IDAT
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002691
2692The "location" member is set automatically according to
2693what part of the output file has already been written.
2694You can change its value after calling png_set_unknown_chunks()
2695as demonstrated in pngtest.c. Within each of the "locations",
2696the chunks are sequenced according to their position in the
2697structure (that is, the value of "i", which is the order in which
2698the chunk was either read from the input file or defined with
2699png_set_unknown_chunks).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002700
2701A quick word about text and num_text. text is an array of png_text
2702structures. num_text is the number of valid structures in the array.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002703Each png_text structure holds a language code, a keyword, a text value,
2704and a compression type.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002705
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002706The compression types have the same valid numbers as the compression
2707types of the image data. Currently, the only valid number is zero.
2708However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002709images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002710text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002711Because tEXt and zTXt chunks don't have a language field, if you
2712specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
2713any language code or translated keyword will not be written out.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002714
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002715Until text gets around 1000 bytes, it is not worth compressing it.
2716After the text has been written out to the file, the compression type
2717is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2718so that it isn't written out again at the end (in case you are calling
2719png_write_end() with the same struct.
2720
2721The keywords that are given in the PNG Specification are:
2722
2723 Title Short (one line) title or
2724 caption for image
2725 Author Name of image's creator
2726 Description Description of image (possibly long)
2727 Copyright Copyright notice
2728 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002729 (usually RFC 1123 format, see below)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002730 Software Software used to create the image
2731 Disclaimer Legal disclaimer
2732 Warning Warning of nature of content
2733 Source Device used to create the image
2734 Comment Miscellaneous comment; conversion
2735 from other image format
2736
2737The keyword-text pairs work like this. Keywords should be short
2738simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002739keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002740on keywords. You can repeat keywords in a file. You can even write
2741some text before the image and some after. For example, you may want
2742to put a description of the image before the image, but leave the
2743disclaimer until after, so viewers working over modem connections
2744don't have to wait for the disclaimer to go over the modem before
2745they start seeing the image. Finally, keywords should be full
2746words, not abbreviations. Keywords and text are in the ISO 8859-1
2747(Latin-1) character set (a superset of regular ASCII) and can not
2748contain NUL characters, and should not contain control or other
2749unprintable characters. To make the comments widely readable, stick
2750with basic ASCII, and avoid machine specific character set extensions
2751like the IBM-PC character set. The keyword must be present, but
2752you can leave off the text string on non-compressed pairs.
2753Compressed pairs must have a text string, as only the text string
2754is compressed anyway, so the compression would be meaningless.
2755
2756PNG supports modification time via the png_time structure. Two
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002757conversion routines are provided, png_convert_from_time_t() for
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002758time_t and png_convert_from_struct_tm() for struct tm. The
2759time_t routine uses gmtime(). You don't have to use either of
2760these, but if you wish to fill in the png_time structure directly,
2761you should provide the time in universal time (GMT) if possible
2762instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002763year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002764that months start with 1.
2765
2766If you want to store the time of the original image creation, you should
2767use a plain tEXt chunk with the "Creation Time" keyword. This is
2768necessary because the "creation time" of a PNG image is somewhat vague,
2769depending on whether you mean the PNG file, the time the image was
2770created in a non-PNG format, a still photo from which the image was
2771scanned, or possibly the subject matter itself. In order to facilitate
2772machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002773tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002774although this isn't a requirement. Unlike the tIME chunk, the
2775"Creation Time" tEXt chunk is not expected to be automatically changed
2776by the software. To facilitate the use of RFC 1123 dates, a function
2777png_convert_to_rfc1123(png_timep) is provided to convert from PNG
2778time to an RFC 1123 format string.
2779
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002780.SS Writing unknown chunks
2781
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002782You can use the png_set_unknown_chunks function to queue up chunks
2783for writing. You give it a chunk name, raw data, and a size; that's
2784all there is to it. The chunks will be written by the next following
2785png_write_info_before_PLTE, png_write_info, or png_write_end function.
2786Any chunks previously read into the info structure's unknown-chunk
2787list will also be written out in a sequence that satisfies the PNG
2788specification's ordering rules.
2789
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002790.SS The high-level write interface
2791
2792At this point there are two ways to proceed; through the high-level
2793write interface, or through a sequence of low-level write operations.
2794You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002795in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002796transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002797
2798 PNG_TRANSFORM_IDENTITY No transformation
2799 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002800 PNG_TRANSFORM_PACKSWAP Change order of packed
2801 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002802 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002803 PNG_TRANSFORM_SHIFT Normalize pixels to the
2804 sBIT depth
2805 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
2806 to BGRA
2807 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
2808 to AG
2809 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
2810 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002811 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
2812 PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
2813
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002814If you have valid image data in the info structure (you can use
2815png_set_rows() to put image data in the info structure), simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002816
2817 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
2818
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002819where png_transforms is an integer containing the bitwise OR of some set of
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002820transformation flags. This call is equivalent to png_write_info(),
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002821followed the set of transformations indicated by the transform mask,
2822then png_write_image(), and finally png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002823
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002824(The final parameter of this call is not yet used. Someday it might point
2825to transformation parameters required by some future output transform.)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002826
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05002827You must use png_transforms and not call any png_set_transform() functions
2828when you use png_write_png().
2829
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002830.SS The low-level write interface
2831
2832If you are going the low-level route instead, you are now ready to
2833write all the file information up to the actual image data. You do
2834this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002835
2836 png_write_info(png_ptr, info_ptr);
2837
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002838Note that there is one transformation you may need to do before
2839png_write_info(). In PNG files, the alpha channel in an image is the
2840level of opacity. If your data is supplied as a level of
2841transparency, you can invert the alpha channel before you write it, so
2842that 0 is fully transparent and 255 (in 8-bit or paletted images) or
284365535 (in 16-bit images) is fully opaque, with
2844
2845 png_set_invert_alpha(png_ptr);
2846
2847This must appear before png_write_info() instead of later with the
2848other transformations because in the case of paletted images the tRNS
2849chunk data has to be inverted before the tRNS chunk is written. If
2850your image is not a paletted image, the tRNS data (which in such cases
2851represents a single color to be rendered as transparent) won't need to
2852be changed, and you can safely do this transformation after your
2853png_write_info() call.
2854
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002855If you need to write a private chunk that you want to appear before
2856the PLTE chunk when PLTE is present, you can write the PNG info in
2857two steps, and insert code to write your own chunk between them:
2858
2859 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002860 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002861 png_write_info(png_ptr, info_ptr);
2862
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002863After you've written the file information, you can set up the library
2864to handle any special transformations of the image data. The various
2865ways to transform the data will be described in the order that they
2866should occur. This is important, as some of these change the color
2867type and/or bit depth of the data, and some others only work on
2868certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002869checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002870make sure to only enable a transformation if it will be valid for the
2871data. For example, don't swap red and blue on grayscale data.
2872
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002873PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002874the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002875to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
2876bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002877
2878 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
2879
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002880where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002881PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
2882is stored XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002883
2884PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2885they can, resulting in, for example, 8 pixels per byte for 1 bit files.
2886If the data is supplied at 1 pixel per byte, use this code, which will
2887correctly pack the pixels into a single byte:
2888
2889 png_set_packing(png_ptr);
2890
2891PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
2892data is of another bit depth, you can write an sBIT chunk into the
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002893file so that decoders can recover the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002894
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002895 /* Set the true bit depth of the image data */
2896 if (color_type & PNG_COLOR_MASK_COLOR)
2897 {
2898 sig_bit.red = true_bit_depth;
2899 sig_bit.green = true_bit_depth;
2900 sig_bit.blue = true_bit_depth;
2901 }
2902 else
2903 {
2904 sig_bit.gray = true_bit_depth;
2905 }
2906 if (color_type & PNG_COLOR_MASK_ALPHA)
2907 {
2908 sig_bit.alpha = true_bit_depth;
2909 }
2910
2911 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
2912
2913If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002914one 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 -06002915this will scale the values to appear to be the correct bit depth as
2916is required by PNG.
2917
2918 png_set_shift(png_ptr, &sig_bit);
2919
2920PNG files store 16 bit pixels in network byte order (big-endian,
2921ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002922supplied the other way (little-endian, i.e. least significant bits
2923first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002924
2925 if (bit_depth > 8)
2926 png_set_swap(png_ptr);
2927
2928If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2929need to change the order the pixels are packed into bytes, you can use:
2930
2931 if (bit_depth < 8)
2932 png_set_packswap(png_ptr);
2933
2934PNG files store 3 color pixels in red, green, blue order. This code
2935would be used if they are supplied as blue, green, red:
2936
2937 png_set_bgr(png_ptr);
2938
2939PNG files describe monochrome as black being zero and white being
2940one. This code would be used if the pixels are supplied with this reversed
2941(black being one and white being zero):
2942
2943 png_set_invert_mono(png_ptr);
2944
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002945Finally, you can write your own transformation function if none of
2946the existing ones meets your needs. This is done by setting a callback
2947with
2948
2949 png_set_write_user_transform_fn(png_ptr,
2950 write_transform_fn);
2951
2952You must supply the function
2953
2954 void write_transform_fn(png_ptr ptr, row_info_ptr
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002955 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002956
2957See pngtest.c for a working example. Your function will be called
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002958before any of the other transformations are processed.
2959
2960You can also set up a pointer to a user structure for use by your
2961callback function.
2962
2963 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
2964
2965The user_channels and user_depth parameters of this function are ignored
2966when writing; you can set them to zero as shown.
2967
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002968You can retrieve the pointer via the function png_get_user_transform_ptr().
2969For example:
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002970
2971 voidp write_user_transform_ptr =
2972 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002973
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002974It is possible to have libpng flush any pending output, either manually,
2975or automatically after a certain number of lines have been written. To
2976flush the output stream a single time call:
2977
2978 png_write_flush(png_ptr);
2979
2980and to have libpng flush the output stream periodically after a certain
2981number of scanlines have been written, call:
2982
2983 png_set_flush(png_ptr, nrows);
2984
2985Note that the distance between rows is from the last time png_write_flush()
2986was called, or the first row of the image if it has never been called.
2987So if you write 50 lines, and then png_set_flush 25, it will flush the
2988output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002989png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002990If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002991RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002992may be acceptable for real-time applications). Infrequent flushing will
2993only degrade the compression performance by a few percent over images
2994that do not use flushing.
2995
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002996.SS Writing the image data
2997
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002998That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002999The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003000whole image in memory, you can just call png_write_image() and libpng
3001will write the image. You will need to pass in an array of pointers to
3002each row. This function automatically handles interlacing, so you don't
3003need to call png_set_interlace_handling() or call this function multiple
3004times, or any of that other stuff necessary with png_write_rows().
3005
3006 png_write_image(png_ptr, row_pointers);
3007
3008where row_pointers is:
3009
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003010 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003011
3012You can point to void or char or whatever you use for pixels.
3013
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003014If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003015use png_write_rows() instead. If the file is not interlaced,
3016this is simple:
3017
3018 png_write_rows(png_ptr, row_pointers,
3019 number_of_rows);
3020
3021row_pointers is the same as in the png_write_image() call.
3022
3023If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003024a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003025
3026 png_bytep row_pointer = row;
3027
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003028 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003029
3030When the file is interlaced, things can get a good deal more
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003031complicated. The only currently (as of the PNG Specification
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003032version 1.2, dated July 1999) defined interlacing scheme for PNG files
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003033is the "Adam7" interlace scheme, that breaks down an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003034image into seven smaller images of varying size. libpng will build
3035these images for you, or you can do them yourself. If you want to
3036build them yourself, see the PNG specification for details of which
3037pixels to write when.
3038
3039If you don't want libpng to handle the interlacing details, just
3040use png_set_interlace_handling() and call png_write_rows() the
3041correct number of times to write all seven sub-images.
3042
3043If you want libpng to build the sub-images, call this before you start
3044writing any rows:
3045
3046 number_of_passes =
3047 png_set_interlace_handling(png_ptr);
3048
3049This will return the number of passes needed. Currently, this
3050is seven, but may change if another interlace type is added.
3051
3052Then write the complete image number_of_passes times.
3053
3054 png_write_rows(png_ptr, row_pointers,
3055 number_of_rows);
3056
3057As some of these rows are not used, and thus return immediately,
3058you may want to read about interlacing in the PNG specification,
3059and only update the rows that are actually used.
3060
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003061.SS Finishing a sequential write
3062
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003063After you are finished writing the image, you should finish writing
3064the file. If you are interested in writing comments or time, you should
3065pass an appropriately filled png_info pointer. If you are not interested,
3066you can pass NULL.
3067
3068 png_write_end(png_ptr, info_ptr);
3069
3070When you are done, you can free all memory used by libpng like this:
3071
3072 png_destroy_write_struct(&png_ptr, &info_ptr);
3073
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003074It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003075point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003076
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003077 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003078 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003079 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003080 more of
3081 PNG_FREE_PLTE, PNG_FREE_TRNS,
3082 PNG_FREE_HIST, PNG_FREE_ICCP,
3083 PNG_FREE_PCAL, PNG_FREE_ROWS,
3084 PNG_FREE_SCAL, PNG_FREE_SPLT,
3085 PNG_FREE_TEXT, PNG_FREE_UNKN,
3086 or simply PNG_FREE_ALL
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003087 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003088 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003089
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003090This function may be safely called when the relevant storage has
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003091already been freed, or has not yet been allocated, or was allocated
3092by the user and not by libpng, and will in those
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003093cases do nothing. The "seq" parameter is ignored if only one item
3094of the selected data type, such as PLTE, is allowed. If "seq" is not
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003095-1, and multiple items are allowed for the data type identified in
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003096the mask, such as text or sPLT, only the n'th item in the structure
3097is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003098
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003099If you allocated data such as a palette that you passed
3100in to libpng with png_set_*, you must not free it until just before the call to
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003101png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003102
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003103The default behavior is only to free data that was allocated internally
3104by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003105or so that it will free data that was allocated by the user with png_malloc()
3106or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003107
3108 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003109 mask - which data elements are affected
3110 same choices as in png_free_data()
3111 freer - one of
3112 PNG_DESTROY_WILL_FREE_DATA
3113 PNG_SET_WILL_FREE_DATA
3114 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003115
3116For example, to transfer responsibility for some data from a read structure
3117to a write structure, you could use
3118
3119 png_data_freer(read_ptr, read_info_ptr,
3120 PNG_USER_WILL_FREE_DATA,
3121 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3122 png_data_freer(write_ptr, write_info_ptr,
3123 PNG_DESTROY_WILL_FREE_DATA,
3124 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3125
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003126thereby briefly reassigning responsibility for freeing to the user but
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003127immediately afterwards reassigning it once more to the write_destroy
3128function. Having done this, it would then be safe to destroy the read
3129structure and continue to use the PLTE, tRNS, and hIST data in the write
3130structure.
3131
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003132This function only affects data that has already been allocated.
3133You can call this function before calling after the png_set_*() functions
3134to control whether the user or png_destroy_*() is supposed to free the data.
3135When the user assumes responsibility for libpng-allocated data, the
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003136application must use
3137png_free() to free it, and when the user transfers responsibility to libpng
3138for data that the user has allocated, the user must have used png_malloc()
3139or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003140
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003141If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3142separately, do not transfer responsibility for freeing text_ptr to libpng,
3143because when libpng fills a png_text structure it combines these members with
3144the key member, and png_free_data() will free only text_ptr.key. Similarly,
3145if you transfer responsibility for free'ing text_ptr from libpng to your
3146application, your application must not separately free those members.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003147For a more compact example of writing a PNG image, see the file example.c.
3148
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003149.SH V. Modifying/Customizing libpng:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003150
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003151There are three issues here. The first is changing how libpng does
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003152standard things like memory allocation, input/output, and error handling.
3153The second deals with more complicated things like adding new chunks,
3154adding new transformations, and generally changing how libpng works.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003155Both of those are compile-time issues; that is, they are generally
3156determined at the time the code is written, and there is rarely a need
3157to provide the user with a means of changing them. The third is a
3158run-time issue: choosing between and/or tuning one or more alternate
3159versions of computationally intensive routines; specifically, optimized
3160assembly-language (and therefore compiler- and platform-dependent)
3161versions.
3162
3163Memory allocation, input/output, and error handling
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003164
3165All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003166goes through callbacks that are user-settable. The default routines are
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003167in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003168these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003169
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -05003170Memory allocation is done through the functions png_malloc()
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003171and png_free(). These currently just call the standard C functions. If
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003172your pointers can't access more then 64K at a time, you will want to set
3173MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
3174memory allocation on a platform will change between applications, these
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003175functions must be modified in the library at compile time. If you prefer
3176to use a different method of allocating and freeing data, you can use
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -05003177png_create_read_struct_2() or png_create_write_struct_2() to register
3178your own functions as described above.
Glenn Randers-Pehrsoncfbed9b2002-05-21 18:06:08 -05003179These functions also provide a void pointer that can be retrieved via
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003180
3181 mem_ptr=png_get_mem_ptr(png_ptr);
3182
3183Your replacement memory functions must have prototypes as follows:
3184
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003185 png_voidp malloc_fn(png_structp png_ptr,
Glenn Randers-Pehrsonae498dc2001-11-24 14:53:31 -06003186 png_size_t size);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003187 void free_fn(png_structp png_ptr, png_voidp ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003188
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003189Your malloc_fn() must return NULL in case of failure. The png_malloc()
3190function will normally call png_error() if it receives a NULL from the
3191system memory allocator or from your replacement malloc_fn().
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05003192
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003193Input/Output in libpng is done through png_read() and png_write(),
3194which currently just call fread() and fwrite(). The FILE * is stored in
3195png_struct and is initialized via png_init_io(). If you wish to change
3196the method of I/O, the library supplies callbacks that you can set
3197through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003198time, instead of calling the png_init_io() function. These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003199also provide a void pointer that can be retrieved via the function
3200png_get_io_ptr(). For example:
3201
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003202 png_set_read_fn(png_structp read_ptr,
3203 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003204
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003205 png_set_write_fn(png_structp write_ptr,
3206 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003207 png_flush_ptr output_flush_fn);
3208
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003209 voidp read_io_ptr = png_get_io_ptr(read_ptr);
3210 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003211
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003212The replacement I/O functions must have prototypes as follows:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003213
3214 void user_read_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05003215 png_bytep data, png_size_t length);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003216 void user_write_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05003217 png_bytep data, png_size_t length);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003218 void user_flush_data(png_structp png_ptr);
3219
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003220The user_read_data() function is responsible for detecting and
3221handling end-of-data errors.
3222
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003223Supplying NULL for the read, write, or flush functions sets them back
3224to using the default C stream functions. It is an error to read from
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003225a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003226
3227Error handling in libpng is done through png_error() and png_warning().
3228Errors handled through png_error() are fatal, meaning that png_error()
3229should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003230setjmp() and longjmp() (unless you have compiled libpng with
3231PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
3232but you could change this to do things like exit() if you should wish.
3233
3234On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003235to print a warning message, and then control returns to the calling code.
3236By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003237fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
3238(because you don't want the messages) or PNG_NO_STDIO defined (because
3239fprintf() isn't available). If you wish to change the behavior of the error
3240functions, you will need to set up your own message callbacks. These
3241functions are normally supplied at the time that the png_struct is created.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003242It is also possible to redirect errors and warnings to your own replacement
3243functions after png_create_*_struct() has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003244
3245 png_set_error_fn(png_structp png_ptr,
3246 png_voidp error_ptr, png_error_ptr error_fn,
3247 png_error_ptr warning_fn);
3248
3249 png_voidp error_ptr = png_get_error_ptr(png_ptr);
3250
3251If NULL is supplied for either error_fn or warning_fn, then the libpng
3252default function will be used, calling fprintf() and/or longjmp() if a
3253problem is encountered. The replacement error functions should have
3254parameters as follows:
3255
3256 void user_error_fn(png_structp png_ptr,
3257 png_const_charp error_msg);
3258 void user_warning_fn(png_structp png_ptr,
3259 png_const_charp warning_msg);
3260
3261The motivation behind using setjmp() and longjmp() is the C++ throw and
3262catch exception handling methods. This makes the code much easier to write,
3263as there is no need to check every return code of every function call.
3264However, there are some uncertainties about the status of local variables
3265after a longjmp, so the user may want to be careful about doing anything after
3266setjmp returns non-zero besides returning itself. Consult your compiler
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003267documentation for more details. For an alternative approach, you may wish
3268to use the "cexcept" facility (see http://cexcept.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003269
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003270.SS Custom chunks
3271
3272If you need to read or write custom chunks, you may need to get deeper
3273into the libpng code. The library now has mechanisms for storing
3274and writing chunks of unknown type; you can even declare callbacks
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003275for custom chunks. However, this may not be good enough if the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003276library code itself needs to know about interactions between your
3277chunk and existing `intrinsic' chunks.
3278
3279If you need to write a new intrinsic chunk, first read the PNG
3280specification. Acquire a first level of
3281understanding of how it works. Pay particular attention to the
3282sections that describe chunk names, and look at how other chunks were
3283designed, so you can do things similarly. Second, check out the
3284sections of libpng that read and write chunks. Try to find a chunk
3285that is similar to yours and use it as a template. More details can
3286be found in the comments inside the code. It is best to handle unknown
3287chunks in a generic method, via callback functions, instead of by
3288modifying libpng functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003289
3290If you wish to write your own transformation for the data, look through
3291the part of the code that does the transformations, and check out some of
3292the simpler ones to get an idea of how they work. Try to find a similar
3293transformation to the one you want to add and copy off of it. More details
3294can be found in the comments inside the code itself.
3295
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003296.SS Configuring for 16 bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003297
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003298You will want to look into zconf.h to tell zlib (and thus libpng) that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003299it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003300won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003301
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003302.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003303
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003304For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003305have to limit zlib's memory usage via a png_set_compression_mem_level()
3306call. See zlib.h or zconf.h in the zlib library for more information.
3307
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003308.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003309
3310Libpng's support for medium model has been tested on most of the popular
3311compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
3312defined, and FAR gets defined to far in pngconf.h, and you should be
3313all set. Everything in the library (except for zlib's structure) is
3314expecting far data. You must use the typedefs with the p or pp on
3315the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003316note that the rows of data are defined as png_bytepp, which is an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003317unsigned char far * far *.
3318
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003319.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003320
3321You will need to write new error and warning functions that use the GUI
3322interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003323warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003324in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003325They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003326you may also have to change the memory allocators (png_malloc, etc.).
3327
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003328.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003329
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05003330All includes for libpng are in pngconf.h. If you need to add, change
3331or delete an include, this is the place to do it. The includes that
3332are not needed outside libpng are placed inside pngpriv.h, which is
3333only used by the routines inside libpng itself.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003334
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003335.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003336
3337There are special functions to configure the compression. Perhaps the
3338most useful one changes the compression level, which currently uses
3339input compression values in the range 0 - 9. The library normally
3340uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
3341have shown that for a large majority of images, compression values in
3342the range 3-6 compress nearly as well as higher levels, and do so much
3343faster. For online applications it may be desirable to have maximum speed
3344(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
3345specify no compression (Z_NO_COMPRESSION = 0), but this would create
3346files larger than just storing the raw bitmap. You can specify the
3347compression level by calling:
3348
3349 png_set_compression_level(png_ptr, level);
3350
3351Another useful one is to reduce the memory level used by the library.
3352The memory level defaults to 8, but it can be lowered if you are
3353short on memory (running DOS, for example, where you only have 640K).
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003354Note that the memory level does have an effect on compression; among
3355other things, lower levels will result in sections of incompressible
3356data being emitted in smaller stored blocks, with a correspondingly
3357larger relative overhead of up to 15% in the worst case.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003358
3359 png_set_compression_mem_level(png_ptr, level);
3360
3361The other functions are for configuring zlib. They are not recommended
3362for normal use and may result in writing an invalid PNG file. See
3363zlib.h for more information on what these mean.
3364
3365 png_set_compression_strategy(png_ptr,
3366 strategy);
3367 png_set_compression_window_bits(png_ptr,
3368 window_bits);
3369 png_set_compression_method(png_ptr, method);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003370 png_set_compression_buffer_size(png_ptr, size);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003371
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003372.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003373
3374If you want to control whether libpng uses filtering or not, which
3375filters are used, and how it goes about picking row filters, you
3376can call one of these functions. The selection and configuration
3377of row filters can have a significant impact on the size and
3378encoding speed and a somewhat lesser impact on the decoding speed
3379of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003380images (with and without alpha), but not for paletted images nor
3381for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003382
3383The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003384currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003385parameter sets which filter(s), if any, should be used for each
3386scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
3387to turn filtering on and off, respectively.
3388
3389Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3390PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003391ORed together with '|' to specify one or more filters to use.
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003392These filters are described in more detail in the PNG specification.
3393If you intend to change the filter type during the course of writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003394the image, you should start with flags set for all of the filters
3395you intend to use so that libpng can initialize its internal
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003396structures appropriately for all of the filter types. (Note that this
3397means the first row must always be adaptively filtered, because libpng
3398currently does not allocate the filter buffers until png_write_row()
3399is called for the first time.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003400
3401 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003402 PNG_FILTER_UP | PNG_FILTER_AVE |
3403 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003404
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003405 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3406 filters);
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003407 The second parameter can also be
3408 PNG_INTRAPIXEL_DIFFERENCING if you are
3409 writing a PNG to be embedded in a MNG
3410 datastream. This parameter must be the
3411 same as the value of filter_method used
3412 in png_set_IHDR().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003413
3414It is also possible to influence how libpng chooses from among the
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003415available filters. This is done in one or both of two ways - by
3416telling it how important it is to keep the same filter for successive
3417rows, and by telling it the relative computational costs of the filters.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003418
3419 double weights[3] = {1.5, 1.3, 1.1},
3420 costs[PNG_FILTER_VALUE_LAST] =
3421 {1.0, 1.3, 1.3, 1.5, 1.7};
3422
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003423 png_set_filter_heuristics(png_ptr,
3424 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003425 weights, costs);
3426
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003427The weights are multiplying factors that indicate to libpng that the
3428row filter should be the same for successive rows unless another row filter
3429is that many times better than the previous filter. In the above example,
3430if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003431"sum of absolute differences" 1.5 x 1.3 times higher than other filters
3432and still be chosen, while the NONE filter could have a sum 1.1 times
3433higher than other filters and still be chosen. Unspecified weights are
3434taken to be 1.0, and the specified weights should probably be declining
3435like those above in order to emphasize recent filters over older filters.
3436
3437The filter costs specify for each filter type a relative decoding cost
3438to be considered when selecting row filters. This means that filters
3439with higher costs are less likely to be chosen over filters with lower
3440costs, unless their "sum of absolute differences" is that much smaller.
3441The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003442the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003443size.
3444
3445Note that the numbers above were invented purely for this example and
3446are given only to help explain the function usage. Little testing has
3447been done to find optimum values for either the costs or the weights.
3448
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003449.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003450
3451There are a bunch of #define's in pngconf.h that control what parts of
3452libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003453never going to use a capability, you can change the #define to #undef
3454before recompiling libpng and save yourself code and data space, or
3455you can turn off individual capabilities with defines that begin with
3456PNG_NO_.
3457
3458You can also turn all of the transforms and ancillary chunk capabilities
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003459off en masse with compiler directives that define
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003460PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3461or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003462along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003463want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003464the extra transformations but still leave the library fully capable of reading
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003465and writing PNG files with all known public chunks
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003466Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003467produces a library that is incapable of reading or writing ancillary chunks.
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003468If you are not using the progressive reading capability, you can
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003469turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003470this with the INTERLACING capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003471
3472All the reading and writing specific code are in separate files, so the
3473linker should only grab the files it needs. However, if you want to
3474make sure, or if you are building a stand alone library, all the
3475reading files start with pngr and all the writing files start with
3476pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
3477are used for both reading and writing, and always need to be included.
3478The progressive reader is in pngpread.c
3479
3480If you are creating or distributing a dynamically linked library (a .so
3481or DLL file), you should not remove or disable any parts of the library,
3482as this will cause applications linked with different versions of the
3483library to fail if they call functions not available in your library.
3484The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003485those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003486
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003487.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003488
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003489The macro definition PNG_DEBUG can be used to request debugging
3490printout. Set it to an integer value in the range 0 to 3. Higher
3491numbers result in increasing amounts of debugging information. The
3492information is printed to the "stderr" file, unless another file
3493name is specified in the PNG_DEBUG_FILE macro definition.
3494
3495When PNG_DEBUG > 0, the following functions (macros) become available:
3496
3497 png_debug(level, message)
3498 png_debug1(level, message, p1)
3499 png_debug2(level, message, p1, p2)
3500
3501in which "level" is compared to PNG_DEBUG to decide whether to print
3502the message, "message" is the formatted string to be printed,
3503and p1 and p2 are parameters that are to be embedded in the string
3504according to printf-style formatting directives. For example,
3505
3506 png_debug1(2, "foo=%d\n", foo);
3507
3508is expanded to
3509
3510 if(PNG_DEBUG > 2)
3511 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
3512
3513When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3514can still use PNG_DEBUG to control your own debugging:
3515
3516 #ifdef PNG_DEBUG
3517 fprintf(stderr, ...
3518 #endif
3519
3520When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3521having level = 0 will be printed. There aren't any such statements in
3522this version of libpng, but if you insert some they will be printed.
3523
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003524.SH VI. Runtime optimization
3525
3526A new feature in libpng 1.2.0 is the ability to dynamically switch between
3527standard and optimized versions of some routines. Currently these are
3528limited to three computationally intensive tasks when reading PNG files:
3529decoding row filters, expanding interlacing, and combining interlaced or
3530transparent row data with previous row data. Currently the optimized
3531versions are available only for x86 (Intel, AMD, etc.) platforms with
3532MMX support, though this may change in future versions. (For example,
3533the non-MMX assembler optimizations for zlib might become similarly
3534runtime-selectable in future releases, in which case libpng could be
3535extended to support them. Alternatively, the compile-time choice of
3536floating-point versus integer routines for gamma correction might become
3537runtime-selectable.)
3538
3539Because such optimizations tend to be very platform- and compiler-dependent,
3540both in how they are written and in how they perform, the new runtime code
3541in libpng has been written to allow programs to query, enable, and disable
3542either specific optimizations or all such optimizations. For example, to
3543enable all possible optimizations (bearing in mind that some "optimizations"
3544may actually run more slowly in rare cases):
3545
3546 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3547 png_uint_32 mask, flags;
3548
3549 flags = png_get_asm_flags(png_ptr);
3550 mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
3551 png_set_asm_flags(png_ptr, flags | mask);
3552 #endif
3553
3554To enable only optimizations relevant to reading PNGs, use PNG_SELECT_READ
3555by itself when calling png_get_asm_flagmask(); similarly for optimizing
3556only writing. To disable all optimizations:
3557
3558 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3559 flags = png_get_asm_flags(png_ptr);
3560 mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
3561 png_set_asm_flags(png_ptr, flags & ~mask);
3562 #endif
3563
3564To enable or disable only MMX-related features, use png_get_mmx_flagmask()
3565in place of png_get_asm_flagmask(). The mmx version takes one additional
3566parameter:
3567
3568 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3569 int selection = PNG_SELECT_READ | PNG_SELECT_WRITE;
3570 int compilerID;
3571
3572 mask = png_get_mmx_flagmask(selection, &compilerID);
3573 #endif
3574
3575On return, compilerID will indicate which version of the MMX assembler
3576optimizations was compiled. Currently two flavors exist: Microsoft
3577Visual C++ (compilerID == 1) and GNU C (a.k.a. gcc/gas, compilerID == 2).
3578On non-x86 platforms or on systems compiled without MMX optimizations, a
3579value of -1 is used.
3580
3581Note that both png_get_asm_flagmask() and png_get_mmx_flagmask() return
3582all valid, settable optimization bits for the version of the library that's
3583currently in use. In the case of shared (dynamically linked) libraries,
3584this may include optimizations that did not exist at the time the code was
3585written and compiled. It is also possible, of course, to enable only known,
3586specific optimizations; for example:
3587
3588 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3589 flags = PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
3590 | PNG_ASM_FLAG_MMX_READ_INTERLACE \
3591 | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
3592 | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
3593 | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
3594 | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
3595 png_set_asm_flags(png_ptr, flags);
3596 #endif
3597
3598This method would enable only the MMX read-optimizations available at the
3599time of libpng 1.2.0's release, regardless of whether a later version of
3600the DLL were actually being used. (Also note that these functions did not
3601exist in versions older than 1.2.0, so any attempt to run a dynamically
3602linked app on such an older version would fail.)
3603
3604To determine whether the processor supports MMX instructions at all, use
3605the png_mmx_support() function:
3606
3607 #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
3608 mmxsupport = png_mmx_support();
3609 #endif
3610
3611It returns -1 if MMX support is not compiled into libpng, 0 if MMX code
3612is compiled but MMX is not supported by the processor, or 1 if MMX support
3613is fully available. Note that png_mmx_support(), png_get_mmx_flagmask(),
3614and png_get_asm_flagmask() all may be called without allocating and ini-
3615tializing any PNG structures (for example, as part of a usage screen or
3616"about" box).
3617
3618The following code can be used to prevent an application from using the
3619thread_unsafe features, even if libpng was built with PNG_THREAD_UNSAFE_OK
3620defined:
3621
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -05003622#if defined(PNG_USE_PNGGCCRD) && defined(PNG_MMX_CODE_SUPPORTED) \
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003623 && defined(PNG_THREAD_UNSAFE_OK)
3624 /* Disable thread-unsafe features of pnggccrd */
Glenn Randers-Pehrson86dc9812006-05-10 07:27:44 -05003625 if (png_access_version_number() >= 10200)
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003626 {
3627 png_uint_32 mmx_disable_mask = 0;
3628 png_uint_32 asm_flags;
3629
3630 mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
3631 | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
3632 | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
3633 | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
3634 asm_flags = png_get_asm_flags(png_ptr);
3635 png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);
3636 }
3637#endif
3638
3639For more extensive examples of runtime querying, enabling and disabling
3640of optimized features, see contrib/gregbook/readpng2.c in the libpng
3641source-code distribution.
3642
3643.SH VII. MNG support
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003644
3645The MNG specification (available at http://www.libpng.org/pub/mng) allows
3646certain extensions to PNG for PNG images that are embedded in MNG datastreams.
3647Libpng can support some of these extensions. To enable them, use the
3648png_permit_mng_features() function:
3649
3650 feature_set = png_permit_mng_features(png_ptr, mask)
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003651 mask is a png_uint_32 containing the bitwise OR of the
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003652 features you want to enable. These include
3653 PNG_FLAG_MNG_EMPTY_PLTE
3654 PNG_FLAG_MNG_FILTER_64
3655 PNG_ALL_MNG_FEATURES
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003656 feature_set is a png_uint_32 that is the bitwise AND of
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003657 your mask with the set of MNG features that is
3658 supported by the version of libpng that you are using.
3659
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003660It is an error to use this function when reading or writing a standalone
3661PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
Glenn Randers-Pehrsonf05f8032000-12-23 14:27:39 -06003662in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
3663and the MHDR and MEND chunks. Libpng does not provide support for these
3664or any other MNG chunks; your application must provide its own support for
3665them. You may wish to consider using libmng (available at
3666http://www.libmng.com) instead.
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003667
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003668.SH VIII. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003669
3670It should be noted that versions of libpng later than 0.96 are not
3671distributed by the original libpng author, Guy Schalnat, nor by
3672Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3673distributed versions 0.89 through 0.96, but rather by another member
3674of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3675still alive and well, but they have moved on to other things.
3676
3677The old libpng functions png_read_init(), png_write_init(),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05003678png_info_init(), png_read_destroy(), and png_write_destroy() have been
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05003679moved to PNG_INTERNAL in version 0.95 to discourage their use. These
3680functions will be removed from libpng version 2.0.0.
3681
3682The preferred method of creating and initializing the libpng structures is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003683via the png_create_read_struct(), png_create_write_struct(), and
3684png_create_info_struct() because they isolate the size of the structures
3685from the application, allow version error checking, and also allow the
3686use of custom error handling routines during the initialization, which
3687the old functions do not. The functions png_read_destroy() and
3688png_write_destroy() do not actually free the memory that libpng
3689allocated for these structs, but just reset the data structures, so they
3690can be used instead of png_destroy_read_struct() and
3691png_destroy_write_struct() if you feel there is too much system overhead
3692allocating and freeing the png_struct for each image read.
3693
3694Setting the error callbacks via png_set_message_fn() before
3695png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003696because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003697to fail if the png_ptr was not initialized to zero. It is still possible
3698to set the error callbacks AFTER png_read_init(), or to change them with
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05003699png_set_error_fn(), which is essentially the same function, but with a new
3700name to force compilation errors with applications that try to use the old
3701method.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003702
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003703Starting with version 1.0.7, you can find out which version of the library
3704you are using at run-time:
3705
3706 png_uint_32 libpng_vn = png_access_version_number();
3707
3708The number libpng_vn is constructed from the major version, minor
3709version with leading zero, and release number with leading zero,
3710(e.g., libpng_vn for version 1.0.7 is 10007).
3711
3712You can also check which version of png.h you used when compiling your
3713application:
3714
3715 png_uint_32 application_vn = PNG_LIBPNG_VER;
3716
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003717.SH IX. Y2K Compliance in libpng
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003718
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05003719July 30, 2008
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003720
3721Since the PNG Development group is an ad-hoc body, we can't make
3722an official declaration.
3723
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003724This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05003725upward through 1.4.0beta25 are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003726versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003727
3728Libpng only has three year fields. One is a 2-byte unsigned integer that
3729will hold years up to 65535. The other two hold the date in text
3730format, and will hold years up to 9999.
3731
3732The integer is
3733 "png_uint_16 year" in png_time_struct.
3734
3735The strings are
3736 "png_charp time_buffer" in png_struct and
3737 "near_time_buffer", which is a local character string in png.c.
3738
3739There are seven time-related functions:
3740
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003741 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003742 (formerly png_convert_to_rfc_1152() in error)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003743 png_convert_from_struct_tm() in pngwrite.c, called
3744 in pngwrite.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003745 png_convert_from_time_t() in pngwrite.c
3746 png_get_tIME() in pngget.c
3747 png_handle_tIME() in pngrutil.c, called in pngread.c
3748 png_set_tIME() in pngset.c
3749 png_write_tIME() in pngwutil.c, called in pngwrite.c
3750
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003751All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003752png_convert_from_time_t() function calls gmtime() to convert from system
3753clock time, which returns (year - 1900), which we properly convert to
3754the full 4-digit year. There is a possibility that applications using
3755libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003756function, or that they are incorrectly passing only a 2-digit year
3757instead of "year - 1900" into the png_convert_from_struct_tm() function,
3758but this is not under our control. The libpng documentation has always
3759stated that it works with 4-digit years, and the APIs have been
3760documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003761
3762The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
3763integer to hold the year, and can hold years as large as 65535.
3764
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003765zlib, upon which libpng depends, is also Y2K compliant. It contains
3766no date-related code.
3767
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003768
3769 Glenn Randers-Pehrson
3770 libpng maintainer
3771 PNG Development Group
3772
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003773.SH NOTE
3774
3775Note about libpng version numbers:
3776
3777Due to various miscommunications, unforeseen code incompatibilities
3778and occasional factors outside the authors' control, version numbering
3779on the library has not always been consistent and straightforward.
3780The following table summarizes matters since version 0.89c, which was
3781the first widely used release:
3782
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003783 source png.h png.h shared-lib
3784 version string int version
3785 ------- ------ ----- ----------
3786 0.89c ("beta 3") 0.89 89 1.0.89
3787 0.90 ("beta 4") 0.90 90 0.90
3788 0.95 ("beta 5") 0.95 95 0.95
3789 0.96 ("beta 6") 0.96 96 0.96
3790 0.97b ("beta 7") 1.00.97 97 1.0.1
3791 0.97c 0.97 97 2.0.97
3792 0.98 0.98 98 2.0.98
3793 0.99 0.99 98 2.0.99
3794 0.99a-m 0.99 99 2.0.99
3795 1.00 1.00 100 2.1.0
3796 1.0.0 1.0.0 100 2.1.0
3797 1.0.0 (from here on, the 100 2.1.0
3798 1.0.1 png.h string is 10001 2.1.0
3799 1.0.1a-e identical to the 10002 from here on, the
3800 1.0.2 source version) 10002 shared library is 2.V
3801 1.0.2a-b 10003 where V is the source
3802 1.0.1 10001 code version except as
3803 1.0.1a-e 10002 2.1.0.1a-e noted.
3804 1.0.2 10002 2.1.0.2
3805 1.0.2a-b 10003 2.1.0.2a-b
3806 1.0.3 10003 2.1.0.3
3807 1.0.3a-d 10004 2.1.0.3a-d
3808 1.0.4 10004 2.1.0.4
3809 1.0.4a-f 10005 2.1.0.4a-f
3810 1.0.5 (+ 2 patches) 10005 2.1.0.5
3811 1.0.5a-d 10006 2.1.0.5a-d
3812 1.0.5e-r 10100 2.1.0.5e-r
3813 1.0.5s-v 10006 2.1.0.5s-v
3814 1.0.6 (+ 3 patches) 10006 2.1.0.6
3815 1.0.6d-g 10007 2.1.0.6d-g
3816 1.0.6h 10007 10.6h
3817 1.0.6i 10007 10.6i
3818 1.0.6j 10007 2.1.0.6j
3819 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
3820 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
3821 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
3822 1.0.7 1 10007 2.1.0.7
3823 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
3824 1.0.8rc1 1 10008 2.1.0.8rc1
3825 1.0.8 1 10008 2.1.0.8
3826 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
3827 1.0.9rc1 1 10009 2.1.0.9rc1
3828 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
3829 1.0.9rc2 1 10009 2.1.0.9rc2
3830 1.0.9 1 10009 2.1.0.9
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06003831 1.0.10beta1 1 10010 2.1.0.10beta1
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003832 1.0.10rc1 1 10010 2.1.0.10rc1
Glenn Randers-Pehrson13cfbac2001-03-30 06:42:28 -06003833 1.0.10 1 10010 2.1.0.10
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -05003834 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05003835 1.0.11rc1 1 10011 2.1.0.11rc1
Glenn Randers-Pehrson32835392001-04-27 08:29:32 -05003836 1.0.11 1 10011 2.1.0.11
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05003837 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
3838 1.0.12rc1 2 10012 2.1.0.12rc1
3839 1.0.12 2 10012 2.1.0.12
3840 1.1.0a-f - 10100 2.1.1.0a-f abandoned
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05003841 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
Glenn Randers-Pehrson5a0be342001-10-18 20:55:13 -05003842 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
3843 1.2.0rc1 3 10200 3.1.2.0rc1
3844 1.2.0 3 10200 3.1.2.0
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -06003845 1.2.1beta-4 3 10201 3.1.2.1beta1-4
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -06003846 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
3847 1.2.1 3 10201 3.1.2.1
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -06003848 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
Glenn Randers-Pehrsonfcbd7872002-04-07 16:35:38 -05003849 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
3850 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
3851 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003852 1.0.13 10 10013 10.so.0.1.0.13
3853 1.2.2 12 10202 12.so.0.1.2.2
Glenn Randers-Pehrson22f28962002-05-13 18:17:09 -05003854 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
3855 1.2.3 12 10203 12.so.0.1.2.3
Glenn Randers-Pehrsond020e9d2002-06-28 09:34:00 -05003856 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -05003857 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
Glenn Randers-Pehrson484a8a12002-07-07 19:15:20 -05003858 1.0.14 10 10014 10.so.0.1.0.14
3859 1.2.4 13 10204 12.so.0.1.2.4
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05003860 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
3861 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003862 1.0.15 10 10015 10.so.0.1.0.15
3863 1.2.5 13 10205 12.so.0.1.2.5
3864 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
Glenn Randers-Pehrson37f116a2004-08-15 07:15:39 -05003865 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
3866 1.0.16 10 10016 10.so.0.1.0.16
3867 1.2.6 13 10206 12.so.0.1.2.6
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05003868 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05003869 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
3870 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
Glenn Randers-Pehrson250dfe12004-09-11 21:19:54 -05003871 1.0.17 10 10017 12.so.0.1.0.17
3872 1.2.7 13 10207 12.so.0.1.2.7
Glenn Randers-Pehrson40936072004-11-20 11:18:40 -06003873 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
Glenn Randers-Pehrson584b96e2004-11-29 15:08:00 -06003874 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
3875 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06003876 1.0.18 10 10018 12.so.0.1.0.18
3877 1.2.8 13 10208 12.so.0.1.2.8
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06003878 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -06003879 1.2.9beta4-11 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrson3a512032006-03-31 05:29:33 -06003880 1.2.9rc1 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsona7d0c942006-04-14 06:22:52 -05003881 1.2.9 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05003882 1.2.10beta1-7 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -05003883 1.2.10rc1-2 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson86dc9812006-05-10 07:27:44 -05003884 1.2.10 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05003885 1.4.0beta1-6 14 10400 14.so.0.0[.0]
3886 1.2.11beta1-4 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson3424ee72006-07-12 13:33:47 -05003887 1.4.0beta7-8 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrson701dbaa2006-11-17 09:36:54 -06003888 1.2.11 13 10211 12.so.0.11[.0]
3889 1.2.12 13 10212 12.so.0.12[.0]
3890 1.4.0beta9-14 14 10400 14.so.0.0[.0]
3891 1.2.13 13 10213 12.so.0.13[.0]
Glenn Randers-Pehrson72b63302008-07-22 13:59:07 -05003892 1.4.0beta15-23 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003893
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003894Henceforth the source version will match the shared-library minor
3895and patch numbers; the shared-library major version number will be
3896used for changes in backward compatibility, as it is intended. The
3897PNG_PNGLIB_VER macro, which is not used within libpng but is available
3898for applications, is an unsigned integer of the form xyyzz corresponding
3899to the source version x.y.z (leading zeros in y and z). Beta versions
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06003900were given the previous public release number plus a letter, until
3901version 1.0.6j; from then on they were given the upcoming public
3902release number plus "betaNN" or "rcN".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003903
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003904.SH "SEE ALSO"
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003905libpngpf(3), png(5)
3906.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003907.IR libpng :
3908.IP
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05003909http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06003910http://www.libpng.org/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003911
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003912.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003913.IR zlib :
3914.IP
3915(generally) at the same location as
3916.I libpng
3917or at
3918.br
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06003919ftp://ftp.info-zip.org/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003920
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003921.LP
3922.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003923.IP
3924(generally) at the same location as
3925.I libpng
3926or at
3927.br
3928ftp://ds.internic.net/rfc/rfc2083.txt
3929.br
3930or (as a W3C Recommendation) at
3931.br
3932http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003933
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003934.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003935In the case of any inconsistency between the PNG specification
3936and this library, the specification takes precedence.
3937
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003938.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003939This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06003940<glennrp at users.sourceforge.net>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003941
3942The contributing authors would like to thank all those who helped
3943with testing, bug fixes, and patience. This wouldn't have been
3944possible without all of you.
3945
3946Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003947
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05003948Libpng version 1.4.0beta25 - July 30, 2008:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003949Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06003950Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003951
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003952Supported by the PNG development group
3953.br
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003954png-mng-implement at lists.sf.net
3955(subscription required; visit
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -06003956png-mng-implement at lists.sourceforge.net (subscription required; visit
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003957https://lists.sourceforge.net/lists/listinfo/png-mng-implement
3958to subscribe).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06003959
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003960.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003961
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06003962(This copy of the libpng notices is provided for your convenience. In case of
3963any discrepancy between this copy and the notices in the file png.h that is
3964included in the libpng distribution, the latter shall prevail.)
3965
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003966If you modify libpng you may insert additional notices immediately following
3967this sentence.
3968
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05003969libpng versions 1.2.6, August 15, 2004, through 1.4.0beta25, July 30, 2008, are
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05003970Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003971distributed according to the same disclaimer and license as libpng-1.2.5
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05003972with the following individual added to the list of Contributing Authors
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003973
3974 Cosmin Truta
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003975
3976libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06003977Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson32fc5ce2000-07-24 06:34:14 -05003978distributed according to the same disclaimer and license as libpng-1.0.6
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003979with the following individuals added to the list of Contributing Authors
3980
3981 Simon-Pierre Cadieux
3982 Eric S. Raymond
3983 Gilles Vollant
3984
3985and with the following additions to the disclaimer:
3986
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003987 There is no warranty against interference with your
3988 enjoyment of the library or against infringement.
3989 There is no warranty that our efforts or the library
3990 will fulfill any of your particular purposes or needs.
3991 This library is provided with all faults, and the entire
3992 risk of satisfactory quality, performance, accuracy, and
3993 effort is with the user.
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003994
3995libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
3996Copyright (c) 1998, 1999 Glenn Randers-Pehrson
3997Distributed according to the same disclaimer and license as libpng-0.96,
3998with the following individuals added to the list of Contributing Authors:
3999
4000 Tom Lane
4001 Glenn Randers-Pehrson
4002 Willem van Schaik
4003
4004libpng versions 0.89, June 1996, through 0.96, May 1997, are
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05004005Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004006Distributed according to the same disclaimer and license as libpng-0.88,
4007with the following individuals added to the list of Contributing Authors:
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004008
4009 John Bowler
4010 Kevin Bracey
4011 Sam Bushell
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004012 Magnus Holmgren
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004013 Greg Roelofs
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004014 Tom Tanner
4015
4016libpng versions 0.5, May 1995, through 0.88, January 1996, are
4017Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
4018
4019For the purposes of this copyright and license, "Contributing Authors"
4020is defined as the following set of individuals:
4021
4022 Andreas Dilger
4023 Dave Martindale
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004024 Guy Eric Schalnat
4025 Paul Schmidt
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004026 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06004027
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004028The PNG Reference Library is supplied "AS IS". The Contributing Authors
4029and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004030including, without limitation, the warranties of merchantability and of
4031fitness for any purpose. The Contributing Authors and Group 42, Inc.
4032assume no liability for direct, indirect, incidental, special, exemplary,
4033or consequential damages, which may result from the use of the PNG
4034Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004035
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004036Permission is hereby granted to use, copy, modify, and distribute this
4037source code, or portions hereof, for any purpose, without fee, subject
4038to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004039
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -050040401. The origin of this source code must not be misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004041
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060040422. Altered versions must be plainly marked as such and
4043 must not be misrepresented as being the original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004044
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060040453. This Copyright notice may not be removed or altered from
4046 any source or altered source distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004047
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004048The Contributing Authors and Group 42, Inc. specifically permit, without
4049fee, and encourage the use of this source code as a component to
4050supporting the PNG file format in commercial products. If you use this
4051source code in a product, acknowledgment is not required but would be
4052appreciated.
4053
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004054
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004055A "png_get_copyright" function is available, for convenient use in "about"
4056boxes and the like:
4057
4058 printf("%s",png_get_copyright(NULL));
4059
4060Also, the PNG logo (in PNG format, of course) is supplied in the
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -05004061files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004062
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004063Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004064certification mark of the Open Source Initiative.
4065
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004066Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06004067glennrp at users.sourceforge.net
Glenn Randers-Pehrsoneb580912008-07-30 14:47:09 -05004068July 30, 2008
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004069
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004070.\" end of man page
4071