blob: 0bdf94e1f8d3a7ecb15941a00e9ef86fad691ae4 [file] [log] [blame]
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001.TH LIBPNG 3 "February 8, 2010"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06003libpng \- Portable Network Graphics (PNG) Reference Library 1.5.0beta01
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004.SH SYNOPSIS
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -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-Pehrsonad81d712009-07-30 15:39:00 -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-Pehrsonad81d712009-07-30 15:39:00 -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-Pehrsonad81d712009-07-30 15:39:00 -050021\fI\fB
22
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050023\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 -060024
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050025\fI\fB
26
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050027\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 -060028
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050029\fI\fB
30
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050031\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 -060032
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050033\fI\fB
34
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050035\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 -060036
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050037\fI\fB
38
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050039\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 -060040
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050041\fI\fB
42
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050043\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060044
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050045\fI\fB
46
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060047\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 -050048
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050049\fI\fB
50
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050051\fBpng_structp png_create_read_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
52
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050053\fI\fB
54
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060055\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 -050056
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050057\fI\fB
58
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050059\fBpng_structp png_create_write_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
60
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050061\fI\fB
62
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050063\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
64
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050065\fI\fB
66
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050067\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
68
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050069\fI\fB
70
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050071\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
72
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050073\fI\fB
74
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050075\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
76
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050077\fI\fB
78
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050079\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
80
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050081\fI\fB
82
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060083\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
84
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050085\fI\fB
86
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050087\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
88
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050089\fI\fB
90
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060091\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 -060092
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050093\fI\fB
94
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050095\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
96
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050097\fI\fB
98
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050099\fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
100
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500101\fI\fB
102
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500103\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
104
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500105\fI\fB
106
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500107\fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
108
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500109\fI\fB
110
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600111\fBpng_uint_32 png_get_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
112
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500113\fI\fB
114
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500115\fBpng_uint_32 png_get_chunk_cache_max (png_structp \fIpng_ptr\fP\fB);\fP
116
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500117\fI\fB
118
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500119\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
120
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500121\fI\fB
122
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500123\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
124
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500125\fI\fB
126
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500127\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
128
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500129\fI\fB
130
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500131\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
132
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500133\fI\fB
134
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500135\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
136
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500137\fI\fB
138
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500139\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
140
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500141\fI\fB
142
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500143\fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
144
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500145\fI\fB
146
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600147\fBpng_uint_32 png_get_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
148
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500149\fI\fB
150
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600151\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
152
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500153\fI\fB
154
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500155\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
156
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500157\fI\fB
158
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500159\fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
160
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500161\fI\fB
162
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600163\fBpng_uint_32 png_get_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_charpp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600164
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500165\fI\fB
166
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500167\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP
168
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500169\fI\fB
170
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500171\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
172
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500173\fI\fB
174
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500175\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
176
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500177\fI\fB
178
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500179\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
180
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500181\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600182
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500183\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
184
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500185\fI\fB
186
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500187\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
188
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500189\fI\fB
190
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600191\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
192
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500193\fI\fB
194
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600195\fBpng_alloc_size_t png_get_chunk_malloc_max (png_structp \fIpng_ptr\fP\fB);\fP
196
197\fI\fB
198
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500199\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
200
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500201\fI\fB
202
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500203\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
204
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500205\fI\fB
206
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500207\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
208
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500209\fI\fB
210
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500211\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
212
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500213\fI\fB
214
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500215\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
216
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500217\fI\fB
218
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500219\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
220
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500221\fI\fB
222
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500223\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
224
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500225\fI\fB
226
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500227\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
228
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500229\fI\fB
230
231\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
232
233\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
234
235\fI\fB
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500236
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600237\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
238
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500239\fI\fB
240
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500241\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
242
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500243\fI\fB
244
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500245\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
246
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500247\fI\fB
248
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500249\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 -0600250
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500251\fI\fB
252
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500253\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
254
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500255\fI\fB
256
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500257\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
258
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500259\fI\fB
260
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500261\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
262
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500263\fI\fB
264
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500265\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_color\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500266
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500267\fI\fB
268
269\fB/* This function is really an inline macro. \fI*/
270
271\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
272
273\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600274
275\fBpng_uint_32 png_get_uint_31 (png_bytep \fIbuf\fP\fB);\fP
276
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500277\fI\fB
278
279\fB/* This function is really an inline macro. \fI*/
280
281\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
282
283\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600284
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600285\fBpng_uint_32 png_get_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
286
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500287\fI\fB
288
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600289\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
290
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500291\fI\fB
292
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500293\fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP
294
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500295\fI\fB
296
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500297\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
298
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500299\fI\fB
300
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500301\fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP
302
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500303\fI\fB
304
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500305\fBpng_uint_32 png_get_valid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
306
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500307\fI\fB
308
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500309\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 -0500310
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500311\fI\fB
312
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500313\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 -0500314
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500315\fI\fB
316
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500317\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
318
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500319\fI\fB
320
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500321\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 -0500322
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500323\fI\fB
324
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500325\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 -0500326
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500327\fI\fB
328
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500329\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
330
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500331\fI\fB
332
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600333\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
334
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500335\fI\fB
336
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500337\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 -0500338
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500339\fI\fB
340
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500341\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 -0500342
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500343\fI\fB
344
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500345\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 -0500346
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500347\fI\fB
348
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500349\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
350
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500351\fI\fB
352
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500353\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
354
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500355\fI\fB
356
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500357\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP
358
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500359\fI\fB
360
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500361\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP
362
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500363\fI\fB
364
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500365\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
366
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500367\fI\fB
368
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500369\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
370
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500371\fI\fB
372
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500373\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
374
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500375\fI\fB
376
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600377\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 -0600378
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500379\fI\fB
380
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500381\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
382
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500383\fI\fB
384
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500385\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
386
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500387\fI\fB
388
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500389\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
390
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500391\fI\fB
392
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500393\fBpng_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
394
395\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600396
397\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
398
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500399\fI\fB
400
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600401\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
402
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500403\fI\fB
404
405\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
406
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500407\fI\fB
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -0500408
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500409\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP
410
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500411\fI\fB
412
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500413\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
414
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500415\fI\fB
416
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500417\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP
418
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500419\fI\fB
420
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500421\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
422
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500423\fI\fB
424
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600425\fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
426
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500427\fI\fB
428
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500429\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
430
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500431\fI\fB
432
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500433\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
434
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500435\fI\fB
436
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500437\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
438
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500439\fI\fB
440
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500441\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
442
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500443\fI\fB
444
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500445\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600446
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500447\fI\fB
448
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500449\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600450
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500451\fI\fB
452
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500453\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600454
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500455\fI\fB
456
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500457\fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600458
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500459\fI\fB
460
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500461\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600462
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500463\fI\fB
464
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500465\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600466
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500467\fI\fB
468
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -0600469\fBvoid png_set_expand_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
470
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500471\fI\fB
472
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500473\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 -0600474
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500475\fI\fB
476
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500477\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 -0600478
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500479\fI\fB
480
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500481\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 -0500482
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500483\fI\fB
484
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500485\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600486
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500487\fI\fB
488
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500489\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 -0600490
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500491\fI\fB
492
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500493\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 -0600494
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500495\fI\fB
496
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600497\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
498
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500499\fI\fB
500
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500501\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600502
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500503\fI\fB
504
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500505\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600506
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500507\fI\fB
508
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500509\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 -0600510
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500511\fI\fB
512
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600513\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 -0600514
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500515\fI\fB
516
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500517\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600518
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500519\fI\fB
520
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500521\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
522
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500523\fI\fB
524
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500525\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600526
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500527\fI\fB
528
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500529\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600530
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500531\fI\fB
532
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500533\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 -0600534
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500535\fI\fB
536
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600537\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 -0600538
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500539\fI\fB
540
Glenn Randers-Pehrson1e6ed732009-11-20 22:06:56 -0600541\fBjmp_buf* png_set_longjmp_fn (png_structp \fP\fIpng_ptr\fP\fB, png_longjmp_ptr \fP\fIlongjmp_fn\fP\fB, size_t \fIjmp_buf_size\fP\fB);\fP
542
543\fI\fB
544
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600545\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
546
547\fI\fB
548
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500549\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 -0600550
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500551\fI\fB
552
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500553\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 -0600554
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500555\fI\fB
556
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500557\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600558
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500559\fI\fB
560
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500561\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600562
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500563\fI\fB
564
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500565\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600566
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500567\fI\fB
568
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500569\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 -0600570
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500571\fI\fB
572
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500573\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 -0600574
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500575\fI\fB
576
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500577\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 -0600578
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500579\fI\fB
580
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500581\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 -0600582
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500583\fI\fB
584
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500585\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 -0600586
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500587\fI\fB
588
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500589\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 -0600590
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500591\fI\fB
592
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500593\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 -0600594
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500595\fI\fB
596
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600597\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP
598
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500599\fI\fB
600
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600601\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 -0600602
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500603\fI\fB
604
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600605\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP
606
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500607\fI\fB
608
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500609\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 -0600610
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500611\fI\fB
612
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600613\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
614
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500615\fI\fB
616
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500617\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 -0600618
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500619\fI\fB
620
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500621\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 -0600622
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500623\fI\fB
624
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600625\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 -0600626
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500627\fI\fB
628
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500629\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 -0600630
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500631\fI\fB
632
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500633\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 -0600634
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500635\fI\fB
636
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500637\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600638
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500639\fI\fB
640
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500641\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600642
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500643\fI\fB
644
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500645\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600646
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500647\fI\fB
648
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500649\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600650
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500651\fI\fB
652
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500653\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 -0600654
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500655\fI\fB
656
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500657\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 -0600658
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500659\fI\fB
660
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -0500661\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500662
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500663\fI\fB
664
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500665\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600666
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500667\fI\fB
668
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600669\fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP
670
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500671\fI\fB
672
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500673\fBvoid png_set_unknown_chunk_location(png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP
674
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500675\fI\fB
676
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600677\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 -0600678
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500679\fI\fB
680
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500681\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
682
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500683\fI\fB
684
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500685\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 -0600686
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500687\fI\fB
688
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500689\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 -0600690
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500691\fI\fB
692
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500693\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 -0600694
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500695\fI\fB
696
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500697\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 -0600698
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500699\fI\fB
700
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500701\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
702
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500703\fI\fB
704
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500705\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 -0600706
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500707\fI\fB
708
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500709\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600710
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500711\fI\fB
712
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500713\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 -0600714
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500715\fI\fB
716
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500717\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 -0600718
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500719\fI\fB
720
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500721\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 -0600722
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500723\fI\fB
724
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500725\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600726
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500727\fI\fB
728
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500729\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 -0600730
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500731\fI\fB
732
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500733\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 -0600734
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500735\fI\fB
736
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500737\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600738
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500739\fI\fB
740
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500741\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 -0600742
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500743\fI\fB
744
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500745\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600746
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500747\fI\fB
748
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600749\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
750
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500751\fI\fB
752
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600753\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600754
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500755\fI\fB
756
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500757\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600758
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500759\fI\fB
760
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500761\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600762
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500763\fI\fB
764
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500765\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
766
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500767\fI\fB
768
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500769\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
770
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500771\fI\fB
772
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500773\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
774
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500775\fI\fB
776
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600777.SH DESCRIPTION
778The
779.I libpng
780library supports encoding, decoding, and various manipulations of
781the Portable Network Graphics (PNG) format image files. It uses the
782.IR zlib(3)
783compression library.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600784Following is a copy of the libpng.txt file that accompanies libpng.
785.SH LIBPNG.TXT
786libpng.txt - A description on how to use and modify libpng
787
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600788 libpng version 1.5.0beta01 - February 8, 2010
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600789 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -0600790 <glennrp at users.sourceforge.net>
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500791 Copyright (c) 1998-2009 Glenn Randers-Pehrson
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -0500792
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -0500793 This document is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -0500794 For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -0500795 and license in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600796
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500797 Based on:
798
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600799 libpng versions 0.97, January 1998, through 1.5.0beta01 - February 8, 2010
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500800 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500801 Copyright (c) 1998-2009 Glenn Randers-Pehrson
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600802
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600803 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600804 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600805 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600806
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600807 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600808 For conditions of distribution and use, see copyright
809 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600810 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600811
812 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600813 Copyright (c) 1995, 1996 Frank J. T. Wojcik
814 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600815
816.SH I. Introduction
817
818This file describes how to use and modify the PNG reference library
819(known as libpng) for your own use. There are five sections to this
820file: introduction, structures, reading, writing, and modification and
821configuration notes for various special platforms. In addition to this
822file, example.c is a good starting point for using the library, as
823it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600824will need. We assume that libpng is already installed; see the
825INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600826
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500827For examples of libpng usage, see the files "example.c", "pngtest.c",
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -0600828and the files in the "contrib" directory, all of which are included in
829the libpng distribution.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500830
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600831Libpng was written as a companion to the PNG specification, as a way
832of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500833file format in application programs.
834
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500835The PNG specification (second edition), November 2003, is available as
836a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
837<http://www.w3.org/TR/2003/REC-PNG-20031110/
838The W3C and ISO documents have identical technical content.
839
840The PNG-1.2 specification is available at
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500841<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
842to the PNG specification (second edition) but has some additional material.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500843
844The PNG-1.0 specification is available
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -0500845as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500846W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
847
848Some additional 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-Pehrson56f63962008-10-06 10:16:17 -0500882same instance of a structure.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600883
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600884.SH II. Structures
885
886There are two main structures that are important to libpng, png_struct
887and png_info. The first, png_struct, is an internal structure that
888will not, for the most part, be used by a user except as the first
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600889variable passed to every libpng function call.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600890
891The png_info structure is designed to provide information about the
892PNG file. At one time, the fields of png_info were intended to be
893directly accessible to the user. However, this tended to cause problems
894with applications using dynamically loaded libraries, and as a result
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500895a set of interface functions for png_info (the png_get_*() and png_set_*()
896functions) was developed. The fields of png_info are still available for
897older applications, but it is suggested that applications use the new
898interfaces if at all possible.
899
900Applications that do make direct access to the members of png_struct (except
901for png_ptr->jmpbuf) must be recompiled whenever the library is updated,
902and applications that make direct access to the members of png_info must
903be recompiled if they were compiled or loaded with libpng version 1.0.6,
904in which the members were in a different order. In version 1.0.7, the
905members of the png_info structure reverted to the old order, as they were
906in versions 0.97c through 1.0.5. Starting with version 2.0.0, both
907structures are going to be hidden, and the contents of the structures will
908only be accessible through the png_get/png_set functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600909
910The png.h header file is an invaluable reference for programming with libpng.
911And while I'm on the topic, make sure you include the libpng header file:
912
913#include <png.h>
914
915.SH III. Reading
916
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600917We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600918in a PNG file sequentially, briefly explaining the syntax and purpose
919of each one. See example.c and png.h for more detail. While
920progressive reading is covered in the next section, you will still
921need some of the functions discussed in this section to read a PNG
922file.
923
924.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600925
926You will want to do the I/O initialization(*) before you get into libpng,
927so if it doesn't work, you don't have much to undo. Of course, you
928will also want to insure that you are, in fact, dealing with a PNG
929file. Libpng provides a simple check to see if a file is a PNG file.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500930To use it, pass in the first 1 to 8 bytes of the file to the function
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -0500931png_sig_cmp(), and it will return 0 (false) if the bytes match the
932corresponding bytes of the PNG signature, or nonzero (true) otherwise.
933Of course, the more bytes you pass in, the greater the accuracy of the
934prediction.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600935
936If you are intending to keep the file pointer open for use in libpng,
937you must ensure you don't read more than 8 bytes from the beginning
938of the file, and you also have to make a call to png_set_sig_bytes_read()
939with the number of bytes you read from the beginning. Libpng will
940then only check the bytes (if any) that your program didn't read.
941
942(*): If you are not using the standard I/O functions, you will need
943to replace them with custom functions. See the discussion under
944Customizing libpng.
945
946
947 FILE *fp = fopen(file_name, "rb");
948 if (!fp)
949 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500950 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600951 }
952 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600953 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600954 if (!is_png)
955 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500956 return (NOT_PNG);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600957 }
958
959
960Next, png_struct and png_info need to be allocated and initialized. In
961order to ensure that the size of these structures is correct even with a
962dynamically linked libpng, there are functions to initialize and
963allocate the structures. We also pass the library version, optional
964pointers to error handling functions, and a pointer to a data struct for
965use by the error functions, if necessary (the pointer and functions can
966be NULL if the default error handlers are to be used). See the section
967on Changes to Libpng below regarding the old initialization functions.
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500968The structure allocation functions quietly return NULL if they fail to
969create the structure, so your application should check for that.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600970
971 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500972 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600973 user_error_fn, user_warning_fn);
974 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500975 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600976
977 png_infop info_ptr = png_create_info_struct(png_ptr);
978 if (!info_ptr)
979 {
980 png_destroy_read_struct(&png_ptr,
981 (png_infopp)NULL, (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500982 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600983 }
984
985 png_infop end_info = png_create_info_struct(png_ptr);
986 if (!end_info)
987 {
988 png_destroy_read_struct(&png_ptr, &info_ptr,
989 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500990 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600991 }
992
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500993If you want to use your own memory allocation routines,
994define PNG_USER_MEM_SUPPORTED and use
995png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600996
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500997 png_structp png_ptr = png_create_read_struct_2
998 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
999 user_error_fn, user_warning_fn, (png_voidp)
1000 user_mem_ptr, user_malloc_fn, user_free_fn);
1001
1002The error handling routines passed to png_create_read_struct()
1003and the memory alloc/free routines passed to png_create_struct_2()
1004are only necessary if you are not using the libpng supplied error
1005handling and memory alloc/free functions.
1006
1007When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001008to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001009your png_jmpbuf(png_ptr). If you read the file from different
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001010routines, you will need to update the jmpbuf field every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001011a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001012
1013See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001014information on setjmp/longjmp. See the discussion on libpng error
1015handling in the Customizing Libpng section below for more information
1016on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001017back to your setjmp, you will want to call png_destroy_read_struct() to
1018free any memory.
1019
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001020 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001021 {
1022 png_destroy_read_struct(&png_ptr, &info_ptr,
1023 &end_info);
1024 fclose(fp);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001025 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001026 }
1027
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001028If you would rather avoid the complexity of setjmp/longjmp issues,
1029you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
1030errors will result in a call to PNG_ABORT() which defaults to abort().
1031
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001032Now you need to set up the input code. The default for libpng is to
1033use the C function fread(). If you use this, you will need to pass a
1034valid FILE * in the function png_init_io(). Be sure that the file is
1035opened in binary mode. If you wish to handle reading data in another
1036way, you need not call the png_init_io() function, but you must then
1037implement the libpng I/O methods discussed in the Customizing Libpng
1038section below.
1039
1040 png_init_io(png_ptr, fp);
1041
1042If you had previously opened the file and read any of the signature from
1043the beginning in order to see if this was a PNG file, you need to let
1044libpng know that there are some bytes missing from the start of the file.
1045
1046 png_set_sig_bytes(png_ptr, number);
1047
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001048You can change the zlib compression buffer size to be used while
1049reading compressed data with
1050
1051 png_set_compression_buffer_size(png_ptr, buffer_size);
1052
1053where the default size is 8192 bytes. Note that the buffer size
1054is changed immediately and the buffer is reallocated immediately,
1055instead of setting a flag to be acted upon later.
1056
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001057.SS Setting up callback code
1058
1059You can set up a callback function to handle any unknown chunks in the
1060input stream. You must supply the function
1061
1062 read_chunk_callback(png_ptr ptr,
1063 png_unknown_chunkp chunk);
1064 {
1065 /* The unknown chunk structure contains your
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001066 chunk data, along with similar data for any other
1067 unknown chunks: */
1068
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001069 png_byte name[5];
1070 png_byte *data;
1071 png_size_t size;
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001072
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001073 /* Note that libpng has already taken care of
1074 the CRC handling */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001075
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001076 /* put your code here. Search for your chunk in the
1077 unknown chunk structure, process it, and return one
1078 of the following: */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001079
1080 return (-n); /* chunk had an error */
1081 return (0); /* did not recognize */
1082 return (n); /* success */
1083 }
1084
1085(You can give your function another name that you like instead of
1086"read_chunk_callback")
1087
1088To inform libpng about your function, use
1089
1090 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1091 read_chunk_callback);
1092
1093This names not only the callback function, but also a user pointer that
1094you can retrieve with
1095
1096 png_get_user_chunk_ptr(png_ptr);
1097
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001098If you call the png_set_read_user_chunk_fn() function, then all unknown
1099chunks will be saved when read, in case your callback function will need
1100one or more of them. This behavior can be changed with the
1101png_set_keep_unknown_chunks() function, described below.
1102
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001103At this point, you can set up a callback function that will be
1104called after each row has been read, which you can use to control
1105a progress meter or the like. It's demonstrated in pngtest.c.
1106You must supply a function
1107
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001108 void read_row_callback(png_ptr ptr, png_uint_32 row,
1109 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001110 {
1111 /* put your code here */
1112 }
1113
1114(You can give it another name that you like instead of "read_row_callback")
1115
1116To inform libpng about your function, use
1117
1118 png_set_read_status_fn(png_ptr, read_row_callback);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001119
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001120.SS Unknown-chunk handling
1121
1122Now you get to set the way the library processes unknown chunks in the
1123input PNG stream. Both known and unknown chunks will be read. Normal
1124behavior is that known chunks will be parsed into information in
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001125various info_ptr members while unknown chunks will be discarded. This
1126behavior can be wasteful if your application will never use some known
1127chunk types. To change this, you can call:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001128
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001129 png_set_keep_unknown_chunks(png_ptr, keep,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001130 chunk_list, num_chunks);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001131 keep - 0: default unknown chunk handling
1132 1: ignore; do not keep
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001133 2: keep only if safe-to-copy
1134 3: keep even if unsafe-to-copy
1135 You can use these definitions:
1136 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1137 PNG_HANDLE_CHUNK_NEVER 1
1138 PNG_HANDLE_CHUNK_IF_SAFE 2
1139 PNG_HANDLE_CHUNK_ALWAYS 3
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001140 chunk_list - list of chunks affected (a byte string,
1141 five bytes per chunk, NULL or '\0' if
1142 num_chunks is 0)
1143 num_chunks - number of chunks affected; if 0, all
Glenn Randers-Pehrsondff799e2004-08-07 21:42:49 -05001144 unknown chunks are affected. If nonzero,
1145 only the chunks in the list are affected
1146
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001147Unknown chunks declared in this way will be saved as raw data onto a
1148list of png_unknown_chunk structures. If a chunk that is normally
1149known to libpng is named in the list, it will be handled as unknown,
1150according to the "keep" directive. If a chunk is named in successive
1151instances of png_set_keep_unknown_chunks(), the final instance will
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001152take precedence. The IHDR and IEND chunks should not be named in
1153chunk_list; if they are, libpng will process them normally anyway.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001154
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001155Here is an example of the usage of png_set_keep_unknown_chunks(),
1156where the private "vpAg" chunk will later be processed by a user chunk
1157callback function:
1158
1159 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1160
1161 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1162 png_byte unused_chunks[]=
1163 {
1164 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1165 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1166 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1167 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1168 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1169 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1170 };
1171 #endif
1172
1173 ...
1174
1175 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1176 /* ignore all unknown chunks: */
1177 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
1178 /* except for vpAg: */
1179 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
1180 /* also ignore unused known chunks: */
1181 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1182 (int)sizeof(unused_chunks)/5);
1183 #endif
1184
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001185.SS User limits
1186
1187The PNG specification allows the width and height of an image to be as
1188large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1189Since very few applications really need to process such large images,
1190we have imposed an arbitrary 1-million limit on rows and columns.
1191Larger images will be rejected immediately with a png_error() call. If
1192you wish to override this limit, you can use
1193
1194 png_set_user_limits(png_ptr, width_max, height_max);
1195
1196to set your own limits, or use width_max = height_max = 0x7fffffffL
1197to allow all valid dimensions (libpng may reject some very large images
1198anyway because of potential buffer overflow conditions).
1199
1200You should put this statement after you create the PNG structure and
1201before calling png_read_info(), png_read_png(), or png_process_data().
1202If you need to retrieve the limits that are being applied, use
1203
1204 width_max = png_get_user_width_max(png_ptr);
1205 height_max = png_get_user_height_max(png_ptr);
1206
1207The PNG specification sets no limit on the number of ancillary chunks
1208allowed in a PNG datastream. You can impose a limit on the total number
1209of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1210
1211 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1212
1213where 0x7fffffffL means unlimited. You can retrieve this limit with
1214
1215 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1216
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05001217This limit also applies to the number of buffers that can be allocated
1218by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1219
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001220You can also set a limit on the amount of memory that a compressed chunk
1221other than IDAT can occupy, with
1222
1223 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1224
1225and you can retrieve the limit with
1226
1227 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1228
1229Any chunks that would cause either of these limits to be exceeded will
1230be ignored.
1231
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001232.SS The high-level read interface
1233
1234At this point there are two ways to proceed; through the high-level
1235read interface, or through a sequence of low-level read operations.
1236You can use the high-level interface if (a) you are willing to read
1237the entire image into memory, and (b) the input transformations
1238you want to do are limited to the following set:
1239
1240 PNG_TRANSFORM_IDENTITY No transformation
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001241 PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
1242 8 bits
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001243 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001244 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1245 samples to bytes
1246 PNG_TRANSFORM_PACKSWAP Change order of packed
1247 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001248 PNG_TRANSFORM_EXPAND Perform set_expand()
1249 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001250 PNG_TRANSFORM_SHIFT Normalize pixels to the
1251 sBIT depth
1252 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1253 to BGRA
1254 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1255 to AG
1256 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1257 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001258 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05001259 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1260 to RGB (or GA to RGBA)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001261
1262(This excludes setting a background color, doing gamma transformation,
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001263dithering, and setting filler.) If this is the case, simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001264
1265 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1266
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001267where png_transforms is an integer containing the bitwise OR of some
1268set of transformation flags. This call is equivalent to png_read_info(),
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001269followed the set of transformations indicated by the transform mask,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001270then png_read_image(), and finally png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001271
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001272(The final parameter of this call is not yet used. Someday it might point
1273to transformation parameters required by some future input transform.)
1274
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001275You must use png_transforms and not call any png_set_transform() functions
1276when you use png_read_png().
1277
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001278After you have called png_read_png(), you can retrieve the image data
1279with
1280
1281 row_pointers = png_get_rows(png_ptr, info_ptr);
1282
1283where row_pointers is an array of pointers to the pixel data for each row:
1284
1285 png_bytep row_pointers[height];
1286
1287If you know your image size and pixel size ahead of time, you can allocate
1288row_pointers prior to calling png_read_png() with
1289
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001290 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001291 png_error (png_ptr,
1292 "Image is too tall to process in memory");
1293 if (width > PNG_UINT_32_MAX/pixel_size)
1294 png_error (png_ptr,
1295 "Image is too wide to process in memory");
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001296 row_pointers = png_malloc(png_ptr,
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001297 height*png_sizeof(png_bytep));
1298 for (int i=0; i<height, i++)
1299 row_pointers[i]=NULL; /* security precaution */
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001300 for (int i=0; i<height, i++)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001301 row_pointers[i]=png_malloc(png_ptr,
1302 width*pixel_size);
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001303 png_set_rows(png_ptr, info_ptr, &row_pointers);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001304
1305Alternatively you could allocate your image in one big block and define
1306row_pointers[i] to point into the proper places in your block.
1307
1308If you use png_set_rows(), the application is responsible for freeing
1309row_pointers (and row_pointers[i], if they were separately allocated).
1310
1311If you don't allocate row_pointers ahead of time, png_read_png() will
1312do it, and it'll be free'ed when you call png_destroy_*().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001313
1314.SS The low-level read interface
1315
1316If you are going the low-level route, you are now ready to read all
1317the file information up to the actual image data. You do this with a
1318call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001319
1320 png_read_info(png_ptr, info_ptr);
1321
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001322This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001323
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001324.SS Querying the info structure
1325
1326Functions are used to get the information from the info_ptr once it
1327has been read. Note that these fields may not be completely filled
1328in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001329
1330 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1331 &bit_depth, &color_type, &interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001332 &compression_type, &filter_method);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001333
1334 width - holds the width of the image
1335 in pixels (up to 2^31).
1336 height - holds the height of the image
1337 in pixels (up to 2^31).
1338 bit_depth - holds the bit depth of one of the
1339 image channels. (valid values are
1340 1, 2, 4, 8, 16 and depend also on
1341 the color_type. See also
1342 significant bits (sBIT) below).
1343 color_type - describes which color/alpha channels
1344 are present.
1345 PNG_COLOR_TYPE_GRAY
1346 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001347 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001348 (bit depths 8, 16)
1349 PNG_COLOR_TYPE_PALETTE
1350 (bit depths 1, 2, 4, 8)
1351 PNG_COLOR_TYPE_RGB
1352 (bit_depths 8, 16)
1353 PNG_COLOR_TYPE_RGB_ALPHA
1354 (bit_depths 8, 16)
1355
1356 PNG_COLOR_MASK_PALETTE
1357 PNG_COLOR_MASK_COLOR
1358 PNG_COLOR_MASK_ALPHA
1359
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001360 filter_method - (must be PNG_FILTER_TYPE_BASE
1361 for PNG 1.0, and can also be
1362 PNG_INTRAPIXEL_DIFFERENCING if
1363 the PNG datastream is embedded in
1364 a MNG-1.0 datastream)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001365 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1366 for PNG 1.0)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001367 interlace_type - (PNG_INTERLACE_NONE or
1368 PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05001369
1370 Any or all of interlace_type, compression_type, or
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001371 filter_method can be NULL if you are
1372 not interested in their values.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001373
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05001374 Note that png_get_IHDR() returns 32-bit data into
1375 the application's width and height variables.
1376 This is an unsafe situation if these are 16-bit
1377 variables. In such situations, the
1378 png_get_image_width() and png_get_image_height()
1379 functions described below are safer.
1380
1381 width = png_get_image_width(png_ptr,
1382 info_ptr);
1383 height = png_get_image_height(png_ptr,
1384 info_ptr);
1385 bit_depth = png_get_bit_depth(png_ptr,
1386 info_ptr);
1387 color_type = png_get_color_type(png_ptr,
1388 info_ptr);
1389 filter_method = png_get_filter_type(png_ptr,
1390 info_ptr);
1391 compression_type = png_get_compression_type(png_ptr,
1392 info_ptr);
1393 interlace_type = png_get_interlace_type(png_ptr,
1394 info_ptr);
1395
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001396 channels = png_get_channels(png_ptr, info_ptr);
1397 channels - number of channels of info for the
1398 color type (valid values are 1 (GRAY,
1399 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1400 4 (RGB_ALPHA or RGB + filler byte))
1401 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1402 rowbytes - number of bytes needed to hold a row
1403
1404 signature = png_get_signature(png_ptr, info_ptr);
1405 signature - holds the signature read from the
1406 file (if any). The data is kept in
1407 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001408 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001409 application had already read in 4
1410 bytes of signature before starting
1411 libpng, the remaining 4 bytes would
1412 be in signature[4] through signature[7]
1413 (see png_set_sig_bytes())).
1414
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001415These are also important, but their validity depends on whether the chunk
1416has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1417png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1418data has been read, or zero if it is missing. The parameters to the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001419png_get_<chunk> are set directly if they are simple data types, or a
1420pointer into the info_ptr is returned for any complex types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001421
1422 png_get_PLTE(png_ptr, info_ptr, &palette,
1423 &num_palette);
1424 palette - the palette for the file
1425 (array of png_color)
1426 num_palette - number of entries in the palette
1427
1428 png_get_gAMA(png_ptr, info_ptr, &gamma);
1429 gamma - the gamma the file is written
1430 at (PNG_INFO_gAMA)
1431
1432 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1433 srgb_intent - the rendering intent (PNG_INFO_sRGB)
1434 The presence of the sRGB chunk
1435 means that the pixel data is in the
1436 sRGB color space. This chunk also
1437 implies specific values of gAMA and
1438 cHRM.
1439
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001440 png_get_iCCP(png_ptr, info_ptr, &name,
1441 &compression_type, &profile, &proflen);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001442 name - The profile name.
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001443 compression - The compression type; always
1444 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1445 You may give NULL to this argument to
1446 ignore it.
1447 profile - International Color Consortium color
1448 profile data. May contain NULs.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001449 proflen - length of profile data in bytes.
1450
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001451 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1452 sig_bit - the number of significant bits for
1453 (PNG_INFO_sBIT) each of the gray,
1454 red, green, and blue channels,
1455 whichever are appropriate for the
1456 given color type (png_color_16)
1457
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05001458 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
1459 &num_trans, &trans_color);
1460 trans_alpha - array of alpha (transparency)
1461 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05001462 trans_color - graylevel or color sample values of
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05001463 the single transparent color for
1464 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001465 num_trans - number of transparent entries
1466 (PNG_INFO_tRNS)
1467
1468 png_get_hIST(png_ptr, info_ptr, &hist);
1469 (PNG_INFO_hIST)
1470 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001471 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001472
1473 png_get_tIME(png_ptr, info_ptr, &mod_time);
1474 mod_time - time image was last modified
1475 (PNG_VALID_tIME)
1476
1477 png_get_bKGD(png_ptr, info_ptr, &background);
1478 background - background color (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001479 valid 16-bit red, green and blue
1480 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001481
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001482 num_comments = png_get_text(png_ptr, info_ptr,
1483 &text_ptr, &num_text);
1484 num_comments - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001485 text_ptr - array of png_text holding image
1486 comments
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001487 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001488 on "text" PNG_TEXT_COMPRESSION_NONE
1489 PNG_TEXT_COMPRESSION_zTXt
1490 PNG_ITXT_COMPRESSION_NONE
1491 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001492 text_ptr[i].key - keyword for comment. Must contain
1493 1-79 characters.
1494 text_ptr[i].text - text comments for current
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001495 keyword. Can be empty.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001496 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001497 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001498 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001499 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001500 text_ptr[i].lang - language of comment (empty
1501 string for unknown).
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06001502 text_ptr[i].lang_key - keyword in UTF-8
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001503 (empty string for unknown).
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05001504 Note that the itxt_length, lang, and lang_key
1505 members of the text_ptr structure only exist
1506 when the library is built with iTXt chunk support.
1507
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001508 num_text - number of comments (same as
1509 num_comments; you can put NULL here
1510 to avoid the duplication)
1511 Note while png_set_text() will accept text, language,
1512 and translated keywords that can be NULL pointers, the
1513 structure returned by png_get_text will always contain
1514 regular zero-terminated C strings. They might be
1515 empty strings but they will never be NULL pointers.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001516
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001517 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1518 &palette_ptr);
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001519 palette_ptr - array of palette structures holding
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001520 contents of one or more sPLT chunks
1521 read.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001522 num_spalettes - number of sPLT chunks read.
1523
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001524 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001525 &unit_type);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001526 offset_x - positive offset from the left edge
1527 of the screen
1528 offset_y - positive offset from the top edge
1529 of the screen
1530 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1531
1532 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001533 &unit_type);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001534 res_x - pixels/unit physical resolution in
1535 x direction
1536 res_y - pixels/unit physical resolution in
1537 x direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001538 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001539 PNG_RESOLUTION_METER
1540
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001541 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1542 &height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001543 unit - physical scale units (an integer)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001544 width - width of a pixel in physical scale units
1545 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001546 (width and height are doubles)
1547
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001548 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1549 &height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001550 unit - physical scale units (an integer)
1551 width - width of a pixel in physical scale units
1552 height - height of a pixel in physical scale units
1553 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001554
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001555 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1556 info_ptr, &unknowns)
1557 unknowns - array of png_unknown_chunk
1558 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001559 unknowns[i].name - name of unknown chunk
1560 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001561 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001562 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001563
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001564 The value of "i" corresponds to the order in which the
1565 chunks were read from the PNG file or inserted with the
1566 png_set_unknown_chunks() function.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001567
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001568The data from the pHYs chunk can be retrieved in several convenient
1569forms:
1570
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001571 res_x = png_get_x_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001572 info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001573 res_y = png_get_y_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001574 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001575 res_x_and_y = png_get_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001576 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001577 res_x = png_get_x_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001578 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001579 res_y = png_get_y_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001580 info_ptr)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001581 res_x_and_y = png_get_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001582 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001583 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001584 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001585
1586 (Each of these returns 0 [signifying "unknown"] if
1587 the data is not present or if res_x is 0;
1588 res_x_and_y is 0 if res_x != res_y)
1589
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001590The data from the oFFs chunk can be retrieved in several convenient
1591forms:
1592
1593 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1594 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1595 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1596 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1597
1598 (Each of these returns 0 [signifying "unknown" if both
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001599 x and y are 0] if the data is not present or if the
1600 chunk is present but the unit is the pixel)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001601
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001602For more information, see the png_info definition in png.h and the
1603PNG specification for chunk contents. Be careful with trusting
1604rowbytes, as some of the transformations could increase the space
1605needed to hold a row (expand, filler, gray_to_rgb, etc.).
1606See png_read_update_info(), below.
1607
1608A quick word about text_ptr and num_text. PNG stores comments in
1609keyword/text pairs, one pair per chunk, with no limit on the number
1610of text chunks, and a 2^31 byte limit on their size. While there are
1611suggested keywords, there is no requirement to restrict the use to these
1612strings. It is strongly suggested that keywords and text be sensible
1613to humans (that's the point), so don't use abbreviations. Non-printing
1614symbols are not allowed. See the PNG specification for more details.
1615There is also no requirement to have text after the keyword.
1616
1617Keywords should be limited to 79 Latin-1 characters without leading or
1618trailing spaces, but non-consecutive spaces are allowed within the
1619keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001620The text_ptr is an array of png_text structures, each holding a
1621pointer to a language string, a pointer to a keyword and a pointer to
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001622a text string. The text string, language code, and translated
1623keyword may be empty or NULL pointers. The keyword/text
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001624pairs are put into the array in the order that they are received.
1625However, some or all of the text chunks may be after the image, so, to
1626make sure you have read all the text chunks, don't mess with these
1627until after you read the stuff after the image. This will be
1628mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001629
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001630.SS Input transformations
1631
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001632After you've read the header information, you can set up the library
1633to handle any special transformations of the image data. The various
1634ways to transform the data will be described in the order that they
1635should occur. This is important, as some of these change the color
1636type and/or bit depth of the data, and some others only work on
1637certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001638checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001639make sure to only enable a transformation if it will be valid for the
1640data. For example, don't swap red and blue on grayscale data.
1641
1642The colors used for the background and transparency values should be
1643supplied in the same format/depth as the current image data. They
1644are stored in the same format/depth as the image data in a bKGD or tRNS
1645chunk, so this is what libpng expects for this data. The colors are
1646transformed to keep in sync with the image data when an application
1647calls the png_read_update_info() routine (see below).
1648
1649Data will be decoded into the supplied row buffers packed into bytes
1650unless the library has been told to transform it into another format.
1651For example, 4 bit/pixel paletted or grayscale data will be returned
16522 pixels/byte with the leftmost pixel in the high-order bits of the
1653byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001654in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
1655is called to insert filler bytes, either before or after each RGB triplet.
165616-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
1657byte of the color value first, unless png_set_strip_16() is called to
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06001658transform it to regular RGB RGB triplets, or png_set_filler() or
1659png_set_add alpha() is called to insert filler bytes, either before or
1660after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
1661be modified with
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001662png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001663
1664The following code transforms grayscale images of less than 8 to 8 bits,
1665changes paletted images to RGB, and adds a full alpha channel if there is
1666transparency information in a tRNS chunk. This is most useful on
1667grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1668viewing application that wishes to treat all images in the same way.
1669
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001670 if (color_type == PNG_COLOR_TYPE_PALETTE)
1671 png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001672
1673 if (color_type == PNG_COLOR_TYPE_GRAY &&
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06001674 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001675
1676 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001677 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1678
1679These three functions are actually aliases for png_set_expand(), added
1680in libpng version 1.0.4, with the function names expanded to improve code
1681readability. In some future version they may actually do different
1682things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001683
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06001684As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
1685added. It expands the sample depth without changing tRNS to alpha.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001686
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001687As of libpng version 1.5.0beta01, not all possible expansions are supported.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001688
1689In the following table, the 01 means grayscale with depth<8, 31 means
1690indexed with depth<8, other numerals represent the color type, "T" means
1691the tRNS chunk is present, A means an alpha channel is present, and O
1692means tRNS or alpha is present but all pixels in the image are opaque.
1693
1694 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
1695 TO
1696 01 -
1697 31 -
1698 0 1 -
1699 0T -
1700 0O -
1701 2 GX -
1702 2T -
1703 2O -
1704 3 1 -
1705 3T -
1706 3O -
1707 4A T -
1708 4O -
1709 6A GX TX TX -
1710 6O GX TX -
1711
1712Within the matrix,
1713 "-" means the transformation is not supported.
1714 "X" means the transformation is obtained by png_set_expand().
1715 "1" means the transformation is obtained by
1716 png_set_expand_gray_1_2_4_to_8
1717 "G" means the transformation is obtained by
1718 png_set_gray_to_rgb().
1719 "P" means the transformation is obtained by
1720 png_set_expand_palette_to_rgb().
1721 "T" means the transformation is obtained by
1722 png_set_tRNS_to_alpha().
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06001723
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001724PNG can have files with 16 bits per channel. If you only can handle
17258 bits per channel, this will strip the pixels down to 8 bit.
1726
1727 if (bit_depth == 16)
1728 png_set_strip_16(png_ptr);
1729
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001730If, for some reason, you don't need the alpha channel on an image,
1731and you want to remove it rather than combining it with the background
1732(but the image author certainly had in mind that you *would* combine
1733it with the background, so that's what you should probably do):
1734
1735 if (color_type & PNG_COLOR_MASK_ALPHA)
1736 png_set_strip_alpha(png_ptr);
1737
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001738In PNG files, the alpha channel in an image
1739is the level of opacity. If you need the alpha channel in an image to
1740be the level of transparency instead of opacity, you can invert the
1741alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1742fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1743images) is fully transparent, with
1744
1745 png_set_invert_alpha(png_ptr);
1746
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001747PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1748they can, resulting in, for example, 8 pixels per byte for 1 bit
1749files. This code expands to 1 pixel per byte without changing the
1750values of the pixels:
1751
1752 if (bit_depth < 8)
1753 png_set_packing(png_ptr);
1754
1755PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1756stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001757higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
1758to 8 bits/sample in the range [0, 255]). However, it is also possible
1759to convert the PNG pixel data back to the original bit depth of the
1760image. This call reduces the pixels back down to the original bit depth:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001761
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05001762 png_color_8p sig_bit;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001763
1764 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1765 png_set_shift(png_ptr, sig_bit);
1766
1767PNG files store 3-color pixels in red, green, blue order. This code
1768changes the storage of the pixels to blue, green, red:
1769
1770 if (color_type == PNG_COLOR_TYPE_RGB ||
1771 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1772 png_set_bgr(png_ptr);
1773
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001774PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
1775into 4 or 8 bytes for windowing systems that need them in this format:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001776
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001777 if (color_type == PNG_COLOR_TYPE_RGB)
1778 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001779
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001780where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001781either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1782you want the filler before the RGB or after. This transformation
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001783does not affect images that already have full alpha channels. To add an
1784opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
1785will generate RGBA pixels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001786
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001787Note that png_set_filler() does not change the color type. If you want
1788to do that, you can add a true alpha channel with
1789
1790 if (color_type == PNG_COLOR_TYPE_RGB ||
1791 color_type == PNG_COLOR_TYPE_GRAY)
1792 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
1793
1794where "filler" contains the alpha value to assign to each pixel.
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06001795This function was added in libpng-1.2.7.
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05001796
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001797If you are reading an image with an alpha channel, and you need the
1798data as ARGB instead of the normal PNG format RGBA:
1799
1800 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1801 png_set_swap_alpha(png_ptr);
1802
1803For some uses, you may want a grayscale image to be represented as
1804RGB. This code will do that conversion:
1805
1806 if (color_type == PNG_COLOR_TYPE_GRAY ||
1807 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1808 png_set_gray_to_rgb(png_ptr);
1809
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001810Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001811with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001812
1813 if (color_type == PNG_COLOR_TYPE_RGB ||
1814 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001815 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1816 int red_weight, int green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001817
1818 error_action = 1: silently do the conversion
1819 error_action = 2: issue a warning if the original
1820 image has any pixel where
1821 red != green or red != blue
1822 error_action = 3: issue an error and abort the
1823 conversion if the original
1824 image has any pixel where
1825 red != green or red != blue
1826
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001827 red_weight: weight of red component times 100000
1828 green_weight: weight of green component times 100000
1829 If either weight is negative, default
1830 weights (21268, 71514) are used.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001831
1832If you have set error_action = 1 or 2, you can
1833later check whether the image really was gray, after processing
1834the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1835It will return a png_byte that is zero if the image was gray or
18361 if there were any non-gray pixels. bKGD and sBIT data
1837will be silently converted to grayscale, using the green channel
1838data, regardless of the error_action setting.
1839
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001840With red_weight+green_weight<=100000,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001841the normalized graylevel is computed:
1842
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001843 int rw = red_weight * 65536;
1844 int gw = green_weight * 65536;
1845 int bw = 65536 - (rw + gw);
1846 gray = (rw*red + gw*green + bw*blue)/65536;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001847
1848The default values approximate those recommended in the Charles
1849Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06001850Copyright (c) 1998-01-04 Charles Poynton <poynton at inforamp.net>
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001851
1852 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1853
1854Libpng approximates this with
1855
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001856 Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001857
1858which can be expressed with integers as
1859
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001860 Y = (6969 * R + 23434 * G + 2365 * B)/32768
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001861
1862The calculation is done in a linear colorspace, if the image gamma
1863is known.
1864
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06001865If you have a grayscale and you are using png_set_expand_depth(),
1866png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001867a higher bit-depth, you must either supply the background color as a gray
1868value at the original file bit-depth (need_expand = 1) or else supply the
1869background color as an RGB triplet at the final, expanded bit depth
1870(need_expand = 0). Similarly, if you are reading a paletted image, you
1871must either supply the background color as a palette index (need_expand = 1)
1872or as an RGB triplet that may or may not be in the palette (need_expand = 0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001873
1874 png_color_16 my_background;
1875 png_color_16p image_background;
1876
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05001877 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1878 png_set_background(png_ptr, image_background,
1879 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001880 else
1881 png_set_background(png_ptr, &my_background,
1882 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1883
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001884The png_set_background() function tells libpng to composite images
1885with alpha or simple transparency against the supplied background
1886color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1887you may use this color, or supply another color more suitable for
1888the current display (e.g., the background color from a web page). You
1889need to tell libpng whether the color is in the gamma space of the
1890display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
1891(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
1892that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
1893know why anyone would use this, but it's here).
1894
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001895To properly display PNG images on any kind of system, the application needs
1896to know what the display gamma is. Ideally, the user will know this, and
1897the application will allow them to set it. One method of allowing the user
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001898to set the display gamma separately for each system is to check for a
1899SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
1900correctly set.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001901
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001902Note that display_gamma is the overall gamma correction required to produce
1903pleasing results, which depends on the lighting conditions in the surrounding
1904environment. In a dim or brightly lit room, no compensation other than
1905the physical gamma exponent of the monitor is needed, while in a dark room
1906a slightly smaller exponent is better.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001907
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001908 double gamma, screen_gamma;
1909
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001910 if (/* We have a user-defined screen
1911 gamma value */)
1912 {
1913 screen_gamma = user_defined_screen_gamma;
1914 }
1915 /* One way that applications can share the same
1916 screen gamma value */
1917 else if ((gamma_str = getenv("SCREEN_GAMMA"))
1918 != NULL)
1919 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001920 screen_gamma = (double)atof(gamma_str);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001921 }
1922 /* If we don't have another value */
1923 else
1924 {
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001925 screen_gamma = 2.2; /* A good guess for a
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001926 PC monitor in a bright office or a dim room */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001927 screen_gamma = 2.0; /* A good guess for a
1928 PC monitor in a dark room */
1929 screen_gamma = 1.7 or 1.0; /* A good
1930 guess for Mac systems */
1931 }
1932
1933The png_set_gamma() function handles gamma transformations of the data.
1934Pass both the file gamma and the current screen_gamma. If the file does
1935not have a gamma value, you can pass one anyway if you have an idea what
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001936it is (usually 0.45455 is a good guess for GIF images on PCs). Note
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001937that file gammas are inverted from screen gammas. See the discussions
1938on gamma in the PNG specification for an excellent description of what
1939gamma is, and why all applications should support it. It is strongly
1940recommended that PNG viewers support gamma correction.
1941
1942 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
1943 png_set_gamma(png_ptr, screen_gamma, gamma);
1944 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001945 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001946
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001947PNG files describe monochrome as black being zero and white being one.
1948The following code will reverse this (make black be one and white be
1949zero):
1950
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05001951 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
1952 png_set_invert_mono(png_ptr);
1953
1954This function can also be used to invert grayscale and gray-alpha images:
1955
1956 if (color_type == PNG_COLOR_TYPE_GRAY ||
1957 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001958 png_set_invert_mono(png_ptr);
1959
1960PNG files store 16 bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001961ie. most significant bits first). This code changes the storage to the
1962other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001963way PCs store them):
1964
1965 if (bit_depth == 16)
1966 png_set_swap(png_ptr);
1967
1968If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
1969need to change the order the pixels are packed into bytes, you can use:
1970
1971 if (bit_depth < 8)
1972 png_set_packswap(png_ptr);
1973
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001974Finally, you can write your own transformation function if none of
1975the existing ones meets your needs. This is done by setting a callback
1976with
1977
1978 png_set_read_user_transform_fn(png_ptr,
1979 read_transform_fn);
1980
1981You must supply the function
1982
1983 void read_transform_fn(png_ptr ptr, row_info_ptr
1984 row_info, png_bytep data)
1985
1986See pngtest.c for a working example. Your function will be called
1987after all of the other transformations have been processed.
1988
1989You can also set up a pointer to a user structure for use by your
1990callback function, and you can inform libpng that your transform
1991function will change the number of channels or bit depth with the
1992function
1993
1994 png_set_user_transform_info(png_ptr, user_ptr,
1995 user_depth, user_channels);
1996
1997The user's application, not libpng, is responsible for allocating and
1998freeing any memory required for the user structure.
1999
2000You can retrieve the pointer via the function
2001png_get_user_transform_ptr(). For example:
2002
2003 voidp read_user_transform_ptr =
2004 png_get_user_transform_ptr(png_ptr);
2005
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002006The last thing to handle is interlacing; this is covered in detail below,
2007but you must call the function here if you want libpng to handle expansion
2008of the interlaced image.
2009
2010 number_of_passes = png_set_interlace_handling(png_ptr);
2011
2012After setting the transformations, libpng can update your png_info
2013structure to reflect any transformations you've requested with this
2014call. This is most useful to update the info structure's rowbytes
2015field so you can use it to allocate your image memory. This function
2016will also update your palette with the correct screen_gamma and
2017background if these have been given with the calls above.
2018
2019 png_read_update_info(png_ptr, info_ptr);
2020
2021After you call png_read_update_info(), you can allocate any
2022memory you need to hold the image. The row data is simply
2023raw byte data for all forms of images. As the actual allocation
2024varies among applications, no example will be given. If you
2025are allocating one large chunk, you will need to build an
2026array of pointers to each row, as it will be needed for some
2027of the functions below.
2028
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002029.SS Reading image data
2030
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002031After you've allocated memory, you can read the image data.
2032The simplest way to do this is in one function call. If you are
2033allocating enough memory to hold the whole image, you can just
2034call png_read_image() and libpng will read in all the image data
2035and put it in the memory area supplied. You will need to pass in
2036an array of pointers to each row.
2037
2038This function automatically handles interlacing, so you don't need
2039to call png_set_interlace_handling() or call this function multiple
2040times, or any of that other stuff necessary with png_read_rows().
2041
2042 png_read_image(png_ptr, row_pointers);
2043
2044where row_pointers is:
2045
2046 png_bytep row_pointers[height];
2047
2048You can point to void or char or whatever you use for pixels.
2049
2050If you don't want to read in the whole image at once, you can
2051use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002052interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002053
2054 png_read_rows(png_ptr, row_pointers, NULL,
2055 number_of_rows);
2056
2057where row_pointers is the same as in the png_read_image() call.
2058
2059If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002060a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002061
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002062 png_bytep row_pointer = row;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002063 png_read_row(png_ptr, row_pointer, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002064
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002065If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2066get somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002067interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002068is a somewhat complicated 2D interlace scheme, known as Adam7, that
2069breaks down an image into seven smaller images of varying size, based
2070on an 8x8 grid.
2071
2072libpng can fill out those images or it can give them to you "as is".
2073If you want them filled out, there are two ways to do that. The one
2074mentioned in the PNG specification is to expand each pixel to cover
2075those pixels that have not been read yet (the "rectangle" method).
2076This results in a blocky image for the first pass, which gradually
2077smooths out as more pixels are read. The other method is the "sparkle"
2078method, where pixels are drawn only in their final locations, with the
2079rest of the image remaining whatever colors they were initialized to
2080before the start of the read. The first method usually looks better,
2081but tends to be slower, as there are more pixels to put in the rows.
2082
2083If you don't want libpng to handle the interlacing details, just call
2084png_read_rows() seven times to read in all seven images. Each of the
2085images is a valid image by itself, or they can all be combined on an
20868x8 grid to form a single image (although if you intend to combine them
2087you would be far better off using the libpng interlace handling).
2088
2089The first pass will return an image 1/8 as wide as the entire image
2090(every 8th column starting in column 0) and 1/8 as high as the original
2091(every 8th row starting in row 0), the second will be 1/8 as wide
2092(starting in column 4) and 1/8 as high (also starting in row 0). The
2093third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
20941/8 as high (every 8th row starting in row 4), and the fourth pass will
2095be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
2096and every 4th row starting in row 0). The fifth pass will return an
2097image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
2098while the sixth pass will be 1/2 as wide and 1/2 as high as the original
2099(starting in column 1 and row 0). The seventh and final pass will be as
2100wide as the original, and 1/2 as high, containing all of the odd
2101numbered scanlines. Phew!
2102
2103If you want libpng to expand the images, call this before calling
2104png_start_read_image() or png_read_update_info():
2105
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002106 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002107 number_of_passes
2108 = png_set_interlace_handling(png_ptr);
2109
2110This will return the number of passes needed. Currently, this
2111is seven, but may change if another interlace type is added.
2112This function can be called even if the file is not interlaced,
2113where it will return one pass.
2114
2115If you are not going to display the image after each pass, but are
2116going to wait until the entire image is read in, use the sparkle
2117effect. This effect is faster and the end result of either method
2118is exactly the same. If you are planning on displaying the image
2119after each pass, the "rectangle" effect is generally considered the
2120better looking one.
2121
2122If you only want the "sparkle" effect, just call png_read_rows() as
2123normal, with the third parameter NULL. Make sure you make pass over
2124the image number_of_passes times, and you don't change the data in the
2125rows between calls. You can change the locations of the data, just
2126not the data. Each pass only writes the pixels appropriate for that
2127pass, and assumes the data from previous passes is still valid.
2128
2129 png_read_rows(png_ptr, row_pointers, NULL,
2130 number_of_rows);
2131
2132If you only want the first effect (the rectangles), do the same as
2133before except pass the row buffer in the third parameter, and leave
2134the second parameter NULL.
2135
2136 png_read_rows(png_ptr, NULL, row_pointers,
2137 number_of_rows);
2138
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002139.SS Finishing a sequential read
2140
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06002141After you are finished reading the image through the
2142low-level interface, you can finish reading the file. If you are
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002143interested in comments or time, which may be stored either before or
2144after the image data, you should pass the separate png_info struct if
2145you want to keep the comments from before and after the image
2146separate. If you are not interested, you can pass NULL.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002147
2148 png_read_end(png_ptr, end_info);
2149
2150When you are done, you can free all memory allocated by libpng like this:
2151
2152 png_destroy_read_struct(&png_ptr, &info_ptr,
2153 &end_info);
2154
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002155It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002156point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002157
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002158 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002159 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002160 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002161 more of
2162 PNG_FREE_PLTE, PNG_FREE_TRNS,
2163 PNG_FREE_HIST, PNG_FREE_ICCP,
2164 PNG_FREE_PCAL, PNG_FREE_ROWS,
2165 PNG_FREE_SCAL, PNG_FREE_SPLT,
2166 PNG_FREE_TEXT, PNG_FREE_UNKN,
2167 or simply PNG_FREE_ALL
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002168 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002169 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002170
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002171This function may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002172already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002173by the user and not by libpng, and will in those cases do nothing.
2174The "seq" parameter is ignored if only one item of the selected data
2175type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
2176are allowed for the data type identified in the mask, such as text or
2177sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002178
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002179The default behavior is only to free data that was allocated internally
2180by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002181or so that it will free data that was allocated by the user with png_malloc()
2182or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002183
2184 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002185 mask - which data elements are affected
2186 same choices as in png_free_data()
2187 freer - one of
2188 PNG_DESTROY_WILL_FREE_DATA
2189 PNG_SET_WILL_FREE_DATA
2190 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002191
2192This function only affects data that has already been allocated.
2193You can call this function after reading the PNG data but before calling
2194any png_set_*() functions, to control whether the user or the png_set_*()
2195function is responsible for freeing any existing data that might be present,
2196and again after the png_set_*() functions to control whether the user
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002197or png_destroy_*() is supposed to free the data. When the user assumes
2198responsibility for libpng-allocated data, the application must use
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002199png_free() to free it, and when the user transfers responsibility to libpng
2200for data that the user has allocated, the user must have used png_malloc()
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05002201or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002202
2203If you allocated your row_pointers in a single block, as suggested above in
2204the description of the high level read interface, you must not transfer
2205responsibility for freeing it to the png_set_rows or png_read_destroy function,
2206because they would also try to free the individual row_pointers[i].
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002207
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002208If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2209separately, do not transfer responsibility for freeing text_ptr to libpng,
2210because when libpng fills a png_text structure it combines these members with
2211the key member, and png_free_data() will free only text_ptr.key. Similarly,
2212if you transfer responsibility for free'ing text_ptr from libpng to your
2213application, your application must not separately free those members.
2214
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002215The png_free_data() function will turn off the "valid" flag for anything
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002216it frees. If you need to turn the flag off for a chunk that was freed by
2217your application instead of by libpng, you can use
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002218
2219 png_set_invalid(png_ptr, info_ptr, mask);
2220 mask - identifies the chunks to be made invalid,
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002221 containing the bitwise OR of one or
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06002222 more of
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05002223 PNG_INFO_gAMA, PNG_INFO_sBIT,
2224 PNG_INFO_cHRM, PNG_INFO_PLTE,
2225 PNG_INFO_tRNS, PNG_INFO_bKGD,
2226 PNG_INFO_hIST, PNG_INFO_pHYs,
2227 PNG_INFO_oFFs, PNG_INFO_tIME,
2228 PNG_INFO_pCAL, PNG_INFO_sRGB,
2229 PNG_INFO_iCCP, PNG_INFO_sPLT,
2230 PNG_INFO_sCAL, PNG_INFO_IDAT
2231
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002232For a more compact example of reading a PNG image, see the file example.c.
2233
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002234.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002235
2236The progressive reader is slightly different then the non-progressive
2237reader. Instead of calling png_read_info(), png_read_rows(), and
2238png_read_end(), you make one call to png_process_data(), which calls
2239callbacks when it has the info, a row, or the end of the image. You
2240set up these callbacks with png_set_progressive_read_fn(). You don't
2241have to worry about the input/output functions of libpng, as you are
2242giving the library the data directly in png_process_data(). I will
2243assume that you have read the section on reading PNG files above,
2244so I will only highlight the differences (although I will show
2245all of the code).
2246
2247png_structp png_ptr;
2248png_infop info_ptr;
2249
2250 /* An example code fragment of how you would
2251 initialize the progressive reader in your
2252 application. */
2253 int
2254 initialize_png_reader()
2255 {
2256 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002257 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002258 user_error_fn, user_warning_fn);
2259 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002260 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002261 info_ptr = png_create_info_struct(png_ptr);
2262 if (!info_ptr)
2263 {
2264 png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
2265 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002266 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002267 }
2268
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002269 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002270 {
2271 png_destroy_read_struct(&png_ptr, &info_ptr,
2272 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002273 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002274 }
2275
2276 /* This one's new. You can provide functions
2277 to be called when the header info is valid,
2278 when each row is completed, and when the image
2279 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002280 you can specify NULL parameters. Even when all
2281 three functions are NULL, you need to call
2282 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002283 any struct as the user_ptr (cast to a void pointer
2284 for the function call), and retrieve the pointer
2285 from inside the callbacks using the function
2286
2287 png_get_progressive_ptr(png_ptr);
2288
2289 which will return a void pointer, which you have
2290 to cast appropriately.
2291 */
2292 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
2293 info_callback, row_callback, end_callback);
2294
2295 return 0;
2296 }
2297
2298 /* A code fragment that you call as you receive blocks
2299 of data */
2300 int
2301 process_data(png_bytep buffer, png_uint_32 length)
2302 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002303 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002304 {
2305 png_destroy_read_struct(&png_ptr, &info_ptr,
2306 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002307 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002308 }
2309
2310 /* This one's new also. Simply give it a chunk
2311 of data from the file stream (in order, of
2312 course). On machines with segmented memory
2313 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002314 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002315 of 4K. Although you can give it much less if
2316 necessary (I assume you can give it chunks of
2317 1 byte, I haven't tried less then 256 bytes
2318 yet). When this function returns, you may
2319 want to display any rows that were generated
2320 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002321 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002322 */
2323 png_process_data(png_ptr, info_ptr, buffer, length);
2324 return 0;
2325 }
2326
2327 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002328 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002329 has been supplied so all of the header has been
2330 read.
2331 */
2332 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002333 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002334 {
2335 /* Do any setup here, including setting any of
2336 the transformations mentioned in the Reading
2337 PNG files section. For now, you _must_ call
2338 either png_start_read_image() or
2339 png_read_update_info() after all the
2340 transformations are set (even if you don't set
2341 any). You may start getting rows before
2342 png_process_data() returns, so this is your
2343 last chance to prepare for that.
2344 */
2345 }
2346
2347 /* This function is called when each row of image
2348 data is complete */
2349 void
2350 row_callback(png_structp png_ptr, png_bytep new_row,
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05002351 png_uint_32 row_num, int pass)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002352 {
2353 /* If the image is interlaced, and you turned
2354 on the interlace handler, this function will
2355 be called for every row in every pass. Some
2356 of these rows will not be changed from the
2357 previous pass. When the row is not changed,
2358 the new_row variable will be NULL. The rows
2359 and passes are called in order, so you don't
2360 really need the row_num and pass, but I'm
2361 supplying them because it may make your life
2362 easier.
2363
2364 For the non-NULL rows of interlaced images,
2365 you must call png_progressive_combine_row()
2366 passing in the row and the old row. You can
2367 call this function for NULL rows (it will just
2368 return) and for non-interlaced images (it just
2369 does the memcpy for you) if it will make the
2370 code easier. Thus, you can just do this for
2371 all cases:
2372 */
2373
2374 png_progressive_combine_row(png_ptr, old_row,
2375 new_row);
2376
2377 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05002378 previously for the row. Note that the first
2379 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002380 the old row, so the rows do not have to be
2381 initialized. After the first pass (and only
2382 for interlaced images), you will have to pass
2383 the current row, and the function will combine
2384 the old row and the new row.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002385 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002386 }
2387
2388 void
2389 end_callback(png_structp png_ptr, png_infop info)
2390 {
2391 /* This function is called after the whole image
2392 has been read, including any chunks after the
2393 image (up to and including the IEND). You
2394 will usually have the same info chunk as you
2395 had in the header, although some data may have
2396 been added to the comments and time fields.
2397
2398 Most people won't do much here, perhaps setting
2399 a flag that marks the image as finished.
2400 */
2401 }
2402
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002403
2404
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002405.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002406
2407Much of this is very similar to reading. However, everything of
2408importance is repeated here, so you won't have to constantly look
2409back up in the reading section to understand writing.
2410
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002411.SS Setup
2412
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002413You will want to do the I/O initialization before you get into libpng,
2414so if it doesn't work, you don't have anything to undo. If you are not
2415using the standard I/O functions, you will need to replace them with
2416custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002417
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002418 FILE *fp = fopen(file_name, "wb");
2419 if (!fp)
2420 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002421 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002422 }
2423
2424Next, png_struct and png_info need to be allocated and initialized.
2425As these can be both relatively large, you may not want to store these
2426on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002427will want to check if they return NULL. If you are also reading,
2428you won't want to name your read structure and your write structure
2429both "png_ptr"; you can call them anything you like, such as
2430"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002431
2432 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002433 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002434 user_error_fn, user_warning_fn);
2435 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002436 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002437
2438 png_infop info_ptr = png_create_info_struct(png_ptr);
2439 if (!info_ptr)
2440 {
2441 png_destroy_write_struct(&png_ptr,
2442 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002443 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002444 }
2445
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002446If you want to use your own memory allocation routines,
2447define PNG_USER_MEM_SUPPORTED and use
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002448png_create_write_struct_2() instead of png_create_write_struct():
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05002449
2450 png_structp png_ptr = png_create_write_struct_2
2451 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2452 user_error_fn, user_warning_fn, (png_voidp)
2453 user_mem_ptr, user_malloc_fn, user_free_fn);
2454
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002455After you have these structures, you will need to set up the
2456error handling. When libpng encounters an error, it expects to
2457longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002458setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002459write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002460the png_jmpbuf(png_ptr) every time you enter a new routine that will
2461call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002462for your compiler for more information on setjmp/longjmp. See
2463the discussion on libpng error handling in the Customizing Libpng
2464section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002465
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002466 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002467 {
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05002468 png_destroy_write_struct(&png_ptr, &info_ptr);
2469 fclose(fp);
2470 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002471 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002472 ...
2473 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002474
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002475If you would rather avoid the complexity of setjmp/longjmp issues,
2476you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
2477errors will result in a call to PNG_ABORT() which defaults to abort().
2478
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002479Now you need to set up the output code. The default for libpng is to
2480use the C function fwrite(). If you use this, you will need to pass a
2481valid FILE * in the function png_init_io(). Be sure that the file is
2482opened in binary mode. Again, if you wish to handle writing data in
2483another way, see the discussion on libpng I/O handling in the Customizing
2484Libpng section below.
2485
2486 png_init_io(png_ptr, fp);
2487
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05002488If you are embedding your PNG into a datastream such as MNG, and don't
2489want libpng to write the 8-byte signature, or if you have already
2490written the signature in your application, use
2491
2492 png_set_sig_bytes(png_ptr, 8);
2493
2494to inform libpng that it should not write a signature.
2495
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002496.SS Write callbacks
2497
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002498At this point, you can set up a callback function that will be
2499called after each row has been written, which you can use to control
2500a progress meter or the like. It's demonstrated in pngtest.c.
2501You must supply a function
2502
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002503 void write_row_callback(png_ptr, png_uint_32 row,
2504 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06002505 {
2506 /* put your code here */
2507 }
2508
2509(You can give it another name that you like instead of "write_row_callback")
2510
2511To inform libpng about your function, use
2512
2513 png_set_write_status_fn(png_ptr, write_row_callback);
2514
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002515You now have the option of modifying how the compression library will
2516run. The following functions are mainly for testing, but may be useful
2517in some cases, like if you need to write PNG files extremely fast and
2518are willing to give up some compression, or if you want to get the
2519maximum possible compression at the expense of slower writing. If you
2520have no special needs in this area, let the library do what it wants by
2521not calling this function at all, as it has been tuned to deliver a good
2522speed/compression ratio. The second parameter to png_set_filter() is
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002523the filter method, for which the only valid values are 0 (as of the
2524July 1999 PNG specification, version 1.2) or 64 (if you are writing
2525a PNG datastream that is to be embedded in a MNG datastream). The third
2526parameter is a flag that indicates which filter type(s) are to be tested
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002527for each scanline. See the PNG specification for details on the specific
2528filter types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002529
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002530
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002531 /* turn on or off filtering, and/or choose
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002532 specific filters. You can use either a single
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002533 PNG_FILTER_VALUE_NAME or the bitwise OR of one
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002534 or more PNG_FILTER_NAME masks. */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002535 png_set_filter(png_ptr, 0,
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002536 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
2537 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
2538 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05002539 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002540 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
2541 PNG_ALL_FILTERS);
2542
2543If an application
2544wants to start and stop using particular filters during compression,
2545it should start out with all of the filters (to ensure that the previous
2546row of pixels will be stored in case it's needed later), and then add
2547and remove them after the start of compression.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002548
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002549If you are writing a PNG datastream that is to be embedded in a MNG
2550datastream, the second parameter can be either 0 or 64.
2551
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002552The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002553library, and should mostly be ignored unless you really know what you are
2554doing. The only generally useful call is png_set_compression_level()
2555which changes how much time zlib spends on trying to compress the image
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002556data. See the Compression Library (zlib.h and algorithm.txt, distributed
2557with zlib) for details on the compression levels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002558
2559 /* set the zlib compression level */
2560 png_set_compression_level(png_ptr,
2561 Z_BEST_COMPRESSION);
2562
2563 /* set other zlib parameters */
2564 png_set_compression_mem_level(png_ptr, 8);
2565 png_set_compression_strategy(png_ptr,
2566 Z_DEFAULT_STRATEGY);
2567 png_set_compression_window_bits(png_ptr, 15);
2568 png_set_compression_method(png_ptr, 8);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002569 png_set_compression_buffer_size(png_ptr, 8192)
2570
2571extern PNG_EXPORT(void,png_set_zbuf_size)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002572
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002573.SS Setting the contents of info for output
2574
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002575You now need to fill in the png_info structure with all the data you
2576wish to write before the actual image. Note that the only thing you
2577are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002578chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002579the latest PNG specification for more information on that. If you
2580wish to write them before the image, fill them in now, and flag that
2581data as being valid. If you want to wait until after the data, don't
2582fill them until png_write_end(). For all the fields in png_info and
2583their data types, see png.h. For explanations of what the fields
2584contain, see the PNG specification.
2585
2586Some of the more important parts of the png_info are:
2587
2588 png_set_IHDR(png_ptr, info_ptr, width, height,
2589 bit_depth, color_type, interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002590 compression_type, filter_method)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002591 width - holds the width of the image
2592 in pixels (up to 2^31).
2593 height - holds the height of the image
2594 in pixels (up to 2^31).
2595 bit_depth - holds the bit depth of one of the
2596 image channels.
2597 (valid values are 1, 2, 4, 8, 16
2598 and depend also on the
2599 color_type. See also significant
2600 bits (sBIT) below).
2601 color_type - describes which color/alpha
2602 channels are present.
2603 PNG_COLOR_TYPE_GRAY
2604 (bit depths 1, 2, 4, 8, 16)
2605 PNG_COLOR_TYPE_GRAY_ALPHA
2606 (bit depths 8, 16)
2607 PNG_COLOR_TYPE_PALETTE
2608 (bit depths 1, 2, 4, 8)
2609 PNG_COLOR_TYPE_RGB
2610 (bit_depths 8, 16)
2611 PNG_COLOR_TYPE_RGB_ALPHA
2612 (bit_depths 8, 16)
2613
2614 PNG_COLOR_MASK_PALETTE
2615 PNG_COLOR_MASK_COLOR
2616 PNG_COLOR_MASK_ALPHA
2617
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002618 interlace_type - PNG_INTERLACE_NONE or
2619 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002620 compression_type - (must be
2621 PNG_COMPRESSION_TYPE_DEFAULT)
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002622 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
2623 or, if you are writing a PNG to
2624 be embedded in a MNG datastream,
2625 can also be
2626 PNG_INTRAPIXEL_DIFFERENCING)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002627
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002628If you call png_set_IHDR(), the call must appear before any of the
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05002629other png_set_*() functions, because they might require access to some of
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002630the IHDR settings. The remaining png_set_*() functions can be called
2631in any order.
2632
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05002633If you wish, you can reset the compression_type, interlace_type, or
2634filter_method later by calling png_set_IHDR() again; if you do this, the
2635width, height, bit_depth, and color_type must be the same in each call.
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05002636
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002637 png_set_PLTE(png_ptr, info_ptr, palette,
2638 num_palette);
2639 palette - the palette for the file
2640 (array of png_color)
2641 num_palette - number of entries in the palette
2642
2643 png_set_gAMA(png_ptr, info_ptr, gamma);
2644 gamma - the gamma the image was created
2645 at (PNG_INFO_gAMA)
2646
2647 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2648 srgb_intent - the rendering intent
2649 (PNG_INFO_sRGB) The presence of
2650 the sRGB chunk means that the pixel
2651 data is in the sRGB color space.
2652 This chunk also implies specific
2653 values of gAMA and cHRM. Rendering
2654 intent is the CSS-1 property that
2655 has been defined by the International
2656 Color Consortium
2657 (http://www.color.org).
2658 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002659 PNG_sRGB_INTENT_SATURATION,
2660 PNG_sRGB_INTENT_PERCEPTUAL,
2661 PNG_sRGB_INTENT_ABSOLUTE, or
2662 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002663
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002664
2665 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2666 srgb_intent);
2667 srgb_intent - the rendering intent
2668 (PNG_INFO_sRGB) The presence of the
2669 sRGB chunk means that the pixel
2670 data is in the sRGB color space.
2671 This function also causes gAMA and
2672 cHRM chunks with the specific values
2673 that are consistent with sRGB to be
2674 written.
2675
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002676 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2677 profile, proflen);
2678 name - The profile name.
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002679 compression - The compression type; always
2680 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2681 You may give NULL to this argument to
2682 ignore it.
2683 profile - International Color Consortium color
2684 profile data. May contain NULs.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002685 proflen - length of profile data in bytes.
2686
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002687 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2688 sig_bit - the number of significant bits for
2689 (PNG_INFO_sBIT) each of the gray, red,
2690 green, and blue channels, whichever are
2691 appropriate for the given color type
2692 (png_color_16)
2693
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002694 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
2695 num_trans, trans_color);
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002696 trans_alpha - array of alpha (transparency)
2697 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05002698 trans_color - graylevel or color sample values
2699 (in order red, green, blue) of the
2700 single transparent color for
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05002701 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002702 num_trans - number of transparent entries
2703 (PNG_INFO_tRNS)
2704
2705 png_set_hIST(png_ptr, info_ptr, hist);
2706 (PNG_INFO_hIST)
2707 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002708 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002709
2710 png_set_tIME(png_ptr, info_ptr, mod_time);
2711 mod_time - time image was last modified
2712 (PNG_VALID_tIME)
2713
2714 png_set_bKGD(png_ptr, info_ptr, background);
2715 background - background color (PNG_VALID_bKGD)
2716
2717 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2718 text_ptr - array of png_text holding image
2719 comments
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002720 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002721 on "text" PNG_TEXT_COMPRESSION_NONE
2722 PNG_TEXT_COMPRESSION_zTXt
2723 PNG_ITXT_COMPRESSION_NONE
2724 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002725 text_ptr[i].key - keyword for comment. Must contain
2726 1-79 characters.
2727 text_ptr[i].text - text comments for current
2728 keyword. Can be NULL or empty.
2729 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002730 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002731 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002732 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002733 text_ptr[i].lang - language of comment (NULL or
2734 empty for unknown).
2735 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
2736 or empty for unknown).
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002737 Note that the itxt_length, lang, and lang_key
2738 members of the text_ptr structure only exist
2739 when the library is built with iTXt chunk support.
2740
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002741 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002742
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002743 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
2744 num_spalettes);
2745 palette_ptr - array of png_sPLT_struct structures
2746 to be added to the list of palettes
2747 in the info structure.
2748 num_spalettes - number of palette structures to be
2749 added.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002750
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002751 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2752 unit_type);
2753 offset_x - positive offset from the left
2754 edge of the screen
2755 offset_y - positive offset from the top
2756 edge of the screen
2757 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2758
2759 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2760 unit_type);
2761 res_x - pixels/unit physical resolution
2762 in x direction
2763 res_y - pixels/unit physical resolution
2764 in y direction
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002765 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002766 PNG_RESOLUTION_METER
2767
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002768 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002769 unit - physical scale units (an integer)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002770 width - width of a pixel in physical scale units
2771 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002772 (width and height are doubles)
2773
2774 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
2775 unit - physical scale units (an integer)
2776 width - width of a pixel in physical scale units
2777 height - height of a pixel in physical scale units
2778 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002779
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002780 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
2781 num_unknowns)
2782 unknowns - array of png_unknown_chunk
2783 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002784 unknowns[i].name - name of unknown chunk
2785 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002786 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002787 unknowns[i].location - position to write chunk in file
2788 0: do not write chunk
2789 PNG_HAVE_IHDR: before PLTE
2790 PNG_HAVE_PLTE: before IDAT
2791 PNG_AFTER_IDAT: after IDAT
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002792
2793The "location" member is set automatically according to
2794what part of the output file has already been written.
2795You can change its value after calling png_set_unknown_chunks()
2796as demonstrated in pngtest.c. Within each of the "locations",
2797the chunks are sequenced according to their position in the
2798structure (that is, the value of "i", which is the order in which
2799the chunk was either read from the input file or defined with
2800png_set_unknown_chunks).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002801
2802A quick word about text and num_text. text is an array of png_text
2803structures. num_text is the number of valid structures in the array.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002804Each png_text structure holds a language code, a keyword, a text value,
2805and a compression type.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002806
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002807The compression types have the same valid numbers as the compression
2808types of the image data. Currently, the only valid number is zero.
2809However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002810images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002811text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002812Because tEXt and zTXt chunks don't have a language field, if you
2813specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
2814any language code or translated keyword will not be written out.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002815
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002816Until text gets around 1000 bytes, it is not worth compressing it.
2817After the text has been written out to the file, the compression type
2818is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2819so that it isn't written out again at the end (in case you are calling
2820png_write_end() with the same struct.
2821
2822The keywords that are given in the PNG Specification are:
2823
2824 Title Short (one line) title or
2825 caption for image
2826 Author Name of image's creator
2827 Description Description of image (possibly long)
2828 Copyright Copyright notice
2829 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002830 (usually RFC 1123 format, see below)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002831 Software Software used to create the image
2832 Disclaimer Legal disclaimer
2833 Warning Warning of nature of content
2834 Source Device used to create the image
2835 Comment Miscellaneous comment; conversion
2836 from other image format
2837
2838The keyword-text pairs work like this. Keywords should be short
2839simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002840keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002841on keywords. You can repeat keywords in a file. You can even write
2842some text before the image and some after. For example, you may want
2843to put a description of the image before the image, but leave the
2844disclaimer until after, so viewers working over modem connections
2845don't have to wait for the disclaimer to go over the modem before
2846they start seeing the image. Finally, keywords should be full
2847words, not abbreviations. Keywords and text are in the ISO 8859-1
2848(Latin-1) character set (a superset of regular ASCII) and can not
2849contain NUL characters, and should not contain control or other
2850unprintable characters. To make the comments widely readable, stick
2851with basic ASCII, and avoid machine specific character set extensions
2852like the IBM-PC character set. The keyword must be present, but
2853you can leave off the text string on non-compressed pairs.
2854Compressed pairs must have a text string, as only the text string
2855is compressed anyway, so the compression would be meaningless.
2856
2857PNG supports modification time via the png_time structure. Two
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002858conversion routines are provided, png_convert_from_time_t() for
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002859time_t and png_convert_from_struct_tm() for struct tm. The
2860time_t routine uses gmtime(). You don't have to use either of
2861these, but if you wish to fill in the png_time structure directly,
2862you should provide the time in universal time (GMT) if possible
2863instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002864year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002865that months start with 1.
2866
2867If you want to store the time of the original image creation, you should
2868use a plain tEXt chunk with the "Creation Time" keyword. This is
2869necessary because the "creation time" of a PNG image is somewhat vague,
2870depending on whether you mean the PNG file, the time the image was
2871created in a non-PNG format, a still photo from which the image was
2872scanned, or possibly the subject matter itself. In order to facilitate
2873machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002874tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002875although this isn't a requirement. Unlike the tIME chunk, the
2876"Creation Time" tEXt chunk is not expected to be automatically changed
2877by the software. To facilitate the use of RFC 1123 dates, a function
2878png_convert_to_rfc1123(png_timep) is provided to convert from PNG
2879time to an RFC 1123 format string.
2880
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002881.SS Writing unknown chunks
2882
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002883You can use the png_set_unknown_chunks function to queue up chunks
2884for writing. You give it a chunk name, raw data, and a size; that's
2885all there is to it. The chunks will be written by the next following
2886png_write_info_before_PLTE, png_write_info, or png_write_end function.
2887Any chunks previously read into the info structure's unknown-chunk
2888list will also be written out in a sequence that satisfies the PNG
2889specification's ordering rules.
2890
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002891.SS The high-level write interface
2892
2893At this point there are two ways to proceed; through the high-level
2894write interface, or through a sequence of low-level write operations.
2895You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05002896in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002897transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002898
2899 PNG_TRANSFORM_IDENTITY No transformation
2900 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002901 PNG_TRANSFORM_PACKSWAP Change order of packed
2902 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002903 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002904 PNG_TRANSFORM_SHIFT Normalize pixels to the
2905 sBIT depth
2906 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
2907 to BGRA
2908 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
2909 to AG
2910 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
2911 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002912 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson1eb14e92008-12-10 07:14:45 -06002913 PNG_TRANSFORM_STRIP_FILLER Strip out filler
2914 bytes (deprecated).
2915 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
2916 filler bytes
2917 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
2918 filler bytes
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002919
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002920If you have valid image data in the info structure (you can use
2921png_set_rows() to put image data in the info structure), simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002922
2923 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
2924
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05002925where png_transforms is an integer containing the bitwise OR of some set of
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002926transformation flags. This call is equivalent to png_write_info(),
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002927followed the set of transformations indicated by the transform mask,
2928then png_write_image(), and finally png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002929
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002930(The final parameter of this call is not yet used. Someday it might point
2931to transformation parameters required by some future output transform.)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002932
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05002933You must use png_transforms and not call any png_set_transform() functions
2934when you use png_write_png().
2935
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002936.SS The low-level write interface
2937
2938If you are going the low-level route instead, you are now ready to
2939write all the file information up to the actual image data. You do
2940this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002941
2942 png_write_info(png_ptr, info_ptr);
2943
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002944Note that there is one transformation you may need to do before
2945png_write_info(). In PNG files, the alpha channel in an image is the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002946level of opacity. If your data is supplied as a level of transparency,
2947you can invert the alpha channel before you write it, so that 0 is
2948fully transparent and 255 (in 8-bit or paletted images) or 65535
2949(in 16-bit images) is fully opaque, with
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002950
2951 png_set_invert_alpha(png_ptr);
2952
2953This must appear before png_write_info() instead of later with the
2954other transformations because in the case of paletted images the tRNS
2955chunk data has to be inverted before the tRNS chunk is written. If
2956your image is not a paletted image, the tRNS data (which in such cases
2957represents a single color to be rendered as transparent) won't need to
2958be changed, and you can safely do this transformation after your
2959png_write_info() call.
2960
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002961If you need to write a private chunk that you want to appear before
2962the PLTE chunk when PLTE is present, you can write the PNG info in
2963two steps, and insert code to write your own chunk between them:
2964
2965 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002966 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06002967 png_write_info(png_ptr, info_ptr);
2968
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002969After you've written the file information, you can set up the library
2970to handle any special transformations of the image data. The various
2971ways to transform the data will be described in the order that they
2972should occur. This is important, as some of these change the color
2973type and/or bit depth of the data, and some others only work on
2974certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002975checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002976make sure to only enable a transformation if it will be valid for the
2977data. For example, don't swap red and blue on grayscale data.
2978
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002979PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06002980the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002981to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
2982bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002983
2984 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
2985
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002986where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002987PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
2988is stored XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002989
2990PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2991they can, resulting in, for example, 8 pixels per byte for 1 bit files.
2992If the data is supplied at 1 pixel per byte, use this code, which will
2993correctly pack the pixels into a single byte:
2994
2995 png_set_packing(png_ptr);
2996
2997PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
2998data is of another bit depth, you can write an sBIT chunk into the
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002999file so that decoders can recover the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003000
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003001 /* Set the true bit depth of the image data */
3002 if (color_type & PNG_COLOR_MASK_COLOR)
3003 {
3004 sig_bit.red = true_bit_depth;
3005 sig_bit.green = true_bit_depth;
3006 sig_bit.blue = true_bit_depth;
3007 }
3008 else
3009 {
3010 sig_bit.gray = true_bit_depth;
3011 }
3012 if (color_type & PNG_COLOR_MASK_ALPHA)
3013 {
3014 sig_bit.alpha = true_bit_depth;
3015 }
3016
3017 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
3018
3019If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003020one 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 -06003021this will scale the values to appear to be the correct bit depth as
3022is required by PNG.
3023
3024 png_set_shift(png_ptr, &sig_bit);
3025
3026PNG files store 16 bit pixels in network byte order (big-endian,
3027ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003028supplied the other way (little-endian, i.e. least significant bits
3029first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003030
3031 if (bit_depth > 8)
3032 png_set_swap(png_ptr);
3033
3034If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
3035need to change the order the pixels are packed into bytes, you can use:
3036
3037 if (bit_depth < 8)
3038 png_set_packswap(png_ptr);
3039
3040PNG files store 3 color pixels in red, green, blue order. This code
3041would be used if they are supplied as blue, green, red:
3042
3043 png_set_bgr(png_ptr);
3044
3045PNG files describe monochrome as black being zero and white being
3046one. This code would be used if the pixels are supplied with this reversed
3047(black being one and white being zero):
3048
3049 png_set_invert_mono(png_ptr);
3050
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003051Finally, you can write your own transformation function if none of
3052the existing ones meets your needs. This is done by setting a callback
3053with
3054
3055 png_set_write_user_transform_fn(png_ptr,
3056 write_transform_fn);
3057
3058You must supply the function
3059
3060 void write_transform_fn(png_ptr ptr, row_info_ptr
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003061 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003062
3063See pngtest.c for a working example. Your function will be called
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003064before any of the other transformations are processed.
3065
3066You can also set up a pointer to a user structure for use by your
3067callback function.
3068
3069 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
3070
3071The user_channels and user_depth parameters of this function are ignored
3072when writing; you can set them to zero as shown.
3073
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003074You can retrieve the pointer via the function png_get_user_transform_ptr().
3075For example:
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003076
3077 voidp write_user_transform_ptr =
3078 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003079
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003080It is possible to have libpng flush any pending output, either manually,
3081or automatically after a certain number of lines have been written. To
3082flush the output stream a single time call:
3083
3084 png_write_flush(png_ptr);
3085
3086and to have libpng flush the output stream periodically after a certain
3087number of scanlines have been written, call:
3088
3089 png_set_flush(png_ptr, nrows);
3090
3091Note that the distance between rows is from the last time png_write_flush()
3092was called, or the first row of the image if it has never been called.
3093So if you write 50 lines, and then png_set_flush 25, it will flush the
3094output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003095png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003096If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003097RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003098may be acceptable for real-time applications). Infrequent flushing will
3099only degrade the compression performance by a few percent over images
3100that do not use flushing.
3101
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003102.SS Writing the image data
3103
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003104That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003105The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003106whole image in memory, you can just call png_write_image() and libpng
3107will write the image. You will need to pass in an array of pointers to
3108each row. This function automatically handles interlacing, so you don't
3109need to call png_set_interlace_handling() or call this function multiple
3110times, or any of that other stuff necessary with png_write_rows().
3111
3112 png_write_image(png_ptr, row_pointers);
3113
3114where row_pointers is:
3115
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003116 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003117
3118You can point to void or char or whatever you use for pixels.
3119
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003120If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003121use png_write_rows() instead. If the file is not interlaced,
3122this is simple:
3123
3124 png_write_rows(png_ptr, row_pointers,
3125 number_of_rows);
3126
3127row_pointers is the same as in the png_write_image() call.
3128
3129If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003130a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003131
3132 png_bytep row_pointer = row;
3133
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003134 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003135
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003136When the file is interlaced, things can get a good deal more complicated.
3137The only currently (as of the PNG Specification version 1.2, dated July
31381999) defined interlacing scheme for PNG files is the "Adam7" interlace
3139scheme, that breaks down an image into seven smaller images of varying
3140size. libpng will build these images for you, or you can do them
3141yourself. If you want to build them yourself, see the PNG specification
3142for details of which pixels to write when.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003143
3144If you don't want libpng to handle the interlacing details, just
3145use png_set_interlace_handling() and call png_write_rows() the
3146correct number of times to write all seven sub-images.
3147
3148If you want libpng to build the sub-images, call this before you start
3149writing any rows:
3150
3151 number_of_passes =
3152 png_set_interlace_handling(png_ptr);
3153
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003154This will return the number of passes needed. Currently, this is seven,
3155but may change if another interlace type is added.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003156
3157Then write the complete image number_of_passes times.
3158
3159 png_write_rows(png_ptr, row_pointers,
3160 number_of_rows);
3161
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003162As some of these rows are not used, and thus return immediately, you may
3163want to read about interlacing in the PNG specification, and only update
3164the rows that are actually used.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003165
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003166.SS Finishing a sequential write
3167
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003168After you are finished writing the image, you should finish writing
3169the file. If you are interested in writing comments or time, you should
3170pass an appropriately filled png_info pointer. If you are not interested,
3171you can pass NULL.
3172
3173 png_write_end(png_ptr, info_ptr);
3174
3175When you are done, you can free all memory used by libpng like this:
3176
3177 png_destroy_write_struct(&png_ptr, &info_ptr);
3178
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003179It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003180point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003181
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003182 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003183 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003184 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003185 more of
3186 PNG_FREE_PLTE, PNG_FREE_TRNS,
3187 PNG_FREE_HIST, PNG_FREE_ICCP,
3188 PNG_FREE_PCAL, PNG_FREE_ROWS,
3189 PNG_FREE_SCAL, PNG_FREE_SPLT,
3190 PNG_FREE_TEXT, PNG_FREE_UNKN,
3191 or simply PNG_FREE_ALL
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003192 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003193 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003194
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003195This function may be safely called when the relevant storage has
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003196already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003197by the user and not by libpng, and will in those cases do nothing.
3198The "seq" parameter is ignored if only one item of the selected data
3199type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3200are allowed for the data type identified in the mask, such as text or
3201sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003202
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003203If you allocated data such as a palette that you passed in to libpng
3204with png_set_*, you must not free it until just before the call to
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003205png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003206
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003207The default behavior is only to free data that was allocated internally
3208by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003209or so that it will free data that was allocated by the user with png_malloc()
3210or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003211
3212 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003213 mask - which data elements are affected
3214 same choices as in png_free_data()
3215 freer - one of
3216 PNG_DESTROY_WILL_FREE_DATA
3217 PNG_SET_WILL_FREE_DATA
3218 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003219
3220For example, to transfer responsibility for some data from a read structure
3221to a write structure, you could use
3222
3223 png_data_freer(read_ptr, read_info_ptr,
3224 PNG_USER_WILL_FREE_DATA,
3225 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3226 png_data_freer(write_ptr, write_info_ptr,
3227 PNG_DESTROY_WILL_FREE_DATA,
3228 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3229
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003230thereby briefly reassigning responsibility for freeing to the user but
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003231immediately afterwards reassigning it once more to the write_destroy
3232function. Having done this, it would then be safe to destroy the read
3233structure and continue to use the PLTE, tRNS, and hIST data in the write
3234structure.
3235
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003236This function only affects data that has already been allocated.
3237You can call this function before calling after the png_set_*() functions
3238to control whether the user or png_destroy_*() is supposed to free the data.
3239When the user assumes responsibility for libpng-allocated data, the
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003240application must use
3241png_free() to free it, and when the user transfers responsibility to libpng
3242for data that the user has allocated, the user must have used png_malloc()
3243or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003244
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003245If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3246separately, do not transfer responsibility for freeing text_ptr to libpng,
3247because when libpng fills a png_text structure it combines these members with
3248the key member, and png_free_data() will free only text_ptr.key. Similarly,
3249if you transfer responsibility for free'ing text_ptr from libpng to your
3250application, your application must not separately free those members.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003251For a more compact example of writing a PNG image, see the file example.c.
3252
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003253.SH V. Modifying/Customizing libpng:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003254
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003255There are two issues here. The first is changing how libpng does
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003256standard things like memory allocation, input/output, and error handling.
3257The second deals with more complicated things like adding new chunks,
3258adding new transformations, and generally changing how libpng works.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003259Both of those are compile-time issues; that is, they are generally
3260determined at the time the code is written, and there is rarely a need
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003261to provide the user with a means of changing them.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003262
3263Memory allocation, input/output, and error handling
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003264
3265All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06003266goes through callbacks that are user-settable. The default routines are
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003267in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003268these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003269
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003270Memory allocation is done through the functions png_malloc(), png_calloc(),
3271and png_free(). These currently just call the standard C functions.
3272png_calloc() calls png_malloc() and then png_memset() to clear the newly
3273allocated memory to zero. If your pointers can't access more then 64K
3274at a time, you will want to set MAXSEG_64K in zlib.h. Since it is
3275unlikely that the method of handling memory allocation on a platform
3276will change between applications, these functions must be modified in
3277the library at compile time. If you prefer to use a different method
3278of allocating and freeing data, you can use png_create_read_struct_2() or
3279png_create_write_struct_2() to register your own functions as described
3280above. These functions also provide a void pointer that can be retrieved
3281via
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003282
3283 mem_ptr=png_get_mem_ptr(png_ptr);
3284
3285Your replacement memory functions must have prototypes as follows:
3286
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003287 png_voidp malloc_fn(png_structp png_ptr,
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06003288 png_alloc_size_t size);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003289 void free_fn(png_structp png_ptr, png_voidp ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003290
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05003291Your malloc_fn() must return NULL in case of failure. The png_malloc()
3292function will normally call png_error() if it receives a NULL from the
3293system memory allocator or from your replacement malloc_fn().
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05003294
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003295Your free_fn() will never be called with a NULL ptr, since libpng's
3296png_free() checks for NULL before calling free_fn().
3297
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003298Input/Output in libpng is done through png_read() and png_write(),
3299which currently just call fread() and fwrite(). The FILE * is stored in
3300png_struct and is initialized via png_init_io(). If you wish to change
3301the method of I/O, the library supplies callbacks that you can set
3302through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003303time, instead of calling the png_init_io() function. These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003304also provide a void pointer that can be retrieved via the function
3305png_get_io_ptr(). For example:
3306
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003307 png_set_read_fn(png_structp read_ptr,
3308 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003309
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003310 png_set_write_fn(png_structp write_ptr,
3311 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003312 png_flush_ptr output_flush_fn);
3313
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003314 voidp read_io_ptr = png_get_io_ptr(read_ptr);
3315 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003316
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003317The replacement I/O functions must have prototypes as follows:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003318
3319 void user_read_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05003320 png_bytep data, png_size_t length);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003321 void user_write_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05003322 png_bytep data, png_size_t length);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003323 void user_flush_data(png_structp png_ptr);
3324
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003325The user_read_data() function is responsible for detecting and
3326handling end-of-data errors.
3327
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003328Supplying NULL for the read, write, or flush functions sets them back
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003329to using the default C stream functions, which expect the io_ptr to
3330point to a standard *FILE structure. It is probably a mistake
3331to use NULL for one of write_data_fn and output_flush_fn but not both
3332of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
3333It is an error to read from a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003334
3335Error handling in libpng is done through png_error() and png_warning().
3336Errors handled through png_error() are fatal, meaning that png_error()
3337should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003338setjmp() and longjmp() (unless you have compiled libpng with
3339PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
3340but you could change this to do things like exit() if you should wish.
3341
3342On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003343to print a warning message, and then control returns to the calling code.
3344By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003345fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
3346(because you don't want the messages) or PNG_NO_STDIO defined (because
3347fprintf() isn't available). If you wish to change the behavior of the error
3348functions, you will need to set up your own message callbacks. These
3349functions are normally supplied at the time that the png_struct is created.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003350It is also possible to redirect errors and warnings to your own replacement
3351functions after png_create_*_struct() has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003352
3353 png_set_error_fn(png_structp png_ptr,
3354 png_voidp error_ptr, png_error_ptr error_fn,
3355 png_error_ptr warning_fn);
3356
3357 png_voidp error_ptr = png_get_error_ptr(png_ptr);
3358
3359If NULL is supplied for either error_fn or warning_fn, then the libpng
3360default function will be used, calling fprintf() and/or longjmp() if a
3361problem is encountered. The replacement error functions should have
3362parameters as follows:
3363
3364 void user_error_fn(png_structp png_ptr,
3365 png_const_charp error_msg);
3366 void user_warning_fn(png_structp png_ptr,
3367 png_const_charp warning_msg);
3368
3369The motivation behind using setjmp() and longjmp() is the C++ throw and
3370catch exception handling methods. This makes the code much easier to write,
3371as there is no need to check every return code of every function call.
3372However, there are some uncertainties about the status of local variables
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003373after a longjmp, so the user may want to be careful about doing anything
3374after setjmp returns non-zero besides returning itself. Consult your
3375compiler documentation for more details. For an alternative approach, you
3376may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003377
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003378.SS Custom chunks
3379
3380If you need to read or write custom chunks, you may need to get deeper
3381into the libpng code. The library now has mechanisms for storing
3382and writing chunks of unknown type; you can even declare callbacks
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003383for custom chunks. However, this may not be good enough if the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003384library code itself needs to know about interactions between your
3385chunk and existing `intrinsic' chunks.
3386
3387If you need to write a new intrinsic chunk, first read the PNG
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003388specification. Acquire a first level of understanding of how it works.
3389Pay particular attention to the sections that describe chunk names,
3390and look at how other chunks were designed, so you can do things
3391similarly. Second, check out the sections of libpng that read and
3392write chunks. Try to find a chunk that is similar to yours and use
3393it as a template. More details can be found in the comments inside
3394the code. It is best to handle unknown chunks in a generic method,
3395via callback functions, instead of by modifying libpng functions.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003396
3397If you wish to write your own transformation for the data, look through
3398the part of the code that does the transformations, and check out some of
3399the simpler ones to get an idea of how they work. Try to find a similar
3400transformation to the one you want to add and copy off of it. More details
3401can be found in the comments inside the code itself.
3402
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003403.SS Configuring for 16 bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003404
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003405You will want to look into zconf.h to tell zlib (and thus libpng) that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003406it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003407won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003408
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003409.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003410
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003411For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003412have to limit zlib's memory usage via a png_set_compression_mem_level()
3413call. See zlib.h or zconf.h in the zlib library for more information.
3414
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003415.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003416
3417Libpng's support for medium model has been tested on most of the popular
3418compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
3419defined, and FAR gets defined to far in pngconf.h, and you should be
3420all set. Everything in the library (except for zlib's structure) is
3421expecting far data. You must use the typedefs with the p or pp on
3422the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003423note that the rows of data are defined as png_bytepp, which is an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003424unsigned char far * far *.
3425
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003426.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003427
3428You will need to write new error and warning functions that use the GUI
3429interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003430warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003431in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003432They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003433you may also have to change the memory allocators (png_malloc, etc.).
3434
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003435.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003436
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05003437All includes for libpng are in pngconf.h. If you need to add, change
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003438or delete an include, this is the place to do it.
3439The includes that are not needed outside libpng are placed in pngpriv.h,
3440which is only used by the routines inside libpng itself.
3441The files in libpng proper only include pngpriv.h and png.h, which
3442in turn includes pngconf.h.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003443
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003444.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003445
3446There are special functions to configure the compression. Perhaps the
3447most useful one changes the compression level, which currently uses
3448input compression values in the range 0 - 9. The library normally
3449uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
3450have shown that for a large majority of images, compression values in
3451the range 3-6 compress nearly as well as higher levels, and do so much
3452faster. For online applications it may be desirable to have maximum speed
3453(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
3454specify no compression (Z_NO_COMPRESSION = 0), but this would create
3455files larger than just storing the raw bitmap. You can specify the
3456compression level by calling:
3457
3458 png_set_compression_level(png_ptr, level);
3459
3460Another useful one is to reduce the memory level used by the library.
3461The memory level defaults to 8, but it can be lowered if you are
3462short on memory (running DOS, for example, where you only have 640K).
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003463Note that the memory level does have an effect on compression; among
3464other things, lower levels will result in sections of incompressible
3465data being emitted in smaller stored blocks, with a correspondingly
3466larger relative overhead of up to 15% in the worst case.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003467
3468 png_set_compression_mem_level(png_ptr, level);
3469
3470The other functions are for configuring zlib. They are not recommended
3471for normal use and may result in writing an invalid PNG file. See
3472zlib.h for more information on what these mean.
3473
3474 png_set_compression_strategy(png_ptr,
3475 strategy);
3476 png_set_compression_window_bits(png_ptr,
3477 window_bits);
3478 png_set_compression_method(png_ptr, method);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003479 png_set_compression_buffer_size(png_ptr, size);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003480
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003481.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003482
3483If you want to control whether libpng uses filtering or not, which
3484filters are used, and how it goes about picking row filters, you
3485can call one of these functions. The selection and configuration
3486of row filters can have a significant impact on the size and
3487encoding speed and a somewhat lesser impact on the decoding speed
3488of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003489images (with and without alpha), but not for paletted images nor
3490for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003491
3492The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003493currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003494parameter sets which filter(s), if any, should be used for each
3495scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
3496to turn filtering on and off, respectively.
3497
3498Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3499PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003500ORed together with '|' to specify one or more filters to use.
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003501These filters are described in more detail in the PNG specification.
3502If you intend to change the filter type during the course of writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003503the image, you should start with flags set for all of the filters
3504you intend to use so that libpng can initialize its internal
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003505structures appropriately for all of the filter types. (Note that this
3506means the first row must always be adaptively filtered, because libpng
3507currently does not allocate the filter buffers until png_write_row()
3508is called for the first time.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003509
3510 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003511 PNG_FILTER_UP | PNG_FILTER_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003512 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003513
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003514 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3515 filters);
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003516 The second parameter can also be
3517 PNG_INTRAPIXEL_DIFFERENCING if you are
3518 writing a PNG to be embedded in a MNG
3519 datastream. This parameter must be the
3520 same as the value of filter_method used
3521 in png_set_IHDR().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003522
3523It is also possible to influence how libpng chooses from among the
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003524available filters. This is done in one or both of two ways - by
3525telling it how important it is to keep the same filter for successive
3526rows, and by telling it the relative computational costs of the filters.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003527
3528 double weights[3] = {1.5, 1.3, 1.1},
3529 costs[PNG_FILTER_VALUE_LAST] =
3530 {1.0, 1.3, 1.3, 1.5, 1.7};
3531
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05003532 png_set_filter_heuristics(png_ptr,
3533 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003534 weights, costs);
3535
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003536The weights are multiplying factors that indicate to libpng that the
3537row filter should be the same for successive rows unless another row filter
3538is that many times better than the previous filter. In the above example,
3539if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003540"sum of absolute differences" 1.5 x 1.3 times higher than other filters
3541and still be chosen, while the NONE filter could have a sum 1.1 times
3542higher than other filters and still be chosen. Unspecified weights are
3543taken to be 1.0, and the specified weights should probably be declining
3544like those above in order to emphasize recent filters over older filters.
3545
3546The filter costs specify for each filter type a relative decoding cost
3547to be considered when selecting row filters. This means that filters
3548with higher costs are less likely to be chosen over filters with lower
3549costs, unless their "sum of absolute differences" is that much smaller.
3550The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003551the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003552size.
3553
3554Note that the numbers above were invented purely for this example and
3555are given only to help explain the function usage. Little testing has
3556been done to find optimum values for either the costs or the weights.
3557
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003558.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003559
3560There are a bunch of #define's in pngconf.h that control what parts of
3561libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003562never going to use a capability, you can change the #define to #undef
3563before recompiling libpng and save yourself code and data space, or
3564you can turn off individual capabilities with defines that begin with
3565PNG_NO_.
3566
3567You can also turn all of the transforms and ancillary chunk capabilities
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003568off en masse with compiler directives that define
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003569PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3570or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003571along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003572want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
3573transformations but still leave the library fully capable of reading
3574and writing PNG files with all known public chunks. Use of the
3575PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
3576that is incapable of reading or writing ancillary chunks. If you are
3577not using the progressive reading capability, you can turn that off
3578with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
3579capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003580
3581All the reading and writing specific code are in separate files, so the
3582linker should only grab the files it needs. However, if you want to
3583make sure, or if you are building a stand alone library, all the
3584reading files start with pngr and all the writing files start with
3585pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
3586are used for both reading and writing, and always need to be included.
3587The progressive reader is in pngpread.c
3588
3589If you are creating or distributing a dynamically linked library (a .so
3590or DLL file), you should not remove or disable any parts of the library,
3591as this will cause applications linked with different versions of the
3592library to fail if they call functions not available in your library.
3593The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003594those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003595
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003596.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003597
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003598The macro definition PNG_DEBUG can be used to request debugging
3599printout. Set it to an integer value in the range 0 to 3. Higher
3600numbers result in increasing amounts of debugging information. The
3601information is printed to the "stderr" file, unless another file
3602name is specified in the PNG_DEBUG_FILE macro definition.
3603
3604When PNG_DEBUG > 0, the following functions (macros) become available:
3605
3606 png_debug(level, message)
3607 png_debug1(level, message, p1)
3608 png_debug2(level, message, p1, p2)
3609
3610in which "level" is compared to PNG_DEBUG to decide whether to print
3611the message, "message" is the formatted string to be printed,
3612and p1 and p2 are parameters that are to be embedded in the string
3613according to printf-style formatting directives. For example,
3614
3615 png_debug1(2, "foo=%d\n", foo);
3616
3617is expanded to
3618
3619 if(PNG_DEBUG > 2)
3620 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
3621
3622When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3623can still use PNG_DEBUG to control your own debugging:
3624
3625 #ifdef PNG_DEBUG
3626 fprintf(stderr, ...
3627 #endif
3628
3629When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3630having level = 0 will be printed. There aren't any such statements in
3631this version of libpng, but if you insert some they will be printed.
3632
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05003633.SH VI. MNG support
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003634
3635The MNG specification (available at http://www.libpng.org/pub/mng) allows
3636certain extensions to PNG for PNG images that are embedded in MNG datastreams.
3637Libpng can support some of these extensions. To enable them, use the
3638png_permit_mng_features() function:
3639
3640 feature_set = png_permit_mng_features(png_ptr, mask)
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003641 mask is a png_uint_32 containing the bitwise OR of the
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003642 features you want to enable. These include
3643 PNG_FLAG_MNG_EMPTY_PLTE
3644 PNG_FLAG_MNG_FILTER_64
3645 PNG_ALL_MNG_FEATURES
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003646 feature_set is a png_uint_32 that is the bitwise AND of
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06003647 your mask with the set of MNG features that is
3648 supported by the version of libpng that you are using.
3649
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003650It is an error to use this function when reading or writing a standalone
3651PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
Glenn Randers-Pehrsonf05f8032000-12-23 14:27:39 -06003652in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
3653and the MHDR and MEND chunks. Libpng does not provide support for these
3654or any other MNG chunks; your application must provide its own support for
3655them. You may wish to consider using libmng (available at
3656http://www.libmng.com) instead.
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003657
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003658.SH VII. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003659
3660It should be noted that versions of libpng later than 0.96 are not
3661distributed by the original libpng author, Guy Schalnat, nor by
3662Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3663distributed versions 0.89 through 0.96, but rather by another member
3664of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3665still alive and well, but they have moved on to other things.
3666
3667The old libpng functions png_read_init(), png_write_init(),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05003668png_info_init(), png_read_destroy(), and png_write_destroy() have been
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05003669moved to PNG_INTERNAL in version 0.95 to discourage their use. These
3670functions will be removed from libpng version 2.0.0.
3671
3672The preferred method of creating and initializing the libpng structures is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003673via the png_create_read_struct(), png_create_write_struct(), and
3674png_create_info_struct() because they isolate the size of the structures
3675from the application, allow version error checking, and also allow the
3676use of custom error handling routines during the initialization, which
3677the old functions do not. The functions png_read_destroy() and
3678png_write_destroy() do not actually free the memory that libpng
3679allocated for these structs, but just reset the data structures, so they
3680can be used instead of png_destroy_read_struct() and
3681png_destroy_write_struct() if you feel there is too much system overhead
3682allocating and freeing the png_struct for each image read.
3683
3684Setting the error callbacks via png_set_message_fn() before
3685png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003686because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003687to fail if the png_ptr was not initialized to zero. It is still possible
3688to set the error callbacks AFTER png_read_init(), or to change them with
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05003689png_set_error_fn(), which is essentially the same function, but with a new
3690name to force compilation errors with applications that try to use the old
3691method.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003692
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003693Starting with version 1.0.7, you can find out which version of the library
3694you are using at run-time:
3695
3696 png_uint_32 libpng_vn = png_access_version_number();
3697
3698The number libpng_vn is constructed from the major version, minor
3699version with leading zero, and release number with leading zero,
3700(e.g., libpng_vn for version 1.0.7 is 10007).
3701
3702You can also check which version of png.h you used when compiling your
3703application:
3704
3705 png_uint_32 application_vn = PNG_LIBPNG_VER;
3706
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003707.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06003708
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003709Support for user memory management was enabled by default. To
3710accomplish this, the functions png_create_read_struct_2(),
3711png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
3712png_malloc_default(), and png_free_default() were added.
3713
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -06003714Support for the iTXt chunk has been enabled by default as of
3715version 1.2.41.
3716
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003717Support for certain MNG features was enabled.
3718
3719Support for numbered error messages was added. However, we never got
3720around to actually numbering the error messages. The function
3721png_set_strip_error_numbers() was added (Note: the prototype for this
3722function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
3723builds of libpng-1.2.15. It was restored in libpng-1.2.36).
3724
3725The png_malloc_warn() function was added at libpng-1.2.3. This issues
3726a png_warning and returns NULL instead of aborting when it fails to
3727acquire the requested memory allocation.
3728
3729Support for setting user limits on image width and height was enabled
3730by default. The functions png_set_user_limits(), png_get_user_width_max(),
3731and png_get_user_height_max() were added at libpng-1.2.6.
3732
3733The png_set_add_alpha() function was added at libpng-1.2.7.
3734
3735The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
3736Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
3737tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
3738deprecated.
3739
3740A number of macro definitions in support of runtime selection of
3741assembler code features (especially Intel MMX code support) were
3742added at libpng-1.2.0:
3743
3744 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
3745 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
3746 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
3747 PNG_ASM_FLAG_MMX_READ_INTERLACE
3748 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
3749 PNG_ASM_FLAG_MMX_READ_FILTER_UP
3750 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
3751 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
3752 PNG_ASM_FLAGS_INITIALIZED
3753 PNG_MMX_READ_FLAGS
3754 PNG_MMX_FLAGS
3755 PNG_MMX_WRITE_FLAGS
3756 PNG_MMX_FLAGS
3757
3758We added the following functions in support of runtime
3759selection of assembler code features:
3760
3761 png_get_mmx_flagmask()
3762 png_set_mmx_thresholds()
3763 png_get_asm_flags()
3764 png_get_mmx_bitdepth_threshold()
3765 png_get_mmx_rowbytes_threshold()
3766 png_set_asm_flags()
3767
3768We replaced all of these functions with simple stubs in libpng-1.2.20,
3769when the Intel assembler code was removed due to a licensing issue.
3770
Glenn Randers-Pehrson3d893a02009-08-31 13:32:46 -05003771These macros are deprecated:
3772
3773 PNG_READ_TRANSFORMS_NOT_SUPPORTED
3774 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
3775 PNG_NO_SEQUENTIAL_READ_SUPPORTED
3776 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
3777 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
3778 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
3779
3780They have been replaced, respectively, by:
3781
3782 PNG_NO_READ_TRANSFORMS
3783 PNG_NO_PROGRESSIVE_READ
3784 PNG_NO_SEQUENTIAL_READ
3785 PNG_NO_WRITE_TRANSFORMS
3786 PNG_NO_READ_ANCILLARY_CHUNKS
3787 PNG_NO_WRITE_ANCILLARY_CHUNKS
3788
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003789PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
3790deprecated since libpng-1.0.16 and libpng-1.2.6.
3791
3792The function
3793 png_check_sig(sig, num)
3794was replaced with
3795 !png_sig_cmp(sig, 0, num)
3796It has been deprecated since libpng-0.90.
3797
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003798The function
3799 png_set_gray_1_2_4_to_8()
3800which also expands tRNS to alpha was replaced with
3801 png_set_expand_gray_1_2_4_to_8()
3802which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06003803
Glenn Randers-Pehrsond740c842009-11-04 19:01:54 -06003804.SH IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
3805
3806Private libpng prototypes and macro definitions were moved from
3807png.h and pngconf.h into a new pngpriv.h header file.
3808
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003809Functions png_set_benign_errors(), png_benign_error(), and
3810png_chunk_benign_error() were added.
3811
3812Support for setting the maximum amount of memory that the application
3813will allocate for reading chunks was added, as a security measure.
3814The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
3815were added to the library.
3816
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003817We implemented support for I/O states by adding png_ptr member io_state
3818and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003819
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05003820We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
3821input transforms.
3822
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05003823Checking for and reporting of errors in the IHDR chunk is more thorough.
3824
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06003825Support for global arrays was removed, to improve thread safety.
3826
3827Some obsolete/deprecated macros and functions have been removed.
3828
3829Typecasted NULL definitions such as
3830 #define png_voidp_NULL (png_voidp)NULL
3831were eliminated. If you used these in your application, just use
3832NULL instead.
3833
3834The png_struct and info_struct members "trans" and "trans_values" were
3835changed to "trans_alpha" and "trans_color", respectively.
3836
3837The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06003838were removed.
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06003839
3840The PNG_1_0_X and PNG_1_2_X macros were eliminated.
3841
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05003842The PNG_LEGACY_SUPPORTED macro was eliminated.
3843
3844Many WIN32_WCE #ifdefs were removed.
3845
3846The functions png_read_init(info_ptr), png_write_init(info_ptr),
3847png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
3848have been removed. They have been deprecated since libpng-0.95.
3849
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003850The png_permit_empty_plte() was removed. It has been deprecated
3851since libpng-1.0.9. Use png_permit_mng_features() instead.
3852
3853We removed the obsolete stub functions png_get_mmx_flagmask(),
3854png_set_mmx_thresholds(), png_get_asm_flags(),
3855png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
3856png_set_asm_flags(), and png_mmx_supported()
3857
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06003858We removed the obsolete png_check_sig(), png_memcpy_check(), and
3859png_memset_check() functions. Instead use !png_sig_cmp(), png_memcpy(),
3860and png_memset(), respectively.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003861
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06003862The function png_set_gray_1_2_4_to_8() was removed. It has been
3863deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
3864png_set_expand_gray_1_2_4_to_8() because the former function also
3865expanded palette images.
3866
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003867We changed the prototype for png_malloc() from
3868 png_malloc(png_structp png_ptr, png_uint_32 size)
3869to
3870 png_malloc(png_structp png_ptr, png_alloc_size_t size)
3871
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06003872This also applies to the prototype for the user replacement malloc_fn().
3873
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06003874The png_calloc() function was added and is used in place of
3875of "png_malloc(); png_memset();" except in the case in png_read_png()
3876where the array consists of pointers; in this case a "for" loop is used
3877after the png_malloc() to set the pointers to NULL, to give robust.
3878behavior in case the application runs out of memory part-way through
3879the process.
3880
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003881We changed the prototypes of png_get_compression_buffer_size() and
3882png_set_compression_buffer_size() to work with png_size_t instead of
3883png_uint_32.
3884
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06003885Support for numbered error messages was removed by default, since we
3886never got around to actually numbering the error messages. The function
3887png_set_strip_error_numbers() was removed from the library by default.
3888
3889The png_zalloc() and png_zfree() functions are no longer exported.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003890The png_zalloc() function no longer zeroes out the memory that it
3891allocates.
3892
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05003893We removed the trailing '.' from the warning and error messages.
3894
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05003895.SH X. Detecting libpng
3896
3897The png_get_io_ptr() function has been present since libpng-0.88, has never
3898changed, and is unaffected by conditional compilation macros. It is the
3899best choice for use in configure scripts for detecting the presence of any
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05003900libpng version since 0.88. In an autoconf "configure.in" you could use
3901
3902 AC_CHECK_LIB(png, png_get_io_ptr, ...
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05003903
3904.SH XI. Source code repository
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003905
3906Since about February 2009, version 1.2.34, libpng has been under "git" source
3907control. The git repository was built from old libpng-x.y.z.tar.gz files
3908going back to version 0.70. You can access the git repository (read only)
3909at
3910
3911 git://libpng.git.sourceforge.net/gitroot/libpng
3912
3913or you can browse it via "gitweb" at
3914
3915 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
3916
3917Patches can be sent to glennrp at users.sourceforge.net or to
3918png-mng-implement at lists.sourceforge.net or you can upload them to
3919the libpng bug tracker at
3920
3921 http://libpng.sourceforge.net
3922
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05003923.SH XII. Coding style
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003924
3925Our coding style is similar to the "Allman" style, with curly
3926braces on separate lines:
3927
3928 if (condition)
3929 {
3930 action;
3931 }
3932
3933 else if (another condition)
3934 {
3935 another action;
3936 }
3937
3938The braces can be omitted from simple one-line actions:
3939
3940 if (condition)
3941 return (0);
3942
3943We use 3-space indentation, except for continued statements which
3944are usually indented the same as the first line of the statement
3945plus four more spaces.
3946
Glenn Randers-Pehrson5ade7ed2009-09-30 15:11:49 -05003947For macro definitions we use 2-space indentation, always leaving the "#"
3948in the first column.
3949
3950 #ifndef PNG_NO_FEATURE
3951 # ifndef PNG_FEATURE_SUPPORTED
3952 # define PNG_FEATURE_SUPPORTED
3953 # endif
3954 #endif
3955
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003956Comments appear with the leading "/*" at the same indentation as
3957the statement that follows the comment:
3958
3959 /* Single-line comment */
3960 statement;
3961
3962 /* Multiple-line
3963 * comment
3964 */
3965 statement;
3966
3967Very short comments can be placed at the end of the statement
3968to which they pertain:
3969
3970 statement; /* comment */
3971
3972We don't use C++ style ("//") comments. We have, however,
3973used them in the past in some now-abandoned MMX assembler
3974code.
3975
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003976Functions and their curly braces are not indented, and
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003977exported functions are marked with PNGAPI:
3978
3979 /* This is a public function that is visible to
3980 * application programers. It does thus-and-so.
3981 */
3982 void PNGAPI
3983 png_exported_function(png_ptr, png_info, foo)
3984 {
3985 body;
3986 }
3987
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05003988The prototypes for all exported functions appear in png.h,
3989above the comment that says
3990
3991 /* Maintainer: Put new public prototypes here ... */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003992
3993We mark all non-exported functions with "/* PRIVATE */"":
3994
3995 void /* PRIVATE */
3996 png_non_exported_function(png_ptr, png_info, foo)
3997 {
3998 body;
3999 }
4000
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05004001The prototypes for non-exported functions (except for those in
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004002pngtest) appear in
4003pngpriv.h
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05004004above the comment that says
4005
4006 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05004007
4008The names of all exported functions and variables begin
4009with "png_", and all publicly visible C preprocessor
4010macros begin with "PNG_".
4011
4012We put a space after each comma and after each semicolon
4013in "for" statments, and we put spaces before and after each
4014C binary operator and after "for" or "while". We don't
4015put a space between a typecast and the expression being
4016cast, nor do we put one between a function name and the
4017left parenthesis that follows it:
4018
4019 for (i = 2; i > 0; --i)
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05004020 y[i] = a(x) + (int)b;
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05004021
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05004022We prefer #ifdef and #ifndef to #if defined() and if !defined()
4023when there is only one macro being tested.
4024
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05004025We do not use the TAB character for indentation in the C sources.
4026
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06004027Lines do not exceed 80 characters.
4028
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004029Other rules can be inferred by inspecting the libpng source.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05004030
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05004031.SH XIII. Y2K Compliance in libpng
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05004032
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004033February 8, 2010
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004034
4035Since the PNG Development group is an ad-hoc body, we can't make
4036an official declaration.
4037
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004038This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004039upward through 1.5.0beta01 are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004040versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004041
4042Libpng only has three year fields. One is a 2-byte unsigned integer that
4043will hold years up to 65535. The other two hold the date in text
4044format, and will hold years up to 9999.
4045
4046The integer is
4047 "png_uint_16 year" in png_time_struct.
4048
4049The strings are
4050 "png_charp time_buffer" in png_struct and
4051 "near_time_buffer", which is a local character string in png.c.
4052
4053There are seven time-related functions:
4054
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004055 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004056 (formerly png_convert_to_rfc_1152() in error)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004057 png_convert_from_struct_tm() in pngwrite.c, called
4058 in pngwrite.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004059 png_convert_from_time_t() in pngwrite.c
4060 png_get_tIME() in pngget.c
4061 png_handle_tIME() in pngrutil.c, called in pngread.c
4062 png_set_tIME() in pngset.c
4063 png_write_tIME() in pngwutil.c, called in pngwrite.c
4064
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004065All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004066png_convert_from_time_t() function calls gmtime() to convert from system
4067clock time, which returns (year - 1900), which we properly convert to
4068the full 4-digit year. There is a possibility that applications using
4069libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004070function, or that they are incorrectly passing only a 2-digit year
4071instead of "year - 1900" into the png_convert_from_struct_tm() function,
4072but this is not under our control. The libpng documentation has always
4073stated that it works with 4-digit years, and the APIs have been
4074documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004075
4076The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
4077integer to hold the year, and can hold years as large as 65535.
4078
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004079zlib, upon which libpng depends, is also Y2K compliant. It contains
4080no date-related code.
4081
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004082
4083 Glenn Randers-Pehrson
4084 libpng maintainer
4085 PNG Development Group
4086
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004087.SH NOTE
4088
4089Note about libpng version numbers:
4090
4091Due to various miscommunications, unforeseen code incompatibilities
4092and occasional factors outside the authors' control, version numbering
4093on the library has not always been consistent and straightforward.
4094The following table summarizes matters since version 0.89c, which was
4095the first widely used release:
4096
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004097 source png.h png.h shared-lib
4098 version string int version
4099 ------- ------ ----- ----------
4100 0.89c ("beta 3") 0.89 89 1.0.89
4101 0.90 ("beta 4") 0.90 90 0.90
4102 0.95 ("beta 5") 0.95 95 0.95
4103 0.96 ("beta 6") 0.96 96 0.96
4104 0.97b ("beta 7") 1.00.97 97 1.0.1
4105 0.97c 0.97 97 2.0.97
4106 0.98 0.98 98 2.0.98
4107 0.99 0.99 98 2.0.99
4108 0.99a-m 0.99 99 2.0.99
4109 1.00 1.00 100 2.1.0
4110 1.0.0 1.0.0 100 2.1.0
4111 1.0.0 (from here on, the 100 2.1.0
4112 1.0.1 png.h string is 10001 2.1.0
4113 1.0.1a-e identical to the 10002 from here on, the
4114 1.0.2 source version) 10002 shared library is 2.V
4115 1.0.2a-b 10003 where V is the source
4116 1.0.1 10001 code version except as
4117 1.0.1a-e 10002 2.1.0.1a-e noted.
4118 1.0.2 10002 2.1.0.2
4119 1.0.2a-b 10003 2.1.0.2a-b
4120 1.0.3 10003 2.1.0.3
4121 1.0.3a-d 10004 2.1.0.3a-d
4122 1.0.4 10004 2.1.0.4
4123 1.0.4a-f 10005 2.1.0.4a-f
4124 1.0.5 (+ 2 patches) 10005 2.1.0.5
4125 1.0.5a-d 10006 2.1.0.5a-d
4126 1.0.5e-r 10100 2.1.0.5e-r
4127 1.0.5s-v 10006 2.1.0.5s-v
4128 1.0.6 (+ 3 patches) 10006 2.1.0.6
4129 1.0.6d-g 10007 2.1.0.6d-g
4130 1.0.6h 10007 10.6h
4131 1.0.6i 10007 10.6i
4132 1.0.6j 10007 2.1.0.6j
4133 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
4134 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
4135 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
4136 1.0.7 1 10007 2.1.0.7
4137 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
4138 1.0.8rc1 1 10008 2.1.0.8rc1
4139 1.0.8 1 10008 2.1.0.8
4140 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
4141 1.0.9rc1 1 10009 2.1.0.9rc1
4142 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
4143 1.0.9rc2 1 10009 2.1.0.9rc2
4144 1.0.9 1 10009 2.1.0.9
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06004145 1.0.10beta1 1 10010 2.1.0.10beta1
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004146 1.0.10rc1 1 10010 2.1.0.10rc1
Glenn Randers-Pehrson13cfbac2001-03-30 06:42:28 -06004147 1.0.10 1 10010 2.1.0.10
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -05004148 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05004149 1.0.11rc1 1 10011 2.1.0.11rc1
Glenn Randers-Pehrson32835392001-04-27 08:29:32 -05004150 1.0.11 1 10011 2.1.0.11
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05004151 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
4152 1.0.12rc1 2 10012 2.1.0.12rc1
4153 1.0.12 2 10012 2.1.0.12
4154 1.1.0a-f - 10100 2.1.1.0a-f abandoned
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05004155 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
Glenn Randers-Pehrson5a0be342001-10-18 20:55:13 -05004156 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
4157 1.2.0rc1 3 10200 3.1.2.0rc1
4158 1.2.0 3 10200 3.1.2.0
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -06004159 1.2.1beta-4 3 10201 3.1.2.1beta1-4
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -06004160 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
4161 1.2.1 3 10201 3.1.2.1
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -06004162 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
Glenn Randers-Pehrsonfcbd7872002-04-07 16:35:38 -05004163 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
4164 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
4165 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004166 1.0.13 10 10013 10.so.0.1.0.13
4167 1.2.2 12 10202 12.so.0.1.2.2
Glenn Randers-Pehrson22f28962002-05-13 18:17:09 -05004168 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
4169 1.2.3 12 10203 12.so.0.1.2.3
Glenn Randers-Pehrsond020e9d2002-06-28 09:34:00 -05004170 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -05004171 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
Glenn Randers-Pehrson484a8a12002-07-07 19:15:20 -05004172 1.0.14 10 10014 10.so.0.1.0.14
4173 1.2.4 13 10204 12.so.0.1.2.4
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05004174 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
4175 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004176 1.0.15 10 10015 10.so.0.1.0.15
4177 1.2.5 13 10205 12.so.0.1.2.5
4178 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
Glenn Randers-Pehrson37f116a2004-08-15 07:15:39 -05004179 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
4180 1.0.16 10 10016 10.so.0.1.0.16
4181 1.2.6 13 10206 12.so.0.1.2.6
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05004182 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05004183 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
4184 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
Glenn Randers-Pehrson250dfe12004-09-11 21:19:54 -05004185 1.0.17 10 10017 12.so.0.1.0.17
4186 1.2.7 13 10207 12.so.0.1.2.7
Glenn Randers-Pehrson40936072004-11-20 11:18:40 -06004187 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
Glenn Randers-Pehrson584b96e2004-11-29 15:08:00 -06004188 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
4189 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06004190 1.0.18 10 10018 12.so.0.1.0.18
4191 1.2.8 13 10208 12.so.0.1.2.8
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06004192 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -06004193 1.2.9beta4-11 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrson3a512032006-03-31 05:29:33 -06004194 1.2.9rc1 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsona7d0c942006-04-14 06:22:52 -05004195 1.2.9 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05004196 1.2.10beta1-7 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -05004197 1.2.10rc1-2 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson86dc9812006-05-10 07:27:44 -05004198 1.2.10 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05004199 1.4.0beta1-6 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05004200 1.2.11beta1-4 13 10210 12.so.0.11[.0]
Glenn Randers-Pehrson3424ee72006-07-12 13:33:47 -05004201 1.4.0beta7-8 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrson701dbaa2006-11-17 09:36:54 -06004202 1.2.11 13 10211 12.so.0.11[.0]
4203 1.2.12 13 10212 12.so.0.12[.0]
4204 1.4.0beta9-14 14 10400 14.so.0.0[.0]
4205 1.2.13 13 10213 12.so.0.13[.0]
Glenn Randers-Pehrson97a9b482008-10-25 20:03:28 -05004206 1.4.0beta15-36 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsonfa028102009-10-10 06:15:21 -05004207 1.4.0beta37-87 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson733da8c2009-10-30 00:00:15 -05004208 1.4.0rc01 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06004209 1.4.0beta88-109 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson67a83db2010-01-01 18:26:18 -06004210 1.4.0rc02-08 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsondbcfb712009-12-25 14:24:18 -06004211 1.4.0 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004212 1.4.1beta01-03 14 10401 14.so.14.1[.0]
4213 1.4.1rc01 14 10401 14.so.14.1[.0]
4214 1.4.1beta04-09 14 10401 14.so.14.1[.0]
4215 1.5.0beta01 15 10500 15.so.15.1[.0]
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004216
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004217Henceforth the source version will match the shared-library minor
4218and patch numbers; the shared-library major version number will be
4219used for changes in backward compatibility, as it is intended. The
4220PNG_PNGLIB_VER macro, which is not used within libpng but is available
4221for applications, is an unsigned integer of the form xyyzz corresponding
4222to the source version x.y.z (leading zeros in y and z). Beta versions
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06004223were given the previous public release number plus a letter, until
4224version 1.0.6j; from then on they were given the upcoming public
4225release number plus "betaNN" or "rcN".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004226
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004227.SH "SEE ALSO"
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004228libpngpf(3), png(5)
4229.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004230.IR libpng :
4231.IP
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05004232http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06004233http://www.libpng.org/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004234
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004235.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004236.IR zlib :
4237.IP
4238(generally) at the same location as
4239.I libpng
4240or at
4241.br
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06004242ftp://ftp.info-zip.org/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004243
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004244.LP
4245.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004246.IP
4247(generally) at the same location as
4248.I libpng
4249or at
4250.br
4251ftp://ds.internic.net/rfc/rfc2083.txt
4252.br
4253or (as a W3C Recommendation) at
4254.br
4255http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004256
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004257.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004258In the case of any inconsistency between the PNG specification
4259and this library, the specification takes precedence.
4260
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004261.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004262This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06004263<glennrp at users.sourceforge.net>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004264
4265The contributing authors would like to thank all those who helped
4266with testing, bug fixes, and patience. This wouldn't have been
4267possible without all of you.
4268
4269Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004270
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004271Libpng version 1.5.0beta01 - February 8, 2010:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004272Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06004273Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004274
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004275Supported by the PNG development group
4276.br
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06004277png-mng-implement at lists.sf.net
4278(subscription required; visit
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -06004279png-mng-implement at lists.sourceforge.net (subscription required; visit
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06004280https://lists.sourceforge.net/lists/listinfo/png-mng-implement
4281to subscribe).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004282
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004283.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004284
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06004285(This copy of the libpng notices is provided for your convenience. In case of
4286any discrepancy between this copy and the notices in the file png.h that is
4287included in the libpng distribution, the latter shall prevail.)
4288
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004289If you modify libpng you may insert additional notices immediately following
4290this sentence.
4291
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05004292This code is released under the libpng license.
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05004293
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004294libpng versions 1.2.6, August 15, 2004, through 1.5.0beta01, February 8, 2010, are
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05004295Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004296distributed according to the same disclaimer and license as libpng-1.2.5
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05004297with the following individual added to the list of Contributing Authors
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004298
4299 Cosmin Truta
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004300
4301libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06004302Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson32fc5ce2000-07-24 06:34:14 -05004303distributed according to the same disclaimer and license as libpng-1.0.6
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004304with the following individuals added to the list of Contributing Authors
4305
4306 Simon-Pierre Cadieux
4307 Eric S. Raymond
4308 Gilles Vollant
4309
4310and with the following additions to the disclaimer:
4311
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004312 There is no warranty against interference with your
4313 enjoyment of the library or against infringement.
4314 There is no warranty that our efforts or the library
4315 will fulfill any of your particular purposes or needs.
4316 This library is provided with all faults, and the entire
4317 risk of satisfactory quality, performance, accuracy, and
4318 effort is with the user.
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004319
4320libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
4321Copyright (c) 1998, 1999 Glenn Randers-Pehrson
4322Distributed according to the same disclaimer and license as libpng-0.96,
4323with the following individuals added to the list of Contributing Authors:
4324
4325 Tom Lane
4326 Glenn Randers-Pehrson
4327 Willem van Schaik
4328
4329libpng versions 0.89, June 1996, through 0.96, May 1997, are
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05004330Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004331Distributed according to the same disclaimer and license as libpng-0.88,
4332with the following individuals added to the list of Contributing Authors:
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004333
4334 John Bowler
4335 Kevin Bracey
4336 Sam Bushell
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004337 Magnus Holmgren
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004338 Greg Roelofs
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004339 Tom Tanner
4340
4341libpng versions 0.5, May 1995, through 0.88, January 1996, are
4342Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
4343
4344For the purposes of this copyright and license, "Contributing Authors"
4345is defined as the following set of individuals:
4346
4347 Andreas Dilger
4348 Dave Martindale
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004349 Guy Eric Schalnat
4350 Paul Schmidt
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004351 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06004352
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004353The PNG Reference Library is supplied "AS IS". The Contributing Authors
4354and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004355including, without limitation, the warranties of merchantability and of
4356fitness for any purpose. The Contributing Authors and Group 42, Inc.
4357assume no liability for direct, indirect, incidental, special, exemplary,
4358or consequential damages, which may result from the use of the PNG
4359Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004360
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004361Permission is hereby granted to use, copy, modify, and distribute this
4362source code, or portions hereof, for any purpose, without fee, subject
4363to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004364
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -050043651. The origin of this source code must not be misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004366
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060043672. Altered versions must be plainly marked as such and
4368 must not be misrepresented as being the original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004369
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060043703. This Copyright notice may not be removed or altered from
4371 any source or altered source distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004372
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004373The Contributing Authors and Group 42, Inc. specifically permit, without
4374fee, and encourage the use of this source code as a component to
4375supporting the PNG file format in commercial products. If you use this
4376source code in a product, acknowledgment is not required but would be
4377appreciated.
4378
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004379
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004380A "png_get_copyright" function is available, for convenient use in "about"
4381boxes and the like:
4382
4383 printf("%s",png_get_copyright(NULL));
4384
4385Also, the PNG logo (in PNG format, of course) is supplied in the
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -05004386files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004387
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004388Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05004389certification mark of the Open Source Initiative.
4390
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004391Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06004392glennrp at users.sourceforge.net
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004393February 8, 2010
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05004394
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004395.\" end of man page
4396