blob: 5f6eed985bacf8a725188b731f310d07e1d6db47 [file] [log] [blame]
John Bowler736f40f2011-08-25 16:19:44 -05001.TH LIBPNG 3 "August 25, 2011"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrson9d824eb2011-08-17 07:52:32 -05003libpng \- Portable Network Graphics (PNG) Reference Library 1.5.5beta06
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-Pehrsonbb98bcb2011-01-22 16:27:39 -060019\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
20
21\fI\fB
22
23\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
24
25\fI\fB
26
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -050027\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
28
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050029\fI\fB
30
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050031\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 -060032
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050033\fI\fB
34
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050035\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 -060036
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050037\fI\fB
38
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050039\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 -060040
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050041\fI\fB
42
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050043\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 -060044
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050045\fI\fB
46
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050047\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 -060048
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050049\fI\fB
50
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050051\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060052
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_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 -050056
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050057\fI\fB
58
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060059\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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050060
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050061\fI\fB
62
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060063\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 -050064
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050065\fI\fB
66
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060067\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
68
69\fI\fB
70
71\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050072
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050073\fI\fB
74
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050075\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\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_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
80
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050081\fI\fB
82
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050083\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
84
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050085\fI\fB
86
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060087\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
88
89\fI\fB
90
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050091\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
92
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050093\fI\fB
94
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050095\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
96
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050097\fI\fB
98
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060099\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
100
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500101\fI\fB
102
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600103\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500104
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500105\fI\fB
106
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600107\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600108
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500109\fI\fB
110
John Bowler0a5c9c02011-01-22 17:36:34 -0600111\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500112
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500113\fI\fB
114
John Bowler0a5c9c02011-01-22 17:36:34 -0600115\fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500116
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500117\fI\fB
118
John Bowler0a5c9c02011-01-22 17:36:34 -0600119\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500120
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500121\fI\fB
122
John Bowler0a5c9c02011-01-22 17:36:34 -0600123\fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500124
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500125\fI\fB
126
John Bowler0a5c9c02011-01-22 17:36:34 -0600127\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600128
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500129\fI\fB
130
John Bowler736f40f2011-08-25 16:19:44 -0500131\fBpng_uint_32 png_get_cHRM_XYZ (png_structp \fIpng_ptr,
132
133\fBpng_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*red_X\fP\fB, double \fP\fI*red_Y\fP\fB, double \fI*red_Z,
134
135\fBdouble \fP\fI*green_X\fP\fB, double \fP\fI*green_Y\fP\fB, double \fP\fI*green_Z\fP\fB, double \fI*blue_X,
136
137\fBdouble \fP\fI*blue_Y\fP\fB, double \fI*blue_Z\fP\fB);\fP
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500138
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500139\fI\fB
140
John Bowler736f40f2011-08-25 16:19:44 -0500141\fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fI*int_red_X\fP\fB, png_fixed_point \fP\fI*int_red_Y\fP\fB, png_fixed_point \fP\fI*int_red_Z\fP\fB, png_fixed_point \fP\fI*int_green_X\fP\fB, png_fixed_point \fP\fI*int_green_Y\fP\fB, png_fixed_point \fP\fI*int_green_Z\fP\fB, png_fixed_point \fP\fI*int_blue_X\fP\fB, png_fixed_point \fP\fI*int_blue_Y\fP\fB, png_fixed_point \fI*int_blue_Z\fP\fB);\fP
142
143\fI\fB
144
145\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
146
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600147\fI\fB
148
John Bowler0a5c9c02011-01-22 17:36:34 -0600149\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600150
151\fI\fB
152
John Bowler0a5c9c02011-01-22 17:36:34 -0600153\fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500154
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500155\fI\fB
156
John Bowler0a5c9c02011-01-22 17:36:34 -0600157\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500158
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500159\fI\fB
160
John Bowler0a5c9c02011-01-22 17:36:34 -0600161\fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500162
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500163\fI\fB
164
John Bowler0a5c9c02011-01-22 17:36:34 -0600165\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500166
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500167\fI\fB
168
John Bowlerf19abd62011-01-22 18:29:24 -0600169\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP
170
171\fI\fB
172
173\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
174
175\fI\fB
176
John Bowler0a5c9c02011-01-22 17:36:34 -0600177\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500178
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500179\fI\fB
180
John Bowler0a5c9c02011-01-22 17:36:34 -0600181\fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500182
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500183\fI\fB
184
John Bowler0a5c9c02011-01-22 17:36:34 -0600185\fBpng_uint_32 png_get_gAMA (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500186
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500187\fI\fB
188
John Bowler0a5c9c02011-01-22 17:36:34 -0600189\fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600190
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500191\fI\fB
192
John Bowler0a5c9c02011-01-22 17:36:34 -0600193\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600194
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500195\fI\fB
196
John Bowler0a5c9c02011-01-22 17:36:34 -0600197\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500198
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500199\fI\fB
200
John Bowler0a5c9c02011-01-22 17:36:34 -0600201\fBpng_uint_32 png_get_hIST (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500202
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500203\fI\fB
204
John Bowler0a5c9c02011-01-22 17:36:34 -0600205\fBpng_uint_32 png_get_iCCP (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_bytepp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600206
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500207\fI\fB
208
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500209\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
210
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500211\fI\fB
212
John Bowler0a5c9c02011-01-22 17:36:34 -0600213\fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500214
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500215\fI\fB
216
John Bowler0a5c9c02011-01-22 17:36:34 -0600217\fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500218
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500219\fI\fB
220
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500221\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
222
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500223\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600224
John Bowler0a5c9c02011-01-22 17:36:34 -0600225\fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500226
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500227\fI\fB
228
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600229\fBpng_const_bytep png_get_io_chunk_name (png_structp \fIpng_ptr\fP\fB);\fP
230
231\fI\fB
232
John Bowler0a5c9c02011-01-22 17:36:34 -0600233\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -0600234
235\fI\fB
236
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500237\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
238
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500239\fI\fB
240
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -0600241\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
242
243\fI\fB
244
John Bowler0a5c9c02011-01-22 17:36:34 -0600245\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600246
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500247\fI\fB
248
John Bowler0a5c9c02011-01-22 17:36:34 -0600249\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500250
251\fI\fB
252
John Bowler0a5c9c02011-01-22 17:36:34 -0600253\fBpng_uint_32 png_get_oFFs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500254
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500255\fI\fB
256
John Bowler0a5c9c02011-01-22 17:36:34 -0600257\fBpng_uint_32 png_get_pCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500258
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500259\fI\fB
260
John Bowler0a5c9c02011-01-22 17:36:34 -0600261\fBpng_uint_32 png_get_pHYs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500262
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500263\fI\fB
264
John Bowler0a5c9c02011-01-22 17:36:34 -0600265\fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500266
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500267\fI\fB
268
John Bowler0a5c9c02011-01-22 17:36:34 -0600269\fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_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
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600270
271\fI\fB
272
John Bowler0a5c9c02011-01-22 17:36:34 -0600273\fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500274
275\fI\fB
276
John Bowler0a5c9c02011-01-22 17:36:34 -0600277\fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600278
279\fI\fB
280
John Bowler0a5c9c02011-01-22 17:36:34 -0600281\fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500282
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500283\fI\fB
284
John Bowler0a5c9c02011-01-22 17:36:34 -0600285\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500286
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500287\fI\fB
288
John Bowler0a5c9c02011-01-22 17:36:34 -0600289\fBpng_uint_32 png_get_PLTE (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500290
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500291\fI\fB
292
John Bowler0a5c9c02011-01-22 17:36:34 -0600293\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr)
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500294
John Bowler0a5c9c02011-01-22 17:36:34 -0600295\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500296
297\fI\fB
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500298
John Bowler0a5c9c02011-01-22 17:36:34 -0600299\fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600300
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500301\fI\fB
302
John Bowler0a5c9c02011-01-22 17:36:34 -0600303\fBpng_uint_32 png_get_sBIT (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500304
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500305\fI\fB
306
John Bowler0a5c9c02011-01-22 17:36:34 -0600307\fBvoid png_get_sCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, double* \fP\fIwidth\fP\fB, double* \fIheight\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500308
309\fI\fB
310
John Bowler0a5c9c02011-01-22 17:36:34 -0600311\fBvoid png_get_sCAL_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_fixed_pointp \fP\fIwidth\fP\fB, png_fixed_pointp \fIheight\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500312
313\fI\fB
314
John Bowler0a5c9c02011-01-22 17:36:34 -0600315\fBvoid png_get_sCAL_s (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_charpp \fP\fIwidth\fP\fB, png_charpp \fIheight\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500316
317\fI\fB
318
John Bowler0a5c9c02011-01-22 17:36:34 -0600319\fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500320
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500321\fI\fB
322
John Bowler0a5c9c02011-01-22 17:36:34 -0600323\fBpng_uint_32 png_get_sPLT (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600324
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500325\fI\fB
326
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600327\fBpng_uint_32 png_get_sRGB (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int \fI*file_srgb_intent\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500328
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500329\fI\fB
330
John Bowler0a5c9c02011-01-22 17:36:34 -0600331\fBpng_uint_32 png_get_text (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500332
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500333\fI\fB
334
John Bowler0a5c9c02011-01-22 17:36:34 -0600335\fBpng_uint_32 png_get_tIME (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500336
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500337\fI\fB
338
John Bowler0a5c9c02011-01-22 17:36:34 -0600339\fBpng_uint_32 png_get_tRNS (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans_alpha\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 -0500340
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500341\fI\fB
342
343\fB/* This function is really an inline macro. \fI*/
344
345\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
346
347\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600348
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -0600349\fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600350
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500351\fI\fB
352
353\fB/* This function is really an inline macro. \fI*/
354
355\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
356
357\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600358
John Bowler0a5c9c02011-01-22 17:36:34 -0600359\fBpng_uint_32 png_get_unknown_chunks (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600360
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500361\fI\fB
362
John Bowler0a5c9c02011-01-22 17:36:34 -0600363\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600364
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500365\fI\fB
366
John Bowler0a5c9c02011-01-22 17:36:34 -0600367\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500368
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500369\fI\fB
370
John Bowler0a5c9c02011-01-22 17:36:34 -0600371\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500372
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500373\fI\fB
374
John Bowler0a5c9c02011-01-22 17:36:34 -0600375\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500376
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500377\fI\fB
378
John Bowler0a5c9c02011-01-22 17:36:34 -0600379\fBpng_uint_32 png_get_valid (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500380
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500381\fI\fB
382
John Bowler0a5c9c02011-01-22 17:36:34 -0600383\fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500384
385\fI\fB
386
John Bowler0a5c9c02011-01-22 17:36:34 -0600387\fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500388
389\fI\fB
390
John Bowler0a5c9c02011-01-22 17:36:34 -0600391\fBpng_int_32 png_get_x_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500392
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500393\fI\fB
394
John Bowler0a5c9c02011-01-22 17:36:34 -0600395\fBpng_int_32 png_get_x_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500396
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500397\fI\fB
398
John Bowler0a5c9c02011-01-22 17:36:34 -0600399\fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600400
401\fI\fB
402
John Bowler0a5c9c02011-01-22 17:36:34 -0600403\fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500404
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500405\fI\fB
406
John Bowler0a5c9c02011-01-22 17:36:34 -0600407\fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500408
409\fI\fB
410
John Bowler0a5c9c02011-01-22 17:36:34 -0600411\fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500412
413\fI\fB
414
John Bowler0a5c9c02011-01-22 17:36:34 -0600415\fBpng_int_32 png_get_y_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500416
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500417\fI\fB
418
John Bowler0a5c9c02011-01-22 17:36:34 -0600419\fBpng_int_32 png_get_y_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500420
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500421\fI\fB
422
John Bowler0a5c9c02011-01-22 17:36:34 -0600423\fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600424
425\fI\fB
426
John Bowler0a5c9c02011-01-22 17:36:34 -0600427\fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500428
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500429\fI\fB
430
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600431\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
432
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500433\fI\fB
434
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600435\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
436
437\fI\fB
438
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500439\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 -0500440
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500441\fI\fB
442
Glenn Randers-Pehrsonf98726a2010-02-19 09:54:53 -0600443\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
444
445\fI\fB
446
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500447\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 -0500448
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500449\fI\fB
450
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600451\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
452
453\fI\fB
454
455\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
456
457\fI\fB
458
459\fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500460
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500461\fI\fB
462
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500463\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
464
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500465\fI\fB
466
John Bowlerf19abd62011-01-22 18:29:24 -0600467\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
468
469\fI\fB
470
471\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
472
473\fI\fB
474
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500475\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
476
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500477\fI\fB
478
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500479\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
480
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500481\fI\fB
482
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500483\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
484
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500485\fI\fB
486
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500487\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
488
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500489\fI\fB
490
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600491\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 -0600492
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500493\fI\fB
494
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500495\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
496
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500497\fI\fB
498
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500499\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
500
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500501\fI\fB
502
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500503\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
504
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500505\fI\fB
506
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600507\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
508
509\fI\fB
510
511\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500512
513\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600514
515\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
516
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500517\fI\fB
518
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600519\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
520
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500521\fI\fB
522
523\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
524
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500525\fI\fB
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -0500526
Glenn Randers-Pehrsonc7822512011-05-07 21:23:43 -0500527\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP
528
529\fI\fB
530
531\fBvoid png_set_alpha_mode_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, png_fixed_point \fIoutput_gamma\fP\fB);\fP
532
533\fI\fB
534
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500535\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
536
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500537\fI\fB
538
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500539\fBvoid png_set_background_fixed (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, png_uint_32 \fIbackground_gamma\fP\fB);\fP
540
541\fI\fB
542
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600543\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
544
545\fI\fB
546
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500547\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
548
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500549\fI\fB
550
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500551\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
552
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500553\fI\fB
554
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500555\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
556
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500557\fI\fB
558
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600559\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
560
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500561\fI\fB
562
John Bowler736f40f2011-08-25 16:19:44 -0500563\fBvoid png_set_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIred_X\fP\fB, double \fP\fIred_Y\fP\fB, double \fP\fIred_Z\fP\fB, double \fP\fIgreen_X\fP\fB, double \fIgreen_Y,
564
565\fBdouble \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP
566
567\fI\fB
568
569\fBvoid png_set_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fIint_red_X\fP\fB, png_fixed_point \fP\fIint_red_Y\fP\fB, png_fixed_point \fP\fIint_red_Z\fP\fB, png_fixed_point \fP\fIint_green_X\fP\fB, png_fixed_point \fP\fIint_green_Y\fP\fB, png_fixed_point \fP\fIint_green_Z\fP\fB, png_fixed_point \fP\fIint_blue_X\fP\fB, png_fixed_point \fP\fIint_blue_Y\fP\fB, png_fixed_point \fIint_blue_Z\fP\fB);\fP
570
571\fI\fB
572
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500573\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
574
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500575\fI\fB
576
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500577\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
578
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500579\fI\fB
580
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500581\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
582
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500583\fI\fB
584
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500585\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
586
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500587\fI\fB
588
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500589\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 -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_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\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-Pehrson4393a9a1999-09-17 12:27:26 -0500597\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 -0600598
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500599\fI\fB
600
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500601\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 -0600602
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500603\fI\fB
604
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -0600605\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsonc85f5f62011-02-13 05:56:07 -0600606
607\fI\fB
608
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -0600609\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600610
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500611\fI\fB
612
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600613\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -0600614
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500615\fI\fB
616
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500617\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 -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_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 -0600622
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500623\fI\fB
624
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500625\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 -0500626
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500627\fI\fB
628
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500629\fBvoid png_set_filter_heuristics_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_fixed_point_p \fP\fIfilter_weights\fP\fB, png_fixed_point_p \fIfilter_costs\fP\fB);\fP
630
631\fI\fB
632
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500633\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\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_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 -0600638
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500639\fI\fB
640
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500641\fBvoid png_set_gamma_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIscreen_gamma\fP\fB, png_uint_32 \fIdefault_file_gamma\fP\fB);\fP
642
643\fI\fB
644
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500645\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 -0600646
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500647\fI\fB
648
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600649\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
650
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500651\fI\fB
652
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600653\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\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_gray_to_rgb (png_structp \fIpng_ptr\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-Pehrson4393a9a1999-09-17 12:27:26 -0500661\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 -0600662
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500663\fI\fB
664
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -0600665\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_const_bytep \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600666
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500667\fI\fB
668
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500669\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600670
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500671\fI\fB
672
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500673\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
674
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500675\fI\fB
676
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500677\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600678
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500679\fI\fB
680
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500681\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600682
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500683\fI\fB
684
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500685\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 -0600686
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500687\fI\fB
688
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600689\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 -0600690
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500691\fI\fB
692
Glenn Randers-Pehrson1e6ed732009-11-20 22:06:56 -0600693\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
694
695\fI\fB
696
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600697\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
698
699\fI\fB
700
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600701\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
702
703\fI\fB
704
705\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 -0600706
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500707\fI\fB
708
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500709\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 -0600710
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500711\fI\fB
712
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500713\fBvoid png_set_packing (png_structp \fIpng_ptr\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_set_packswap (png_structp \fIpng_ptr\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-Pehrsonbb98bcb2011-01-22 16:27:39 -0600721\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\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_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 -0600726
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500727\fI\fB
728
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500729\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 -0600730
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500731\fI\fB
732
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500733\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 -0600734
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500735\fI\fB
736
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500737\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 -0600738
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500739\fI\fB
740
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -0500741\fBvoid png_set_quantize (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_quantize\fP\fB);\fP
742
743\fI\fB
744
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500745\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 -0600746
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500747\fI\fB
748
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500749\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 -0600750
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500751\fI\fB
752
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600753\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
754
755\fI\fB
756
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500757\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 -0600758
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500759\fI\fB
760
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600761\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
762
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500763\fI\fB
764
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500765\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_uint_32 \fP\fIred\fP\fB, png_uint_32 \fIgreen\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600766
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500767\fI\fB
768
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600769\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
770
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500771\fI\fB
772
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500773\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 -0600774
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500775\fI\fB
776
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500777\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
778
779\fI\fB
780
781\fBvoid png_set_sCAL_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_fixed_point \fP\fIwidth\fP\fB, png_fixed_point \fIheight\fP\fB);\fP
782
783\fI\fB
784
785\fBvoid png_set_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
786
787\fI\fB
788
Glenn Randers-Pehrsonc4a82142011-06-18 00:44:08 -0500789\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
790
791\fI\fB
792
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500793\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 -0600794
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500795\fI\fB
796
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500797\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 -0600798
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500799\fI\fB
800
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600801\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 -0600802
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500803\fI\fB
804
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600805\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600806
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500807\fI\fB
808
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600809\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600810
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500811\fI\fB
812
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500813\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600814
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500815\fI\fB
816
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500817\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600818
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500819\fI\fB
820
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600821\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
822
823\fI\fB
824
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500825\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600826
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500827\fI\fB
828
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500829\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600830
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500831\fI\fB
832
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500833\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 -0600834
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500835\fI\fB
836
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500837\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
838
839\fI\fB
840
841\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
842
843\fI\fB
844
845\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
846
847\fI\fB
848
849\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
850
851\fI\fB
852
853\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
854
855\fI\fB
856
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500857\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 -0600858
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500859\fI\fB
860
Glenn Randers-Pehrsonf3c51e42011-01-15 10:25:25 -0600861\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans_alpha\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500862
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500863\fI\fB
864
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600865\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600866
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500867\fI\fB
868
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600869\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
870
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500871\fI\fB
872
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600873\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
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600874
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500875\fI\fB
876
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500877\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
878
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500879\fI\fB
880
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500881\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 -0600882
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500883\fI\fB
884
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500885\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 -0600886
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500887\fI\fB
888
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500889\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 -0600890
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500891\fI\fB
892
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500893\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 -0600894
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500895\fI\fB
896
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500897\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 -0600898
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500899\fI\fB
900
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500901\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600902
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500903\fI\fB
904
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500905\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 -0600906
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500907\fI\fB
908
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500909\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 -0600910
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500911\fI\fB
912
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500913\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 -0600914
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500915\fI\fB
916
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500917\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600918
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500919\fI\fB
920
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500921\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 -0600922
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500923\fI\fB
924
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500925\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 -0600926
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500927\fI\fB
928
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500929\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600930
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500931\fI\fB
932
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500933\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 -0600934
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500935\fI\fB
936
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500937\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 -0600938
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500939\fI\fB
940
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600941\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
942
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500943\fI\fB
944
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600945\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 -0600946
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500947\fI\fB
948
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500949\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 -0600950
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500951\fI\fB
952
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500953\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 -0600954
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500955\fI\fB
956
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500957\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
958
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500959\fI\fB
960
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500961\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
962
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500963\fI\fB
964
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500965\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
966
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500967\fI\fB
968
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600969.SH DESCRIPTION
970The
971.I libpng
972library supports encoding, decoding, and various manipulations of
973the Portable Network Graphics (PNG) format image files. It uses the
974.IR zlib(3)
975compression library.
Glenn Randers-Pehrson557b2562010-10-17 12:55:04 -0500976Following is a copy of the libpng-manual.txt file that accompanies libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600977.SH LIBPNG.TXT
Glenn Randers-Pehrson557b2562010-10-17 12:55:04 -0500978libpng-manual.txt - A description on how to use and modify libpng
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600979
John Bowler736f40f2011-08-25 16:19:44 -0500980 libpng version 1.5.5beta06 - August 25, 2011
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600981 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -0600982 <glennrp at users.sourceforge.net>
Glenn Randers-Pehrson9f45c8e2011-01-15 19:35:03 -0600983 Copyright (c) 1998-2011 Glenn Randers-Pehrson
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -0500984
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -0500985 This document is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -0500986 For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -0500987 and license in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600988
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500989 Based on:
990
John Bowler736f40f2011-08-25 16:19:44 -0500991 libpng versions 0.97, January 1998, through 1.5.5beta06 - August 25, 2011
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500992 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson9f45c8e2011-01-15 19:35:03 -0600993 Copyright (c) 1998-2011 Glenn Randers-Pehrson
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600994
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600995 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600996 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600997 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600998
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600999 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001000 For conditions of distribution and use, see copyright
1001 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001002 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001003
1004 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001005 Copyright (c) 1995, 1996 Frank J. T. Wojcik
1006 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001007
1008.SH I. Introduction
1009
1010This file describes how to use and modify the PNG reference library
1011(known as libpng) for your own use. There are five sections to this
1012file: introduction, structures, reading, writing, and modification and
1013configuration notes for various special platforms. In addition to this
1014file, example.c is a good starting point for using the library, as
1015it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001016will need. We assume that libpng is already installed; see the
1017INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001018
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001019For examples of libpng usage, see the files "example.c", "pngtest.c",
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001020and the files in the "contrib" directory, all of which are included in
1021the libpng distribution.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001022
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001023Libpng was written as a companion to the PNG specification, as a way
1024of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001025file format in application programs.
1026
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001027The PNG specification (second edition), November 2003, is available as
1028a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
1029<http://www.w3.org/TR/2003/REC-PNG-20031110/
1030The W3C and ISO documents have identical technical content.
1031
1032The PNG-1.2 specification is available at
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001033<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
1034to the PNG specification (second edition) but has some additional material.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001035
1036The PNG-1.0 specification is available
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001037as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001038W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
1039
1040Some additional chunks are described in the special-purpose public chunks
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001041documents at <http://www.libpng.org/pub/png/documents/>.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001042
1043Other information
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001044about PNG, and the latest version of libpng, can be found at the PNG home
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001045page, <http://www.libpng.org/pub/png/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001046
1047Most users will not have to modify the library significantly; advanced
1048users may want to modify it more. All attempts were made to make it as
1049complete as possible, while keeping the code easy to understand.
1050Currently, this library only supports C. Support for other languages
1051is being considered.
1052
1053Libpng has been designed to handle multiple sessions at one time,
1054to be easily modifiable, to be portable to the vast majority of
1055machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
1056to use. The ultimate goal of libpng is to promote the acceptance of
1057the PNG file format in whatever way possible. While there is still
1058work to be done (see the TODO file), libpng should cover the
1059majority of the needs of its users.
1060
1061Libpng uses zlib for its compression and decompression of PNG files.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001062Further information about zlib, and the latest version of zlib, can
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001063be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001064The zlib compression utility is a general purpose utility that is
1065useful for more than PNG files, and can be used without libpng.
1066See the documentation delivered with zlib for more details.
1067You can usually find the source files for the zlib utility wherever you
1068find the libpng source files.
1069
1070Libpng is thread safe, provided the threads are using different
1071instances of the structures. Each thread should have its own
1072png_struct and png_info instances, and thus its own image.
1073Libpng does not protect itself against two threads using the
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05001074same instance of a structure.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001075
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001076.SH II. Structures
1077
1078There are two main structures that are important to libpng, png_struct
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001079and png_info. Both are internal structures that are no longer exposed
1080in the libpng interface (as of libpng 1.5.0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001081
1082The png_info structure is designed to provide information about the
1083PNG file. At one time, the fields of png_info were intended to be
1084directly accessible to the user. However, this tended to cause problems
1085with applications using dynamically loaded libraries, and as a result
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001086a set of interface functions for png_info (the png_get_*() and png_set_*()
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001087functions) was developed, and direct access to the png_info fields was
1088deprecated..
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001089
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001090The png_struct structure is the object used by the library to decode a
1091single image. As of 1.5.0 this structure is also not exposed.
1092
1093Almost all libpng APIs require a pointer to a png_struct as the first argument.
1094Many (in particular the png_set and png_get APIs) also require a pointer
1095to png_info as the second argument. Some application visible macros
1096defined in png.h designed for basic data access (reading and writing
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001097integers in the PNG format) don't take a png_info pointer, but it's almost
1098always safe to assume that a (png_struct*) has to be passed to call an API
1099function.
1100
1101You can have more than one png_info structure associated with an image,
1102as illustrated in pngtest.c, one for information valid prior to the
1103IDAT chunks and another (called "end_info" below) for things after them.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001104
1105The png.h header file is an invaluable reference for programming with libpng.
1106And while I'm on the topic, make sure you include the libpng header file:
1107
1108#include <png.h>
1109
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001110and also (as of libpng-1.5.0) the zlib header file, if you need it:
1111
1112#include <zlib.h>
1113
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001114.SS Types
1115
1116The png.h header file defines a number of integral types used by the
1117APIs. Most of these are fairly obvious; for example types corresponding
1118to integers of particular sizes and types for passing color values.
1119
1120One exception is how non-integral numbers are handled. For application
1121convenience most APIs that take such numbers have C (double) arguments,
1122however internally PNG, and libpng, use 32 bit signed integers and encode
1123the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
1124macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
1125which is simply (png_int_32).
1126
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001127All APIs that take (double) arguments also have a matching API that
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001128takes the corresponding fixed point integer arguments. The fixed point
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001129API has the same name as the floating point one with "_fixed" appended.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001130The actual range of values permitted in the APIs is frequently less than
1131the full range of (png_fixed_point) (-21474 to +21474). When APIs require
1132a non-negative argument the type is recorded as png_uint_32 above. Consult
1133the header file and the text below for more information.
1134
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001135Special care must be take with sCAL chunk handling because the chunk itself
1136uses non-integral values encoded as strings containing decimal floating point
1137numbers. See the comments in the header file.
1138
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001139.SS Configuration
1140
1141The main header file function declarations are frequently protected by C
1142preprocessing directives of the form:
1143
1144 #ifdef PNG_feature_SUPPORTED
1145 declare-function
1146 #endif
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001147 ...
1148 #ifdef PNG_feature_SUPPORTED
1149 use-function
1150 #endif
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001151
1152The library can be built without support for these APIs, although a
1153standard build will have all implemented APIs. Application programs
1154should check the feature macros before using an API for maximum
1155portability. From libpng 1.5.0 the feature macros set during the build
1156of libpng are recorded in the header file "pnglibconf.h" and this file
1157is always included by png.h.
1158
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001159If you don't need to change the library configuration from the default, skip to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001160the next section ("Reading").
1161
1162Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
1163of the build project files in the 'projects' directory simply copy
1164scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
1165systems do not permit easy auto-configuration of the library - they only
1166support the default configuration.
1167
1168The easiest way to make minor changes to the libpng configuration when
1169auto-configuration is supported is to add definitions to the command line
1170using (typically) CPPFLAGS. For example:
1171
1172CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
1173
1174will change the internal libpng math implementation for gamma correction and
1175other arithmetic calculations to fixed point, avoiding the need for fast
1176floating point support. The result can be seen in the generated pnglibconf.h -
1177make sure it contains the changed feature macro setting.
1178
1179If you need to make more extensive configuration changes - more than one or two
1180feature macro settings - you can either add -DPNG_USER_CONFIG to the build
1181command line and put a list of feature macro settings in pngusr.h or you can set
1182DFA_XTRA (a makefile variable) to a file containing the same information in the
1183form of 'option' settings.
1184
1185A. Changing pnglibconf.h
1186
1187A variety of methods exist to build libpng. Not all of these support
1188reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
1189rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
1190
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001191Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
1192pnglibconf.h and changing the lines defining the supported features, paying
1193very close attention to the 'option' information in scripts/pnglibconf.dfa
1194that describes those features and their requirements. This is easy to get
1195wrong.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001196
1197B. Configuration using DFA_XTRA
1198
1199Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
1200variant such as 'nawk' or 'gawk', is available. The configure build will
1201automatically find an appropriate awk and build pnglibconf.h.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001202The scripts/pnglibconf.mak file contains a set of make rules for doing the
1203same thing if configure is not used, and many of the makefiles in the scripts
1204directory use this approach.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001205
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001206When rebuilding simply write a new file containing changed options and set
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001207DFA_XTRA to the name of this file. This causes the build to append the new file
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001208to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
1209of the following forms:
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001210
1211everything = off
1212
1213This turns all optional features off. Include it at the start of pngusr.dfa to
1214make it easier to build a minimal configuration. You will need to turn at least
1215some features on afterward to enable either reading or writing code, or both.
1216
1217option feature on
1218option feature off
1219
1220Enable or disable a single feature. This will automatically enable other
1221features required by a feature that is turned on or disable other features that
1222require a feature which is turned off. Conflicting settings will cause an error
1223message to be emitted by awk.
1224
1225setting feature default value
1226
1227Changes the default value of setting 'feature' to 'value'. There are a small
1228number of settings listed at the top of pnglibconf.h, they are documented in the
1229source code. Most of these values have performance implications for the library
1230but most of them have no visible effect on the API. Some can also be overridden
1231from the API.
1232
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001233This method of building a customized pnglibconf.h is illustrated in
1234contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
1235pngusr.dfa in these directories.
1236
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001237C. Configuration using PNG_USR_CONFIG
1238
1239If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
1240pngusr.h will automatically be included before the options in
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001241scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
1242macro definitions turning features on or off or setting settings.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001243
1244Apart from the global setting "everything = off" all the options listed above
1245can be set using macros in pngusr.h:
1246
1247#define PNG_feature_SUPPORTED
1248
1249is equivalent to:
1250
1251option feature on
1252
1253#define PNG_NO_feature
1254
1255is equivalent to:
1256
1257option feature off
1258
1259#define PNG_feature value
1260
1261is equivalent to:
1262
1263setting feature default value
1264
1265Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
1266pngusr file you supply override the contents of scripts/pnglibconf.dfa
1267
1268If confusing or incomprehensible behavior results it is possible to
1269examine the intermediate file pnglibconf.dfn to find the full set of
1270dependency information for each setting and option. Simply locate the
1271feature in the file and read the C comments that precede it.
1272
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001273This method is also illustrated in the contrib/pngminim/* makefiles and
1274pngusr.h.
1275
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001276.SH III. Reading
1277
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001278We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001279in a PNG file sequentially, briefly explaining the syntax and purpose
1280of each one. See example.c and png.h for more detail. While
1281progressive reading is covered in the next section, you will still
1282need some of the functions discussed in this section to read a PNG
1283file.
1284
1285.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001286
1287You will want to do the I/O initialization(*) before you get into libpng,
1288so if it doesn't work, you don't have much to undo. Of course, you
1289will also want to insure that you are, in fact, dealing with a PNG
1290file. Libpng provides a simple check to see if a file is a PNG file.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001291To use it, pass in the first 1 to 8 bytes of the file to the function
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05001292png_sig_cmp(), and it will return 0 (false) if the bytes match the
1293corresponding bytes of the PNG signature, or nonzero (true) otherwise.
1294Of course, the more bytes you pass in, the greater the accuracy of the
1295prediction.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001296
1297If you are intending to keep the file pointer open for use in libpng,
1298you must ensure you don't read more than 8 bytes from the beginning
1299of the file, and you also have to make a call to png_set_sig_bytes_read()
1300with the number of bytes you read from the beginning. Libpng will
1301then only check the bytes (if any) that your program didn't read.
1302
1303(*): If you are not using the standard I/O functions, you will need
1304to replace them with custom functions. See the discussion under
1305Customizing libpng.
1306
1307
1308 FILE *fp = fopen(file_name, "rb");
1309 if (!fp)
1310 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001311 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001312 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001313
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001314 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06001315 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001316
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001317 if (!is_png)
1318 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001319 return (NOT_PNG);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001320 }
1321
1322
1323Next, png_struct and png_info need to be allocated and initialized. In
1324order to ensure that the size of these structures is correct even with a
1325dynamically linked libpng, there are functions to initialize and
1326allocate the structures. We also pass the library version, optional
1327pointers to error handling functions, and a pointer to a data struct for
1328use by the error functions, if necessary (the pointer and functions can
1329be NULL if the default error handlers are to be used). See the section
1330on Changes to Libpng below regarding the old initialization functions.
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001331The structure allocation functions quietly return NULL if they fail to
1332create the structure, so your application should check for that.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001333
1334 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001335 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001336 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001337
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001338 if (!png_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001339 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001340
1341 png_infop info_ptr = png_create_info_struct(png_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001342
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001343 if (!info_ptr)
1344 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001345 png_destroy_read_struct(&png_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001346 (png_infopp)NULL, (png_infopp)NULL);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001347 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001348 }
1349
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001350If you want to use your own memory allocation routines,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001351use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001352png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001353
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001354 png_structp png_ptr = png_create_read_struct_2
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05001355 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001356 user_error_fn, user_warning_fn, (png_voidp)
1357 user_mem_ptr, user_malloc_fn, user_free_fn);
1358
1359The error handling routines passed to png_create_read_struct()
1360and the memory alloc/free routines passed to png_create_struct_2()
1361are only necessary if you are not using the libpng supplied error
1362handling and memory alloc/free functions.
1363
1364When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001365to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001366your png_jmpbuf(png_ptr). If you read the file from different
John Bowlere6dc85b2011-04-27 14:47:15 -05001367routines, you will need to update the longjmp buffer every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001368a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001369
1370See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001371information on setjmp/longjmp. See the discussion on libpng error
1372handling in the Customizing Libpng section below for more information
1373on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001374back to your setjmp, you will want to call png_destroy_read_struct() to
1375free any memory.
1376
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001377 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001378 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001379 png_destroy_read_struct(&png_ptr, &info_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001380 &end_info);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001381 fclose(fp);
1382 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001383 }
1384
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05001385Pass (png_infopp)NULL instead of &end_info if you didn't create
1386an end_info structure.
1387
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001388If you would rather avoid the complexity of setjmp/longjmp issues,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05001389you can compile libpng with PNG_NO_SETJMP, in which case
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001390errors will result in a call to PNG_ABORT() which defaults to abort().
1391
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05001392You can #define PNG_ABORT() to a function that does something
1393more useful than abort(), as long as your function does not
1394return.
1395
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001396Now you need to set up the input code. The default for libpng is to
1397use the C function fread(). If you use this, you will need to pass a
1398valid FILE * in the function png_init_io(). Be sure that the file is
1399opened in binary mode. If you wish to handle reading data in another
1400way, you need not call the png_init_io() function, but you must then
1401implement the libpng I/O methods discussed in the Customizing Libpng
1402section below.
1403
1404 png_init_io(png_ptr, fp);
1405
1406If you had previously opened the file and read any of the signature from
1407the beginning in order to see if this was a PNG file, you need to let
1408libpng know that there are some bytes missing from the start of the file.
1409
1410 png_set_sig_bytes(png_ptr, number);
1411
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001412You can change the zlib compression buffer size to be used while
1413reading compressed data with
1414
1415 png_set_compression_buffer_size(png_ptr, buffer_size);
1416
1417where the default size is 8192 bytes. Note that the buffer size
1418is changed immediately and the buffer is reallocated immediately,
1419instead of setting a flag to be acted upon later.
1420
Glenn Randers-Pehrson9dd1cdf2011-01-06 21:42:36 -06001421If you want CRC errors to be handled in a different manner than
1422the default, use
1423
1424 png_set_crc_action(png_ptr, crit_action, ancil_action);
1425
1426The values for png_set_crc_action() say how libpng is to handle CRC errors in
1427ancillary and critical chunks, and whether to use the data contained
1428therein. Note that it is impossible to "discard" data in a critical
1429chunk.
1430
1431Choices for (int) crit_action are
1432 PNG_CRC_DEFAULT 0 error/quit
1433 PNG_CRC_ERROR_QUIT 1 error/quit
1434 PNG_CRC_WARN_USE 3 warn/use data
1435 PNG_CRC_QUIET_USE 4 quiet/use data
1436 PNG_CRC_NO_CHANGE 5 use the current value
1437
1438Choices for (int) ancil_action are
1439 PNG_CRC_DEFAULT 0 error/quit
1440 PNG_CRC_ERROR_QUIT 1 error/quit
1441 PNG_CRC_WARN_DISCARD 2 warn/discard data
1442 PNG_CRC_WARN_USE 3 warn/use data
1443 PNG_CRC_QUIET_USE 4 quiet/use data
1444 PNG_CRC_NO_CHANGE 5 use the current value
1445
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001446.SS Setting up callback code
1447
1448You can set up a callback function to handle any unknown chunks in the
1449input stream. You must supply the function
1450
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06001451 read_chunk_callback(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001452 png_unknown_chunkp chunk);
1453 {
1454 /* The unknown chunk structure contains your
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001455 chunk data, along with similar data for any other
1456 unknown chunks: */
1457
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001458 png_byte name[5];
1459 png_byte *data;
1460 png_size_t size;
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001461
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001462 /* Note that libpng has already taken care of
1463 the CRC handling */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001464
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001465 /* put your code here. Search for your chunk in the
1466 unknown chunk structure, process it, and return one
1467 of the following: */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001468
1469 return (-n); /* chunk had an error */
1470 return (0); /* did not recognize */
1471 return (n); /* success */
1472 }
1473
1474(You can give your function another name that you like instead of
1475"read_chunk_callback")
1476
1477To inform libpng about your function, use
1478
1479 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1480 read_chunk_callback);
1481
1482This names not only the callback function, but also a user pointer that
1483you can retrieve with
1484
1485 png_get_user_chunk_ptr(png_ptr);
1486
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001487If you call the png_set_read_user_chunk_fn() function, then all unknown
1488chunks will be saved when read, in case your callback function will need
1489one or more of them. This behavior can be changed with the
1490png_set_keep_unknown_chunks() function, described below.
1491
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001492At this point, you can set up a callback function that will be
1493called after each row has been read, which you can use to control
1494a progress meter or the like. It's demonstrated in pngtest.c.
1495You must supply a function
1496
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06001497 void read_row_callback(png_structp png_ptr,
1498 png_uint_32 row, int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001499 {
1500 /* put your code here */
1501 }
1502
1503(You can give it another name that you like instead of "read_row_callback")
1504
1505To inform libpng about your function, use
1506
1507 png_set_read_status_fn(png_ptr, read_row_callback);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001508
John Bowler59010e52011-02-16 06:16:31 -06001509When this function is called the row has already been completely processed and
1510the 'row' and 'pass' refer to the next row to be handled. For the
1511non-interlaced case the row that was just handled is simply one less than the
1512passed in row number, and pass will always be 0. For the interlaced case the
1513same applies unless the row value is 0, in which case the row just handled was
1514the last one from one of the preceding passes. Because interlacing may skip a
1515pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1516need to know what the last pass is record (row,pass) from the callback and use
1517the last recorded value each time.
1518
1519As with the user transform you can find the output row using the
1520PNG_ROW_FROM_PASS_ROW macro.
1521
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001522.SS Unknown-chunk handling
1523
1524Now you get to set the way the library processes unknown chunks in the
1525input PNG stream. Both known and unknown chunks will be read. Normal
1526behavior is that known chunks will be parsed into information in
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001527various info_ptr members while unknown chunks will be discarded. This
1528behavior can be wasteful if your application will never use some known
1529chunk types. To change this, you can call:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001530
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001531 png_set_keep_unknown_chunks(png_ptr, keep,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001532 chunk_list, num_chunks);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001533 keep - 0: default unknown chunk handling
1534 1: ignore; do not keep
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001535 2: keep only if safe-to-copy
1536 3: keep even if unsafe-to-copy
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001537
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001538 You can use these definitions:
1539 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1540 PNG_HANDLE_CHUNK_NEVER 1
1541 PNG_HANDLE_CHUNK_IF_SAFE 2
1542 PNG_HANDLE_CHUNK_ALWAYS 3
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001543
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001544 chunk_list - list of chunks affected (a byte string,
1545 five bytes per chunk, NULL or '\0' if
1546 num_chunks is 0)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001547
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001548 num_chunks - number of chunks affected; if 0, all
Glenn Randers-Pehrsondff799e2004-08-07 21:42:49 -05001549 unknown chunks are affected. If nonzero,
1550 only the chunks in the list are affected
1551
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001552Unknown chunks declared in this way will be saved as raw data onto a
1553list of png_unknown_chunk structures. If a chunk that is normally
1554known to libpng is named in the list, it will be handled as unknown,
1555according to the "keep" directive. If a chunk is named in successive
1556instances of png_set_keep_unknown_chunks(), the final instance will
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001557take precedence. The IHDR and IEND chunks should not be named in
1558chunk_list; if they are, libpng will process them normally anyway.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001559If you know that your application will never make use of some particular
1560chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001561
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001562Here is an example of the usage of png_set_keep_unknown_chunks(),
1563where the private "vpAg" chunk will later be processed by a user chunk
1564callback function:
1565
1566 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1567
1568 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1569 png_byte unused_chunks[]=
1570 {
1571 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1572 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1573 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1574 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1575 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1576 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1577 };
1578 #endif
1579
1580 ...
1581
1582 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1583 /* ignore all unknown chunks: */
1584 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001585
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001586 /* except for vpAg: */
1587 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001588
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001589 /* also ignore unused known chunks: */
1590 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1591 (int)sizeof(unused_chunks)/5);
1592 #endif
1593
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001594.SS User limits
1595
1596The PNG specification allows the width and height of an image to be as
1597large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1598Since very few applications really need to process such large images,
1599we have imposed an arbitrary 1-million limit on rows and columns.
1600Larger images will be rejected immediately with a png_error() call. If
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05001601you wish to change this limit, you can use
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001602
1603 png_set_user_limits(png_ptr, width_max, height_max);
1604
1605to set your own limits, or use width_max = height_max = 0x7fffffffL
1606to allow all valid dimensions (libpng may reject some very large images
1607anyway because of potential buffer overflow conditions).
1608
1609You should put this statement after you create the PNG structure and
1610before calling png_read_info(), png_read_png(), or png_process_data().
Glenn Randers-Pehrsoncc277082011-06-10 21:17:34 -05001611
1612When writing a PNG datastream, put this statement before calling
1613png_write_info() or png_write_png().
1614
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001615If you need to retrieve the limits that are being applied, use
1616
1617 width_max = png_get_user_width_max(png_ptr);
1618 height_max = png_get_user_height_max(png_ptr);
1619
1620The PNG specification sets no limit on the number of ancillary chunks
1621allowed in a PNG datastream. You can impose a limit on the total number
1622of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1623
1624 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1625
1626where 0x7fffffffL means unlimited. You can retrieve this limit with
1627
1628 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1629
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05001630This limit also applies to the number of buffers that can be allocated
1631by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1632
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001633You can also set a limit on the amount of memory that a compressed chunk
1634other than IDAT can occupy, with
1635
1636 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1637
1638and you can retrieve the limit with
1639
1640 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1641
1642Any chunks that would cause either of these limits to be exceeded will
1643be ignored.
1644
John Bowlercb0b2962011-05-12 21:48:29 -05001645.SS Information about your system
1646
1647If you intend to display the PNG or to incorporate it in other image data you
1648need to tell libpng information about your display or drawing surface so that
1649libpng can convert the values in the image to match the display.
1650
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001651From libpng-1.5.4 this information can be set before reading the PNG file
John Bowlercb0b2962011-05-12 21:48:29 -05001652header. In earlier versions png_set_gamma() existed but behaved incorrectly if
1653called before the PNG file header had been read and png_set_alpha_mode() did not
1654exist.
1655
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001656If you need to support versions prior to libpng-1.5.4 test the version number
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001657as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1658described in the appropriate manual page.
John Bowlercb0b2962011-05-12 21:48:29 -05001659
1660You give libpng the encoding expected by your system expressed as a 'gamma'
1661value. You can also specify a default encoding for the PNG file in
1662case the required information is missing from the file. By default libpng
1663assumes that the PNG data matches your system, to keep this default call:
1664
1665 png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
1666
1667or you can use the fixed point equivalent:
1668
1669 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
1670
1671If you don't know the gamma for you system it is probably 2.2 - a good
1672approximation to the IEC standard for display systems (sRGB). If images are
1673too contrasty or washed out you got the value wrong - check your system
1674documentation!
1675
1676Many systems permit the system gamma to be changed via a lookup table in the
1677display driver, a few systems, including older Macs, change the response by
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001678default. As of 1.5.4 three special values are available to handle common
John Bowlercb0b2962011-05-12 21:48:29 -05001679situations:
1680
1681 PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
1682 standard. This matches almost all systems.
1683 PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6)
1684 Apple Macintosh system with the default settings.
1685 PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
1686 system expects data with no gamma encoding.
1687
1688You would use the linear (unencoded) value if you need to process the pixel
1689values further because this avoids the need to decode and reencode each
1690component value whenever arithmetic is performed. A lot of graphics software
1691uses linear values for this reason, often with higher precision component values
1692to preserve overall accuracy.
1693
1694The second thing you may need to tell libpng about is how your system handles
1695alpha channel information. Some, but not all, PNG files contain an alpha
1696channel. To display these files correctly you need to compose the data onto a
1697suitable background, as described in the PNG specification.
1698
1699Libpng only supports composing onto a single color (using png_set_background;
1700see below.) Otherwise you must do the composition yourself and, in this case,
1701you may need to call png_set_alpha_mode:
1702
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001703#if PNG_LIBPNG_VER >= 10504
John Bowlercb0b2962011-05-12 21:48:29 -05001704 png_set_alpha_mode(png_ptr, mode, screen_gamma);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001705#endif
John Bowlercb0b2962011-05-12 21:48:29 -05001706
1707The screen_gamma value is the same as the argument to png_set_gamma, however how
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001708it affects the output depends on the mode. png_set_alpha_mode() sets the file
John Bowlercb0b2962011-05-12 21:48:29 -05001709gamma default to 1/screen_gamma, so normally you don't need to call
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001710png_set_gamma. If you need different defaults call png_set_gamma() before
1711png_set_alpha_mode() - if you call it after it will override the settings made
1712by png_set_alpha_mode().
John Bowlercb0b2962011-05-12 21:48:29 -05001713
1714The mode is as follows:
1715
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001716 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
1717green and blue, or gray, components are gamma encoded color
1718values and are not premultiplied by the alpha value. The
1719alpha value is a linear measure of the contribution of the
1720pixel to the corresponding final output pixel.
John Bowlercb0b2962011-05-12 21:48:29 -05001721
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001722You should normally use this format if you intend to perform
1723color correction on the color values; most, maybe all, color
1724correction software has no handling for the alpha channel and,
1725anyway, the math to handle pre-multiplied component values is
1726unnecessarily complex.
John Bowlercb0b2962011-05-12 21:48:29 -05001727
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001728Before you do any arithmetic on the component values you need
1729to remove the gamma encoding and multiply out the alpha
1730channel. See the PNG specification for more detail. It is
1731important to note that when an image with an alpha channel is
1732scaled, linear encoded, pre-multiplied component values must
1733be used!
John Bowlercb0b2962011-05-12 21:48:29 -05001734
1735The remaining modes assume you don't need to do any further color correction or
1736that if you do your color correction software knows all about alpha (it
1737probably doesn't!)
1738
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001739 PNG_ALPHA_STANDARD: The data libpng produces is encoded in the standard way
1740assumed by most correctly written graphics software.
1741The gamma encoding will be removed by libpng and the
1742linear component values will be pre-multiplied by the
1743alpha channel.
John Bowlercb0b2962011-05-12 21:48:29 -05001744
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001745With this format the final image must be re-encoded to
1746match the display gamma before the image is displayed.
1747If your system doesn't do that, yet still seems to
1748perform arithmetic on the pixels without decoding them,
1749it is broken - check out the modes below.
John Bowlercb0b2962011-05-12 21:48:29 -05001750
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001751With PNG_ALPHA_STANDARD libpng always produces linear
1752component values, whatever screen_gamma you supply. The
1753screen_gamma value is, however, used as a default for
1754the file gamma if the PNG file has no gamma information.
John Bowlercb0b2962011-05-12 21:48:29 -05001755
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001756If you call png_set_gamma() after png_set_alpha_mode() you
1757will override the linear encoding. Instead the
1758pre-multiplied pixel values will be gamma encoded but
1759the alpha channel will still be linear. This may
1760actually match the requirements of some broken software,
1761but it is unlikely.
John Bowlercb0b2962011-05-12 21:48:29 -05001762
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001763While linear 8-bit data is often used it has
1764insufficient precision for any image with a reasonable
1765dynamic range. To avoid problems, and if your software
1766supports it, use png_set_expand_16() to force all
1767components to 16 bits.
John Bowlercb0b2962011-05-12 21:48:29 -05001768
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001769 PNG_ALPHA_OPTIMIZED: This mode is the same as PNG_ALPHA_STANDARD except that
1770completely opaque pixels are gamma encoded according to
1771the screen_gamma value. Pixels with alpha less than 1.0
1772will still have linear components.
John Bowlercb0b2962011-05-12 21:48:29 -05001773
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001774Use this format if you have control over your
1775compositing software and do don't do other arithmetic
1776(such as scaling) on the data you get from libpng. Your
1777compositing software can simply copy opaque pixels to
1778the output but still has linear values for the
1779non-opaque pixels.
John Bowlercb0b2962011-05-12 21:48:29 -05001780
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001781In normal compositing, where the alpha channel encodes
1782partial pixel coverage (as opposed to broad area
1783translucency), the inaccuracies of the 8-bit
1784representation of non-opaque pixels are irrelevant.
John Bowlercb0b2962011-05-12 21:48:29 -05001785
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001786You can also try this format if your software is broken;
1787it might look better.
John Bowlercb0b2962011-05-12 21:48:29 -05001788
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001789 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD however all component values,
1790including the alpha channel are gamma encoded. This is
1791an appropriate format to try if your software, or more
1792likely hardware, is totally broken: if it performs
1793linear arithmetic directly on gamma encoded values.
John Bowlercb0b2962011-05-12 21:48:29 -05001794
1795In most cases of broken software or hardware the bug in the final display
1796manifests as a subtle halo around composited parts of the image. You may not
1797even perceive this as a halo; the composited part of the image may simply appear
1798separate from the background, as though it had been cut out of paper and pasted
1799on afterward.
1800
1801If you don't have to deal with bugs in software or hardware, or if you can fix
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001802them, there are three recommended ways of using png_set_alpha_mode():
John Bowlercb0b2962011-05-12 21:48:29 -05001803
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001804 png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
1805 screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001806
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001807You can do color correction on the result (libpng does not currently
1808support color correction internally.) When you handle the alpha channel
1809you need to undo the gamma encoding and multiply out the alpha.
1810
1811 png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
1812 screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001813 png_set_expand_16(png_ptr);
John Bowlercb0b2962011-05-12 21:48:29 -05001814
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001815If you are using the high level interface don't call png_set_expand_16();
1816instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
John Bowlercb0b2962011-05-12 21:48:29 -05001817
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001818With this mode you can't do color correction, but you can do arithmetic,
1819including composition and scaling, on the data without further processing.
1820
1821 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1822 screen_gamma);
1823
1824You can avoid the expansion to 16-bit components with this mode, but you
1825lose the ability to scale the image or perform other linear arithmetic.
1826All you can do is compose the result onto a matching output. Since this
1827mode is libpng specific you also need to write your own composition
1828software.
John Bowlercb0b2962011-05-12 21:48:29 -05001829
1830If you don't need, or can't handle, the alpha channel you can call
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001831png_set_background() to remove it by compositing against a fixed color. Don't
1832call png_set_strip_alpha() to do this - it will leave spurious pixel values in
John Bowlercb0b2962011-05-12 21:48:29 -05001833transparent parts of this image.
1834
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001835 png_set_background(png_ptr, &background_color,
1836 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
John Bowlercb0b2962011-05-12 21:48:29 -05001837
1838The background_color is an RGB or grayscale value according to the data format
1839libpng will produce for you. Because you don't yet know the format of the PNG
1840file if you call png_set_background at this point you must arrange for the
1841format produced by libpng to always have 8-bit or 16-bit components and then
1842store the color as an 8-bit or 16-bit color as appropriate. The color contains
1843separate gray and RGB component values, so you can let libpng produce gray or
1844RGB output according to the input format, but low bit depth grayscale images
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05001845must always be converted to at least 8-bit format. (Even though low bit depth
John Bowlercb0b2962011-05-12 21:48:29 -05001846grayscale images can't have an alpha channel they can have a transparent
1847color!)
1848
1849You set the transforms you need later, either as flags to the high level
1850interface or libpng API calls for the low level interface. For reference the
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001851settings and API calls required are:
John Bowlercb0b2962011-05-12 21:48:29 -05001852
18538-bit values:
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001854 PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
1855 png_set_expand(png_ptr); png_set_scale_16(png_ptr);
John Bowlercb0b2962011-05-12 21:48:29 -05001856
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001857 If you must get exactly the same inaccurate results
1858 produced by default in versions prior to libpng-1.5.4,
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001859 use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001860 instead.
1861
John Bowlercb0b2962011-05-12 21:48:29 -0500186216-bit values:
1863 PNG_TRANSFORM_EXPAND_16
1864 png_set_expand_16(png_ptr);
1865
1866In either case palette image data will be expanded to RGB. If you just want
1867color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1868to the list.
1869
1870Calling png_set_background before the PNG file header is read will not work
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001871prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
John Bowlercb0b2962011-05-12 21:48:29 -05001872errors it is therefore much safer to call png_set_background after the head has
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001873been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
John Bowlercb0b2962011-05-12 21:48:29 -05001874used with the high level interface.
1875
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001876.SS The high-level read interface
1877
1878At this point there are two ways to proceed; through the high-level
1879read interface, or through a sequence of low-level read operations.
1880You can use the high-level interface if (a) you are willing to read
1881the entire image into memory, and (b) the input transformations
1882you want to do are limited to the following set:
1883
1884 PNG_TRANSFORM_IDENTITY No transformation
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001885 PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
1886 8-bit accurately
1887 PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
1888 8-bit less accurately
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001889 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001890 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1891 samples to bytes
1892 PNG_TRANSFORM_PACKSWAP Change order of packed
1893 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001894 PNG_TRANSFORM_EXPAND Perform set_expand()
1895 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001896 PNG_TRANSFORM_SHIFT Normalize pixels to the
1897 sBIT depth
1898 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1899 to BGRA
1900 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1901 to AG
1902 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1903 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001904 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05001905 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1906 to RGB (or GA to RGBA)
John Bowlera9b34192011-05-08 19:46:51 -05001907 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001908
1909(This excludes setting a background color, doing gamma transformation,
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05001910quantizing, and setting filler.) If this is the case, simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001911
1912 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1913
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001914where png_transforms is an integer containing the bitwise OR of some
1915set of transformation flags. This call is equivalent to png_read_info(),
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001916followed the set of transformations indicated by the transform mask,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001917then png_read_image(), and finally png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001918
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001919(The final parameter of this call is not yet used. Someday it might point
1920to transformation parameters required by some future input transform.)
1921
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001922You must use png_transforms and not call any png_set_transform() functions
1923when you use png_read_png().
1924
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001925After you have called png_read_png(), you can retrieve the image data
1926with
1927
1928 row_pointers = png_get_rows(png_ptr, info_ptr);
1929
1930where row_pointers is an array of pointers to the pixel data for each row:
1931
1932 png_bytep row_pointers[height];
1933
1934If you know your image size and pixel size ahead of time, you can allocate
1935row_pointers prior to calling png_read_png() with
1936
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001937 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001938 png_error (png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001939 "Image is too tall to process in memory");
1940
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001941 if (width > PNG_UINT_32_MAX/pixel_size)
1942 png_error (png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001943 "Image is too wide to process in memory");
1944
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001945 row_pointers = png_malloc(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001946 height*png_sizeof(png_bytep));
1947
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001948 for (int i=0; i<height, i++)
1949 row_pointers[i]=NULL; /* security precaution */
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001950
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001951 for (int i=0; i<height, i++)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001952 row_pointers[i]=png_malloc(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001953 width*pixel_size);
1954
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001955 png_set_rows(png_ptr, info_ptr, &row_pointers);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001956
1957Alternatively you could allocate your image in one big block and define
1958row_pointers[i] to point into the proper places in your block.
1959
1960If you use png_set_rows(), the application is responsible for freeing
1961row_pointers (and row_pointers[i], if they were separately allocated).
1962
1963If you don't allocate row_pointers ahead of time, png_read_png() will
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001964do it, and it'll be free'ed by libpng when you call png_destroy_*().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001965
1966.SS The low-level read interface
1967
1968If you are going the low-level route, you are now ready to read all
1969the file information up to the actual image data. You do this with a
1970call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001971
1972 png_read_info(png_ptr, info_ptr);
1973
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001974This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001975
John Bowlercb0b2962011-05-12 21:48:29 -05001976This also copies some of the data from the PNG file into the decode structure
1977for use in later transformations. Important information copied in is:
1978
19791) The PNG file gamma from the gAMA chunk. This overwrites the default value
1980provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1981
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -050019822) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
John Bowlercb0b2962011-05-12 21:48:29 -05001983damages the information provided by an earlier call to png_set_background
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05001984resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
John Bowlercb0b2962011-05-12 21:48:29 -05001985
19863) The number of significant bits in each component value. Libpng uses this to
1987optimize gamma handling by reducing the internal lookup table sizes.
1988
19894) The transparent color information from a tRNS chunk. This can be modified by
1990a later call to png_set_tRNS.
1991
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001992.SS Querying the info structure
1993
1994Functions are used to get the information from the info_ptr once it
1995has been read. Note that these fields may not be completely filled
1996in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001997
1998 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1999 &bit_depth, &color_type, &interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002000 &compression_type, &filter_method);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002001
2002 width - holds the width of the image
2003 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002004
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002005 height - holds the height of the image
2006 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002007
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002008 bit_depth - holds the bit depth of one of the
2009 image channels. (valid values are
2010 1, 2, 4, 8, 16 and depend also on
2011 the color_type. See also
2012 significant bits (sBIT) below).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002013
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002014 color_type - describes which color/alpha channels
2015 are present.
2016 PNG_COLOR_TYPE_GRAY
2017 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002018 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002019 (bit depths 8, 16)
2020 PNG_COLOR_TYPE_PALETTE
2021 (bit depths 1, 2, 4, 8)
2022 PNG_COLOR_TYPE_RGB
2023 (bit_depths 8, 16)
2024 PNG_COLOR_TYPE_RGB_ALPHA
2025 (bit_depths 8, 16)
2026
2027 PNG_COLOR_MASK_PALETTE
2028 PNG_COLOR_MASK_COLOR
2029 PNG_COLOR_MASK_ALPHA
2030
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002031 interlace_type - (PNG_INTERLACE_NONE or
2032 PNG_INTERLACE_ADAM7)
2033
2034 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
2035 for PNG 1.0)
2036
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002037 filter_method - (must be PNG_FILTER_TYPE_BASE
2038 for PNG 1.0, and can also be
2039 PNG_INTRAPIXEL_DIFFERENCING if
2040 the PNG datastream is embedded in
2041 a MNG-1.0 datastream)
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002042
2043 Any or all of interlace_type, compression_type, or
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002044 filter_method can be NULL if you are
2045 not interested in their values.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002046
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002047 Note that png_get_IHDR() returns 32-bit data into
2048 the application's width and height variables.
2049 This is an unsafe situation if these are 16-bit
2050 variables. In such situations, the
2051 png_get_image_width() and png_get_image_height()
2052 functions described below are safer.
2053
2054 width = png_get_image_width(png_ptr,
2055 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002056
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002057 height = png_get_image_height(png_ptr,
2058 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002059
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002060 bit_depth = png_get_bit_depth(png_ptr,
2061 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002062
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002063 color_type = png_get_color_type(png_ptr,
2064 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002065
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002066 interlace_type = png_get_interlace_type(png_ptr,
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002067 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002068
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002069 compression_type = png_get_compression_type(png_ptr,
2070 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002071
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002072 filter_method = png_get_filter_type(png_ptr,
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002073 info_ptr);
2074
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002075 channels = png_get_channels(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002076
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002077 channels - number of channels of info for the
2078 color type (valid values are 1 (GRAY,
2079 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
2080 4 (RGB_ALPHA or RGB + filler byte))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002081
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002082 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002083
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002084 rowbytes - number of bytes needed to hold a row
2085
2086 signature = png_get_signature(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002087
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002088 signature - holds the signature read from the
2089 file (if any). The data is kept in
2090 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002091 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002092 application had already read in 4
2093 bytes of signature before starting
2094 libpng, the remaining 4 bytes would
2095 be in signature[4] through signature[7]
2096 (see png_set_sig_bytes())).
2097
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002098These are also important, but their validity depends on whether the chunk
2099has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
2100png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
2101data has been read, or zero if it is missing. The parameters to the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002102png_get_<chunk> are set directly if they are simple data types, or a
2103pointer into the info_ptr is returned for any complex types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002104
2105 png_get_PLTE(png_ptr, info_ptr, &palette,
2106 &num_palette);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002107
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002108 palette - the palette for the file
2109 (array of png_color)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002110
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002111 num_palette - number of entries in the palette
2112
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002113 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
Glenn Randers-Pehrson27742382011-01-27 09:37:34 -06002114 png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002115
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002116 file_gamma - the gamma at which the file is
2117 written (PNG_INFO_gAMA)
2118
2119 int_file_gamma - 100,000 times the gamma at which the
2120 file is written
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002121
2122 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002123
Glenn Randers-Pehrson27742382011-01-27 09:37:34 -06002124 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002125 The presence of the sRGB chunk
2126 means that the pixel data is in the
2127 sRGB color space. This chunk also
2128 implies specific values of gAMA and
2129 cHRM.
2130
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002131 png_get_iCCP(png_ptr, info_ptr, &name,
2132 &compression_type, &profile, &proflen);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002133
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002134 name - The profile name.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002135
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002136 compression_type - The compression type; always
2137 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2138 You may give NULL to this argument to
2139 ignore it.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002140
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002141 profile - International Color Consortium color
2142 profile data. May contain NULs.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002143
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002144 proflen - length of profile data in bytes.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002145
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002146 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002147
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002148 sig_bit - the number of significant bits for
2149 (PNG_INFO_sBIT) each of the gray,
2150 red, green, and blue channels,
2151 whichever are appropriate for the
2152 given color type (png_color_16)
2153
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002154 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
2155 &num_trans, &trans_color);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002156
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002157 trans_alpha - array of alpha (transparency)
2158 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002159
Glenn Randers-Pehrsonf3c51e42011-01-15 10:25:25 -06002160 num_trans - number of transparent entries
2161 (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002162
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05002163 trans_color - graylevel or color sample values of
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05002164 the single transparent color for
2165 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002166
2167 png_get_hIST(png_ptr, info_ptr, &hist);
2168 (PNG_INFO_hIST)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002169
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002170 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002171 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002172
2173 png_get_tIME(png_ptr, info_ptr, &mod_time);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002174
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002175 mod_time - time image was last modified
2176 (PNG_VALID_tIME)
2177
2178 png_get_bKGD(png_ptr, info_ptr, &background);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002179
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002180 background - background color (of type
2181 png_color_16p) (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002182 valid 16-bit red, green and blue
2183 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002184
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002185 num_comments = png_get_text(png_ptr, info_ptr,
2186 &text_ptr, &num_text);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002187
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002188 num_comments - number of comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002189
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002190 text_ptr - array of png_text holding image
2191 comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002192
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002193 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002194 on "text" PNG_TEXT_COMPRESSION_NONE
2195 PNG_TEXT_COMPRESSION_zTXt
2196 PNG_ITXT_COMPRESSION_NONE
2197 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002198
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002199 text_ptr[i].key - keyword for comment. Must contain
2200 1-79 characters.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002201
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002202 text_ptr[i].text - text comments for current
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002203 keyword. Can be empty.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002204
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002205 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002206 after decompression, 0 for iTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002207
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002208 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002209 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002210
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002211 text_ptr[i].lang - language of comment (empty
2212 string for unknown).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002213
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06002214 text_ptr[i].lang_key - keyword in UTF-8
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002215 (empty string for unknown).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002216
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002217 Note that the itxt_length, lang, and lang_key
2218 members of the text_ptr structure only exist
2219 when the library is built with iTXt chunk support.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002220 Prior to libpng-1.4.0, the default build was
Glenn Randers-Pehrsond4e1ddb2011-07-27 20:09:57 -05002221 without iTXt chunk support.
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002222
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002223 num_text - number of comments (same as
2224 num_comments; you can put NULL here
2225 to avoid the duplication)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002226
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002227 Note while png_set_text() will accept text, language,
2228 and translated keywords that can be NULL pointers, the
2229 structure returned by png_get_text will always contain
2230 regular zero-terminated C strings. They might be
2231 empty strings but they will never be NULL pointers.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002232
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002233 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
2234 &palette_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002235
2236 num_spalettes - number of sPLT chunks read.
2237
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002238 palette_ptr - array of palette structures holding
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002239 contents of one or more sPLT chunks
2240 read.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002241
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002242 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002243 &unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002244
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002245 offset_x - positive offset from the left edge
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002246 of the screen (can be negative)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002247
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002248 offset_y - positive offset from the top edge
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002249 of the screen (can be negative)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002250
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002251 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2252
2253 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002254 &unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002255
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002256 res_x - pixels/unit physical resolution in
2257 x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002258
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002259 res_y - pixels/unit physical resolution in
2260 x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002261
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002262 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002263 PNG_RESOLUTION_METER
2264
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002265 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
2266 &height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002267
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002268 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002269
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002270 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002271
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002272 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002273 (width and height are doubles)
2274
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002275 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
2276 &height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002277
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002278 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002279
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002280 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002281 (expressed as a string)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002282
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002283 height - height of a pixel in physical scale units
2284 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002285
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002286 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
2287 info_ptr, &unknowns)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002288
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002289 unknowns - array of png_unknown_chunk
2290 structures holding unknown chunks
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002291
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002292 unknowns[i].name - name of unknown chunk
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002293
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002294 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002295
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002296 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002297
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002298 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002299
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002300 The value of "i" corresponds to the order in which the
2301 chunks were read from the PNG file or inserted with the
2302 png_set_unknown_chunks() function.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002303
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002304 The value of "location" is a bitwise "or" of
2305
2306 PNG_HAVE_IHDR (0x01)
2307 PNG_HAVE_PLTE (0x02)
2308 PNG_AFTER_IDAT (0x08)
2309
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002310The data from the pHYs chunk can be retrieved in several convenient
2311forms:
2312
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002313 res_x = png_get_x_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002314 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002315
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002316 res_y = png_get_y_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002317 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002318
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002319 res_x_and_y = png_get_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002320 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002321
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002322 res_x = png_get_x_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002323 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002324
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002325 res_y = png_get_y_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002326 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002327
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002328 res_x_and_y = png_get_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002329 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002330
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002331 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002332 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002333
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002334 Each of these returns 0 [signifying "unknown"] if
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002335 the data is not present or if res_x is 0;
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002336 res_x_and_y is 0 if res_x != res_y
2337
2338 Note that because of the way the resolutions are
2339 stored internally, the inch conversions won't
2340 come out to exactly even number. For example,
2341 72 dpi is stored as 0.28346 pixels/meter, and
2342 when this is retrieved it is 71.9988 dpi, so
2343 be sure to round the returned value appropriately
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002344 if you want to display a reasonable-looking result.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002345
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002346The data from the oFFs chunk can be retrieved in several convenient
2347forms:
2348
2349 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002350
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002351 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002352
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002353 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002354
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002355 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
2356
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002357 Each of these returns 0 [signifying "unknown" if both
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002358 x and y are 0] if the data is not present or if the
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002359 chunk is present but the unit is the pixel. The
2360 remark about inexact inch conversions applies here
2361 as well, because a value in inches can't always be
2362 converted to microns and back without some loss
2363 of precision.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002364
John Bowlercb0b2962011-05-12 21:48:29 -05002365For more information, see the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002366PNG specification for chunk contents. Be careful with trusting
2367rowbytes, as some of the transformations could increase the space
2368needed to hold a row (expand, filler, gray_to_rgb, etc.).
2369See png_read_update_info(), below.
2370
2371A quick word about text_ptr and num_text. PNG stores comments in
2372keyword/text pairs, one pair per chunk, with no limit on the number
2373of text chunks, and a 2^31 byte limit on their size. While there are
2374suggested keywords, there is no requirement to restrict the use to these
2375strings. It is strongly suggested that keywords and text be sensible
2376to humans (that's the point), so don't use abbreviations. Non-printing
2377symbols are not allowed. See the PNG specification for more details.
2378There is also no requirement to have text after the keyword.
2379
2380Keywords should be limited to 79 Latin-1 characters without leading or
2381trailing spaces, but non-consecutive spaces are allowed within the
2382keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002383The text_ptr is an array of png_text structures, each holding a
2384pointer to a language string, a pointer to a keyword and a pointer to
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002385a text string. The text string, language code, and translated
2386keyword may be empty or NULL pointers. The keyword/text
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002387pairs are put into the array in the order that they are received.
2388However, some or all of the text chunks may be after the image, so, to
2389make sure you have read all the text chunks, don't mess with these
2390until after you read the stuff after the image. This will be
2391mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002392
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002393.SS Input transformations
2394
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002395After you've read the header information, you can set up the library
2396to handle any special transformations of the image data. The various
2397ways to transform the data will be described in the order that they
2398should occur. This is important, as some of these change the color
2399type and/or bit depth of the data, and some others only work on
John Bowlercb0b2962011-05-12 21:48:29 -05002400certain color types and bit depths.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002401
John Bowlercb0b2962011-05-12 21:48:29 -05002402Transformations you request are ignored if they don't have any meaning for a
2403particular input data format. However some transformations can have an effect
2404as a result of a previous transformation. If you specify a contradictory set of
2405transformations, for example both adding and removing the alpha channel, you
2406cannot predict the final result.
2407
2408The color used for the transparency values should be supplied in the same
2409format/depth as the current image data. It is stored in the same format/depth
2410as the image data in a tRNS chunk, so this is what libpng expects for this data.
2411
2412The color used for the background value depends on the need_expand argument as
2413described below.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002414
2415Data will be decoded into the supplied row buffers packed into bytes
2416unless the library has been told to transform it into another format.
2417For example, 4 bit/pixel paletted or grayscale data will be returned
24182 pixels/byte with the leftmost pixel in the high-order bits of the
2419byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002420in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2421is called to insert filler bytes, either before or after each RGB triplet.
242216-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002423byte of the color value first, unless png_set_scale_16() is called to
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06002424transform it to regular RGB RGB triplets, or png_set_filler() or
2425png_set_add alpha() is called to insert filler bytes, either before or
2426after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002427be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2428or png_set_scale_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002429
2430The following code transforms grayscale images of less than 8 to 8 bits,
2431changes paletted images to RGB, and adds a full alpha channel if there is
2432transparency information in a tRNS chunk. This is most useful on
2433grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2434viewing application that wishes to treat all images in the same way.
2435
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002436 if (color_type == PNG_COLOR_TYPE_PALETTE)
2437 png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002438
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002439 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002440 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2441
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002442 if (color_type == PNG_COLOR_TYPE_GRAY &&
2443 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2444
2445The first two functions are actually aliases for png_set_expand(), added
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002446in libpng version 1.0.4, with the function names expanded to improve code
2447readability. In some future version they may actually do different
2448things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002449
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06002450As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2451added. It expands the sample depth without changing tRNS to alpha.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002452
John Bowler63d059a2011-02-12 09:03:44 -06002453As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002454png_set_expand(); however, the resultant channels have 16 bits rather than 8.
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002455Use this when the output color or gray channels are made linear to avoid fairly
John Bowler63d059a2011-02-12 09:03:44 -06002456severe accuracy loss.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002457
John Bowler63d059a2011-02-12 09:03:44 -06002458 if (bit_depth < 16)
2459 png_set_expand_16(png_ptr);
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06002460
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002461PNG can have files with 16 bits per channel. If you only can handle
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -050024628 bits per channel, this will strip the pixels down to 8-bit.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002463
2464 if (bit_depth == 16)
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002465#if PNG_LIBPNG_VER >= 10504
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002466 png_set_scale_16(png_ptr);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002467#else
2468 png_set_strip_16(png_ptr);
2469#endif
2470
2471(The more accurate "png_set_scale_16()" API became available in libpng version
24721.5.4).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002473
John Bowlercb0b2962011-05-12 21:48:29 -05002474If you need to process the alpha channel on the image separately from the image
2475data (for example if you convert it to a bitmap mask) it is possible to have
2476libpng strip the channel leaving just RGB or gray data:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002477
2478 if (color_type & PNG_COLOR_MASK_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002479 png_set_strip_alpha(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002480
John Bowlercb0b2962011-05-12 21:48:29 -05002481If you strip the alpha channel you need to find some other way of dealing with
2482the information. If, instead, you want to convert the image to an opaque
2483version with no alpha channel use png_set_background; see below.
John Bowler63d059a2011-02-12 09:03:44 -06002484
2485As of libpng version 1.5.2, almost all useful expansions are supported, the
Glenn Randers-Pehrsoncd116fa2011-05-17 06:56:50 -05002486major ommissions are conversion of grayscale to indexed images (which can be
2487done trivially in the application) and conversion of indexed to grayscale (which
John Bowler63d059a2011-02-12 09:03:44 -06002488can be done by a trivial manipulation of the palette.)
2489
2490In the following table, the 01 means grayscale with depth<8, 31 means
2491indexed with depth<8, other numerals represent the color type, "T" means
2492the tRNS chunk is present, A means an alpha channel is present, and O
2493means tRNS or alpha is present but all pixels in the image are opaque.
2494
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002495 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
John Bowler63d059a2011-02-12 09:03:44 -06002496 TO
2497 01 - [G] - - - - - - - - - - - - -
2498 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
2499 0 1 G + . . G G G G G G B B GB GB
2500 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
2501 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
2502 2 C P C C C + . . C - - CB CB B B
2503 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
2504 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
2505 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
2506 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
2507 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
2508 4A lA G A T T GA GT GT GA GT GT + BA G GBA
2509 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
2510 6A CA PA CA C C A T tT PA P P C CBA + BA
2511 6O CA PBA CA C C A tT T PA P P CBA C BA +
2512
2513Within the matrix,
2514 "+" identifies entries where 'from' and 'to' are the same.
2515 "-" means the transformation is not supported.
2516 "." means nothing is necessary (a tRNS chunk can just be ignored).
2517 "t" means the transformation is obtained by png_set_tRNS.
2518 "A" means the transformation is obtained by png_set_add_alpha().
2519 "X" means the transformation is obtained by png_set_expand().
2520 "1" means the transformation is obtained by
2521 png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() if there
2522 is no transparency in the original or the final format).
2523 "C" means the transformation is obtained by png_set_gray_to_rgb().
Glenn Randers-Pehrsonc36074e2011-05-16 09:08:51 -05002524 "G" means the transformation is obtained by png_set_rgb_to_gray().
John Bowler63d059a2011-02-12 09:03:44 -06002525 "P" means the transformation is obtained by
2526 png_set_expand_palette_to_rgb().
2527 "p" means the transformation is obtained by png_set_packing().
2528 "Q" means the transformation is obtained by png_set_quantize().
2529 "T" means the transformation is obtained by png_set_tRNS_to_alpha().
2530 "B" means the transformation is obtained by png_set_background(), or
2531 png_strip_alpha().
John Bowler63d059a2011-02-12 09:03:44 -06002532
2533When an entry has multiple transforms listed all are required to cause the
2534right overall transformation. When two transforms are separated by a comma
2535either will do the job. When transforms are enclosed in [] the transform should
2536do the job but this is currently unimplemented - a different format will result
2537if the suggested transformations are used.
2538
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002539In PNG files, the alpha channel in an image
2540is the level of opacity. If you need the alpha channel in an image to
2541be the level of transparency instead of opacity, you can invert the
2542alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2543fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2544images) is fully transparent, with
2545
2546 png_set_invert_alpha(png_ptr);
2547
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002548PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2549they can, resulting in, for example, 8 pixels per byte for 1 bit
2550files. This code expands to 1 pixel per byte without changing the
2551values of the pixels:
2552
2553 if (bit_depth < 8)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002554 png_set_packing(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002555
2556PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
2557stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002558higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2559to 8 bits/sample in the range [0, 255]). However, it is also possible
2560to convert the PNG pixel data back to the original bit depth of the
2561image. This call reduces the pixels back down to the original bit depth:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002562
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05002563 png_color_8p sig_bit;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002564
2565 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002566 png_set_shift(png_ptr, sig_bit);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002567
2568PNG files store 3-color pixels in red, green, blue order. This code
2569changes the storage of the pixels to blue, green, red:
2570
2571 if (color_type == PNG_COLOR_TYPE_RGB ||
2572 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002573 png_set_bgr(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002574
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002575PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2576into 4 or 8 bytes for windowing systems that need them in this format:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002577
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002578 if (color_type == PNG_COLOR_TYPE_RGB)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002579 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002580
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002581where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002582either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2583you want the filler before the RGB or after. This transformation
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002584does not affect images that already have full alpha channels. To add an
2585opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2586will generate RGBA pixels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002587
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002588Note that png_set_filler() does not change the color type. If you want
2589to do that, you can add a true alpha channel with
2590
2591 if (color_type == PNG_COLOR_TYPE_RGB ||
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002592 color_type == PNG_COLOR_TYPE_GRAY)
2593 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002594
2595where "filler" contains the alpha value to assign to each pixel.
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06002596This function was added in libpng-1.2.7.
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002597
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002598If you are reading an image with an alpha channel, and you need the
2599data as ARGB instead of the normal PNG format RGBA:
2600
2601 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002602 png_set_swap_alpha(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002603
2604For some uses, you may want a grayscale image to be represented as
2605RGB. This code will do that conversion:
2606
2607 if (color_type == PNG_COLOR_TYPE_GRAY ||
2608 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002609 png_set_gray_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002610
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002611Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002612with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002613
2614 if (color_type == PNG_COLOR_TYPE_RGB ||
2615 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
John Bowlercb0b2962011-05-12 21:48:29 -05002616 png_set_rgb_to_gray(png_ptr, error_action, double red_weight,
2617 double green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002618
2619 error_action = 1: silently do the conversion
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002620
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002621 error_action = 2: issue a warning if the original
2622 image has any pixel where
2623 red != green or red != blue
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002624
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002625 error_action = 3: issue an error and abort the
2626 conversion if the original
2627 image has any pixel where
2628 red != green or red != blue
2629
John Bowlercb0b2962011-05-12 21:48:29 -05002630 red_weight: weight of red component
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002631
John Bowlercb0b2962011-05-12 21:48:29 -05002632 green_weight: weight of green component
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002633 If either weight is negative, default
John Bowlercb0b2962011-05-12 21:48:29 -05002634 weights are used.
2635
2636In the corresponding fixed point API the red_weight and green_weight values are
2637simply scaled by 100,000:
2638
2639 png_set_rgb_to_gray(png_ptr, error_action, png_fixed_point red_weight,
2640 png_fixed_point green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002641
2642If you have set error_action = 1 or 2, you can
2643later check whether the image really was gray, after processing
2644the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2645It will return a png_byte that is zero if the image was gray or
John Bowlercb0b2962011-05-12 21:48:29 -050026461 if there were any non-gray pixels. Background and sBIT data
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002647will be silently converted to grayscale, using the green channel
John Bowlercb0b2962011-05-12 21:48:29 -05002648data for sBIT, regardless of the error_action setting.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002649
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002650The default values come from the PNG file cHRM chunk if present; otherwise, the
John Bowlercb0b2962011-05-12 21:48:29 -05002651defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2652space, as recommended in the Charles Poynton's Colour FAQ,
2653<http://www.poynton.com/>, in section 9:
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002654
John Bowlercb0b2962011-05-12 21:48:29 -05002655 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002656
Glenn Randers-Pehrson6c988972011-07-29 12:31:16 -05002657 Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
2658
2659Previous versions of this document, 1998 through 2002, recommended a slightly
2660different formula:
2661
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002662 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2663
Glenn Randers-Pehrson6c988972011-07-29 12:31:16 -05002664Libpng uses an integer approximation:
2665
2666 Y = (6968 * R + 23434 * G + 2366 * B)/32768
2667
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002668The calculation is done in a linear colorspace, if the image gamma
Glenn Randers-Pehrson9962b842011-01-24 00:12:14 -06002669can be determined.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002670
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002671The png_set_background() function has been described already; it tells libpng to
John Bowlercb0b2962011-05-12 21:48:29 -05002672composite images with alpha or simple transparency against the supplied
2673background color. For compatibility with versions of libpng earlier than
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05002674libpng-1.5.4 it is recommended that you call the function after reading the file
John Bowlercb0b2962011-05-12 21:48:29 -05002675header, even if you don't want to use the color in a bKGD chunk, if one exists.
2676
2677If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2678you may use this color, or supply another color more suitable for
2679the current display (e.g., the background color from a web page). You
2680need to tell libpng how the color is represented, both the format of the
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002681component values in the color (the number of bits) and the gamma encoding of the
John Bowlercb0b2962011-05-12 21:48:29 -05002682color. The function takes two arguments, background_gamma_mode and need_expand
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002683to convey this information, however only two combinations are likely to be
2684useful:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002685
Glenn Randers-Pehrsoncb47e202011-07-10 06:55:14 -05002686 png_color_16 my_background;
2687 png_color_16p image_background;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002688
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002689 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002690 png_set_background(png_ptr, image_background,
John Bowlercb0b2962011-05-12 21:48:29 -05002691 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002692 else
Glenn Randers-Pehrsoncb47e202011-07-10 06:55:14 -05002693 png_set_background(png_ptr, &my_background,
John Bowlercb0b2962011-05-12 21:48:29 -05002694 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002695
John Bowlercb0b2962011-05-12 21:48:29 -05002696The second call was described above - my_background is in the format of the
2697final, display, output produced by libpng. Because you now know the format of
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05002698the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2699output and to retain palette images (the palette colors will be modified
2700appropriately and the tRNS chunk removed.) However, if you are doing this,
2701take great care not to ask for transformations without checking first that
2702they apply!
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002703
John Bowlercb0b2962011-05-12 21:48:29 -05002704In the first call the background color has the original bit depth and color type
2705of the PNG file. So, for palette images the color is supplied as a palette
2706index and for low bit greyscale images the color is a reduced bit value in
2707image_background->gray.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002708
John Bowlercb0b2962011-05-12 21:48:29 -05002709If you didn't call png_set_gamma() before reading the file header, for example
2710if you need your code to remain compatible with older versions of libpng prior
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05002711to libpng-1.5.4, this is the place to call it.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002712
John Bowlercb0b2962011-05-12 21:48:29 -05002713Do not call it if you called png_set_alpha_mode(); doing so will damage the
2714settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
2715supported then you can certainly do png_set_gamma() before reading the PNG
2716header.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002717
Glenn Randers-Pehrsonc7822512011-05-07 21:23:43 -05002718This API unconditionally sets the screen and file gamma values, so it will
2719override the value in the PNG file unless it is called before the PNG file
2720reading starts. For this reason you must always call it with the PNG file
2721value when you call it in this position:
2722
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002723 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
2724 png_set_gamma(png_ptr, screen_gamma, file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002725
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002726 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002727 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002728
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002729If you need to reduce an RGB file to a paletted file, or if a paletted
2730file has more entries then will fit on your screen, png_set_quantize()
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -05002731will do that. Note that this is a simple match quantization that merely
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002732finds the closest color available. This should work fairly well with
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002733optimized palettes, but fairly badly with linear color cubes. If you
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002734pass a palette that is larger than maximum_colors, the file will
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002735reduce the number of colors in the palette so it will fit into
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002736maximum_colors. If there is a histogram, libpng will use it to make
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002737more intelligent choices when reducing the palette. If there is no
2738histogram, it may not do as good a job.
2739
2740 if (color_type & PNG_COLOR_MASK_COLOR)
2741 {
2742 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002743 PNG_INFO_PLTE))
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002744 {
2745 png_uint_16p histogram = NULL;
2746
2747 png_get_hIST(png_ptr, info_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002748 &histogram);
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002749 png_set_quantize(png_ptr, palette, num_palette,
2750 max_screen_colors, histogram, 1);
2751 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002752
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002753 else
2754 {
2755 png_color std_color_cube[MAX_SCREEN_COLORS] =
2756 { ... colors ... };
2757
2758 png_set_quantize(png_ptr, std_color_cube,
2759 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2760 NULL,0);
2761 }
2762 }
2763
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002764PNG files describe monochrome as black being zero and white being one.
2765The following code will reverse this (make black be one and white be
2766zero):
2767
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05002768 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2769 png_set_invert_mono(png_ptr);
2770
2771This function can also be used to invert grayscale and gray-alpha images:
2772
2773 if (color_type == PNG_COLOR_TYPE_GRAY ||
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002774 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002775 png_set_invert_mono(png_ptr);
2776
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05002777PNG files store 16-bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002778ie. most significant bits first). This code changes the storage to the
2779other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002780way PCs store them):
2781
2782 if (bit_depth == 16)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002783 png_set_swap(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002784
2785If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2786need to change the order the pixels are packed into bytes, you can use:
2787
2788 if (bit_depth < 8)
2789 png_set_packswap(png_ptr);
2790
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002791Finally, you can write your own transformation function if none of
2792the existing ones meets your needs. This is done by setting a callback
2793with
2794
2795 png_set_read_user_transform_fn(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002796 read_transform_fn);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002797
2798You must supply the function
2799
Glenn Randers-Pehrson93215672011-02-13 19:42:19 -06002800 void read_transform_fn(png_structp png_ptr, png_row_infop
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002801 row_info, png_bytep data)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002802
2803See pngtest.c for a working example. Your function will be called
John Bowlerf19abd62011-01-22 18:29:24 -06002804after all of the other transformations have been processed. Take care with
2805interlaced images if you do the interlace yourself - the width of the row is the
2806width in 'row_info', not the overall image width.
2807
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002808If supported, libpng provides two information routines that you can use to find
John Bowlerf19abd62011-01-22 18:29:24 -06002809where you are in processing the image:
2810
2811 png_get_current_pass_number(png_structp png_ptr);
2812 png_get_current_row_number(png_structp png_ptr);
2813
2814Don't try using these outside a transform callback - firstly they are only
2815supported if user transforms are supported, secondly they may well return
2816unexpected results unless the row is actually being processed at the moment they
2817are called.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002818
John Bowlercd113452011-02-16 06:15:13 -06002819With interlaced
2820images the value returned is the row in the input sub-image image. Use
2821PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2822find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2823
2824The discussion of interlace handling above contains more information on how to
2825use these values.
2826
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002827You can also set up a pointer to a user structure for use by your
2828callback function, and you can inform libpng that your transform
2829function will change the number of channels or bit depth with the
2830function
2831
2832 png_set_user_transform_info(png_ptr, user_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002833 user_depth, user_channels);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002834
2835The user's application, not libpng, is responsible for allocating and
2836freeing any memory required for the user structure.
2837
2838You can retrieve the pointer via the function
2839png_get_user_transform_ptr(). For example:
2840
2841 voidp read_user_transform_ptr =
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002842 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002843
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002844The last thing to handle is interlacing; this is covered in detail below,
2845but you must call the function here if you want libpng to handle expansion
2846of the interlaced image.
2847
2848 number_of_passes = png_set_interlace_handling(png_ptr);
2849
2850After setting the transformations, libpng can update your png_info
2851structure to reflect any transformations you've requested with this
2852call. This is most useful to update the info structure's rowbytes
2853field so you can use it to allocate your image memory. This function
2854will also update your palette with the correct screen_gamma and
2855background if these have been given with the calls above.
2856
2857 png_read_update_info(png_ptr, info_ptr);
2858
2859After you call png_read_update_info(), you can allocate any
2860memory you need to hold the image. The row data is simply
2861raw byte data for all forms of images. As the actual allocation
2862varies among applications, no example will be given. If you
2863are allocating one large chunk, you will need to build an
2864array of pointers to each row, as it will be needed for some
2865of the functions below.
2866
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002867Remember: Before you call png_read_update_info(), the png_get_
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002868functions return the values corresponding to the original PNG image.
2869After you call png_read_update_info the values refer to the image
2870that libpng will output. Consequently you must call all the png_set_
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002871functions before you call png_read_update_info(). This is particularly
2872important for png_set_interlace_handling() - if you are going to call
2873png_read_update_info() you must call png_set_interlace_handling() before
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002874it unless you want to receive interlaced output.
2875
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002876.SS Reading image data
2877
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002878After you've allocated memory, you can read the image data.
2879The simplest way to do this is in one function call. If you are
2880allocating enough memory to hold the whole image, you can just
2881call png_read_image() and libpng will read in all the image data
2882and put it in the memory area supplied. You will need to pass in
2883an array of pointers to each row.
2884
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002885This function automatically handles interlacing, so you don't
2886need to call png_set_interlace_handling() (unless you call
2887png_read_update_info()) or call this function multiple times, or any
2888of that other stuff necessary with png_read_rows().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002889
2890 png_read_image(png_ptr, row_pointers);
2891
2892where row_pointers is:
2893
2894 png_bytep row_pointers[height];
2895
2896You can point to void or char or whatever you use for pixels.
2897
2898If you don't want to read in the whole image at once, you can
2899use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002900interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002901
2902 png_read_rows(png_ptr, row_pointers, NULL,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002903 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002904
2905where row_pointers is the same as in the png_read_image() call.
2906
2907If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002908a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002909
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002910 png_bytep row_pointer = row;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002911 png_read_row(png_ptr, row_pointer, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002912
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002913If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2914get somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002915interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
2916a somewhat complicated 2D interlace scheme, known as Adam7, that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002917breaks down an image into seven smaller images of varying size, based
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002918on an 8x8 grid. This number is defined (from libpng 1.5) as
2919PNG_INTERLACE_ADAM7_PASSES in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002920
2921libpng can fill out those images or it can give them to you "as is".
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002922It is almost always better to have libpng handle the interlacing for you.
2923If you want the images filled out, there are two ways to do that. The one
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002924mentioned in the PNG specification is to expand each pixel to cover
2925those pixels that have not been read yet (the "rectangle" method).
2926This results in a blocky image for the first pass, which gradually
2927smooths out as more pixels are read. The other method is the "sparkle"
2928method, where pixels are drawn only in their final locations, with the
2929rest of the image remaining whatever colors they were initialized to
2930before the start of the read. The first method usually looks better,
2931but tends to be slower, as there are more pixels to put in the rows.
2932
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002933If, as is likely, you want libpng to expand the images, call this before
2934calling png_start_read_image() or png_read_update_info():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002935
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002936 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002937 number_of_passes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002938 = png_set_interlace_handling(png_ptr);
2939
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002940This will return the number of passes needed. Currently, this is seven,
2941but may change if another interlace type is added. This function can be
2942called even if the file is not interlaced, where it will return one pass.
2943You then need to read the whole image 'number_of_passes' times. Each time
2944will distribute the pixels from the current pass to the correct place in
2945the output image, so you need to supply the same rows to png_read_rows in
2946each pass.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05002947
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002948If you are not going to display the image after each pass, but are
2949going to wait until the entire image is read in, use the sparkle
2950effect. This effect is faster and the end result of either method
2951is exactly the same. If you are planning on displaying the image
2952after each pass, the "rectangle" effect is generally considered the
2953better looking one.
2954
2955If you only want the "sparkle" effect, just call png_read_rows() as
2956normal, with the third parameter NULL. Make sure you make pass over
2957the image number_of_passes times, and you don't change the data in the
2958rows between calls. You can change the locations of the data, just
2959not the data. Each pass only writes the pixels appropriate for that
2960pass, and assumes the data from previous passes is still valid.
2961
2962 png_read_rows(png_ptr, row_pointers, NULL,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002963 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002964
2965If you only want the first effect (the rectangles), do the same as
2966before except pass the row buffer in the third parameter, and leave
2967the second parameter NULL.
2968
2969 png_read_rows(png_ptr, NULL, row_pointers,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002970 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002971
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002972If you don't want libpng to handle the interlacing details, just call
2973png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
2974Each of the images is a valid image by itself, however you will almost
2975certainly need to distribute the pixels from each sub-image to the
2976correct place. This is where everything gets very tricky.
2977
2978If you want to retrieve the separate images you must pass the correct
2979number of rows to each successive call of png_read_rows(). The calculation
2980gets pretty complicated for small images, where some sub-images may
2981not even exist because either their width or height ends up zero.
2982libpng provides two macros to help you in 1.5 and later versions:
2983
2984 png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
2985 png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
2986
2987Respectively these tell you the width and height of the sub-image
2988corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
2989this can be confusing because the specification refers to the same passes
2990as 1 to 7! Be careful, you must check both the width and height before
2991calling png_read_rows() and not call it for that pass if either is zero.
2992
2993You can, of course, read each sub-image row by row. If you want to
2994produce optimal code to make a pixel-by-pixel transformation of an
2995interlaced image this is the best approach; read each row of each pass,
2996transform it, and write it out to a new interlaced image.
2997
2998If you want to de-interlace the image yourself libpng provides further
2999macros to help that tell you where to place the pixels in the output image.
3000Because the interlacing scheme is rectangular - sub-image pixels are always
3001arranged on a rectangular grid - all you need to know for each pass is the
3002starting column and row in the output image of the first pixel plus the
3003spacing between each pixel. As of libpng 1.5 there are four macros to
3004retrieve this information:
3005
3006 png_uint_32 x = PNG_PASS_START_COL(pass);
3007 png_uint_32 y = PNG_PASS_START_ROW(pass);
3008 png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
3009 png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
3010
3011These allow you to write the obvious loop:
3012
3013 png_uint_32 input_y = 0;
3014 png_uint_32 output_y = PNG_PASS_START_ROW(pass);
3015
3016 while (output_y < output_image_height)
3017 {
3018 png_uint_32 input_x = 0;
3019 png_uint_32 output_x = PNG_PASS_START_COL(pass);
3020
3021 while (output_x < output_image_width)
3022 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003023 image[output_y][output_x] =
3024 subimage[pass][input_y][input_x++];
3025
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003026 output_x += xStep;
3027 }
3028
3029 ++input_y;
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003030 output_y += yStep;
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003031 }
3032
3033Notice that the steps between successive output rows and columns are
3034returned as shifts. This is possible because the pixels in the subimages
3035are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
3036image. In practice you may need to directly calculate the output coordinate
3037given an input coordinate. libpng provides two further macros for this
3038purpose:
3039
3040 png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
3041 png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
3042
3043Finally a pair of macros are provided to tell you if a particular image
3044row or column appears in a given pass:
3045
3046 int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
3047 int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
3048
3049Bear in mind that you will probably also need to check the width and height
3050of the pass in addition to the above to be sure the pass even exists!
3051
3052With any luck you are convinced by now that you don't want to do your own
3053interlace handling. In reality normally the only good reason for doing this
3054is if you are processing PNG files on a pixel-by-pixel basis and don't want
3055to load the whole file into memory when it is interlaced.
3056
3057libpng includes a test program, pngvalid, that illustrates reading and
3058writing of interlaced images. If you can't get interlacing to work in your
3059code and don't want to leave it to libpng (the recommended approach) see
3060how pngvalid.c does it.
3061
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003062.SS Finishing a sequential read
3063
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003064After you are finished reading the image through the
3065low-level interface, you can finish reading the file. If you are
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003066interested in comments or time, which may be stored either before or
3067after the image data, you should pass the separate png_info struct if
3068you want to keep the comments from before and after the image
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003069separate.
3070
3071 png_infop end_info = png_create_info_struct(png_ptr);
3072
3073 if (!end_info)
3074 {
3075 png_destroy_read_struct(&png_ptr, &info_ptr,
3076 (png_infopp)NULL);
3077 return (ERROR);
3078 }
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003079
3080 png_read_end(png_ptr, end_info);
3081
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003082If you are not interested, you should still call png_read_end()
3083but you can pass NULL, avoiding the need to create an end_info structure.
3084
3085 png_read_end(png_ptr, (png_infop)NULL);
3086
Glenn Randers-Pehrson99778e12011-04-20 17:43:52 -05003087If you don't call png_read_end(), then your file pointer will be
3088left pointing to the first chunk after the last IDAT, which is probably
3089not what you want if you expect to read something beyond the end of
3090the PNG datastream.
3091
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003092When you are done, you can free all memory allocated by libpng like this:
3093
3094 png_destroy_read_struct(&png_ptr, &info_ptr,
3095 &end_info);
3096
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003097or, if you didn't create an end_info structure,
3098
3099 png_destroy_read_struct(&png_ptr, &info_ptr,
3100 (png_infopp)NULL);
3101
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003102It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003103point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003104
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003105 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003106
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003107 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003108 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003109 more of
3110 PNG_FREE_PLTE, PNG_FREE_TRNS,
3111 PNG_FREE_HIST, PNG_FREE_ICCP,
3112 PNG_FREE_PCAL, PNG_FREE_ROWS,
3113 PNG_FREE_SCAL, PNG_FREE_SPLT,
3114 PNG_FREE_TEXT, PNG_FREE_UNKN,
3115 or simply PNG_FREE_ALL
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003116
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003117 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003118 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003119
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003120This function may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003121already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003122by the user and not by libpng, and will in those cases do nothing.
3123The "seq" parameter is ignored if only one item of the selected data
3124type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3125are allowed for the data type identified in the mask, such as text or
3126sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003127
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003128The default behavior is only to free data that was allocated internally
3129by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003130or so that it will free data that was allocated by the user with png_malloc()
3131or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003132
3133 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003134
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003135 freer - one of
3136 PNG_DESTROY_WILL_FREE_DATA
3137 PNG_SET_WILL_FREE_DATA
3138 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003139
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003140 mask - which data elements are affected
3141 same choices as in png_free_data()
3142
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003143This function only affects data that has already been allocated.
3144You can call this function after reading the PNG data but before calling
3145any png_set_*() functions, to control whether the user or the png_set_*()
3146function is responsible for freeing any existing data that might be present,
3147and again after the png_set_*() functions to control whether the user
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003148or png_destroy_*() is supposed to free the data. When the user assumes
3149responsibility for libpng-allocated data, the application must use
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003150png_free() to free it, and when the user transfers responsibility to libpng
3151for data that the user has allocated, the user must have used png_malloc()
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05003152or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003153
3154If you allocated your row_pointers in a single block, as suggested above in
3155the description of the high level read interface, you must not transfer
3156responsibility for freeing it to the png_set_rows or png_read_destroy function,
3157because they would also try to free the individual row_pointers[i].
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003158
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003159If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3160separately, do not transfer responsibility for freeing text_ptr to libpng,
3161because when libpng fills a png_text structure it combines these members with
3162the key member, and png_free_data() will free only text_ptr.key. Similarly,
3163if you transfer responsibility for free'ing text_ptr from libpng to your
3164application, your application must not separately free those members.
3165
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003166The png_free_data() function will turn off the "valid" flag for anything
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003167it frees. If you need to turn the flag off for a chunk that was freed by
3168your application instead of by libpng, you can use
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003169
3170 png_set_invalid(png_ptr, info_ptr, mask);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003171
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003172 mask - identifies the chunks to be made invalid,
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003173 containing the bitwise OR of one or
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06003174 more of
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003175 PNG_INFO_gAMA, PNG_INFO_sBIT,
3176 PNG_INFO_cHRM, PNG_INFO_PLTE,
3177 PNG_INFO_tRNS, PNG_INFO_bKGD,
3178 PNG_INFO_hIST, PNG_INFO_pHYs,
3179 PNG_INFO_oFFs, PNG_INFO_tIME,
3180 PNG_INFO_pCAL, PNG_INFO_sRGB,
3181 PNG_INFO_iCCP, PNG_INFO_sPLT,
3182 PNG_INFO_sCAL, PNG_INFO_IDAT
3183
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003184For a more compact example of reading a PNG image, see the file example.c.
3185
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003186.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003187
3188The progressive reader is slightly different then the non-progressive
3189reader. Instead of calling png_read_info(), png_read_rows(), and
3190png_read_end(), you make one call to png_process_data(), which calls
3191callbacks when it has the info, a row, or the end of the image. You
3192set up these callbacks with png_set_progressive_read_fn(). You don't
3193have to worry about the input/output functions of libpng, as you are
3194giving the library the data directly in png_process_data(). I will
3195assume that you have read the section on reading PNG files above,
3196so I will only highlight the differences (although I will show
3197all of the code).
3198
3199png_structp png_ptr;
3200png_infop info_ptr;
3201
3202 /* An example code fragment of how you would
3203 initialize the progressive reader in your
3204 application. */
3205 int
3206 initialize_png_reader()
3207 {
3208 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003209 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003210 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003211
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003212 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003213 return (ERROR);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003214
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003215 info_ptr = png_create_info_struct(png_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003216
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003217 if (!info_ptr)
3218 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003219 png_destroy_read_struct(&png_ptr,
3220 (png_infopp)NULL, (png_infopp)NULL);
3221 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003222 }
3223
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003224 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003225 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003226 png_destroy_read_struct(&png_ptr, &info_ptr,
3227 (png_infopp)NULL);
3228 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003229 }
3230
3231 /* This one's new. You can provide functions
3232 to be called when the header info is valid,
3233 when each row is completed, and when the image
3234 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003235 you can specify NULL parameters. Even when all
3236 three functions are NULL, you need to call
3237 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003238 any struct as the user_ptr (cast to a void pointer
3239 for the function call), and retrieve the pointer
3240 from inside the callbacks using the function
3241
3242 png_get_progressive_ptr(png_ptr);
3243
3244 which will return a void pointer, which you have
3245 to cast appropriately.
3246 */
3247 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
3248 info_callback, row_callback, end_callback);
3249
3250 return 0;
3251 }
3252
3253 /* A code fragment that you call as you receive blocks
3254 of data */
3255 int
3256 process_data(png_bytep buffer, png_uint_32 length)
3257 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003258 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003259 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003260 png_destroy_read_struct(&png_ptr, &info_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003261 (png_infopp)NULL);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003262 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003263 }
3264
3265 /* This one's new also. Simply give it a chunk
3266 of data from the file stream (in order, of
3267 course). On machines with segmented memory
3268 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003269 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003270 of 4K. Although you can give it much less if
3271 necessary (I assume you can give it chunks of
3272 1 byte, I haven't tried less then 256 bytes
3273 yet). When this function returns, you may
3274 want to display any rows that were generated
3275 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003276 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003277 */
3278 png_process_data(png_ptr, info_ptr, buffer, length);
John Bowlerf19abd62011-01-22 18:29:24 -06003279
3280 /* At this point you can call png_process_data_skip if
3281 you want to handle data the library will skip yourself;
3282 it simply returns the number of bytes to skip (and stops
3283 libpng skipping that number of bytes on the next
3284 png_process_data call).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003285 return 0;
3286 }
3287
3288 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003289 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003290 has been supplied so all of the header has been
3291 read.
3292 */
3293 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003294 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003295 {
3296 /* Do any setup here, including setting any of
3297 the transformations mentioned in the Reading
3298 PNG files section. For now, you _must_ call
3299 either png_start_read_image() or
3300 png_read_update_info() after all the
3301 transformations are set (even if you don't set
3302 any). You may start getting rows before
3303 png_process_data() returns, so this is your
3304 last chance to prepare for that.
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003305
3306 This is where you turn on interlace handling,
3307 assuming you don't want to do it yourself.
John Bowlerf19abd62011-01-22 18:29:24 -06003308
3309 If you need to you can stop the processing of
3310 your original input data at this point by calling
3311 png_process_data_pause. This returns the number
3312 of unprocessed bytes from the last png_process_data
3313 call - it is up to you to ensure that the next call
3314 sees these bytes again. If you don't want to bother
3315 with this you can get libpng to cache the unread
3316 bytes by setting the 'save' parameter (see png.h) but
3317 then libpng will have to copy the data internally.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003318 */
3319 }
3320
3321 /* This function is called when each row of image
3322 data is complete */
3323 void
3324 row_callback(png_structp png_ptr, png_bytep new_row,
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05003325 png_uint_32 row_num, int pass)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003326 {
3327 /* If the image is interlaced, and you turned
3328 on the interlace handler, this function will
3329 be called for every row in every pass. Some
3330 of these rows will not be changed from the
3331 previous pass. When the row is not changed,
3332 the new_row variable will be NULL. The rows
3333 and passes are called in order, so you don't
3334 really need the row_num and pass, but I'm
3335 supplying them because it may make your life
3336 easier.
3337
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003338 If you did not turn on interlace handling then
3339 the callback is called for each row of each
3340 sub-image when the image is interlaced. In this
3341 case 'row_num' is the row in the sub-image, not
3342 the row in the output image as it is in all other
3343 cases.
3344
3345 For the non-NULL rows of interlaced images when
3346 you have switched on libpng interlace handling,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003347 you must call png_progressive_combine_row()
3348 passing in the row and the old row. You can
3349 call this function for NULL rows (it will just
3350 return) and for non-interlaced images (it just
3351 does the memcpy for you) if it will make the
3352 code easier. Thus, you can just do this for
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003353 all cases if you switch on interlace handling;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003354 */
3355
3356 png_progressive_combine_row(png_ptr, old_row,
3357 new_row);
3358
3359 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05003360 previously for the row. Note that the first
3361 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003362 the old row, so the rows do not have to be
3363 initialized. After the first pass (and only
3364 for interlaced images), you will have to pass
3365 the current row, and the function will combine
3366 the old row and the new row.
John Bowlerf19abd62011-01-22 18:29:24 -06003367
3368 You can also call png_process_data_pause in this
3369 callback - see above.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003370 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003371 }
3372
3373 void
3374 end_callback(png_structp png_ptr, png_infop info)
3375 {
3376 /* This function is called after the whole image
3377 has been read, including any chunks after the
3378 image (up to and including the IEND). You
3379 will usually have the same info chunk as you
3380 had in the header, although some data may have
3381 been added to the comments and time fields.
3382
3383 Most people won't do much here, perhaps setting
3384 a flag that marks the image as finished.
3385 */
3386 }
3387
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003388
3389
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003390.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003391
3392Much of this is very similar to reading. However, everything of
3393importance is repeated here, so you won't have to constantly look
3394back up in the reading section to understand writing.
3395
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003396.SS Setup
3397
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003398You will want to do the I/O initialization before you get into libpng,
3399so if it doesn't work, you don't have anything to undo. If you are not
3400using the standard I/O functions, you will need to replace them with
3401custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003402
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003403 FILE *fp = fopen(file_name, "wb");
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003404
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003405 if (!fp)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003406 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003407
3408Next, png_struct and png_info need to be allocated and initialized.
3409As these can be both relatively large, you may not want to store these
3410on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003411will want to check if they return NULL. If you are also reading,
3412you won't want to name your read structure and your write structure
3413both "png_ptr"; you can call them anything you like, such as
3414"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003415
3416 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003417 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003418 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003419
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003420 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003421 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003422
3423 png_infop info_ptr = png_create_info_struct(png_ptr);
3424 if (!info_ptr)
3425 {
3426 png_destroy_write_struct(&png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003427 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003428 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003429 }
3430
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003431If you want to use your own memory allocation routines,
3432define PNG_USER_MEM_SUPPORTED and use
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003433png_create_write_struct_2() instead of png_create_write_struct():
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003434
3435 png_structp png_ptr = png_create_write_struct_2
3436 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3437 user_error_fn, user_warning_fn, (png_voidp)
3438 user_mem_ptr, user_malloc_fn, user_free_fn);
3439
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003440After you have these structures, you will need to set up the
3441error handling. When libpng encounters an error, it expects to
3442longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003443setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003444write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003445the png_jmpbuf(png_ptr) every time you enter a new routine that will
3446call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003447for your compiler for more information on setjmp/longjmp. See
3448the discussion on libpng error handling in the Customizing Libpng
3449section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003450
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003451 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003452 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003453 png_destroy_write_struct(&png_ptr, &info_ptr);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003454 fclose(fp);
3455 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003456 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003457 ...
3458 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003459
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003460If you would rather avoid the complexity of setjmp/longjmp issues,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05003461you can compile libpng with PNG_NO_SETJMP, in which case
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003462errors will result in a call to PNG_ABORT() which defaults to abort().
3463
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05003464You can #define PNG_ABORT() to a function that does something
3465more useful than abort(), as long as your function does not
3466return.
3467
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003468Now you need to set up the output code. The default for libpng is to
3469use the C function fwrite(). If you use this, you will need to pass a
3470valid FILE * in the function png_init_io(). Be sure that the file is
3471opened in binary mode. Again, if you wish to handle writing data in
3472another way, see the discussion on libpng I/O handling in the Customizing
3473Libpng section below.
3474
3475 png_init_io(png_ptr, fp);
3476
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05003477If you are embedding your PNG into a datastream such as MNG, and don't
3478want libpng to write the 8-byte signature, or if you have already
3479written the signature in your application, use
3480
3481 png_set_sig_bytes(png_ptr, 8);
3482
3483to inform libpng that it should not write a signature.
3484
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003485.SS Write callbacks
3486
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003487At this point, you can set up a callback function that will be
3488called after each row has been written, which you can use to control
3489a progress meter or the like. It's demonstrated in pngtest.c.
3490You must supply a function
3491
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06003492 void write_row_callback(png_structp png_ptr, png_uint_32 row,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003493 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003494 {
3495 /* put your code here */
3496 }
3497
3498(You can give it another name that you like instead of "write_row_callback")
3499
3500To inform libpng about your function, use
3501
3502 png_set_write_status_fn(png_ptr, write_row_callback);
3503
John Bowler59010e52011-02-16 06:16:31 -06003504When this function is called the row has already been completely processed and
3505it has also been written out. The 'row' and 'pass' refer to the next row to be
3506handled. For the
3507non-interlaced case the row that was just handled is simply one less than the
3508passed in row number, and pass will always be 0. For the interlaced case the
3509same applies unless the row value is 0, in which case the row just handled was
3510the last one from one of the preceding passes. Because interlacing may skip a
3511pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3512need to know what the last pass is record (row,pass) from the callback and use
3513the last recorded value each time.
3514
3515As with the user transform you can find the output row using the
3516PNG_ROW_FROM_PASS_ROW macro.
3517
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003518You now have the option of modifying how the compression library will
3519run. The following functions are mainly for testing, but may be useful
3520in some cases, like if you need to write PNG files extremely fast and
3521are willing to give up some compression, or if you want to get the
3522maximum possible compression at the expense of slower writing. If you
3523have no special needs in this area, let the library do what it wants by
3524not calling this function at all, as it has been tuned to deliver a good
3525speed/compression ratio. The second parameter to png_set_filter() is
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003526the filter method, for which the only valid values are 0 (as of the
3527July 1999 PNG specification, version 1.2) or 64 (if you are writing
3528a PNG datastream that is to be embedded in a MNG datastream). The third
3529parameter is a flag that indicates which filter type(s) are to be tested
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003530for each scanline. See the PNG specification for details on the specific
3531filter types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003532
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003533
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003534 /* turn on or off filtering, and/or choose
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003535 specific filters. You can use either a single
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003536 PNG_FILTER_VALUE_NAME or the bitwise OR of one
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003537 or more PNG_FILTER_NAME masks.
3538 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003539 png_set_filter(png_ptr, 0,
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003540 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
3541 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
3542 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003543 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003544 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3545 PNG_ALL_FILTERS);
3546
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003547If an application wants to start and stop using particular filters during
3548compression, it should start out with all of the filters (to ensure that
3549the previous row of pixels will be stored in case it's needed later),
3550and then add and remove them after the start of compression.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003551
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003552If you are writing a PNG datastream that is to be embedded in a MNG
3553datastream, the second parameter can be either 0 or 64.
3554
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003555The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003556library, and should mostly be ignored unless you really know what you are
3557doing. The only generally useful call is png_set_compression_level()
3558which changes how much time zlib spends on trying to compress the image
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003559data. See the Compression Library (zlib.h and algorithm.txt, distributed
3560with zlib) for details on the compression levels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003561
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06003562 #include zlib.h
3563
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003564 /* Set the zlib compression level */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003565 png_set_compression_level(png_ptr,
3566 Z_BEST_COMPRESSION);
3567
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003568 /* Set other zlib parameters for compressing IDAT */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003569 png_set_compression_mem_level(png_ptr, 8);
3570 png_set_compression_strategy(png_ptr,
3571 Z_DEFAULT_STRATEGY);
3572 png_set_compression_window_bits(png_ptr, 15);
3573 png_set_compression_method(png_ptr, 8);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003574 png_set_compression_buffer_size(png_ptr, 8192)
3575
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003576 /* Set zlib parameters for text compression
3577 * If you don't call these, the parameters
3578 * fall back on those defined for IDAT chunks
3579 */
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05003580 png_set_text_compression_mem_level(png_ptr, 8);
3581 png_set_text_compression_strategy(png_ptr,
3582 Z_DEFAULT_STRATEGY);
3583 png_set_text_compression_window_bits(png_ptr, 15);
3584 png_set_text_compression_method(png_ptr, 8);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003585
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003586.SS Setting the contents of info for output
3587
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003588You now need to fill in the png_info structure with all the data you
3589wish to write before the actual image. Note that the only thing you
3590are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003591chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003592the latest PNG specification for more information on that. If you
3593wish to write them before the image, fill them in now, and flag that
3594data as being valid. If you want to wait until after the data, don't
3595fill them until png_write_end(). For all the fields in png_info and
3596their data types, see png.h. For explanations of what the fields
3597contain, see the PNG specification.
3598
3599Some of the more important parts of the png_info are:
3600
3601 png_set_IHDR(png_ptr, info_ptr, width, height,
3602 bit_depth, color_type, interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003603 compression_type, filter_method)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003604
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003605 width - holds the width of the image
3606 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003607
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003608 height - holds the height of the image
3609 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003610
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003611 bit_depth - holds the bit depth of one of the
3612 image channels.
3613 (valid values are 1, 2, 4, 8, 16
3614 and depend also on the
3615 color_type. See also significant
3616 bits (sBIT) below).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003617
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003618 color_type - describes which color/alpha
3619 channels are present.
3620 PNG_COLOR_TYPE_GRAY
3621 (bit depths 1, 2, 4, 8, 16)
3622 PNG_COLOR_TYPE_GRAY_ALPHA
3623 (bit depths 8, 16)
3624 PNG_COLOR_TYPE_PALETTE
3625 (bit depths 1, 2, 4, 8)
3626 PNG_COLOR_TYPE_RGB
3627 (bit_depths 8, 16)
3628 PNG_COLOR_TYPE_RGB_ALPHA
3629 (bit_depths 8, 16)
3630
3631 PNG_COLOR_MASK_PALETTE
3632 PNG_COLOR_MASK_COLOR
3633 PNG_COLOR_MASK_ALPHA
3634
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003635 interlace_type - PNG_INTERLACE_NONE or
3636 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003637
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003638 compression_type - (must be
3639 PNG_COMPRESSION_TYPE_DEFAULT)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003640
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003641 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
3642 or, if you are writing a PNG to
3643 be embedded in a MNG datastream,
3644 can also be
3645 PNG_INTRAPIXEL_DIFFERENCING)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003646
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003647If you call png_set_IHDR(), the call must appear before any of the
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05003648other png_set_*() functions, because they might require access to some of
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003649the IHDR settings. The remaining png_set_*() functions can be called
3650in any order.
3651
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003652If you wish, you can reset the compression_type, interlace_type, or
3653filter_method later by calling png_set_IHDR() again; if you do this, the
3654width, height, bit_depth, and color_type must be the same in each call.
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05003655
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003656 png_set_PLTE(png_ptr, info_ptr, palette,
3657 num_palette);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003658
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003659 palette - the palette for the file
3660 (array of png_color)
3661 num_palette - number of entries in the palette
3662
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003663 png_set_gAMA(png_ptr, info_ptr, file_gamma);
3664 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003665
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003666 file_gamma - the gamma at which the image was
3667 created (PNG_INFO_gAMA)
3668
3669 int_file_gamma - 100,000 times the gamma at which
3670 the image was created
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003671
3672 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003673
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003674 srgb_intent - the rendering intent
3675 (PNG_INFO_sRGB) The presence of
3676 the sRGB chunk means that the pixel
3677 data is in the sRGB color space.
3678 This chunk also implies specific
3679 values of gAMA and cHRM. Rendering
3680 intent is the CSS-1 property that
3681 has been defined by the International
3682 Color Consortium
3683 (http://www.color.org).
3684 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06003685 PNG_sRGB_INTENT_SATURATION,
3686 PNG_sRGB_INTENT_PERCEPTUAL,
3687 PNG_sRGB_INTENT_ABSOLUTE, or
3688 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003689
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003690
3691 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
3692 srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003693
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003694 srgb_intent - the rendering intent
3695 (PNG_INFO_sRGB) The presence of the
3696 sRGB chunk means that the pixel
3697 data is in the sRGB color space.
3698 This function also causes gAMA and
3699 cHRM chunks with the specific values
3700 that are consistent with sRGB to be
3701 written.
3702
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003703 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003704 profile, proflen);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003705
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003706 name - The profile name.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003707
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003708 compression_type - The compression type; always
3709 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
3710 You may give NULL to this argument to
3711 ignore it.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003712
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003713 profile - International Color Consortium color
3714 profile data. May contain NULs.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003715
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003716 proflen - length of profile data in bytes.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003717
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003718 png_set_sBIT(png_ptr, info_ptr, sig_bit);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003719
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003720 sig_bit - the number of significant bits for
3721 (PNG_INFO_sBIT) each of the gray, red,
3722 green, and blue channels, whichever are
3723 appropriate for the given color type
3724 (png_color_16)
3725
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05003726 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3727 num_trans, trans_color);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003728
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05003729 trans_alpha - array of alpha (transparency)
3730 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003731
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003732 num_trans - number of transparent entries
3733 (PNG_INFO_tRNS)
3734
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003735 trans_color - graylevel or color sample values
3736 (in order red, green, blue) of the
3737 single transparent color for
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003738 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003739
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003740 png_set_hIST(png_ptr, info_ptr, hist);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003741
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003742 hist - histogram of palette (array of
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003743 png_uint_16) (PNG_INFO_hIST)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003744
3745 png_set_tIME(png_ptr, info_ptr, mod_time);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003746
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003747 mod_time - time image was last modified
3748 (PNG_VALID_tIME)
3749
3750 png_set_bKGD(png_ptr, info_ptr, background);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003751
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05003752 background - background color (of type
3753 png_color_16p) (PNG_VALID_bKGD)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003754
3755 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003756
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003757 text_ptr - array of png_text holding image
3758 comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003759
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003760 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003761 on "text" PNG_TEXT_COMPRESSION_NONE
3762 PNG_TEXT_COMPRESSION_zTXt
3763 PNG_ITXT_COMPRESSION_NONE
3764 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003765 text_ptr[i].key - keyword for comment. Must contain
3766 1-79 characters.
3767 text_ptr[i].text - text comments for current
3768 keyword. Can be NULL or empty.
3769 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003770 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003771 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003772 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003773 text_ptr[i].lang - language of comment (NULL or
3774 empty for unknown).
3775 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
3776 or empty for unknown).
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05003777 Note that the itxt_length, lang, and lang_key
3778 members of the text_ptr structure only exist
3779 when the library is built with iTXt chunk support.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003780 Prior to libpng-1.4.0 the library was built by default
3781 without iTXt support.
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05003782
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003783 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003784
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003785 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3786 num_spalettes);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003787
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003788 palette_ptr - array of png_sPLT_struct structures
3789 to be added to the list of palettes
3790 in the info structure.
3791 num_spalettes - number of palette structures to be
3792 added.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003793
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003794 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
3795 unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003796
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003797 offset_x - positive offset from the left
3798 edge of the screen
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003799
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003800 offset_y - positive offset from the top
3801 edge of the screen
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003802
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003803 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
3804
3805 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
3806 unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003807
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003808 res_x - pixels/unit physical resolution
3809 in x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003810
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003811 res_y - pixels/unit physical resolution
3812 in y direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003813
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003814 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003815 PNG_RESOLUTION_METER
3816
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003817 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003818
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003819 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003820
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003821 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003822
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003823 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003824 (width and height are doubles)
3825
3826 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003827
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003828 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003829
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003830 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003831 expressed as a string
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003832
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003833 height - height of a pixel in physical scale units
3834 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003835
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003836 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
3837 num_unknowns)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003838
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003839 unknowns - array of png_unknown_chunk
3840 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003841 unknowns[i].name - name of unknown chunk
3842 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003843 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003844 unknowns[i].location - position to write chunk in file
3845 0: do not write chunk
3846 PNG_HAVE_IHDR: before PLTE
3847 PNG_HAVE_PLTE: before IDAT
3848 PNG_AFTER_IDAT: after IDAT
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003849
3850The "location" member is set automatically according to
3851what part of the output file has already been written.
3852You can change its value after calling png_set_unknown_chunks()
3853as demonstrated in pngtest.c. Within each of the "locations",
3854the chunks are sequenced according to their position in the
3855structure (that is, the value of "i", which is the order in which
3856the chunk was either read from the input file or defined with
3857png_set_unknown_chunks).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003858
3859A quick word about text and num_text. text is an array of png_text
3860structures. num_text is the number of valid structures in the array.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003861Each png_text structure holds a language code, a keyword, a text value,
3862and a compression type.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003863
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003864The compression types have the same valid numbers as the compression
3865types of the image data. Currently, the only valid number is zero.
3866However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003867images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003868text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003869Because tEXt and zTXt chunks don't have a language field, if you
3870specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3871any language code or translated keyword will not be written out.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003872
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003873Until text gets around a few hundred bytes, it is not worth compressing it.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003874After the text has been written out to the file, the compression type
3875is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3876so that it isn't written out again at the end (in case you are calling
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003877png_write_end() with the same struct).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003878
3879The keywords that are given in the PNG Specification are:
3880
3881 Title Short (one line) title or
3882 caption for image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003883
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003884 Author Name of image's creator
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003885
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003886 Description Description of image (possibly long)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003887
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003888 Copyright Copyright notice
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003889
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003890 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003891 (usually RFC 1123 format, see below)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003892
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003893 Software Software used to create the image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003894
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003895 Disclaimer Legal disclaimer
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003896
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003897 Warning Warning of nature of content
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003898
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003899 Source Device used to create the image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003900
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003901 Comment Miscellaneous comment; conversion
3902 from other image format
3903
3904The keyword-text pairs work like this. Keywords should be short
3905simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003906keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003907on keywords. You can repeat keywords in a file. You can even write
3908some text before the image and some after. For example, you may want
3909to put a description of the image before the image, but leave the
3910disclaimer until after, so viewers working over modem connections
3911don't have to wait for the disclaimer to go over the modem before
3912they start seeing the image. Finally, keywords should be full
3913words, not abbreviations. Keywords and text are in the ISO 8859-1
3914(Latin-1) character set (a superset of regular ASCII) and can not
3915contain NUL characters, and should not contain control or other
3916unprintable characters. To make the comments widely readable, stick
3917with basic ASCII, and avoid machine specific character set extensions
3918like the IBM-PC character set. The keyword must be present, but
3919you can leave off the text string on non-compressed pairs.
3920Compressed pairs must have a text string, as only the text string
3921is compressed anyway, so the compression would be meaningless.
3922
3923PNG supports modification time via the png_time structure. Two
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003924conversion routines are provided, png_convert_from_time_t() for
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003925time_t and png_convert_from_struct_tm() for struct tm. The
3926time_t routine uses gmtime(). You don't have to use either of
3927these, but if you wish to fill in the png_time structure directly,
3928you should provide the time in universal time (GMT) if possible
3929instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003930year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003931that months start with 1.
3932
3933If you want to store the time of the original image creation, you should
3934use a plain tEXt chunk with the "Creation Time" keyword. This is
3935necessary because the "creation time" of a PNG image is somewhat vague,
3936depending on whether you mean the PNG file, the time the image was
3937created in a non-PNG format, a still photo from which the image was
3938scanned, or possibly the subject matter itself. In order to facilitate
3939machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003940tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003941although this isn't a requirement. Unlike the tIME chunk, the
3942"Creation Time" tEXt chunk is not expected to be automatically changed
3943by the software. To facilitate the use of RFC 1123 dates, a function
3944png_convert_to_rfc1123(png_timep) is provided to convert from PNG
3945time to an RFC 1123 format string.
3946
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003947.SS Writing unknown chunks
3948
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003949You can use the png_set_unknown_chunks function to queue up chunks
3950for writing. You give it a chunk name, raw data, and a size; that's
3951all there is to it. The chunks will be written by the next following
3952png_write_info_before_PLTE, png_write_info, or png_write_end function.
3953Any chunks previously read into the info structure's unknown-chunk
3954list will also be written out in a sequence that satisfies the PNG
3955specification's ordering rules.
3956
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003957.SS The high-level write interface
3958
3959At this point there are two ways to proceed; through the high-level
3960write interface, or through a sequence of low-level write operations.
3961You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003962in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003963transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003964
3965 PNG_TRANSFORM_IDENTITY No transformation
3966 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003967 PNG_TRANSFORM_PACKSWAP Change order of packed
3968 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003969 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003970 PNG_TRANSFORM_SHIFT Normalize pixels to the
3971 sBIT depth
3972 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
3973 to BGRA
3974 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
3975 to AG
3976 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
3977 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003978 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson1eb14e92008-12-10 07:14:45 -06003979 PNG_TRANSFORM_STRIP_FILLER Strip out filler
3980 bytes (deprecated).
3981 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
3982 filler bytes
3983 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
3984 filler bytes
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003985
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003986If you have valid image data in the info structure (you can use
3987png_set_rows() to put image data in the info structure), simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003988
3989 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
3990
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003991where png_transforms is an integer containing the bitwise OR of some set of
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003992transformation flags. This call is equivalent to png_write_info(),
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003993followed the set of transformations indicated by the transform mask,
3994then png_write_image(), and finally png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003995
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003996(The final parameter of this call is not yet used. Someday it might point
3997to transformation parameters required by some future output transform.)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003998
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05003999You must use png_transforms and not call any png_set_transform() functions
4000when you use png_write_png().
4001
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004002.SS The low-level write interface
4003
4004If you are going the low-level route instead, you are now ready to
4005write all the file information up to the actual image data. You do
4006this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004007
4008 png_write_info(png_ptr, info_ptr);
4009
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004010Note that there is one transformation you may need to do before
4011png_write_info(). In PNG files, the alpha channel in an image is the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004012level of opacity. If your data is supplied as a level of transparency,
4013you can invert the alpha channel before you write it, so that 0 is
4014fully transparent and 255 (in 8-bit or paletted images) or 65535
4015(in 16-bit images) is fully opaque, with
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004016
4017 png_set_invert_alpha(png_ptr);
4018
4019This must appear before png_write_info() instead of later with the
4020other transformations because in the case of paletted images the tRNS
4021chunk data has to be inverted before the tRNS chunk is written. If
4022your image is not a paletted image, the tRNS data (which in such cases
4023represents a single color to be rendered as transparent) won't need to
4024be changed, and you can safely do this transformation after your
4025png_write_info() call.
4026
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06004027If you need to write a private chunk that you want to appear before
4028the PLTE chunk when PLTE is present, you can write the PNG info in
4029two steps, and insert code to write your own chunk between them:
4030
4031 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004032 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06004033 png_write_info(png_ptr, info_ptr);
4034
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004035After you've written the file information, you can set up the library
4036to handle any special transformations of the image data. The various
4037ways to transform the data will be described in the order that they
4038should occur. This is important, as some of these change the color
4039type and/or bit depth of the data, and some others only work on
4040certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004041checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004042make sure to only enable a transformation if it will be valid for the
4043data. For example, don't swap red and blue on grayscale data.
4044
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004045PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06004046the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004047to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
4048bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004049
4050 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
4051
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004052where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004053PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
4054is stored XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004055
4056PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
4057they can, resulting in, for example, 8 pixels per byte for 1 bit files.
4058If the data is supplied at 1 pixel per byte, use this code, which will
4059correctly pack the pixels into a single byte:
4060
4061 png_set_packing(png_ptr);
4062
4063PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
4064data is of another bit depth, you can write an sBIT chunk into the
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004065file so that decoders can recover the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004066
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004067 /* Set the true bit depth of the image data */
4068 if (color_type & PNG_COLOR_MASK_COLOR)
4069 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004070 sig_bit.red = true_bit_depth;
4071 sig_bit.green = true_bit_depth;
4072 sig_bit.blue = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004073 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004074
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004075 else
4076 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004077 sig_bit.gray = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004078 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004079
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004080 if (color_type & PNG_COLOR_MASK_ALPHA)
4081 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004082 sig_bit.alpha = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004083 }
4084
4085 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
4086
4087If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004088one 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 -06004089this will scale the values to appear to be the correct bit depth as
4090is required by PNG.
4091
4092 png_set_shift(png_ptr, &sig_bit);
4093
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05004094PNG files store 16-bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004095ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004096supplied the other way (little-endian, i.e. least significant bits
4097first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004098
4099 if (bit_depth > 8)
4100 png_set_swap(png_ptr);
4101
4102If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
4103need to change the order the pixels are packed into bytes, you can use:
4104
4105 if (bit_depth < 8)
4106 png_set_packswap(png_ptr);
4107
4108PNG files store 3 color pixels in red, green, blue order. This code
4109would be used if they are supplied as blue, green, red:
4110
4111 png_set_bgr(png_ptr);
4112
4113PNG files describe monochrome as black being zero and white being
4114one. This code would be used if the pixels are supplied with this reversed
4115(black being one and white being zero):
4116
4117 png_set_invert_mono(png_ptr);
4118
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004119Finally, you can write your own transformation function if none of
4120the existing ones meets your needs. This is done by setting a callback
4121with
4122
4123 png_set_write_user_transform_fn(png_ptr,
4124 write_transform_fn);
4125
4126You must supply the function
4127
Glenn Randers-Pehrson93215672011-02-13 19:42:19 -06004128 void write_transform_fn(png_structp png_ptr, png_row_infop
4129 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004130
4131See pngtest.c for a working example. Your function will be called
John Bowlerf19abd62011-01-22 18:29:24 -06004132before any of the other transformations are processed. If supported
4133libpng also supplies an information routine that may be called from
4134your callback:
4135
4136 png_get_current_row_number(png_ptr);
John Bowlercd113452011-02-16 06:15:13 -06004137 png_get_current_pass_number(png_ptr);
John Bowlerf19abd62011-01-22 18:29:24 -06004138
John Bowlercd113452011-02-16 06:15:13 -06004139This returns the current row passed to the transform. With interlaced
4140images the value returned is the row in the input sub-image image. Use
4141PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
4142find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
4143
4144The discussion of interlace handling above contains more information on how to
4145use these values.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004146
4147You can also set up a pointer to a user structure for use by your
4148callback function.
4149
4150 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
4151
4152The user_channels and user_depth parameters of this function are ignored
4153when writing; you can set them to zero as shown.
4154
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004155You can retrieve the pointer via the function png_get_user_transform_ptr().
4156For example:
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004157
4158 voidp write_user_transform_ptr =
4159 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004160
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004161It is possible to have libpng flush any pending output, either manually,
4162or automatically after a certain number of lines have been written. To
4163flush the output stream a single time call:
4164
4165 png_write_flush(png_ptr);
4166
4167and to have libpng flush the output stream periodically after a certain
4168number of scanlines have been written, call:
4169
4170 png_set_flush(png_ptr, nrows);
4171
4172Note that the distance between rows is from the last time png_write_flush()
4173was called, or the first row of the image if it has never been called.
4174So if you write 50 lines, and then png_set_flush 25, it will flush the
4175output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004176png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004177If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004178RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004179may be acceptable for real-time applications). Infrequent flushing will
4180only degrade the compression performance by a few percent over images
4181that do not use flushing.
4182
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004183.SS Writing the image data
4184
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004185That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004186The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004187whole image in memory, you can just call png_write_image() and libpng
4188will write the image. You will need to pass in an array of pointers to
4189each row. This function automatically handles interlacing, so you don't
4190need to call png_set_interlace_handling() or call this function multiple
4191times, or any of that other stuff necessary with png_write_rows().
4192
4193 png_write_image(png_ptr, row_pointers);
4194
4195where row_pointers is:
4196
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004197 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004198
4199You can point to void or char or whatever you use for pixels.
4200
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004201If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004202use png_write_rows() instead. If the file is not interlaced,
4203this is simple:
4204
4205 png_write_rows(png_ptr, row_pointers,
4206 number_of_rows);
4207
4208row_pointers is the same as in the png_write_image() call.
4209
4210If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004211a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004212
4213 png_bytep row_pointer = row;
4214
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004215 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004216
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004217When the file is interlaced, things can get a good deal more complicated.
4218The only currently (as of the PNG Specification version 1.2, dated July
42191999) defined interlacing scheme for PNG files is the "Adam7" interlace
4220scheme, that breaks down an image into seven smaller images of varying
4221size. libpng will build these images for you, or you can do them
4222yourself. If you want to build them yourself, see the PNG specification
4223for details of which pixels to write when.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004224
4225If you don't want libpng to handle the interlacing details, just
4226use png_set_interlace_handling() and call png_write_rows() the
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004227correct number of times to write all the sub-images
4228(png_set_interlace_handling() returns the number of sub-images.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004229
4230If you want libpng to build the sub-images, call this before you start
4231writing any rows:
4232
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004233 number_of_passes = png_set_interlace_handling(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004234
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004235This will return the number of passes needed. Currently, this is seven,
4236but may change if another interlace type is added.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004237
4238Then write the complete image number_of_passes times.
4239
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004240 png_write_rows(png_ptr, row_pointers, number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004241
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004242Think carefully before you write an interlaced image. Typically code that
4243reads such images reads all the image data into memory, uncompressed, before
4244doing any processing. Only code that can display an image on the fly can
4245take advantage of the interlacing and even then the image has to be exactly
4246the correct size for the output device, because scaling an image requires
4247adjacent pixels and these are not available until all the passes have been
4248read.
4249
4250If you do write an interlaced image you will hardly ever need to handle
4251the interlacing yourself. Call png_set_interlace_handling() and use the
4252approach described above.
4253
4254The only time it is conceivable that you will really need to write an
4255interlaced image pass-by-pass is when you have read one pass by pass and
4256made some pixel-by-pixel transformation to it, as described in the read
4257code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
4258to determine the size of each sub-image in turn and simply write the rows
4259you obtained from the read code.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004260
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004261.SS Finishing a sequential write
4262
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004263After you are finished writing the image, you should finish writing
4264the file. If you are interested in writing comments or time, you should
4265pass an appropriately filled png_info pointer. If you are not interested,
4266you can pass NULL.
4267
4268 png_write_end(png_ptr, info_ptr);
4269
4270When you are done, you can free all memory used by libpng like this:
4271
4272 png_destroy_write_struct(&png_ptr, &info_ptr);
4273
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004274It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05004275point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004276
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004277 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004278
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004279 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004280 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004281 more of
4282 PNG_FREE_PLTE, PNG_FREE_TRNS,
4283 PNG_FREE_HIST, PNG_FREE_ICCP,
4284 PNG_FREE_PCAL, PNG_FREE_ROWS,
4285 PNG_FREE_SCAL, PNG_FREE_SPLT,
4286 PNG_FREE_TEXT, PNG_FREE_UNKN,
4287 or simply PNG_FREE_ALL
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004288
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004289 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004290 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004291
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05004292This function may be safely called when the relevant storage has
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004293already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004294by the user and not by libpng, and will in those cases do nothing.
4295The "seq" parameter is ignored if only one item of the selected data
4296type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
4297are allowed for the data type identified in the mask, such as text or
4298sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004299
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004300If you allocated data such as a palette that you passed in to libpng
4301with png_set_*, you must not free it until just before the call to
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004302png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004303
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004304The default behavior is only to free data that was allocated internally
4305by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004306or so that it will free data that was allocated by the user with png_malloc()
4307or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004308
4309 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004310
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004311 freer - one of
4312 PNG_DESTROY_WILL_FREE_DATA
4313 PNG_SET_WILL_FREE_DATA
4314 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004315
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004316 mask - which data elements are affected
4317 same choices as in png_free_data()
4318
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004319For example, to transfer responsibility for some data from a read structure
4320to a write structure, you could use
4321
4322 png_data_freer(read_ptr, read_info_ptr,
4323 PNG_USER_WILL_FREE_DATA,
4324 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004325
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004326 png_data_freer(write_ptr, write_info_ptr,
4327 PNG_DESTROY_WILL_FREE_DATA,
4328 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4329
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004330thereby briefly reassigning responsibility for freeing to the user but
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004331immediately afterwards reassigning it once more to the write_destroy
4332function. Having done this, it would then be safe to destroy the read
4333structure and continue to use the PLTE, tRNS, and hIST data in the write
4334structure.
4335
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004336This function only affects data that has already been allocated.
4337You can call this function before calling after the png_set_*() functions
4338to control whether the user or png_destroy_*() is supposed to free the data.
4339When the user assumes responsibility for libpng-allocated data, the
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004340application must use
4341png_free() to free it, and when the user transfers responsibility to libpng
4342for data that the user has allocated, the user must have used png_malloc()
4343or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004344
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004345If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
4346separately, do not transfer responsibility for freeing text_ptr to libpng,
4347because when libpng fills a png_text structure it combines these members with
4348the key member, and png_free_data() will free only text_ptr.key. Similarly,
4349if you transfer responsibility for free'ing text_ptr from libpng to your
4350application, your application must not separately free those members.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004351For a more compact example of writing a PNG image, see the file example.c.
4352
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004353.SH V. Modifying/Customizing libpng:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004354
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004355There are two issues here. The first is changing how libpng does
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004356standard things like memory allocation, input/output, and error handling.
4357The second deals with more complicated things like adding new chunks,
4358adding new transformations, and generally changing how libpng works.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004359Both of those are compile-time issues; that is, they are generally
4360determined at the time the code is written, and there is rarely a need
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004361to provide the user with a means of changing them.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004362
4363Memory allocation, input/output, and error handling
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004364
4365All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004366goes through callbacks that are user-settable. The default routines are
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004367in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004368these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004369
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004370Memory allocation is done through the functions png_malloc(), png_calloc(),
4371and png_free(). These currently just call the standard C functions.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05004372png_calloc() calls png_malloc() and then clears the newly
4373allocated memory to zero. There is limited support for certain systems
4374with segmented memory architectures and the types of pointers declared by
4375png.h match this; you will have to use appropriate pointers in your
4376application. Since it is
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004377unlikely that the method of handling memory allocation on a platform
4378will change between applications, these functions must be modified in
4379the library at compile time. If you prefer to use a different method
4380of allocating and freeing data, you can use png_create_read_struct_2() or
4381png_create_write_struct_2() to register your own functions as described
4382above. These functions also provide a void pointer that can be retrieved
4383via
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004384
4385 mem_ptr=png_get_mem_ptr(png_ptr);
4386
4387Your replacement memory functions must have prototypes as follows:
4388
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004389 png_voidp malloc_fn(png_structp png_ptr,
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004390 png_alloc_size_t size);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004391
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004392 void free_fn(png_structp png_ptr, png_voidp ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004393
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004394Your malloc_fn() must return NULL in case of failure. The png_malloc()
4395function will normally call png_error() if it receives a NULL from the
4396system memory allocator or from your replacement malloc_fn().
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05004397
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004398Your free_fn() will never be called with a NULL ptr, since libpng's
4399png_free() checks for NULL before calling free_fn().
4400
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004401Input/Output in libpng is done through png_read() and png_write(),
4402which currently just call fread() and fwrite(). The FILE * is stored in
4403png_struct and is initialized via png_init_io(). If you wish to change
4404the method of I/O, the library supplies callbacks that you can set
4405through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004406time, instead of calling the png_init_io() function. These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004407also provide a void pointer that can be retrieved via the function
4408png_get_io_ptr(). For example:
4409
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004410 png_set_read_fn(png_structp read_ptr,
4411 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004412
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004413 png_set_write_fn(png_structp write_ptr,
4414 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004415 png_flush_ptr output_flush_fn);
4416
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004417 voidp read_io_ptr = png_get_io_ptr(read_ptr);
4418 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004419
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004420The replacement I/O functions must have prototypes as follows:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004421
4422 void user_read_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05004423 png_bytep data, png_size_t length);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004424
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004425 void user_write_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05004426 png_bytep data, png_size_t length);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004427
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004428 void user_flush_data(png_structp png_ptr);
4429
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004430The user_read_data() function is responsible for detecting and
4431handling end-of-data errors.
4432
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004433Supplying NULL for the read, write, or flush functions sets them back
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004434to using the default C stream functions, which expect the io_ptr to
4435point to a standard *FILE structure. It is probably a mistake
4436to use NULL for one of write_data_fn and output_flush_fn but not both
4437of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4438It is an error to read from a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004439
4440Error handling in libpng is done through png_error() and png_warning().
4441Errors handled through png_error() are fatal, meaning that png_error()
4442should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004443setjmp() and longjmp() (unless you have compiled libpng with
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05004444PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
Glenn Randers-Pehrson60988072010-04-13 22:11:06 -05004445but you could change this to do things like exit() if you should wish,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05004446as long as your function does not return.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004447
4448On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004449to print a warning message, and then control returns to the calling code.
4450By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004451fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
4452(because you don't want the messages) or PNG_NO_STDIO defined (because
4453fprintf() isn't available). If you wish to change the behavior of the error
4454functions, you will need to set up your own message callbacks. These
4455functions are normally supplied at the time that the png_struct is created.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004456It is also possible to redirect errors and warnings to your own replacement
4457functions after png_create_*_struct() has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004458
4459 png_set_error_fn(png_structp png_ptr,
4460 png_voidp error_ptr, png_error_ptr error_fn,
4461 png_error_ptr warning_fn);
4462
4463 png_voidp error_ptr = png_get_error_ptr(png_ptr);
4464
4465If NULL is supplied for either error_fn or warning_fn, then the libpng
4466default function will be used, calling fprintf() and/or longjmp() if a
4467problem is encountered. The replacement error functions should have
4468parameters as follows:
4469
4470 void user_error_fn(png_structp png_ptr,
4471 png_const_charp error_msg);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004472
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004473 void user_warning_fn(png_structp png_ptr,
4474 png_const_charp warning_msg);
4475
4476The motivation behind using setjmp() and longjmp() is the C++ throw and
4477catch exception handling methods. This makes the code much easier to write,
4478as there is no need to check every return code of every function call.
4479However, there are some uncertainties about the status of local variables
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004480after a longjmp, so the user may want to be careful about doing anything
4481after setjmp returns non-zero besides returning itself. Consult your
4482compiler documentation for more details. For an alternative approach, you
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004483may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4484which is illustrated in pngvalid.c and in contrib/visupng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004485
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004486.SS Custom chunks
4487
4488If you need to read or write custom chunks, you may need to get deeper
4489into the libpng code. The library now has mechanisms for storing
4490and writing chunks of unknown type; you can even declare callbacks
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06004491for custom chunks. However, this may not be good enough if the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004492library code itself needs to know about interactions between your
4493chunk and existing `intrinsic' chunks.
4494
4495If you need to write a new intrinsic chunk, first read the PNG
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004496specification. Acquire a first level of understanding of how it works.
4497Pay particular attention to the sections that describe chunk names,
4498and look at how other chunks were designed, so you can do things
4499similarly. Second, check out the sections of libpng that read and
4500write chunks. Try to find a chunk that is similar to yours and use
4501it as a template. More details can be found in the comments inside
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004502the code. It is best to handle private or unknown chunks in a generic method,
4503via callback functions, instead of by modifying libpng functions. This
4504is illustrated in pngtest.c, which uses a callback function to handle a
4505private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4506libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004507
4508If you wish to write your own transformation for the data, look through
4509the part of the code that does the transformations, and check out some of
4510the simpler ones to get an idea of how they work. Try to find a similar
4511transformation to the one you want to add and copy off of it. More details
4512can be found in the comments inside the code itself.
4513
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05004514.SS Configuring for 16-bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004515
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004516You will want to look into zconf.h to tell zlib (and thus libpng) that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004517it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004518won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004519
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004520.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004521
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004522For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004523have to limit zlib's memory usage via a png_set_compression_mem_level()
4524call. See zlib.h or zconf.h in the zlib library for more information.
4525
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004526.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004527
4528Libpng's support for medium model has been tested on most of the popular
4529compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4530defined, and FAR gets defined to far in pngconf.h, and you should be
4531all set. Everything in the library (except for zlib's structure) is
4532expecting far data. You must use the typedefs with the p or pp on
4533the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004534note that the rows of data are defined as png_bytepp, which is
4535an "unsigned char far * far *".
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004536
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004537.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004538
4539You will need to write new error and warning functions that use the GUI
4540interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004541warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004542in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004543They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004544you may also have to change the memory allocators (png_malloc, etc.).
4545
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004546.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004547
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05004548All includes for libpng are in pngconf.h. If you need to add, change
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004549or delete an include, this is the place to do it.
4550The includes that are not needed outside libpng are placed in pngpriv.h,
4551which is only used by the routines inside libpng itself.
4552The files in libpng proper only include pngpriv.h and png.h, which
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004553%14%in turn includes pngconf.h.
4554in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
4555As of libpng-1.5.0, pngpriv.h also includes three other private header
4556files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
4557that previously appeared in the public headers.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004558
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004559.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004560
4561There are special functions to configure the compression. Perhaps the
4562most useful one changes the compression level, which currently uses
4563input compression values in the range 0 - 9. The library normally
4564uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
4565have shown that for a large majority of images, compression values in
4566the range 3-6 compress nearly as well as higher levels, and do so much
4567faster. For online applications it may be desirable to have maximum speed
4568(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
4569specify no compression (Z_NO_COMPRESSION = 0), but this would create
4570files larger than just storing the raw bitmap. You can specify the
4571compression level by calling:
4572
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06004573 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004574 png_set_compression_level(png_ptr, level);
4575
4576Another useful one is to reduce the memory level used by the library.
4577The memory level defaults to 8, but it can be lowered if you are
4578short on memory (running DOS, for example, where you only have 640K).
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004579Note that the memory level does have an effect on compression; among
4580other things, lower levels will result in sections of incompressible
4581data being emitted in smaller stored blocks, with a correspondingly
4582larger relative overhead of up to 15% in the worst case.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004583
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06004584 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004585 png_set_compression_mem_level(png_ptr, level);
4586
4587The other functions are for configuring zlib. They are not recommended
4588for normal use and may result in writing an invalid PNG file. See
4589zlib.h for more information on what these mean.
4590
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06004591 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004592 png_set_compression_strategy(png_ptr,
4593 strategy);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004594
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004595 png_set_compression_window_bits(png_ptr,
4596 window_bits);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004597
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004598 png_set_compression_method(png_ptr, method);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004599
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004600 png_set_compression_buffer_size(png_ptr, size);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004601
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004602As of libpng version 1.5.4, additional APIs became
4603available to set these separately for non-IDAT
4604compressed chunks such as zTXt, iTXt, and iCCP:
4605
4606 #include zlib.h
4607 #if PNG_LIBPNG_VER <= 10504
4608 png_set_text_compression_level(png_ptr, level);
4609
4610 png_set_text_compression_mem_level(png_ptr, level);
4611
4612 png_set_text_compression_strategy(png_ptr,
4613 strategy);
4614
4615 png_set_text_compression_window_bits(png_ptr,
4616 window_bits);
4617
4618 png_set_text_compression_method(png_ptr, method);
4619 #endif
4620
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004621.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004622
4623If you want to control whether libpng uses filtering or not, which
4624filters are used, and how it goes about picking row filters, you
4625can call one of these functions. The selection and configuration
4626of row filters can have a significant impact on the size and
4627encoding speed and a somewhat lesser impact on the decoding speed
4628of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004629images (with and without alpha), but not for paletted images nor
4630for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004631
4632The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004633currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004634parameter sets which filter(s), if any, should be used for each
4635scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
4636to turn filtering on and off, respectively.
4637
4638Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
4639PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004640ORed together with '|' to specify one or more filters to use.
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004641These filters are described in more detail in the PNG specification.
4642If you intend to change the filter type during the course of writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004643the image, you should start with flags set for all of the filters
4644you intend to use so that libpng can initialize its internal
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004645structures appropriately for all of the filter types. (Note that this
4646means the first row must always be adaptively filtered, because libpng
4647currently does not allocate the filter buffers until png_write_row()
4648is called for the first time.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004649
4650 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05004651 PNG_FILTER_UP | PNG_FILTER_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004652 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004653
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004654 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
4655 filters);
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004656 The second parameter can also be
4657 PNG_INTRAPIXEL_DIFFERENCING if you are
4658 writing a PNG to be embedded in a MNG
4659 datastream. This parameter must be the
4660 same as the value of filter_method used
4661 in png_set_IHDR().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004662
4663It is also possible to influence how libpng chooses from among the
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004664available filters. This is done in one or both of two ways - by
4665telling it how important it is to keep the same filter for successive
4666rows, and by telling it the relative computational costs of the filters.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004667
4668 double weights[3] = {1.5, 1.3, 1.1},
4669 costs[PNG_FILTER_VALUE_LAST] =
4670 {1.0, 1.3, 1.3, 1.5, 1.7};
4671
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004672 png_set_filter_heuristics(png_ptr,
4673 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004674 weights, costs);
4675
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004676The weights are multiplying factors that indicate to libpng that the
4677row filter should be the same for successive rows unless another row filter
4678is that many times better than the previous filter. In the above example,
4679if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004680"sum of absolute differences" 1.5 x 1.3 times higher than other filters
4681and still be chosen, while the NONE filter could have a sum 1.1 times
4682higher than other filters and still be chosen. Unspecified weights are
4683taken to be 1.0, and the specified weights should probably be declining
4684like those above in order to emphasize recent filters over older filters.
4685
4686The filter costs specify for each filter type a relative decoding cost
4687to be considered when selecting row filters. This means that filters
4688with higher costs are less likely to be chosen over filters with lower
4689costs, unless their "sum of absolute differences" is that much smaller.
4690The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004691the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004692size.
4693
4694Note that the numbers above were invented purely for this example and
4695are given only to help explain the function usage. Little testing has
4696been done to find optimum values for either the costs or the weights.
4697
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004698.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004699
4700There are a bunch of #define's in pngconf.h that control what parts of
4701libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004702never going to use a capability, you can change the #define to #undef
4703before recompiling libpng and save yourself code and data space, or
4704you can turn off individual capabilities with defines that begin with
4705PNG_NO_.
4706
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004707In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
4708
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004709You can also turn all of the transforms and ancillary chunk capabilities
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004710off en masse with compiler directives that define
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004711PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
4712or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004713along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004714want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
4715transformations but still leave the library fully capable of reading
4716and writing PNG files with all known public chunks. Use of the
4717PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
4718that is incapable of reading or writing ancillary chunks. If you are
4719not using the progressive reading capability, you can turn that off
4720with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
4721capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004722
4723All the reading and writing specific code are in separate files, so the
4724linker should only grab the files it needs. However, if you want to
4725make sure, or if you are building a stand alone library, all the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004726reading files start with "pngr" and all the writing files start with "pngw".
4727The files that don't match either (like png.c, pngtrans.c, etc.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004728are used for both reading and writing, and always need to be included.
4729The progressive reader is in pngpread.c
4730
4731If you are creating or distributing a dynamically linked library (a .so
4732or DLL file), you should not remove or disable any parts of the library,
4733as this will cause applications linked with different versions of the
4734library to fail if they call functions not available in your library.
4735The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004736those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004737
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004738.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004739
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004740The macro definition PNG_DEBUG can be used to request debugging
4741printout. Set it to an integer value in the range 0 to 3. Higher
4742numbers result in increasing amounts of debugging information. The
4743information is printed to the "stderr" file, unless another file
4744name is specified in the PNG_DEBUG_FILE macro definition.
4745
4746When PNG_DEBUG > 0, the following functions (macros) become available:
4747
4748 png_debug(level, message)
4749 png_debug1(level, message, p1)
4750 png_debug2(level, message, p1, p2)
4751
4752in which "level" is compared to PNG_DEBUG to decide whether to print
4753the message, "message" is the formatted string to be printed,
4754and p1 and p2 are parameters that are to be embedded in the string
4755according to printf-style formatting directives. For example,
4756
4757 png_debug1(2, "foo=%d\n", foo);
4758
4759is expanded to
4760
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004761 if (PNG_DEBUG > 2)
4762 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004763
4764When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
4765can still use PNG_DEBUG to control your own debugging:
4766
4767 #ifdef PNG_DEBUG
4768 fprintf(stderr, ...
4769 #endif
4770
4771When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
4772having level = 0 will be printed. There aren't any such statements in
4773this version of libpng, but if you insert some they will be printed.
4774
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05004775.SH VI. MNG support
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06004776
4777The MNG specification (available at http://www.libpng.org/pub/mng) allows
4778certain extensions to PNG for PNG images that are embedded in MNG datastreams.
4779Libpng can support some of these extensions. To enable them, use the
4780png_permit_mng_features() function:
4781
4782 feature_set = png_permit_mng_features(png_ptr, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004783
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004784 mask is a png_uint_32 containing the bitwise OR of the
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06004785 features you want to enable. These include
4786 PNG_FLAG_MNG_EMPTY_PLTE
4787 PNG_FLAG_MNG_FILTER_64
4788 PNG_ALL_MNG_FEATURES
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004789
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004790 feature_set is a png_uint_32 that is the bitwise AND of
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06004791 your mask with the set of MNG features that is
4792 supported by the version of libpng that you are using.
4793
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06004794It is an error to use this function when reading or writing a standalone
4795PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
Glenn Randers-Pehrsonf05f8032000-12-23 14:27:39 -06004796in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
4797and the MHDR and MEND chunks. Libpng does not provide support for these
4798or any other MNG chunks; your application must provide its own support for
4799them. You may wish to consider using libmng (available at
4800http://www.libmng.com) instead.
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06004801
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004802.SH VII. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004803
4804It should be noted that versions of libpng later than 0.96 are not
4805distributed by the original libpng author, Guy Schalnat, nor by
4806Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
4807distributed versions 0.89 through 0.96, but rather by another member
4808of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
4809still alive and well, but they have moved on to other things.
4810
4811The old libpng functions png_read_init(), png_write_init(),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05004812png_info_init(), png_read_destroy(), and png_write_destroy() have been
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05004813moved to PNG_INTERNAL in version 0.95 to discourage their use. These
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004814functions will be removed from libpng version 1.4.0.
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05004815
4816The preferred method of creating and initializing the libpng structures is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004817via the png_create_read_struct(), png_create_write_struct(), and
4818png_create_info_struct() because they isolate the size of the structures
4819from the application, allow version error checking, and also allow the
4820use of custom error handling routines during the initialization, which
4821the old functions do not. The functions png_read_destroy() and
4822png_write_destroy() do not actually free the memory that libpng
4823allocated for these structs, but just reset the data structures, so they
4824can be used instead of png_destroy_read_struct() and
4825png_destroy_write_struct() if you feel there is too much system overhead
4826allocating and freeing the png_struct for each image read.
4827
4828Setting the error callbacks via png_set_message_fn() before
4829png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004830because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004831to fail if the png_ptr was not initialized to zero. It is still possible
4832to set the error callbacks AFTER png_read_init(), or to change them with
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05004833png_set_error_fn(), which is essentially the same function, but with a new
4834name to force compilation errors with applications that try to use the old
4835method.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004836
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004837Starting with version 1.0.7, you can find out which version of the library
4838you are using at run-time:
4839
4840 png_uint_32 libpng_vn = png_access_version_number();
4841
4842The number libpng_vn is constructed from the major version, minor
4843version with leading zero, and release number with leading zero,
4844(e.g., libpng_vn for version 1.0.7 is 10007).
4845
4846You can also check which version of png.h you used when compiling your
4847application:
4848
4849 png_uint_32 application_vn = PNG_LIBPNG_VER;
4850
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004851.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004852
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004853Support for user memory management was enabled by default. To
4854accomplish this, the functions png_create_read_struct_2(),
4855png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
4856png_malloc_default(), and png_free_default() were added.
4857
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -06004858Support for the iTXt chunk has been enabled by default as of
4859version 1.2.41.
4860
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004861Support for certain MNG features was enabled.
4862
4863Support for numbered error messages was added. However, we never got
4864around to actually numbering the error messages. The function
4865png_set_strip_error_numbers() was added (Note: the prototype for this
4866function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
4867builds of libpng-1.2.15. It was restored in libpng-1.2.36).
4868
4869The png_malloc_warn() function was added at libpng-1.2.3. This issues
4870a png_warning and returns NULL instead of aborting when it fails to
4871acquire the requested memory allocation.
4872
4873Support for setting user limits on image width and height was enabled
4874by default. The functions png_set_user_limits(), png_get_user_width_max(),
4875and png_get_user_height_max() were added at libpng-1.2.6.
4876
4877The png_set_add_alpha() function was added at libpng-1.2.7.
4878
4879The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
4880Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
4881tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
4882deprecated.
4883
4884A number of macro definitions in support of runtime selection of
4885assembler code features (especially Intel MMX code support) were
4886added at libpng-1.2.0:
4887
4888 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
4889 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
4890 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
4891 PNG_ASM_FLAG_MMX_READ_INTERLACE
4892 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
4893 PNG_ASM_FLAG_MMX_READ_FILTER_UP
4894 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
4895 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
4896 PNG_ASM_FLAGS_INITIALIZED
4897 PNG_MMX_READ_FLAGS
4898 PNG_MMX_FLAGS
4899 PNG_MMX_WRITE_FLAGS
4900 PNG_MMX_FLAGS
4901
4902We added the following functions in support of runtime
4903selection of assembler code features:
4904
4905 png_get_mmx_flagmask()
4906 png_set_mmx_thresholds()
4907 png_get_asm_flags()
4908 png_get_mmx_bitdepth_threshold()
4909 png_get_mmx_rowbytes_threshold()
4910 png_set_asm_flags()
4911
4912We replaced all of these functions with simple stubs in libpng-1.2.20,
4913when the Intel assembler code was removed due to a licensing issue.
4914
Glenn Randers-Pehrson3d893a02009-08-31 13:32:46 -05004915These macros are deprecated:
4916
4917 PNG_READ_TRANSFORMS_NOT_SUPPORTED
4918 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
4919 PNG_NO_SEQUENTIAL_READ_SUPPORTED
4920 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
4921 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
4922 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
4923
4924They have been replaced, respectively, by:
4925
4926 PNG_NO_READ_TRANSFORMS
4927 PNG_NO_PROGRESSIVE_READ
4928 PNG_NO_SEQUENTIAL_READ
4929 PNG_NO_WRITE_TRANSFORMS
4930 PNG_NO_READ_ANCILLARY_CHUNKS
4931 PNG_NO_WRITE_ANCILLARY_CHUNKS
4932
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004933PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
4934deprecated since libpng-1.0.16 and libpng-1.2.6.
4935
4936The function
4937 png_check_sig(sig, num)
4938was replaced with
4939 !png_sig_cmp(sig, 0, num)
4940It has been deprecated since libpng-0.90.
4941
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004942The function
4943 png_set_gray_1_2_4_to_8()
4944which also expands tRNS to alpha was replaced with
4945 png_set_expand_gray_1_2_4_to_8()
4946which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004947
Glenn Randers-Pehrsond740c842009-11-04 19:01:54 -06004948.SH IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
4949
4950Private libpng prototypes and macro definitions were moved from
4951png.h and pngconf.h into a new pngpriv.h header file.
4952
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004953Functions png_set_benign_errors(), png_benign_error(), and
4954png_chunk_benign_error() were added.
4955
4956Support for setting the maximum amount of memory that the application
4957will allocate for reading chunks was added, as a security measure.
4958The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
4959were added to the library.
4960
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004961We implemented support for I/O states by adding png_ptr member io_state
4962and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004963
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004964We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
4965input transforms.
4966
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004967Checking for and reporting of errors in the IHDR chunk is more thorough.
4968
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004969Support for global arrays was removed, to improve thread safety.
4970
4971Some obsolete/deprecated macros and functions have been removed.
4972
4973Typecasted NULL definitions such as
4974 #define png_voidp_NULL (png_voidp)NULL
4975were eliminated. If you used these in your application, just use
4976NULL instead.
4977
4978The png_struct and info_struct members "trans" and "trans_values" were
4979changed to "trans_alpha" and "trans_color", respectively.
4980
4981The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004982were removed.
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004983
4984The PNG_1_0_X and PNG_1_2_X macros were eliminated.
4985
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004986The PNG_LEGACY_SUPPORTED macro was eliminated.
4987
4988Many WIN32_WCE #ifdefs were removed.
4989
4990The functions png_read_init(info_ptr), png_write_init(info_ptr),
4991png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
4992have been removed. They have been deprecated since libpng-0.95.
4993
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004994The png_permit_empty_plte() was removed. It has been deprecated
4995since libpng-1.0.9. Use png_permit_mng_features() instead.
4996
4997We removed the obsolete stub functions png_get_mmx_flagmask(),
4998png_set_mmx_thresholds(), png_get_asm_flags(),
4999png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
5000png_set_asm_flags(), and png_mmx_supported()
5001
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005002We removed the obsolete png_check_sig(), png_memcpy_check(), and
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05005003png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
5004and memset(), respectively.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005005
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005006The function png_set_gray_1_2_4_to_8() was removed. It has been
5007deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
5008png_set_expand_gray_1_2_4_to_8() because the former function also
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005009expanded any tRNS chunk to an alpha channel.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005010
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005011Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
5012were added and are used by default instead of the corresponding
5013functions. Unfortunately,
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005014from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005015function) incorrectly returned a value of type png_uint_32.
5016
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005017We changed the prototype for png_malloc() from
5018 png_malloc(png_structp png_ptr, png_uint_32 size)
5019to
5020 png_malloc(png_structp png_ptr, png_alloc_size_t size)
5021
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005022This also applies to the prototype for the user replacement malloc_fn().
5023
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005024The png_calloc() function was added and is used in place of
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05005025of "png_malloc(); memset();" except in the case in png_read_png()
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005026where the array consists of pointers; in this case a "for" loop is used
5027after the png_malloc() to set the pointers to NULL, to give robust.
5028behavior in case the application runs out of memory part-way through
5029the process.
5030
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005031We changed the prototypes of png_get_compression_buffer_size() and
5032png_set_compression_buffer_size() to work with png_size_t instead of
5033png_uint_32.
5034
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005035Support for numbered error messages was removed by default, since we
5036never got around to actually numbering the error messages. The function
5037png_set_strip_error_numbers() was removed from the library by default.
5038
5039The png_zalloc() and png_zfree() functions are no longer exported.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005040The png_zalloc() function no longer zeroes out the memory that it
5041allocates.
5042
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05005043Support for dithering was disabled by default in libpng-1.4.0, because
Glenn Randers-Pehrson9f1cd702011-04-16 19:40:23 -05005044it has not been well tested and doesn't actually "dither".
5045The code was not
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05005046removed, however, and could be enabled by building libpng with
5047PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
5048was reenabled, but the function was renamed png_set_quantize() to
5049reflect more accurately what it actually does. At the same time,
5050the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005051PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5052was renamed to PNG_READ_QUANTIZE_SUPPORTED.
Glenn Randers-Pehrson60988072010-04-13 22:11:06 -05005053
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005054We removed the trailing '.' from the warning and error messages.
5055
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005056.SH X. Changes to Libpng from version 1.4.x to 1.5.x
5057
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005058From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005059function) incorrectly returned a value of type png_uint_32.
5060
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005061A. Changes that affect users of libpng
5062
5063There are no substantial API changes between the non-deprecated parts of
5064the 1.4.5 API and the 1.5.0 API, however the ability to directly access
5065the main libpng control structures, png_struct and png_info, deprecated
5066in earlier versions of libpng, has been completely removed from
5067libpng 1.5.
5068
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005069We no longer include zlib.h in png.h. Applications that need access
5070to information in zlib.h will need to add the '#include "zlib.h"'
5071directive. It does not matter whether it is placed prior to or after
5072the '"#include png.h"' directive.
5073
5074We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
5075png_memcmp(), png_sprintf, and png_memcpy() macros into a private
5076header file (pngpriv.h) that is not accessible to applications.
5077
Glenn Randers-Pehrson9d23b402011-01-08 10:42:01 -06005078In png_get_iCCP, the type of "profile" was changed from png_charpp
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005079to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
Glenn Randers-Pehrson9d23b402011-01-08 10:42:01 -06005080
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005081There are changes of form in png.h, including new and changed macros to
5082declare
Glenn Randers-Pehrsonf5ea1b72011-01-06 06:42:51 -06005083parts of the API. Some API functions with arguments that are pointers to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005084data not modified within the function have been corrected to declare
5085these arguments with PNG_CONST.
5086
5087Much of the internal use of C macros to control the library build has also
5088changed and some of this is visible in the exported header files, in
5089particular the use of macros to control data and API elements visible
5090during application compilation may require significant revision to
5091application code. (It is extremely rare for an application to do this.)
5092
5093Any program that compiled against libpng 1.4 and did not use deprecated
5094features or access internal library structures should compile and work
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -06005095against libpng 1.5, except for the change in the prototype for
5096png_get_iCCP() and png_set_iCCP() API functions mentioned above.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005097
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06005098libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5099interlaced images. The macros return the number of rows and columns in
5100each pass and information that can be used to de-interlace and (if
5101absolutely necessary) interlace an image.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005102
5103libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -06005104the application-provided png_longjmp_ptr on the internal, but application
Glenn Randers-Pehrson33ced442011-04-27 14:58:06 -05005105initialized, longjmp buffer. It is provided as a convenience to avoid
5106the need to use the png_jmpbuf macro, which had the unnecessary side
5107effect of resetting the internal png_longjmp_ptr value.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005108
5109libpng 1.5.0 includes a complete fixed point API. By default this is
5110present along with the corresponding floating point API. In general the
5111fixed point API is faster and smaller than the floating point one because
5112the PNG file format used fixed point, not floating point. This applies
5113even if the library uses floating point in internal calculations. A new
5114macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5115uses floating point arithmetic (the default) or fixed point arithmetic
5116internally for performance critical calculations such as gamma correction.
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005117In some cases, the gamma calculations may produce slightly different
5118results. This has changed the results in png_rgb_to_gray and in alpha
5119composition (png_set_background for example). This applies even if the
5120original image was already linear (gamma == 1.0) and, therefore, it is
5121not necessary to linearize the image. This is because libpng has *not*
5122been changed to optimize that case correctly, yet.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005123
5124Fixed point support for the sCAL chunk comes with an important caveat;
5125the sCAL specification uses a decimal encoding of floating point values
5126and the accuracy of PNG fixed point values is insufficient for
5127representation of these values. Consequently a "string" API
5128(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5129arbitrary sCAL chunks in the absence of either the floating point API or
5130internal floating point calculations.
5131
5132Applications no longer need to include the optional distribution header
5133file pngusr.h or define the corresponding macros during application
5134build in order to see the correct variant of the libpng API. From 1.5.0
5135application code can check for the corresponding _SUPPORTED macro:
5136
5137#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
5138 /* code that uses the inch conversion APIs. */
5139#endif
5140
5141This macro will only be defined if the inch conversion functions have been
5142compiled into libpng. The full set of macros, and whether or not support
5143has been compiled in, are available in the header file pnglibconf.h.
5144This header file is specific to the libpng build. Notice that prior to
51451.5.0 the _SUPPORTED macros would always have the default definition unless
5146reset by pngusr.h or by explicit settings on the compiler command line.
5147These settings may produce compiler warnings or errors in 1.5.0 because
5148of macro redefinition.
5149
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005150From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005151function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
5152is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5153did not exist.)
5154
5155Applications can now choose whether to use these macros or to call the
5156corresponding function by defining PNG_USE_READ_MACROS or
5157PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
5158only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
5159 will lead to a link failure.
Glenn Randers-Pehrson59fa3e92011-01-06 07:07:06 -06005160
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005161Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05005162when compressing the IDAT data and textual data such as zTXt and iCCP.
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005163In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05005164We added five png_set_text_*() functions for setting the parameters to
5165use with textual data.
5166
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005167Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
John Bowlerb2bee332011-06-10 23:24:58 -05005168option was off by default, and slightly inaccurate scaling occurred.
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05005169This option can no longer be turned off, and the choice of accurate
5170or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5171API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5172chopping.
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05005173
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005174Prior to libpng-1.5.4, the png_set_user_limits() function could only be
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05005175used to reduce the width and height limits from the value of
5176PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5177that it could be used to override them. Now this function will reduce or
5178increase the limits.
John Bowlerb2bee332011-06-10 23:24:58 -05005179
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005180B. Changes to the build and configuration of libpng
5181
5182Details of internal changes to the library code can be found in the CHANGES
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005183file and in the GIT repository logs. These will be of no concern to the vast
5184majority of library users or builders, however the few who configure libpng
5185to a non-default feature set may need to change how this is done.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005186
5187There should be no need for library builders to alter build scripts if
5188these use the distributed build support - configure or the makefiles -
5189however users of the makefiles may care to update their build scripts
5190to build pnglibconf.h where the corresponding makefile does not do so.
5191
5192Building libpng with a non-default configuration has changed completely.
5193The old method using pngusr.h should still work correctly even though the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005194way pngusr.h is used in the build has been changed; however, library
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005195builders will probably want to examine the changes to take advantage of
5196new capabilities and to simplify their build system.
5197
5198B.1 Specific changes to library configuration capabilities
5199
5200The library now supports a complete fixed point implementation and can
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005201thus be used on systems that have no floating point support or very
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005202limited or slow support. Previously gamma correction, an essential part
5203of complete PNG support, required reasonably fast floating point.
5204
5205As part of this the choice of internal implementation has been made
5206independent of the choice of fixed versus floating point APIs and all the
5207missing fixed point APIs have been implemented.
5208
5209The exact mechanism used to control attributes of API functions has
5210changed. A single set of operating system independent macro definitions
5211is used and operating system specific directives are defined in
5212pnglibconf.h
5213
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005214As part of this the mechanism used to choose procedure call standards on
5215those systems that allow a choice has been changed. At present this only
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005216affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005217running on Intel processors. As before, PNGAPI is defined where required
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005218to control the exported API functions; however, two new macros, PNGCBAPI
5219and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5220(PNGCAPI) for functions that must match a C library prototype (currently
5221only png_longjmp_ptr, which must match the C longjmp function.) The new
5222approach is documented in pngconf.h
5223
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005224Despite these changes, libpng 1.5.0 only supports the native C function
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005225calling standard on those platforms tested so far (__cdecl on Microsoft
5226Windows). This is because the support requirements for alternative
5227calling conventions seem to no longer exist. Developers who find it
5228necessary to set PNG_API_RULE to 1 should advise the mailing list
5229(png-mng-implement) of this and library builders who use Openwatcom and
5230therefore set PNG_API_RULE to 2 should also contact the mailing list.
5231
5232A new test program, pngvalid, is provided in addition to pngtest.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005233pngvalid validates the arithmetic accuracy of the gamma correction
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005234calculations and includes a number of validations of the file format.
5235A subset of the full range of tests is run when "make check" is done
5236(in the 'configure' build.) pngvalid also allows total allocated memory
5237usage to be evaluated and performs additional memory overwrite validation.
5238
5239Many changes to individual feature macros have been made. The following
5240are the changes most likely to be noticed by library builders who
5241configure libpng:
5242
52431) All feature macros now have consistent naming:
5244
5245#define PNG_NO_feature turns the feature off
5246#define PNG_feature_SUPPORTED turns the feature on
5247
5248pnglibconf.h contains one line for each feature macro which is either:
5249
5250#define PNG_feature_SUPPORTED
5251
5252if the feature is supported or:
5253
5254/*#undef PNG_feature_SUPPORTED*/
5255
5256if it is not. Library code consistently checks for the 'SUPPORTED' macro.
Glenn Randers-Pehrsond0797f52011-07-12 10:28:02 -05005257It does not, and libpng applications should not, check for the 'NO' macro
5258which will not normally be defined even if the feature is not supported.
5259The 'NO' macros are only used internally for setting or not setting the
5260corresponding 'SUPPORTED' macros.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005261
5262Compatibility with the old names is provided as follows:
5263
5264PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5265
5266And the following definitions disable the corresponding feature:
5267
5268PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5269PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5270PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5271PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5272PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5273PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5274
5275Library builders should remove use of the above, inconsistent, names.
5276
52772) Warning and error message formatting was previously conditional on
5278the STDIO feature. The library has been changed to use the
5279CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5280the library no longer uses the printf(3) functions, even though the
5281default read/write implementations use (FILE) style stdio.h functions.
5282
52833) Three feature macros now control the fixed/floating point decisions:
5284
5285PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5286
5287PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5288practice these are normally required internally anyway (because the PNG
5289file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5290merely stops the function from being exported.
5291
5292PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5293point implementation or the fixed point one. Typically the fixed point
5294implementation is larger and slower than the floating point implementation
5295on a system that supports floating point, however it may be faster on a
5296system which lacks floating point hardware and therefore uses a software
5297emulation.
5298
52994) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
5300functions to read and write ints to be disabled independently of
5301PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5302even though the default is to use the macros - this allows applications
5303to choose at app buildtime whether or not to use macros (previously
5304impossible because the functions weren't in the default build.)
5305
5306B.2 Changes to the configuration mechanism
5307
5308Prior to libpng-1.5.0 library builders who needed to configure libpng
5309had either to modify the exported pngconf.h header file to add system
5310specific configuration or had to write feature selection macros into
5311pngusr.h and cause this to be included into pngconf.h by defining
5312PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5313application built without PNG_USER_CONFIG defined would see the
5314unmodified, default, libpng API and thus would probably fail to link.
5315
5316These mechanisms still work in the configure build and in any makefile
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005317build that builds pnglibconf.h, although the feature selection macros
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005318have changed somewhat as described above. In 1.5.0, however, pngusr.h is
5319processed only once, when the exported header file pnglibconf.h is built.
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005320pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005321build of pnglibconf.h and it is never included in an application build.
5322
5323The rarely used alternative of adding a list of feature macros to the
5324CFLAGS setting in the build also still works, however the macros will be
5325copied to pnglibconf.h and this may produce macro redefinition warnings
5326when the individual C files are compiled.
5327
5328All configuration now only works if pnglibconf.h is built from
5329scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
5330(the original author of awk) maintains C source code of that awk and this
5331and all known later implementations (often called by subtly different
5332names - nawk and gawk for example) are adequate to build pnglibconf.h.
5333The Sun Microsystems (now Oracle) program 'awk' is an earlier version
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005334and does not work; this may also apply to other systems that have a
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005335functioning awk called 'nawk'.
5336
5337Configuration options are now documented in scripts/pnglibconf.dfa. This
5338file also includes dependency information that ensures a configuration is
5339consistent; that is, if a feature is switched off dependent features are
5340also removed. As a recommended alternative to using feature macros in
5341pngusr.h a system builder may also define equivalent options in pngusr.dfa
5342(or, indeed, any file) and add that to the configuration by setting
5343DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
5344how to do this, and a case where pngusr.h is still required.
5345
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005346.SH XI. Detecting libpng
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05005347
5348The png_get_io_ptr() function has been present since libpng-0.88, has never
5349changed, and is unaffected by conditional compilation macros. It is the
5350best choice for use in configure scripts for detecting the presence of any
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05005351libpng version since 0.88. In an autoconf "configure.in" you could use
5352
5353 AC_CHECK_LIB(png, png_get_io_ptr, ...
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05005354
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005355.SH XII. Source code repository
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005356
5357Since about February 2009, version 1.2.34, libpng has been under "git" source
5358control. The git repository was built from old libpng-x.y.z.tar.gz files
5359going back to version 0.70. You can access the git repository (read only)
5360at
5361
5362 git://libpng.git.sourceforge.net/gitroot/libpng
5363
5364or you can browse it via "gitweb" at
5365
5366 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
5367
5368Patches can be sent to glennrp at users.sourceforge.net or to
5369png-mng-implement at lists.sourceforge.net or you can upload them to
5370the libpng bug tracker at
5371
5372 http://libpng.sourceforge.net
5373
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005374We also accept patches built from the tar or zip distributions, and
5375simple verbal discriptions of bug fixes, reported either to the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005376SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5377mailing list, or directly to glennrp.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005378
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005379.SH XIII. Coding style
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005380
5381Our coding style is similar to the "Allman" style, with curly
5382braces on separate lines:
5383
5384 if (condition)
5385 {
5386 action;
5387 }
5388
5389 else if (another condition)
5390 {
5391 another action;
5392 }
5393
5394The braces can be omitted from simple one-line actions:
5395
5396 if (condition)
5397 return (0);
5398
5399We use 3-space indentation, except for continued statements which
5400are usually indented the same as the first line of the statement
5401plus four more spaces.
5402
Glenn Randers-Pehrson5ade7ed2009-09-30 15:11:49 -05005403For macro definitions we use 2-space indentation, always leaving the "#"
5404in the first column.
5405
5406 #ifndef PNG_NO_FEATURE
5407 # ifndef PNG_FEATURE_SUPPORTED
5408 # define PNG_FEATURE_SUPPORTED
5409 # endif
5410 #endif
5411
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005412Comments appear with the leading "/*" at the same indentation as
5413the statement that follows the comment:
5414
5415 /* Single-line comment */
5416 statement;
5417
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005418 /* This is a multiple-line
5419 * comment.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005420 */
5421 statement;
5422
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005423Very short comments can be placed after the end of the statement
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005424to which they pertain:
5425
5426 statement; /* comment */
5427
5428We don't use C++ style ("//") comments. We have, however,
5429used them in the past in some now-abandoned MMX assembler
5430code.
5431
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05005432Functions and their curly braces are not indented, and
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005433exported functions are marked with PNGAPI:
5434
5435 /* This is a public function that is visible to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005436 * application programmers. It does thus-and-so.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005437 */
5438 void PNGAPI
5439 png_exported_function(png_ptr, png_info, foo)
5440 {
5441 body;
5442 }
5443
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005444The prototypes for all exported functions appear in png.h,
5445above the comment that says
5446
5447 /* Maintainer: Put new public prototypes here ... */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005448
5449We mark all non-exported functions with "/* PRIVATE */"":
5450
5451 void /* PRIVATE */
5452 png_non_exported_function(png_ptr, png_info, foo)
5453 {
5454 body;
5455 }
5456
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005457The prototypes for non-exported functions (except for those in
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05005458pngtest) appear in
5459pngpriv.h
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005460above the comment that says
5461
5462 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005463
Glenn Randers-Pehrsoncbbe9a52011-01-29 16:12:11 -06005464To avoid polluting the global namespace, the names of all exported
5465functions and variables begin with "png_", and all publicly visible C
5466preprocessor macros begin with "PNG_". We request that applications that
5467use libpng *not* begin any of their own symbols with either of these strings.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005468
5469We put a space after each comma and after each semicolon
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005470in "for" statements, and we put spaces before and after each
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005471C binary operator and after "for" or "while", and before
5472"?". We don't put a space between a typecast and the expression
5473being cast, nor do we put one between a function name and the
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005474left parenthesis that follows it:
5475
5476 for (i = 2; i > 0; --i)
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05005477 y[i] = a(x) + (int)b;
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005478
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05005479We prefer #ifdef and #ifndef to #if defined() and if !defined()
5480when there is only one macro being tested.
5481
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05005482We do not use the TAB character for indentation in the C sources.
5483
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06005484Lines do not exceed 80 characters.
5485
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06005486Other rules can be inferred by inspecting the libpng source.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005487
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005488.SH XIV. Y2K Compliance in libpng
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005489
John Bowler736f40f2011-08-25 16:19:44 -05005490August 25, 2011
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005491
5492Since the PNG Development group is an ad-hoc body, we can't make
5493an official declaration.
5494
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005495This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrson9d824eb2011-08-17 07:52:32 -05005496upward through 1.5.5beta06 are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005497versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005498
5499Libpng only has three year fields. One is a 2-byte unsigned integer that
5500will hold years up to 65535. The other two hold the date in text
5501format, and will hold years up to 9999.
5502
5503The integer is
5504 "png_uint_16 year" in png_time_struct.
5505
5506The strings are
5507 "png_charp time_buffer" in png_struct and
5508 "near_time_buffer", which is a local character string in png.c.
5509
5510There are seven time-related functions:
5511
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005512 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005513 (formerly png_convert_to_rfc_1152() in error)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005514 png_convert_from_struct_tm() in pngwrite.c, called
5515 in pngwrite.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005516 png_convert_from_time_t() in pngwrite.c
5517 png_get_tIME() in pngget.c
5518 png_handle_tIME() in pngrutil.c, called in pngread.c
5519 png_set_tIME() in pngset.c
5520 png_write_tIME() in pngwutil.c, called in pngwrite.c
5521
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005522All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005523png_convert_from_time_t() function calls gmtime() to convert from system
5524clock time, which returns (year - 1900), which we properly convert to
5525the full 4-digit year. There is a possibility that applications using
5526libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005527function, or that they are incorrectly passing only a 2-digit year
5528instead of "year - 1900" into the png_convert_from_struct_tm() function,
5529but this is not under our control. The libpng documentation has always
5530stated that it works with 4-digit years, and the APIs have been
5531documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005532
5533The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
5534integer to hold the year, and can hold years as large as 65535.
5535
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005536zlib, upon which libpng depends, is also Y2K compliant. It contains
5537no date-related code.
5538
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005539
5540 Glenn Randers-Pehrson
5541 libpng maintainer
5542 PNG Development Group
5543
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005544.SH NOTE
5545
5546Note about libpng version numbers:
5547
5548Due to various miscommunications, unforeseen code incompatibilities
5549and occasional factors outside the authors' control, version numbering
5550on the library has not always been consistent and straightforward.
5551The following table summarizes matters since version 0.89c, which was
5552the first widely used release:
5553
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005554 source png.h png.h shared-lib
5555 version string int version
5556 ------- ------ ----- ----------
5557 0.89c ("beta 3") 0.89 89 1.0.89
5558 0.90 ("beta 4") 0.90 90 0.90
5559 0.95 ("beta 5") 0.95 95 0.95
5560 0.96 ("beta 6") 0.96 96 0.96
5561 0.97b ("beta 7") 1.00.97 97 1.0.1
5562 0.97c 0.97 97 2.0.97
5563 0.98 0.98 98 2.0.98
5564 0.99 0.99 98 2.0.99
5565 0.99a-m 0.99 99 2.0.99
5566 1.00 1.00 100 2.1.0
5567 1.0.0 1.0.0 100 2.1.0
5568 1.0.0 (from here on, the 100 2.1.0
5569 1.0.1 png.h string is 10001 2.1.0
5570 1.0.1a-e identical to the 10002 from here on, the
5571 1.0.2 source version) 10002 shared library is 2.V
5572 1.0.2a-b 10003 where V is the source
5573 1.0.1 10001 code version except as
5574 1.0.1a-e 10002 2.1.0.1a-e noted.
5575 1.0.2 10002 2.1.0.2
5576 1.0.2a-b 10003 2.1.0.2a-b
5577 1.0.3 10003 2.1.0.3
5578 1.0.3a-d 10004 2.1.0.3a-d
5579 1.0.4 10004 2.1.0.4
5580 1.0.4a-f 10005 2.1.0.4a-f
5581 1.0.5 (+ 2 patches) 10005 2.1.0.5
5582 1.0.5a-d 10006 2.1.0.5a-d
5583 1.0.5e-r 10100 2.1.0.5e-r
5584 1.0.5s-v 10006 2.1.0.5s-v
5585 1.0.6 (+ 3 patches) 10006 2.1.0.6
5586 1.0.6d-g 10007 2.1.0.6d-g
5587 1.0.6h 10007 10.6h
5588 1.0.6i 10007 10.6i
5589 1.0.6j 10007 2.1.0.6j
Glenn Randers-Pehrson25467032011-01-28 11:58:40 -06005590 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005591 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
5592 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
5593 1.0.7 1 10007 2.1.0.7
5594 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
5595 1.0.8rc1 1 10008 2.1.0.8rc1
5596 1.0.8 1 10008 2.1.0.8
5597 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
5598 1.0.9rc1 1 10009 2.1.0.9rc1
5599 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
5600 1.0.9rc2 1 10009 2.1.0.9rc2
5601 1.0.9 1 10009 2.1.0.9
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06005602 1.0.10beta1 1 10010 2.1.0.10beta1
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005603 1.0.10rc1 1 10010 2.1.0.10rc1
Glenn Randers-Pehrson13cfbac2001-03-30 06:42:28 -06005604 1.0.10 1 10010 2.1.0.10
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -05005605 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05005606 1.0.11rc1 1 10011 2.1.0.11rc1
Glenn Randers-Pehrson32835392001-04-27 08:29:32 -05005607 1.0.11 1 10011 2.1.0.11
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05005608 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
5609 1.0.12rc1 2 10012 2.1.0.12rc1
5610 1.0.12 2 10012 2.1.0.12
5611 1.1.0a-f - 10100 2.1.1.0a-f abandoned
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05005612 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
Glenn Randers-Pehrson5a0be342001-10-18 20:55:13 -05005613 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
5614 1.2.0rc1 3 10200 3.1.2.0rc1
5615 1.2.0 3 10200 3.1.2.0
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -06005616 1.2.1beta-4 3 10201 3.1.2.1beta1-4
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -06005617 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
5618 1.2.1 3 10201 3.1.2.1
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -06005619 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
Glenn Randers-Pehrsonfcbd7872002-04-07 16:35:38 -05005620 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
5621 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
5622 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005623 1.0.13 10 10013 10.so.0.1.0.13
5624 1.2.2 12 10202 12.so.0.1.2.2
Glenn Randers-Pehrson22f28962002-05-13 18:17:09 -05005625 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
5626 1.2.3 12 10203 12.so.0.1.2.3
Glenn Randers-Pehrsond020e9d2002-06-28 09:34:00 -05005627 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -05005628 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
Glenn Randers-Pehrson484a8a12002-07-07 19:15:20 -05005629 1.0.14 10 10014 10.so.0.1.0.14
5630 1.2.4 13 10204 12.so.0.1.2.4
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05005631 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
5632 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005633 1.0.15 10 10015 10.so.0.1.0.15
5634 1.2.5 13 10205 12.so.0.1.2.5
5635 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
Glenn Randers-Pehrson37f116a2004-08-15 07:15:39 -05005636 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
5637 1.0.16 10 10016 10.so.0.1.0.16
5638 1.2.6 13 10206 12.so.0.1.2.6
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05005639 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05005640 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
5641 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
Glenn Randers-Pehrson250dfe12004-09-11 21:19:54 -05005642 1.0.17 10 10017 12.so.0.1.0.17
5643 1.2.7 13 10207 12.so.0.1.2.7
Glenn Randers-Pehrson40936072004-11-20 11:18:40 -06005644 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
Glenn Randers-Pehrson584b96e2004-11-29 15:08:00 -06005645 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
5646 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06005647 1.0.18 10 10018 12.so.0.1.0.18
5648 1.2.8 13 10208 12.so.0.1.2.8
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06005649 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -06005650 1.2.9beta4-11 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrson3a512032006-03-31 05:29:33 -06005651 1.2.9rc1 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsona7d0c942006-04-14 06:22:52 -05005652 1.2.9 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05005653 1.2.10beta1-7 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -05005654 1.2.10rc1-2 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson86dc9812006-05-10 07:27:44 -05005655 1.2.10 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05005656 1.4.0beta1-6 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05005657 1.2.11beta1-4 13 10210 12.so.0.11[.0]
Glenn Randers-Pehrson3424ee72006-07-12 13:33:47 -05005658 1.4.0beta7-8 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrson701dbaa2006-11-17 09:36:54 -06005659 1.2.11 13 10211 12.so.0.11[.0]
5660 1.2.12 13 10212 12.so.0.12[.0]
5661 1.4.0beta9-14 14 10400 14.so.0.0[.0]
5662 1.2.13 13 10213 12.so.0.13[.0]
Glenn Randers-Pehrson97a9b482008-10-25 20:03:28 -05005663 1.4.0beta15-36 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsonfa028102009-10-10 06:15:21 -05005664 1.4.0beta37-87 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson733da8c2009-10-30 00:00:15 -05005665 1.4.0rc01 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06005666 1.4.0beta88-109 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson67a83db2010-01-01 18:26:18 -06005667 1.4.0rc02-08 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsondbcfb712009-12-25 14:24:18 -06005668 1.4.0 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005669 1.4.1beta01-03 14 10401 14.so.14.1[.0]
5670 1.4.1rc01 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06005671 1.4.1beta04-12 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrsonaaf377c2010-03-08 11:20:30 -06005672 1.4.1 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrson5b3d5542010-06-18 21:55:53 -05005673 1.4.2 14 10402 14.so.14.2[.0]
5674 1.4.3 14 10403 14.so.14.3[.0]
Glenn Randers-Pehrson2776d5e2010-11-21 15:18:02 -06005675 1.4.4 14 10404 14.so.14.4[.0]
Glenn Randers-Pehrsonfd20a5a2010-12-27 08:53:08 -06005676 1.5.0beta01-58 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrson64b863c2011-01-04 09:57:06 -06005677 1.5.0rc01-07 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrsonf5ea1b72011-01-06 06:42:51 -06005678 1.5.0 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrsonef123cc2011-01-28 15:20:34 -06005679 1.5.1beta01-11 15 10501 15.so.15.1[.0]
Glenn Randers-Pehrson3d3aae12011-02-02 22:58:27 -06005680 1.5.1rc01-02 15 10501 15.so.15.1[.0]
5681 1.5.1 15 10501 15.so.15.1[.0]
Glenn Randers-Pehrsonf3dd1cc2011-03-18 22:02:20 -05005682 1.5.2beta01-03 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrson77fd0832011-03-24 08:59:48 -05005683 1.5.2rc01-03 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrsondcc35052011-03-31 11:23:49 -05005684 1.5.2 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrson36edbb52011-06-03 07:15:04 -05005685 1.5.3beta01-10 15 10503 15.so.15.3[.0]
Glenn Randers-Pehrsonfb278732011-06-10 20:43:39 -05005686 1.5.3rc01-02 15 10503 15.so.15.3[.0]
Glenn Randers-Pehrson413138a2011-06-13 22:07:37 -05005687 1.5.3beta11 15 10503 15.so.15.3[.0]
5688 1.5.3 [omitted]
Glenn Randers-Pehrson9daf91e2011-06-22 23:10:36 -05005689 1.5.4beta01-08 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrson78bb9da2011-06-30 18:59:45 -05005690 1.5.4rc01 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrsond404b6d2011-07-07 06:24:57 -05005691 1.5.4 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrson9d824eb2011-08-17 07:52:32 -05005692 1.5.5beta01-06 15 10505 15.so.15.5[.0]
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005693
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005694Henceforth the source version will match the shared-library minor
5695and patch numbers; the shared-library major version number will be
5696used for changes in backward compatibility, as it is intended. The
5697PNG_PNGLIB_VER macro, which is not used within libpng but is available
5698for applications, is an unsigned integer of the form xyyzz corresponding
5699to the source version x.y.z (leading zeros in y and z). Beta versions
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06005700were given the previous public release number plus a letter, until
5701version 1.0.6j; from then on they were given the upcoming public
5702release number plus "betaNN" or "rcN".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005703
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005704.SH "SEE ALSO"
Glenn Randers-Pehrson4e763f12010-03-03 10:45:50 -06005705.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
Glenn Randers-Pehrson7fb32a82010-03-03 09:47:49 -06005706
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005707.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005708.IR libpng :
5709.IP
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05005710http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06005711http://www.libpng.org/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005712
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005713.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005714.IR zlib :
5715.IP
5716(generally) at the same location as
5717.I libpng
5718or at
5719.br
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06005720ftp://ftp.info-zip.org/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005721
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005722.LP
5723.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005724.IP
5725(generally) at the same location as
5726.I libpng
5727or at
5728.br
5729ftp://ds.internic.net/rfc/rfc2083.txt
5730.br
5731or (as a W3C Recommendation) at
5732.br
5733http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005734
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005735.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005736In the case of any inconsistency between the PNG specification
5737and this library, the specification takes precedence.
5738
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005739.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005740This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06005741<glennrp at users.sourceforge.net>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005742
5743The contributing authors would like to thank all those who helped
5744with testing, bug fixes, and patience. This wouldn't have been
5745possible without all of you.
5746
5747Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005748
John Bowler736f40f2011-08-25 16:19:44 -05005749Libpng version 1.5.5beta06 - August 25, 2011:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005750Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06005751Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005752
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005753Supported by the PNG development group
5754.br
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06005755png-mng-implement at lists.sf.net
5756(subscription required; visit
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -06005757png-mng-implement at lists.sourceforge.net (subscription required; visit
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06005758https://lists.sourceforge.net/lists/listinfo/png-mng-implement
5759to subscribe).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005760
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005761.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005762
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06005763(This copy of the libpng notices is provided for your convenience. In case of
5764any discrepancy between this copy and the notices in the file png.h that is
5765included in the libpng distribution, the latter shall prevail.)
5766
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005767If you modify libpng you may insert additional notices immediately following
5768this sentence.
5769
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05005770This code is released under the libpng license.
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05005771
John Bowler736f40f2011-08-25 16:19:44 -05005772libpng versions 1.2.6, August 15, 2004, through 1.5.5beta06, August 25, 2011, are
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05005773Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005774distributed according to the same disclaimer and license as libpng-1.2.5
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05005775with the following individual added to the list of Contributing Authors
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005776
5777 Cosmin Truta
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005778
5779libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06005780Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson32fc5ce2000-07-24 06:34:14 -05005781distributed according to the same disclaimer and license as libpng-1.0.6
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005782with the following individuals added to the list of Contributing Authors
5783
5784 Simon-Pierre Cadieux
5785 Eric S. Raymond
5786 Gilles Vollant
5787
5788and with the following additions to the disclaimer:
5789
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005790 There is no warranty against interference with your
5791 enjoyment of the library or against infringement.
5792 There is no warranty that our efforts or the library
5793 will fulfill any of your particular purposes or needs.
5794 This library is provided with all faults, and the entire
5795 risk of satisfactory quality, performance, accuracy, and
5796 effort is with the user.
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005797
5798libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
5799Copyright (c) 1998, 1999 Glenn Randers-Pehrson
5800Distributed according to the same disclaimer and license as libpng-0.96,
5801with the following individuals added to the list of Contributing Authors:
5802
5803 Tom Lane
5804 Glenn Randers-Pehrson
5805 Willem van Schaik
5806
5807libpng versions 0.89, June 1996, through 0.96, May 1997, are
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05005808Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005809Distributed according to the same disclaimer and license as libpng-0.88,
5810with the following individuals added to the list of Contributing Authors:
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005811
5812 John Bowler
5813 Kevin Bracey
5814 Sam Bushell
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005815 Magnus Holmgren
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005816 Greg Roelofs
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005817 Tom Tanner
5818
5819libpng versions 0.5, May 1995, through 0.88, January 1996, are
5820Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
5821
5822For the purposes of this copyright and license, "Contributing Authors"
5823is defined as the following set of individuals:
5824
5825 Andreas Dilger
5826 Dave Martindale
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005827 Guy Eric Schalnat
5828 Paul Schmidt
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005829 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06005830
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005831The PNG Reference Library is supplied "AS IS". The Contributing Authors
5832and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005833including, without limitation, the warranties of merchantability and of
5834fitness for any purpose. The Contributing Authors and Group 42, Inc.
5835assume no liability for direct, indirect, incidental, special, exemplary,
5836or consequential damages, which may result from the use of the PNG
5837Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005838
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005839Permission is hereby granted to use, copy, modify, and distribute this
5840source code, or portions hereof, for any purpose, without fee, subject
5841to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005842
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -050058431. The origin of this source code must not be misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005844
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060058452. Altered versions must be plainly marked as such and
5846 must not be misrepresented as being the original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005847
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060058483. This Copyright notice may not be removed or altered from
5849 any source or altered source distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005850
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005851The Contributing Authors and Group 42, Inc. specifically permit, without
5852fee, and encourage the use of this source code as a component to
5853supporting the PNG file format in commercial products. If you use this
5854source code in a product, acknowledgment is not required but would be
5855appreciated.
5856
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005857
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005858A "png_get_copyright" function is available, for convenient use in "about"
5859boxes and the like:
5860
5861 printf("%s",png_get_copyright(NULL));
5862
5863Also, the PNG logo (in PNG format, of course) is supplied in the
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -05005864files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005865
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005866Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005867certification mark of the Open Source Initiative.
5868
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005869Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06005870glennrp at users.sourceforge.net
John Bowler736f40f2011-08-25 16:19:44 -05005871August 25, 2011
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005872
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005873.\" end of man page
5874