blob: 2094a0cb557414a2c5d91d24e14a21c32b245f17 [file] [log] [blame]
Glenn Randers-Pehrsonfaf38ee2012-02-26 21:11:25 -06001.TH LIBPNG 3 "February 27, 2012"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06003libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta15
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004.SH SYNOPSIS
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -06005\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-Pehrsonc737b7c2012-02-16 20:07:15 -060013\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-Pehrsonc737b7c2012-02-16 20:07:15 -060017\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
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -060021\fI\fB
22
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060023\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
24
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -060025\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-Pehrsonc737b7c2012-02-16 20:07:15 -060029\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-Pehrsonc737b7c2012-02-16 20:07:15 -060033\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-Pehrsonc737b7c2012-02-16 20:07:15 -060037\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-Pehrsonc737b7c2012-02-16 20:07:15 -060041\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-Pehrsonc737b7c2012-02-16 20:07:15 -060045\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-Pehrsonc737b7c2012-02-16 20:07:15 -060049\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-Pehrsonc737b7c2012-02-16 20:07:15 -060053\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-Pehrsonc737b7c2012-02-16 20:07:15 -060057\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-Pehrsonc737b7c2012-02-16 20:07:15 -060061\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-Pehrsonc737b7c2012-02-16 20:07:15 -060065\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
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -060069\fI\fB
70
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060071\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-Pehrsonc737b7c2012-02-16 20:07:15 -060073\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-Pehrsonc737b7c2012-02-16 20:07:15 -060077\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-Pehrsonc737b7c2012-02-16 20:07:15 -060081\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-Pehrsonc737b7c2012-02-16 20:07:15 -060085\fI\fB
86
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060087\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
88
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -060089\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-Pehrsonc737b7c2012-02-16 20:07:15 -060093\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-Pehrsonc737b7c2012-02-16 20:07:15 -060097\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600101\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600105\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600109\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600113\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600117\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600121\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600125\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600129\fI\fB
130
131\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
138
139\fI\fB
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500140
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
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600143\fI\fB
144
John Bowler736f40f2011-08-25 16:19:44 -0500145\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
146
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -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
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600151\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600155\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600159\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600163\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600167\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
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600171\fI\fB
172
John Bowlerf19abd62011-01-22 18:29:24 -0600173\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
174
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600175\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600179\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600183\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600187\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600191\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600195\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600199\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600203\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600207\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600211\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600215\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600219\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-Pehrsonc737b7c2012-02-16 20:07:15 -0600223\fI\fB
224
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-Pehrsonc737b7c2012-02-16 20:07:15 -0600227\fI\fB
228
John Bowler0a5c9c02011-01-22 17:36:34 -0600229\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -0600230
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600231\fI\fB
232
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500233\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
234
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600235\fI\fB
236
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -0600237\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
238
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600239\fI\fB
240
John Bowler0a5c9c02011-01-22 17:36:34 -0600241\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600242
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600243\fI\fB
244
John Bowler0a5c9c02011-01-22 17:36:34 -0600245\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500246
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600247\fI\fB
248
John Bowler0a5c9c02011-01-22 17:36:34 -0600249\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 -0500250
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600251\fI\fB
252
John Bowler0a5c9c02011-01-22 17:36:34 -0600253\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 -0500254
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600255\fI\fB
256
John Bowler0a5c9c02011-01-22 17:36:34 -0600257\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 -0500258
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600259\fI\fB
260
John Bowler0a5c9c02011-01-22 17:36:34 -0600261\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 -0500262
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600263\fI\fB
264
John Bowler0a5c9c02011-01-22 17:36:34 -0600265\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 -0600266
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600267\fI\fB
268
John Bowler0a5c9c02011-01-22 17:36:34 -0600269\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 -0500270
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600271\fI\fB
272
John Bowler0a5c9c02011-01-22 17:36:34 -0600273\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 -0600274
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600275\fI\fB
276
John Bowler0a5c9c02011-01-22 17:36:34 -0600277\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 -0500278
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600279\fI\fB
280
John Bowler0a5c9c02011-01-22 17:36:34 -0600281\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500282
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600283\fI\fB
284
John Bowler0a5c9c02011-01-22 17:36:34 -0600285\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 -0500286
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600287\fI\fB
288
289\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr)
290
291\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
292
293\fI\fB
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500294
John Bowler0a5c9c02011-01-22 17:36:34 -0600295\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 -0600296
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600297\fI\fB
298
John Bowler0a5c9c02011-01-22 17:36:34 -0600299\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 -0500300
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600301\fI\fB
302
John Bowler0a5c9c02011-01-22 17:36:34 -0600303\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 -0500304
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600305\fI\fB
306
John Bowler0a5c9c02011-01-22 17:36:34 -0600307\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 -0500308
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600309\fI\fB
310
John Bowler0a5c9c02011-01-22 17:36:34 -0600311\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 -0500312
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600313\fI\fB
314
John Bowler0a5c9c02011-01-22 17:36:34 -0600315\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 -0500316
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600317\fI\fB
318
John Bowler0a5c9c02011-01-22 17:36:34 -0600319\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 -0600320
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600321\fI\fB
322
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600323\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 -0500324
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600325\fI\fB
326
John Bowler0a5c9c02011-01-22 17:36:34 -0600327\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 -0500328
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600329\fI\fB
330
John Bowler0a5c9c02011-01-22 17:36:34 -0600331\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 -0500332
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600333\fI\fB
334
John Bowler0a5c9c02011-01-22 17:36:34 -0600335\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 -0500336
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600337\fI\fB
338
339\fB/* This function is really an inline macro. \fI*/
340
341\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
342
343\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600344
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -0600345\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 -0600346
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600347\fI\fB
348
349\fB/* This function is really an inline macro. \fI*/
350
351\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
352
353\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600354
John Bowler0a5c9c02011-01-22 17:36:34 -0600355\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 -0600356
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600357\fI\fB
358
John Bowler0a5c9c02011-01-22 17:36:34 -0600359\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600360
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600361\fI\fB
362
John Bowler0a5c9c02011-01-22 17:36:34 -0600363\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500364
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600365\fI\fB
366
John Bowler0a5c9c02011-01-22 17:36:34 -0600367\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500368
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600369\fI\fB
370
John Bowler0a5c9c02011-01-22 17:36:34 -0600371\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500372
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600373\fI\fB
374
John Bowler0a5c9c02011-01-22 17:36:34 -0600375\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 -0500376
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600377\fI\fB
378
John Bowler0a5c9c02011-01-22 17:36:34 -0600379\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 -0500380
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600381\fI\fB
382
John Bowler0a5c9c02011-01-22 17:36:34 -0600383\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 -0500384
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600385\fI\fB
386
John Bowler0a5c9c02011-01-22 17:36:34 -0600387\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 -0500388
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600389\fI\fB
390
John Bowler0a5c9c02011-01-22 17:36:34 -0600391\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 -0500392
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600393\fI\fB
394
John Bowler0a5c9c02011-01-22 17:36:34 -0600395\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 -0600396
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600397\fI\fB
398
John Bowler0a5c9c02011-01-22 17:36:34 -0600399\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 -0500400
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600401\fI\fB
402
John Bowler0a5c9c02011-01-22 17:36:34 -0600403\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 -0500404
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600405\fI\fB
406
John Bowler0a5c9c02011-01-22 17:36:34 -0600407\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 -0500408
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600409\fI\fB
410
John Bowler0a5c9c02011-01-22 17:36:34 -0600411\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 -0500412
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600413\fI\fB
414
John Bowler0a5c9c02011-01-22 17:36:34 -0600415\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 -0500416
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600417\fI\fB
418
John Bowler0a5c9c02011-01-22 17:36:34 -0600419\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 -0600420
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600421\fI\fB
422
John Bowler0a5c9c02011-01-22 17:36:34 -0600423\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 -0500424
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600425\fI\fB
426
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600427\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
428
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600429\fI\fB
430
Glenn Randers-Pehrsone0a6c062011-11-07 23:50:05 -0600431\fBint png_image_begin_read_from_file (png_imagep \fP\fIimage\fP\fB, const char \fI*file_name\fP\fB);\fP
432
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600433\fI\fB
434
Glenn Randers-Pehrsone0a6c062011-11-07 23:50:05 -0600435\fBint png_image_begin_read_from_stdio (png_imagep \fP\fIimage\fP\fB, FILE* \fIfile\fP\fB);\fP
436
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600437\fI\fB
438
Glenn Randers-Pehrsone0a6c062011-11-07 23:50:05 -0600439\fBint, png_image_begin_read_from_memory (png_imagep \fP\fIimage\fP\fB, png_const_voidp \fP\fImemory\fP\fB, png_size_t \fIsize\fP\fB);\fP
440
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600441\fI\fB
442
Glenn Randers-Pehrsone0a6c062011-11-07 23:50:05 -0600443\fBint png_image_finish_read (png_imagep \fP\fIimage\fP\fB, png_colorp \fP\fIbackground\fP\fB, void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride\fP\fB);\fP
444
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600445\fI\fB
446
Glenn Randers-Pehrsone0a6c062011-11-07 23:50:05 -0600447\fBvoid png_image_free (png_imagep \fIimage\fP\fB);\fP
448
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600449\fI\fB
450
451\fBint png_image_write_to_file (png_imagep \fP\fIimage\fP\fB, const char \fP\fI*file\fP\fB, int \fP\fIconvert_to_8bit\fP\fB, const void \fI*buffer,
452
453\fBpng_int_32 \fIrow_stride\fP\fB);\fP
454
455\fI\fB
Glenn Randers-Pehrsone0a6c062011-11-07 23:50:05 -0600456
457\fBint png_image_write_to_stdio (png_imagep \fP\fIimage\fP\fB, FILE \fP\fI*file\fP\fB, int \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fIrow_stride)\fP\fB);\fP
458
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600459\fI\fB
460
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600461\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
462
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600463\fI\fB
464
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500465\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 -0500466
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600467\fI\fB
468
Glenn Randers-Pehrsonf98726a2010-02-19 09:54:53 -0600469\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
470
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600471\fI\fB
472
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500473\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 -0500474
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600475\fI\fB
476
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600477\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
478
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600479\fI\fB
480
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600481\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
482
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600483\fI\fB
484
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600485\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 -0500486
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600487\fI\fB
488
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500489\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
490
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600491\fI\fB
492
John Bowlerf19abd62011-01-22 18:29:24 -0600493\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
494
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600495\fI\fB
496
John Bowlerf19abd62011-01-22 18:29:24 -0600497\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
498
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600499\fI\fB
500
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500501\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
502
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600503\fI\fB
504
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500505\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
506
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600507\fI\fB
508
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500509\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
510
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600511\fI\fB
512
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500513\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
514
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600515\fI\fB
516
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600517\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 -0600518
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600519\fI\fB
520
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500521\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
522
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600523\fI\fB
524
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500525\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
526
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600527\fI\fB
528
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500529\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
530
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600531\fI\fB
532
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600533\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
534
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600535\fI\fB
536
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600537\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 -0500538
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600539\fI\fB
540
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600541\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
542
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600543\fI\fB
544
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600545\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
546
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600547\fI\fB
548
549\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
550
551\fI\fB
552
553\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP
554
555\fI\fB
556
557\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
558
559\fI\fB
Glenn Randers-Pehrsonc7822512011-05-07 21:23:43 -0500560
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500561\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
562
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600563\fI\fB
564
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500565\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
566
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600567\fI\fB
568
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600569\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
570
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600571\fI\fB
572
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500573\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
574
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600575\fI\fB
576
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500577\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
578
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600579\fI\fB
580
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500581\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
582
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600583\fI\fB
584
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600585\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
586
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600587\fI\fB
588
589\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,
590
591\fBdouble \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP
592
593\fI\fB
John Bowler736f40f2011-08-25 16:19:44 -0500594
595\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
596
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600597\fI\fB
598
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500599\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
600
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600601\fI\fB
602
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500603\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
604
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600605\fI\fB
606
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500607\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
608
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600609\fI\fB
610
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500611\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
612
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600613\fI\fB
614
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500615\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 -0600616
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600617\fI\fB
618
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500619\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 -0600620
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600621\fI\fB
622
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500623\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 -0600624
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600625\fI\fB
626
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500627\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 -0600628
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600629\fI\fB
630
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -0600631\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsonc85f5f62011-02-13 05:56:07 -0600632
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600633\fI\fB
634
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -0600635\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600636
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600637\fI\fB
638
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600639\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 -0600640
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600641\fI\fB
642
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500643\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 -0600644
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600645\fI\fB
646
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500647\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 -0600648
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600649\fI\fB
650
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500651\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 -0500652
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600653\fI\fB
654
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500655\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
656
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600657\fI\fB
658
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500659\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600660
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600661\fI\fB
662
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500663\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 -0600664
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600665\fI\fB
666
667\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
668
669\fI\fB
670
671\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
672
673\fI\fB
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500674
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600675\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
676
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600677\fI\fB
678
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600679\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600680
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600681\fI\fB
682
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500683\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600684
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600685\fI\fB
686
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500687\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 -0600688
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600689\fI\fB
690
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -0600691\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 -0600692
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600693\fI\fB
694
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500695\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600696
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600697\fI\fB
698
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500699\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
700
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600701\fI\fB
702
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500703\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600704
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600705\fI\fB
706
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500707\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600708
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600709\fI\fB
710
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500711\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 -0600712
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600713\fI\fB
714
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600715\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 -0600716
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600717\fI\fB
718
Glenn Randers-Pehrson1e6ed732009-11-20 22:06:56 -0600719\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
720
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600721\fI\fB
722
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600723\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
724
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600725\fI\fB
726
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600727\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
728
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600729\fI\fB
730
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600731\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 -0600732
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600733\fI\fB
734
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500735\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 -0600736
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600737\fI\fB
738
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500739\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600740
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600741\fI\fB
742
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500743\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600744
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600745\fI\fB
746
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600747\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600748
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600749\fI\fB
750
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500751\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 -0600752
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600753\fI\fB
754
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500755\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 -0600756
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600757\fI\fB
758
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500759\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 -0600760
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600761\fI\fB
762
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500763\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 -0600764
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600765\fI\fB
766
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -0500767\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
768
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600769\fI\fB
770
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500771\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 -0600772
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600773\fI\fB
774
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500775\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 -0600776
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600777\fI\fB
778
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600779\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
780
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600781\fI\fB
782
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500783\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 -0600784
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600785\fI\fB
786
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600787\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
788
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600789\fI\fB
790
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500791\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 -0600792
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600793\fI\fB
794
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600795\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
796
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600797\fI\fB
798
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500799\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 -0600800
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600801\fI\fB
802
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500803\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
804
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600805\fI\fB
806
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500807\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
808
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600809\fI\fB
810
811\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
812
813\fI\fB
814
815\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
816
817\fI\fB
Glenn Randers-Pehrsonc4a82142011-06-18 00:44:08 -0500818
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500819\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 -0600820
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600821\fI\fB
822
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500823\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 -0600824
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600825\fI\fB
826
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600827\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 -0600828
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600829\fI\fB
830
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600831\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 -0600832
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600833\fI\fB
834
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600835\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 -0600836
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600837\fI\fB
838
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500839\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600840
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600841\fI\fB
842
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500843\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600844
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600845\fI\fB
846
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600847\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
848
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600849\fI\fB
850
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500851\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600852
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600853\fI\fB
854
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500855\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600856
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600857\fI\fB
858
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500859\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 -0600860
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600861\fI\fB
862
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500863\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
864
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600865\fI\fB
866
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500867\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
868
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600869\fI\fB
870
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500871\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
872
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600873\fI\fB
874
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500875\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
876
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600877\fI\fB
878
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500879\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
880
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600881\fI\fB
882
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500883\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 -0600884
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600885\fI\fB
886
Glenn Randers-Pehrsonf3c51e42011-01-15 10:25:25 -0600887\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 -0500888
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600889\fI\fB
890
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600891\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600892
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600893\fI\fB
894
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600895\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
896
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600897\fI\fB
898
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600899\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 -0600900
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600901\fI\fB
902
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500903\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
904
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600905\fI\fB
906
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500907\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 -0600908
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600909\fI\fB
910
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500911\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 -0600912
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600913\fI\fB
914
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500915\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 -0600916
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600917\fI\fB
918
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500919\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 -0600920
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600921\fI\fB
922
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500923\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 -0600924
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600925\fI\fB
926
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500927\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600928
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600929\fI\fB
930
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500931\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 -0600932
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600933\fI\fB
934
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500935\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 -0600936
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600937\fI\fB
938
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500939\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 -0600940
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600941\fI\fB
942
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500943\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600944
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600945\fI\fB
946
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500947\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 -0600948
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600949\fI\fB
950
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500951\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 -0600952
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600953\fI\fB
954
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500955\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600956
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600957\fI\fB
958
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500959\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 -0600960
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600961\fI\fB
962
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500963\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 -0600964
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600965\fI\fB
966
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600967\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
968
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600969\fI\fB
970
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600971\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 -0600972
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600973\fI\fB
974
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500975\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 -0600976
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600977\fI\fB
978
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500979\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 -0600980
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600981\fI\fB
982
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500983\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
984
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600985\fI\fB
986
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500987\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
988
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600989\fI\fB
990
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500991\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
992
Glenn Randers-Pehrsonc737b7c2012-02-16 20:07:15 -0600993\fI\fB
994
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600995.SH DESCRIPTION
996The
997.I libpng
998library supports encoding, decoding, and various manipulations of
999the Portable Network Graphics (PNG) format image files. It uses the
1000.IR zlib(3)
1001compression library.
Glenn Randers-Pehrson557b2562010-10-17 12:55:04 -05001002Following is a copy of the libpng-manual.txt file that accompanies libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001003.SH LIBPNG.TXT
Glenn Randers-Pehrson557b2562010-10-17 12:55:04 -05001004libpng-manual.txt - A description on how to use and modify libpng
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001005
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06001006 libpng version 1.6.0beta15 - February 27, 2012
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001007 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06001008 <glennrp at users.sourceforge.net>
Glenn Randers-Pehrson9f45c8e2011-01-15 19:35:03 -06001009 Copyright (c) 1998-2011 Glenn Randers-Pehrson
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05001010
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05001011 This document is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -05001012 For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05001013 and license in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001014
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001015 Based on:
1016
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06001017 libpng versions 0.97, January 1998, through 1.6.0beta15 - February 27, 2012
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001018 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson9f45c8e2011-01-15 19:35:03 -06001019 Copyright (c) 1998-2011 Glenn Randers-Pehrson
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001020
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001021 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001022 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001023 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001024
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001025 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001026 For conditions of distribution and use, see copyright
1027 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001028 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001029
1030 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001031 Copyright (c) 1995, 1996 Frank J. T. Wojcik
1032 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001033
Glenn Randers-Pehrson6e418422011-12-29 20:57:39 -06001034 TABLE OF CONTENTS
1035
1036 I. Introduction
1037 II. Structures
1038 III. Reading
1039 IV. Writing
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06001040 V. Simplified API
1041 VI. Modifying/Customizing libpng
1042 VII. MNG support
1043 VIII. Changes to Libpng from version 0.88
1044 IX. Changes to Libpng from version 1.0.x to 1.2.x
1045 X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
1046 XI. Changes to Libpng from version 1.4.x to 1.5.x
1047 XII. Changes to Libpng from version 1.5.x to 1.6.x
1048 XIII. Detecting libpng
1049 XIV. Source code repository
1050 XV. Coding style
1051 XVI. Y2K Compliance in libpng
Glenn Randers-Pehrson6e418422011-12-29 20:57:39 -06001052
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001053.SH I. Introduction
1054
1055This file describes how to use and modify the PNG reference library
1056(known as libpng) for your own use. There are five sections to this
1057file: introduction, structures, reading, writing, and modification and
1058configuration notes for various special platforms. In addition to this
1059file, example.c is a good starting point for using the library, as
1060it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001061will need. We assume that libpng is already installed; see the
1062INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001063
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001064For examples of libpng usage, see the files "example.c", "pngtest.c",
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001065and the files in the "contrib" directory, all of which are included in
1066the libpng distribution.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001067
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001068Libpng was written as a companion to the PNG specification, as a way
1069of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001070file format in application programs.
1071
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001072The PNG specification (second edition), November 2003, is available as
1073a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
1074<http://www.w3.org/TR/2003/REC-PNG-20031110/
1075The W3C and ISO documents have identical technical content.
1076
1077The PNG-1.2 specification is available at
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001078<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
1079to the PNG specification (second edition) but has some additional material.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001080
1081The PNG-1.0 specification is available
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001082as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001083W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
1084
1085Some additional chunks are described in the special-purpose public chunks
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001086documents at <http://www.libpng.org/pub/png/documents/>.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001087
1088Other information
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001089about PNG, and the latest version of libpng, can be found at the PNG home
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001090page, <http://www.libpng.org/pub/png/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001091
1092Most users will not have to modify the library significantly; advanced
1093users may want to modify it more. All attempts were made to make it as
1094complete as possible, while keeping the code easy to understand.
1095Currently, this library only supports C. Support for other languages
1096is being considered.
1097
1098Libpng has been designed to handle multiple sessions at one time,
1099to be easily modifiable, to be portable to the vast majority of
1100machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
1101to use. The ultimate goal of libpng is to promote the acceptance of
1102the PNG file format in whatever way possible. While there is still
1103work to be done (see the TODO file), libpng should cover the
1104majority of the needs of its users.
1105
1106Libpng uses zlib for its compression and decompression of PNG files.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001107Further information about zlib, and the latest version of zlib, can
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001108be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001109The zlib compression utility is a general purpose utility that is
1110useful for more than PNG files, and can be used without libpng.
1111See the documentation delivered with zlib for more details.
1112You can usually find the source files for the zlib utility wherever you
1113find the libpng source files.
1114
1115Libpng is thread safe, provided the threads are using different
1116instances of the structures. Each thread should have its own
1117png_struct and png_info instances, and thus its own image.
1118Libpng does not protect itself against two threads using the
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05001119same instance of a structure.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001120
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001121.SH II. Structures
1122
1123There are two main structures that are important to libpng, png_struct
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001124and png_info. Both are internal structures that are no longer exposed
1125in the libpng interface (as of libpng 1.5.0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001126
1127The png_info structure is designed to provide information about the
1128PNG file. At one time, the fields of png_info were intended to be
1129directly accessible to the user. However, this tended to cause problems
1130with applications using dynamically loaded libraries, and as a result
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001131a set of interface functions for png_info (the png_get_*() and png_set_*()
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001132functions) was developed, and direct access to the png_info fields was
1133deprecated..
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001134
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001135The png_struct structure is the object used by the library to decode a
1136single image. As of 1.5.0 this structure is also not exposed.
1137
1138Almost all libpng APIs require a pointer to a png_struct as the first argument.
1139Many (in particular the png_set and png_get APIs) also require a pointer
1140to png_info as the second argument. Some application visible macros
1141defined in png.h designed for basic data access (reading and writing
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001142integers in the PNG format) don't take a png_info pointer, but it's almost
1143always safe to assume that a (png_struct*) has to be passed to call an API
1144function.
1145
1146You can have more than one png_info structure associated with an image,
1147as illustrated in pngtest.c, one for information valid prior to the
1148IDAT chunks and another (called "end_info" below) for things after them.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001149
1150The png.h header file is an invaluable reference for programming with libpng.
1151And while I'm on the topic, make sure you include the libpng header file:
1152
1153#include <png.h>
1154
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001155and also (as of libpng-1.5.0) the zlib header file, if you need it:
1156
1157#include <zlib.h>
1158
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001159.SS Types
1160
1161The png.h header file defines a number of integral types used by the
1162APIs. Most of these are fairly obvious; for example types corresponding
1163to integers of particular sizes and types for passing color values.
1164
1165One exception is how non-integral numbers are handled. For application
1166convenience most APIs that take such numbers have C (double) arguments,
1167however internally PNG, and libpng, use 32 bit signed integers and encode
1168the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
1169macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
1170which is simply (png_int_32).
1171
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001172All APIs that take (double) arguments also have a matching API that
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001173takes the corresponding fixed point integer arguments. The fixed point
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001174API has the same name as the floating point one with "_fixed" appended.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001175The actual range of values permitted in the APIs is frequently less than
1176the full range of (png_fixed_point) (-21474 to +21474). When APIs require
1177a non-negative argument the type is recorded as png_uint_32 above. Consult
1178the header file and the text below for more information.
1179
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001180Special care must be take with sCAL chunk handling because the chunk itself
1181uses non-integral values encoded as strings containing decimal floating point
1182numbers. See the comments in the header file.
1183
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001184.SS Configuration
1185
1186The main header file function declarations are frequently protected by C
1187preprocessing directives of the form:
1188
1189 #ifdef PNG_feature_SUPPORTED
1190 declare-function
1191 #endif
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001192 ...
1193 #ifdef PNG_feature_SUPPORTED
1194 use-function
1195 #endif
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001196
1197The library can be built without support for these APIs, although a
1198standard build will have all implemented APIs. Application programs
1199should check the feature macros before using an API for maximum
1200portability. From libpng 1.5.0 the feature macros set during the build
1201of libpng are recorded in the header file "pnglibconf.h" and this file
1202is always included by png.h.
1203
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001204If you don't need to change the library configuration from the default, skip to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001205the next section ("Reading").
1206
1207Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
1208of the build project files in the 'projects' directory simply copy
1209scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
1210systems do not permit easy auto-configuration of the library - they only
1211support the default configuration.
1212
1213The easiest way to make minor changes to the libpng configuration when
1214auto-configuration is supported is to add definitions to the command line
1215using (typically) CPPFLAGS. For example:
1216
1217CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
1218
1219will change the internal libpng math implementation for gamma correction and
1220other arithmetic calculations to fixed point, avoiding the need for fast
1221floating point support. The result can be seen in the generated pnglibconf.h -
1222make sure it contains the changed feature macro setting.
1223
1224If you need to make more extensive configuration changes - more than one or two
1225feature macro settings - you can either add -DPNG_USER_CONFIG to the build
1226command line and put a list of feature macro settings in pngusr.h or you can set
1227DFA_XTRA (a makefile variable) to a file containing the same information in the
1228form of 'option' settings.
1229
1230A. Changing pnglibconf.h
1231
1232A variety of methods exist to build libpng. Not all of these support
1233reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
1234rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
1235
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001236Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
1237pnglibconf.h and changing the lines defining the supported features, paying
1238very close attention to the 'option' information in scripts/pnglibconf.dfa
1239that describes those features and their requirements. This is easy to get
1240wrong.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001241
1242B. Configuration using DFA_XTRA
1243
1244Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
1245variant such as 'nawk' or 'gawk', is available. The configure build will
1246automatically find an appropriate awk and build pnglibconf.h.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001247The scripts/pnglibconf.mak file contains a set of make rules for doing the
1248same thing if configure is not used, and many of the makefiles in the scripts
1249directory use this approach.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001250
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001251When rebuilding simply write a new file containing changed options and set
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001252DFA_XTRA to the name of this file. This causes the build to append the new file
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001253to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
1254of the following forms:
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001255
1256everything = off
1257
1258This turns all optional features off. Include it at the start of pngusr.dfa to
1259make it easier to build a minimal configuration. You will need to turn at least
1260some features on afterward to enable either reading or writing code, or both.
1261
1262option feature on
1263option feature off
1264
1265Enable or disable a single feature. This will automatically enable other
1266features required by a feature that is turned on or disable other features that
1267require a feature which is turned off. Conflicting settings will cause an error
1268message to be emitted by awk.
1269
1270setting feature default value
1271
1272Changes the default value of setting 'feature' to 'value'. There are a small
1273number of settings listed at the top of pnglibconf.h, they are documented in the
1274source code. Most of these values have performance implications for the library
1275but most of them have no visible effect on the API. Some can also be overridden
1276from the API.
1277
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001278This method of building a customized pnglibconf.h is illustrated in
1279contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
1280pngusr.dfa in these directories.
1281
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001282C. Configuration using PNG_USR_CONFIG
1283
1284If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
1285pngusr.h will automatically be included before the options in
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001286scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
1287macro definitions turning features on or off or setting settings.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001288
1289Apart from the global setting "everything = off" all the options listed above
1290can be set using macros in pngusr.h:
1291
1292#define PNG_feature_SUPPORTED
1293
1294is equivalent to:
1295
1296option feature on
1297
1298#define PNG_NO_feature
1299
1300is equivalent to:
1301
1302option feature off
1303
1304#define PNG_feature value
1305
1306is equivalent to:
1307
1308setting feature default value
1309
1310Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
1311pngusr file you supply override the contents of scripts/pnglibconf.dfa
1312
1313If confusing or incomprehensible behavior results it is possible to
1314examine the intermediate file pnglibconf.dfn to find the full set of
1315dependency information for each setting and option. Simply locate the
1316feature in the file and read the C comments that precede it.
1317
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001318This method is also illustrated in the contrib/pngminim/* makefiles and
1319pngusr.h.
1320
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001321.SH III. Reading
1322
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001323We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001324in a PNG file sequentially, briefly explaining the syntax and purpose
1325of each one. See example.c and png.h for more detail. While
1326progressive reading is covered in the next section, you will still
1327need some of the functions discussed in this section to read a PNG
1328file.
1329
1330.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001331
1332You will want to do the I/O initialization(*) before you get into libpng,
1333so if it doesn't work, you don't have much to undo. Of course, you
1334will also want to insure that you are, in fact, dealing with a PNG
1335file. Libpng provides a simple check to see if a file is a PNG file.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001336To use it, pass in the first 1 to 8 bytes of the file to the function
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05001337png_sig_cmp(), and it will return 0 (false) if the bytes match the
1338corresponding bytes of the PNG signature, or nonzero (true) otherwise.
1339Of course, the more bytes you pass in, the greater the accuracy of the
1340prediction.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001341
1342If you are intending to keep the file pointer open for use in libpng,
1343you must ensure you don't read more than 8 bytes from the beginning
1344of the file, and you also have to make a call to png_set_sig_bytes_read()
1345with the number of bytes you read from the beginning. Libpng will
1346then only check the bytes (if any) that your program didn't read.
1347
1348(*): If you are not using the standard I/O functions, you will need
1349to replace them with custom functions. See the discussion under
1350Customizing libpng.
1351
1352
1353 FILE *fp = fopen(file_name, "rb");
1354 if (!fp)
1355 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001356 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001357 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001358
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001359 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06001360 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001361
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001362 if (!is_png)
1363 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001364 return (NOT_PNG);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001365 }
1366
1367
1368Next, png_struct and png_info need to be allocated and initialized. In
1369order to ensure that the size of these structures is correct even with a
1370dynamically linked libpng, there are functions to initialize and
1371allocate the structures. We also pass the library version, optional
1372pointers to error handling functions, and a pointer to a data struct for
1373use by the error functions, if necessary (the pointer and functions can
1374be NULL if the default error handlers are to be used). See the section
1375on Changes to Libpng below regarding the old initialization functions.
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001376The structure allocation functions quietly return NULL if they fail to
1377create the structure, so your application should check for that.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001378
1379 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001380 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001381 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001382
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001383 if (!png_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001384 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001385
1386 png_infop info_ptr = png_create_info_struct(png_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001387
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001388 if (!info_ptr)
1389 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001390 png_destroy_read_struct(&png_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001391 (png_infopp)NULL, (png_infopp)NULL);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001392 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001393 }
1394
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001395If you want to use your own memory allocation routines,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001396use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001397png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001398
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001399 png_structp png_ptr = png_create_read_struct_2
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05001400 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001401 user_error_fn, user_warning_fn, (png_voidp)
1402 user_mem_ptr, user_malloc_fn, user_free_fn);
1403
1404The error handling routines passed to png_create_read_struct()
1405and the memory alloc/free routines passed to png_create_struct_2()
1406are only necessary if you are not using the libpng supplied error
1407handling and memory alloc/free functions.
1408
1409When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001410to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001411your png_jmpbuf(png_ptr). If you read the file from different
John Bowlere6dc85b2011-04-27 14:47:15 -05001412routines, you will need to update the longjmp buffer every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001413a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001414
1415See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001416information on setjmp/longjmp. See the discussion on libpng error
1417handling in the Customizing Libpng section below for more information
1418on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001419back to your setjmp, you will want to call png_destroy_read_struct() to
1420free any memory.
1421
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001422 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001423 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001424 png_destroy_read_struct(&png_ptr, &info_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001425 &end_info);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001426 fclose(fp);
1427 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001428 }
1429
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05001430Pass (png_infopp)NULL instead of &end_info if you didn't create
1431an end_info structure.
1432
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001433If you would rather avoid the complexity of setjmp/longjmp issues,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05001434you can compile libpng with PNG_NO_SETJMP, in which case
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001435errors will result in a call to PNG_ABORT() which defaults to abort().
1436
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05001437You can #define PNG_ABORT() to a function that does something
1438more useful than abort(), as long as your function does not
1439return.
1440
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001441Now you need to set up the input code. The default for libpng is to
1442use the C function fread(). If you use this, you will need to pass a
1443valid FILE * in the function png_init_io(). Be sure that the file is
1444opened in binary mode. If you wish to handle reading data in another
1445way, you need not call the png_init_io() function, but you must then
1446implement the libpng I/O methods discussed in the Customizing Libpng
1447section below.
1448
1449 png_init_io(png_ptr, fp);
1450
1451If you had previously opened the file and read any of the signature from
1452the beginning in order to see if this was a PNG file, you need to let
1453libpng know that there are some bytes missing from the start of the file.
1454
1455 png_set_sig_bytes(png_ptr, number);
1456
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001457You can change the zlib compression buffer size to be used while
1458reading compressed data with
1459
1460 png_set_compression_buffer_size(png_ptr, buffer_size);
1461
1462where the default size is 8192 bytes. Note that the buffer size
1463is changed immediately and the buffer is reallocated immediately,
1464instead of setting a flag to be acted upon later.
1465
Glenn Randers-Pehrson9dd1cdf2011-01-06 21:42:36 -06001466If you want CRC errors to be handled in a different manner than
1467the default, use
1468
1469 png_set_crc_action(png_ptr, crit_action, ancil_action);
1470
1471The values for png_set_crc_action() say how libpng is to handle CRC errors in
1472ancillary and critical chunks, and whether to use the data contained
1473therein. Note that it is impossible to "discard" data in a critical
1474chunk.
1475
1476Choices for (int) crit_action are
1477 PNG_CRC_DEFAULT 0 error/quit
1478 PNG_CRC_ERROR_QUIT 1 error/quit
1479 PNG_CRC_WARN_USE 3 warn/use data
1480 PNG_CRC_QUIET_USE 4 quiet/use data
1481 PNG_CRC_NO_CHANGE 5 use the current value
1482
1483Choices for (int) ancil_action are
1484 PNG_CRC_DEFAULT 0 error/quit
1485 PNG_CRC_ERROR_QUIT 1 error/quit
1486 PNG_CRC_WARN_DISCARD 2 warn/discard data
1487 PNG_CRC_WARN_USE 3 warn/use data
1488 PNG_CRC_QUIET_USE 4 quiet/use data
1489 PNG_CRC_NO_CHANGE 5 use the current value
1490
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001491.SS Setting up callback code
1492
1493You can set up a callback function to handle any unknown chunks in the
1494input stream. You must supply the function
1495
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06001496 read_chunk_callback(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001497 png_unknown_chunkp chunk);
1498 {
1499 /* The unknown chunk structure contains your
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001500 chunk data, along with similar data for any other
1501 unknown chunks: */
1502
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001503 png_byte name[5];
1504 png_byte *data;
1505 png_size_t size;
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001506
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001507 /* Note that libpng has already taken care of
1508 the CRC handling */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001509
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001510 /* put your code here. Search for your chunk in the
1511 unknown chunk structure, process it, and return one
1512 of the following: */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001513
1514 return (-n); /* chunk had an error */
1515 return (0); /* did not recognize */
1516 return (n); /* success */
1517 }
1518
1519(You can give your function another name that you like instead of
1520"read_chunk_callback")
1521
1522To inform libpng about your function, use
1523
1524 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1525 read_chunk_callback);
1526
1527This names not only the callback function, but also a user pointer that
1528you can retrieve with
1529
1530 png_get_user_chunk_ptr(png_ptr);
1531
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001532If you call the png_set_read_user_chunk_fn() function, then all unknown
1533chunks will be saved when read, in case your callback function will need
1534one or more of them. This behavior can be changed with the
1535png_set_keep_unknown_chunks() function, described below.
1536
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001537At this point, you can set up a callback function that will be
1538called after each row has been read, which you can use to control
1539a progress meter or the like. It's demonstrated in pngtest.c.
1540You must supply a function
1541
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06001542 void read_row_callback(png_structp png_ptr,
1543 png_uint_32 row, int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001544 {
1545 /* put your code here */
1546 }
1547
1548(You can give it another name that you like instead of "read_row_callback")
1549
1550To inform libpng about your function, use
1551
1552 png_set_read_status_fn(png_ptr, read_row_callback);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001553
John Bowler59010e52011-02-16 06:16:31 -06001554When this function is called the row has already been completely processed and
1555the 'row' and 'pass' refer to the next row to be handled. For the
1556non-interlaced case the row that was just handled is simply one less than the
1557passed in row number, and pass will always be 0. For the interlaced case the
1558same applies unless the row value is 0, in which case the row just handled was
1559the last one from one of the preceding passes. Because interlacing may skip a
1560pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1561need to know what the last pass is record (row,pass) from the callback and use
1562the last recorded value each time.
1563
1564As with the user transform you can find the output row using the
1565PNG_ROW_FROM_PASS_ROW macro.
1566
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001567.SS Unknown-chunk handling
1568
1569Now you get to set the way the library processes unknown chunks in the
1570input PNG stream. Both known and unknown chunks will be read. Normal
1571behavior is that known chunks will be parsed into information in
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001572various info_ptr members while unknown chunks will be discarded. This
1573behavior can be wasteful if your application will never use some known
1574chunk types. To change this, you can call:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001575
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001576 png_set_keep_unknown_chunks(png_ptr, keep,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001577 chunk_list, num_chunks);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001578 keep - 0: default unknown chunk handling
1579 1: ignore; do not keep
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001580 2: keep only if safe-to-copy
1581 3: keep even if unsafe-to-copy
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001582
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001583 You can use these definitions:
1584 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1585 PNG_HANDLE_CHUNK_NEVER 1
1586 PNG_HANDLE_CHUNK_IF_SAFE 2
1587 PNG_HANDLE_CHUNK_ALWAYS 3
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001588
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001589 chunk_list - list of chunks affected (a byte string,
1590 five bytes per chunk, NULL or '\0' if
1591 num_chunks is 0)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001592
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001593 num_chunks - number of chunks affected; if 0, all
Glenn Randers-Pehrsondff799e2004-08-07 21:42:49 -05001594 unknown chunks are affected. If nonzero,
1595 only the chunks in the list are affected
1596
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001597Unknown chunks declared in this way will be saved as raw data onto a
1598list of png_unknown_chunk structures. If a chunk that is normally
1599known to libpng is named in the list, it will be handled as unknown,
1600according to the "keep" directive. If a chunk is named in successive
1601instances of png_set_keep_unknown_chunks(), the final instance will
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001602take precedence. The IHDR and IEND chunks should not be named in
1603chunk_list; if they are, libpng will process them normally anyway.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001604If you know that your application will never make use of some particular
1605chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001606
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001607Here is an example of the usage of png_set_keep_unknown_chunks(),
1608where the private "vpAg" chunk will later be processed by a user chunk
1609callback function:
1610
1611 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1612
1613 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1614 png_byte unused_chunks[]=
1615 {
1616 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1617 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1618 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1619 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1620 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1621 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1622 };
1623 #endif
1624
1625 ...
1626
1627 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1628 /* ignore all unknown chunks: */
1629 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001630
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001631 /* except for vpAg: */
1632 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001633
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001634 /* also ignore unused known chunks: */
1635 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1636 (int)sizeof(unused_chunks)/5);
1637 #endif
1638
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001639.SS User limits
1640
1641The PNG specification allows the width and height of an image to be as
1642large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1643Since very few applications really need to process such large images,
1644we have imposed an arbitrary 1-million limit on rows and columns.
1645Larger images will be rejected immediately with a png_error() call. If
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05001646you wish to change this limit, you can use
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001647
1648 png_set_user_limits(png_ptr, width_max, height_max);
1649
1650to set your own limits, or use width_max = height_max = 0x7fffffffL
1651to allow all valid dimensions (libpng may reject some very large images
1652anyway because of potential buffer overflow conditions).
1653
1654You should put this statement after you create the PNG structure and
1655before calling png_read_info(), png_read_png(), or png_process_data().
Glenn Randers-Pehrsoncc277082011-06-10 21:17:34 -05001656
1657When writing a PNG datastream, put this statement before calling
1658png_write_info() or png_write_png().
1659
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001660If you need to retrieve the limits that are being applied, use
1661
1662 width_max = png_get_user_width_max(png_ptr);
1663 height_max = png_get_user_height_max(png_ptr);
1664
1665The PNG specification sets no limit on the number of ancillary chunks
1666allowed in a PNG datastream. You can impose a limit on the total number
1667of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1668
1669 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1670
1671where 0x7fffffffL means unlimited. You can retrieve this limit with
1672
1673 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1674
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05001675This limit also applies to the number of buffers that can be allocated
1676by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1677
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001678You can also set a limit on the amount of memory that a compressed chunk
1679other than IDAT can occupy, with
1680
1681 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1682
1683and you can retrieve the limit with
1684
1685 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1686
1687Any chunks that would cause either of these limits to be exceeded will
1688be ignored.
1689
John Bowlercb0b2962011-05-12 21:48:29 -05001690.SS Information about your system
1691
1692If you intend to display the PNG or to incorporate it in other image data you
1693need to tell libpng information about your display or drawing surface so that
1694libpng can convert the values in the image to match the display.
1695
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001696From libpng-1.5.4 this information can be set before reading the PNG file
John Bowlercb0b2962011-05-12 21:48:29 -05001697header. In earlier versions png_set_gamma() existed but behaved incorrectly if
1698called before the PNG file header had been read and png_set_alpha_mode() did not
1699exist.
1700
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001701If you need to support versions prior to libpng-1.5.4 test the version number
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001702as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1703described in the appropriate manual page.
John Bowlercb0b2962011-05-12 21:48:29 -05001704
1705You give libpng the encoding expected by your system expressed as a 'gamma'
1706value. You can also specify a default encoding for the PNG file in
1707case the required information is missing from the file. By default libpng
1708assumes that the PNG data matches your system, to keep this default call:
1709
1710 png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
1711
1712or you can use the fixed point equivalent:
1713
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06001714 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma,
1715 PNG_FP_1/screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001716
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001717If you don't know the gamma for your system it is probably 2.2 - a good
John Bowlercb0b2962011-05-12 21:48:29 -05001718approximation to the IEC standard for display systems (sRGB). If images are
1719too contrasty or washed out you got the value wrong - check your system
1720documentation!
1721
1722Many systems permit the system gamma to be changed via a lookup table in the
1723display driver, a few systems, including older Macs, change the response by
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001724default. As of 1.5.4 three special values are available to handle common
John Bowlercb0b2962011-05-12 21:48:29 -05001725situations:
1726
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06001727 PNG_DEFAULT_sRGB: Indicates that the system conforms to the
1728 IEC 61966-2-1 standard. This matches almost
1729 all systems.
1730 PNG_GAMMA_MAC_18: Indicates that the system is an older
1731 (pre Mac OS 10.6) Apple Macintosh system with
1732 the default settings.
1733 PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates
1734 that the system expects data with no gamma
1735 encoding.
John Bowlercb0b2962011-05-12 21:48:29 -05001736
1737You would use the linear (unencoded) value if you need to process the pixel
1738values further because this avoids the need to decode and reencode each
1739component value whenever arithmetic is performed. A lot of graphics software
1740uses linear values for this reason, often with higher precision component values
1741to preserve overall accuracy.
1742
1743The second thing you may need to tell libpng about is how your system handles
1744alpha channel information. Some, but not all, PNG files contain an alpha
1745channel. To display these files correctly you need to compose the data onto a
1746suitable background, as described in the PNG specification.
1747
1748Libpng only supports composing onto a single color (using png_set_background;
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001749see below). Otherwise you must do the composition yourself and, in this case,
John Bowlercb0b2962011-05-12 21:48:29 -05001750you may need to call png_set_alpha_mode:
1751
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06001752 #if PNG_LIBPNG_VER >= 10504
1753 png_set_alpha_mode(png_ptr, mode, screen_gamma);
1754 #else
1755 png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);
1756 #endif
John Bowlercb0b2962011-05-12 21:48:29 -05001757
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001758The screen_gamma value is the same as the argument to png_set_gamma; however,
1759how it affects the output depends on the mode. png_set_alpha_mode() sets the
1760file gamma default to 1/screen_gamma, so normally you don't need to call
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001761png_set_gamma. If you need different defaults call png_set_gamma() before
1762png_set_alpha_mode() - if you call it after it will override the settings made
1763by png_set_alpha_mode().
John Bowlercb0b2962011-05-12 21:48:29 -05001764
1765The mode is as follows:
1766
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001767 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
1768green and blue, or gray, components are gamma encoded color
1769values and are not premultiplied by the alpha value. The
1770alpha value is a linear measure of the contribution of the
1771pixel to the corresponding final output pixel.
John Bowlercb0b2962011-05-12 21:48:29 -05001772
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001773You should normally use this format if you intend to perform
1774color correction on the color values; most, maybe all, color
1775correction software has no handling for the alpha channel and,
1776anyway, the math to handle pre-multiplied component values is
1777unnecessarily complex.
John Bowlercb0b2962011-05-12 21:48:29 -05001778
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001779Before you do any arithmetic on the component values you need
1780to remove the gamma encoding and multiply out the alpha
1781channel. See the PNG specification for more detail. It is
1782important to note that when an image with an alpha channel is
1783scaled, linear encoded, pre-multiplied component values must
1784be used!
John Bowlercb0b2962011-05-12 21:48:29 -05001785
1786The remaining modes assume you don't need to do any further color correction or
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001787that if you do, your color correction software knows all about alpha (it
John Bowlercb0b2962011-05-12 21:48:29 -05001788probably doesn't!)
1789
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001790 PNG_ALPHA_STANDARD: The data libpng produces
1791is encoded in the standard way
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001792assumed by most correctly written graphics software.
1793The gamma encoding will be removed by libpng and the
1794linear component values will be pre-multiplied by the
1795alpha channel.
John Bowlercb0b2962011-05-12 21:48:29 -05001796
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001797With this format the final image must be re-encoded to
1798match the display gamma before the image is displayed.
1799If your system doesn't do that, yet still seems to
1800perform arithmetic on the pixels without decoding them,
1801it is broken - check out the modes below.
John Bowlercb0b2962011-05-12 21:48:29 -05001802
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001803With PNG_ALPHA_STANDARD libpng always produces linear
1804component values, whatever screen_gamma you supply. The
1805screen_gamma value is, however, used as a default for
1806the file gamma if the PNG file has no gamma information.
John Bowlercb0b2962011-05-12 21:48:29 -05001807
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001808If you call png_set_gamma() after png_set_alpha_mode() you
1809will override the linear encoding. Instead the
1810pre-multiplied pixel values will be gamma encoded but
1811the alpha channel will still be linear. This may
1812actually match the requirements of some broken software,
1813but it is unlikely.
John Bowlercb0b2962011-05-12 21:48:29 -05001814
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001815While linear 8-bit data is often used it has
1816insufficient precision for any image with a reasonable
1817dynamic range. To avoid problems, and if your software
1818supports it, use png_set_expand_16() to force all
1819components to 16 bits.
John Bowlercb0b2962011-05-12 21:48:29 -05001820
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001821 PNG_ALPHA_OPTIMIZED: This mode is the same
1822as PNG_ALPHA_STANDARD except that
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001823completely opaque pixels are gamma encoded according to
1824the screen_gamma value. Pixels with alpha less than 1.0
1825will still have linear components.
John Bowlercb0b2962011-05-12 21:48:29 -05001826
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001827Use this format if you have control over your
1828compositing software and do don't do other arithmetic
1829(such as scaling) on the data you get from libpng. Your
1830compositing software can simply copy opaque pixels to
1831the output but still has linear values for the
1832non-opaque pixels.
John Bowlercb0b2962011-05-12 21:48:29 -05001833
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001834In normal compositing, where the alpha channel encodes
1835partial pixel coverage (as opposed to broad area
1836translucency), the inaccuracies of the 8-bit
1837representation of non-opaque pixels are irrelevant.
John Bowlercb0b2962011-05-12 21:48:29 -05001838
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001839You can also try this format if your software is broken;
1840it might look better.
John Bowlercb0b2962011-05-12 21:48:29 -05001841
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001842 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD;
1843however, all component values,
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001844including the alpha channel are gamma encoded. This is
1845an appropriate format to try if your software, or more
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001846likely hardware, is totally broken, i.e., if it performs
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001847linear arithmetic directly on gamma encoded values.
John Bowlercb0b2962011-05-12 21:48:29 -05001848
1849In most cases of broken software or hardware the bug in the final display
1850manifests as a subtle halo around composited parts of the image. You may not
1851even perceive this as a halo; the composited part of the image may simply appear
1852separate from the background, as though it had been cut out of paper and pasted
1853on afterward.
1854
1855If 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 -05001856them, there are three recommended ways of using png_set_alpha_mode():
John Bowlercb0b2962011-05-12 21:48:29 -05001857
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001858 png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
1859 screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001860
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001861You can do color correction on the result (libpng does not currently
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001862support color correction internally). When you handle the alpha channel
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001863you need to undo the gamma encoding and multiply out the alpha.
1864
1865 png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
1866 screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001867 png_set_expand_16(png_ptr);
John Bowlercb0b2962011-05-12 21:48:29 -05001868
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001869If you are using the high level interface, don't call png_set_expand_16();
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001870instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
John Bowlercb0b2962011-05-12 21:48:29 -05001871
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001872With this mode you can't do color correction, but you can do arithmetic,
1873including composition and scaling, on the data without further processing.
1874
1875 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1876 screen_gamma);
1877
1878You can avoid the expansion to 16-bit components with this mode, but you
1879lose the ability to scale the image or perform other linear arithmetic.
1880All you can do is compose the result onto a matching output. Since this
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001881mode is libpng-specific you also need to write your own composition
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001882software.
John Bowlercb0b2962011-05-12 21:48:29 -05001883
1884If you don't need, or can't handle, the alpha channel you can call
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001885png_set_background() to remove it by compositing against a fixed color. Don't
1886call png_set_strip_alpha() to do this - it will leave spurious pixel values in
John Bowlercb0b2962011-05-12 21:48:29 -05001887transparent parts of this image.
1888
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001889 png_set_background(png_ptr, &background_color,
1890 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
John Bowlercb0b2962011-05-12 21:48:29 -05001891
1892The background_color is an RGB or grayscale value according to the data format
1893libpng will produce for you. Because you don't yet know the format of the PNG
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05001894file, if you call png_set_background at this point you must arrange for the
John Bowlercb0b2962011-05-12 21:48:29 -05001895format produced by libpng to always have 8-bit or 16-bit components and then
1896store the color as an 8-bit or 16-bit color as appropriate. The color contains
1897separate gray and RGB component values, so you can let libpng produce gray or
1898RGB output according to the input format, but low bit depth grayscale images
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05001899must always be converted to at least 8-bit format. (Even though low bit depth
John Bowlercb0b2962011-05-12 21:48:29 -05001900grayscale images can't have an alpha channel they can have a transparent
1901color!)
1902
1903You set the transforms you need later, either as flags to the high level
1904interface or libpng API calls for the low level interface. For reference the
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001905settings and API calls required are:
John Bowlercb0b2962011-05-12 21:48:29 -05001906
19078-bit values:
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001908 PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
1909 png_set_expand(png_ptr); png_set_scale_16(png_ptr);
John Bowlercb0b2962011-05-12 21:48:29 -05001910
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001911 If you must get exactly the same inaccurate results
1912 produced by default in versions prior to libpng-1.5.4,
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001913 use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001914 instead.
1915
John Bowlercb0b2962011-05-12 21:48:29 -0500191616-bit values:
1917 PNG_TRANSFORM_EXPAND_16
1918 png_set_expand_16(png_ptr);
1919
1920In either case palette image data will be expanded to RGB. If you just want
1921color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1922to the list.
1923
1924Calling png_set_background before the PNG file header is read will not work
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001925prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
John Bowlercb0b2962011-05-12 21:48:29 -05001926errors it is therefore much safer to call png_set_background after the head has
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001927been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
John Bowlercb0b2962011-05-12 21:48:29 -05001928used with the high level interface.
1929
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001930.SS The high-level read interface
1931
1932At this point there are two ways to proceed; through the high-level
1933read interface, or through a sequence of low-level read operations.
1934You can use the high-level interface if (a) you are willing to read
1935the entire image into memory, and (b) the input transformations
1936you want to do are limited to the following set:
1937
1938 PNG_TRANSFORM_IDENTITY No transformation
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001939 PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
1940 8-bit accurately
1941 PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
1942 8-bit less accurately
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001943 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001944 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1945 samples to bytes
1946 PNG_TRANSFORM_PACKSWAP Change order of packed
1947 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001948 PNG_TRANSFORM_EXPAND Perform set_expand()
1949 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001950 PNG_TRANSFORM_SHIFT Normalize pixels to the
1951 sBIT depth
1952 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1953 to BGRA
1954 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1955 to AG
1956 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1957 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001958 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05001959 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1960 to RGB (or GA to RGBA)
John Bowlera9b34192011-05-08 19:46:51 -05001961 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001962
1963(This excludes setting a background color, doing gamma transformation,
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05001964quantizing, and setting filler.) If this is the case, simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001965
1966 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1967
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001968where png_transforms is an integer containing the bitwise OR of some
1969set of transformation flags. This call is equivalent to png_read_info(),
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001970followed the set of transformations indicated by the transform mask,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001971then png_read_image(), and finally png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001972
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001973(The final parameter of this call is not yet used. Someday it might point
1974to transformation parameters required by some future input transform.)
1975
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001976You must use png_transforms and not call any png_set_transform() functions
1977when you use png_read_png().
1978
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001979After you have called png_read_png(), you can retrieve the image data
1980with
1981
1982 row_pointers = png_get_rows(png_ptr, info_ptr);
1983
1984where row_pointers is an array of pointers to the pixel data for each row:
1985
1986 png_bytep row_pointers[height];
1987
1988If you know your image size and pixel size ahead of time, you can allocate
1989row_pointers prior to calling png_read_png() with
1990
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001991 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001992 png_error (png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001993 "Image is too tall to process in memory");
1994
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001995 if (width > PNG_UINT_32_MAX/pixel_size)
1996 png_error (png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001997 "Image is too wide to process in memory");
1998
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001999 row_pointers = png_malloc(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002000 height*png_sizeof(png_bytep));
2001
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002002 for (int i=0; i<height, i++)
2003 row_pointers[i]=NULL; /* security precaution */
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002004
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002005 for (int i=0; i<height, i++)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002006 row_pointers[i]=png_malloc(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002007 width*pixel_size);
2008
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06002009 png_set_rows(png_ptr, info_ptr, &row_pointers);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05002010
2011Alternatively you could allocate your image in one big block and define
2012row_pointers[i] to point into the proper places in your block.
2013
2014If you use png_set_rows(), the application is responsible for freeing
2015row_pointers (and row_pointers[i], if they were separately allocated).
2016
2017If you don't allocate row_pointers ahead of time, png_read_png() will
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002018do it, and it'll be free'ed by libpng when you call png_destroy_*().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002019
2020.SS The low-level read interface
2021
2022If you are going the low-level route, you are now ready to read all
2023the file information up to the actual image data. You do this with a
2024call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002025
2026 png_read_info(png_ptr, info_ptr);
2027
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002028This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002029
John Bowlercb0b2962011-05-12 21:48:29 -05002030This also copies some of the data from the PNG file into the decode structure
2031for use in later transformations. Important information copied in is:
2032
20331) The PNG file gamma from the gAMA chunk. This overwrites the default value
2034provided by an earlier call to png_set_gamma or png_set_alpha_mode.
2035
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -050020362) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
John Bowlercb0b2962011-05-12 21:48:29 -05002037damages the information provided by an earlier call to png_set_background
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002038resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
John Bowlercb0b2962011-05-12 21:48:29 -05002039
20403) The number of significant bits in each component value. Libpng uses this to
2041optimize gamma handling by reducing the internal lookup table sizes.
2042
20434) The transparent color information from a tRNS chunk. This can be modified by
2044a later call to png_set_tRNS.
2045
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002046.SS Querying the info structure
2047
2048Functions are used to get the information from the info_ptr once it
2049has been read. Note that these fields may not be completely filled
2050in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002051
2052 png_get_IHDR(png_ptr, info_ptr, &width, &height,
2053 &bit_depth, &color_type, &interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002054 &compression_type, &filter_method);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002055
2056 width - holds the width of the image
2057 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002058
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002059 height - holds the height of the image
2060 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002061
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002062 bit_depth - holds the bit depth of one of the
2063 image channels. (valid values are
2064 1, 2, 4, 8, 16 and depend also on
2065 the color_type. See also
2066 significant bits (sBIT) below).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002067
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002068 color_type - describes which color/alpha channels
2069 are present.
2070 PNG_COLOR_TYPE_GRAY
2071 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002072 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002073 (bit depths 8, 16)
2074 PNG_COLOR_TYPE_PALETTE
2075 (bit depths 1, 2, 4, 8)
2076 PNG_COLOR_TYPE_RGB
2077 (bit_depths 8, 16)
2078 PNG_COLOR_TYPE_RGB_ALPHA
2079 (bit_depths 8, 16)
2080
2081 PNG_COLOR_MASK_PALETTE
2082 PNG_COLOR_MASK_COLOR
2083 PNG_COLOR_MASK_ALPHA
2084
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002085 interlace_type - (PNG_INTERLACE_NONE or
2086 PNG_INTERLACE_ADAM7)
2087
2088 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
2089 for PNG 1.0)
2090
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002091 filter_method - (must be PNG_FILTER_TYPE_BASE
2092 for PNG 1.0, and can also be
2093 PNG_INTRAPIXEL_DIFFERENCING if
2094 the PNG datastream is embedded in
2095 a MNG-1.0 datastream)
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002096
2097 Any or all of interlace_type, compression_type, or
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002098 filter_method can be NULL if you are
2099 not interested in their values.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002100
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002101 Note that png_get_IHDR() returns 32-bit data into
2102 the application's width and height variables.
2103 This is an unsafe situation if these are 16-bit
2104 variables. In such situations, the
2105 png_get_image_width() and png_get_image_height()
2106 functions described below are safer.
2107
2108 width = png_get_image_width(png_ptr,
2109 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002110
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002111 height = png_get_image_height(png_ptr,
2112 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002113
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002114 bit_depth = png_get_bit_depth(png_ptr,
2115 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002116
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002117 color_type = png_get_color_type(png_ptr,
2118 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002119
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002120 interlace_type = png_get_interlace_type(png_ptr,
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002121 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002122
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002123 compression_type = png_get_compression_type(png_ptr,
2124 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002125
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002126 filter_method = png_get_filter_type(png_ptr,
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002127 info_ptr);
2128
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002129 channels = png_get_channels(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002130
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002131 channels - number of channels of info for the
2132 color type (valid values are 1 (GRAY,
2133 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
2134 4 (RGB_ALPHA or RGB + filler byte))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002135
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002136 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002137
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002138 rowbytes - number of bytes needed to hold a row
2139
2140 signature = png_get_signature(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002141
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002142 signature - holds the signature read from the
2143 file (if any). The data is kept in
2144 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002145 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002146 application had already read in 4
2147 bytes of signature before starting
2148 libpng, the remaining 4 bytes would
2149 be in signature[4] through signature[7]
2150 (see png_set_sig_bytes())).
2151
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002152These are also important, but their validity depends on whether the chunk
2153has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
2154png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
2155data has been read, or zero if it is missing. The parameters to the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002156png_get_<chunk> are set directly if they are simple data types, or a
2157pointer into the info_ptr is returned for any complex types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002158
2159 png_get_PLTE(png_ptr, info_ptr, &palette,
2160 &num_palette);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002161
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002162 palette - the palette for the file
2163 (array of png_color)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002164
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002165 num_palette - number of entries in the palette
2166
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002167 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
Glenn Randers-Pehrson27742382011-01-27 09:37:34 -06002168 png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002169
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002170 file_gamma - the gamma at which the file is
2171 written (PNG_INFO_gAMA)
2172
2173 int_file_gamma - 100,000 times the gamma at which the
2174 file is written
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002175
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002176 png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x,
2177 &red_y, &green_x, &green_y, &blue_x, &blue_y)
2178 png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z,
2179 &green_X, &green_Y, &green_Z, &blue_X, &blue_Y,
2180 &blue_Z)
2181 png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x,
2182 &int_white_y, &int_red_x, &int_red_y,
2183 &int_green_x, &int_green_y, &int_blue_x,
2184 &int_blue_y)
John Bowlerbbd17bd2011-08-25 17:48:18 -05002185 png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002186 &int_red_Z, &int_green_X, &int_green_Y,
2187 &int_green_Z, &int_blue_X, &int_blue_Y,
2188 &int_blue_Z)
John Bowlerbbd17bd2011-08-25 17:48:18 -05002189
2190 {white,red,green,blue}_{x,y}
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002191 A color space encoding specified using the
2192 chromaticities of the end points and the
2193 white point. (PNG_INFO_cHRM)
John Bowlerbbd17bd2011-08-25 17:48:18 -05002194
2195 {red,green,blue}_{X,Y,Z}
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002196 A color space encoding specified using the
2197 encoding end points - the CIE tristimulus
2198 specification of the intended color of the red,
2199 green and blue channels in the PNG RGB data.
2200 The white point is simply the sum of the three
2201 end points. (PNG_INFO_cHRM)
John Bowlerbbd17bd2011-08-25 17:48:18 -05002202
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002203 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002204
Glenn Randers-Pehrson27742382011-01-27 09:37:34 -06002205 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002206 The presence of the sRGB chunk
2207 means that the pixel data is in the
2208 sRGB color space. This chunk also
2209 implies specific values of gAMA and
2210 cHRM.
2211
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002212 png_get_iCCP(png_ptr, info_ptr, &name,
2213 &compression_type, &profile, &proflen);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002214
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002215 name - The profile name.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002216
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002217 compression_type - The compression type; always
2218 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2219 You may give NULL to this argument to
2220 ignore it.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002221
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002222 profile - International Color Consortium color
2223 profile data. May contain NULs.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002224
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002225 proflen - length of profile data in bytes.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002226
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002227 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002228
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002229 sig_bit - the number of significant bits for
2230 (PNG_INFO_sBIT) each of the gray,
2231 red, green, and blue channels,
2232 whichever are appropriate for the
2233 given color type (png_color_16)
2234
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002235 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
2236 &num_trans, &trans_color);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002237
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002238 trans_alpha - array of alpha (transparency)
2239 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002240
Glenn Randers-Pehrsonf3c51e42011-01-15 10:25:25 -06002241 num_trans - number of transparent entries
2242 (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002243
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05002244 trans_color - graylevel or color sample values of
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05002245 the single transparent color for
2246 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002247
2248 png_get_hIST(png_ptr, info_ptr, &hist);
2249 (PNG_INFO_hIST)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002250
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002251 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002252 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002253
2254 png_get_tIME(png_ptr, info_ptr, &mod_time);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002255
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002256 mod_time - time image was last modified
2257 (PNG_VALID_tIME)
2258
2259 png_get_bKGD(png_ptr, info_ptr, &background);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002260
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002261 background - background color (of type
2262 png_color_16p) (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002263 valid 16-bit red, green and blue
2264 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002265
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002266 num_comments = png_get_text(png_ptr, info_ptr,
2267 &text_ptr, &num_text);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002268
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002269 num_comments - number of comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002270
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002271 text_ptr - array of png_text holding image
2272 comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002273
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002274 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002275 on "text" PNG_TEXT_COMPRESSION_NONE
2276 PNG_TEXT_COMPRESSION_zTXt
2277 PNG_ITXT_COMPRESSION_NONE
2278 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002279
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002280 text_ptr[i].key - keyword for comment. Must contain
2281 1-79 characters.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002282
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002283 text_ptr[i].text - text comments for current
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002284 keyword. Can be empty.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002285
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002286 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002287 after decompression, 0 for iTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002288
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002289 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002290 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002291
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002292 text_ptr[i].lang - language of comment (empty
2293 string for unknown).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002294
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06002295 text_ptr[i].lang_key - keyword in UTF-8
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002296 (empty string for unknown).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002297
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002298 Note that the itxt_length, lang, and lang_key
Glenn Randers-Pehrson680da022011-11-21 17:05:41 -06002299 members of the text_ptr structure only exist when the
2300 library is built with iTXt chunk support. Prior to
2301 libpng-1.4.0 the library was built by default without
2302 iTXt support. Also note that when iTXt is supported,
2303 they contain NULL pointers when the "compression"
2304 field contains PNG_TEXT_COMPRESSION_NONE or
2305 PNG_TEXT_COMPRESSION_zTXt.
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002306
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002307 num_text - number of comments (same as
2308 num_comments; you can put NULL here
2309 to avoid the duplication)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002310
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002311 Note while png_set_text() will accept text, language,
2312 and translated keywords that can be NULL pointers, the
2313 structure returned by png_get_text will always contain
2314 regular zero-terminated C strings. They might be
2315 empty strings but they will never be NULL pointers.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002316
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002317 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
2318 &palette_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002319
2320 num_spalettes - number of sPLT chunks read.
2321
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002322 palette_ptr - array of palette structures holding
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002323 contents of one or more sPLT chunks
2324 read.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002325
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002326 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002327 &unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002328
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002329 offset_x - positive offset from the left edge
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002330 of the screen (can be negative)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002331
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002332 offset_y - positive offset from the top edge
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002333 of the screen (can be negative)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002334
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002335 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2336
2337 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002338 &unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002339
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002340 res_x - pixels/unit physical resolution in
2341 x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002342
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002343 res_y - pixels/unit physical resolution in
2344 x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002345
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002346 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002347 PNG_RESOLUTION_METER
2348
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002349 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
2350 &height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002351
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002352 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002353
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002354 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002355
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002356 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002357 (width and height are doubles)
2358
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002359 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
2360 &height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002361
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002362 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002363
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002364 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002365 (expressed as a string)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002366
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002367 height - height of a pixel in physical scale units
2368 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002369
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002370 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
2371 info_ptr, &unknowns)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002372
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002373 unknowns - array of png_unknown_chunk
2374 structures holding unknown chunks
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002375
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002376 unknowns[i].name - name of unknown chunk
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002377
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002378 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002379
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002380 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002381
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002382 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002383
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002384 The value of "i" corresponds to the order in which the
2385 chunks were read from the PNG file or inserted with the
2386 png_set_unknown_chunks() function.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002387
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002388 The value of "location" is a bitwise "or" of
2389
2390 PNG_HAVE_IHDR (0x01)
2391 PNG_HAVE_PLTE (0x02)
2392 PNG_AFTER_IDAT (0x08)
2393
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002394The data from the pHYs chunk can be retrieved in several convenient
2395forms:
2396
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002397 res_x = png_get_x_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002398 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002399
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002400 res_y = png_get_y_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002401 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002402
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002403 res_x_and_y = png_get_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002404 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002405
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002406 res_x = png_get_x_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002407 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002408
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002409 res_y = png_get_y_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002410 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002411
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002412 res_x_and_y = png_get_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002413 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002414
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002415 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002416 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002417
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002418 Each of these returns 0 [signifying "unknown"] if
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002419 the data is not present or if res_x is 0;
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002420 res_x_and_y is 0 if res_x != res_y
2421
2422 Note that because of the way the resolutions are
2423 stored internally, the inch conversions won't
2424 come out to exactly even number. For example,
2425 72 dpi is stored as 0.28346 pixels/meter, and
2426 when this is retrieved it is 71.9988 dpi, so
2427 be sure to round the returned value appropriately
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002428 if you want to display a reasonable-looking result.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002429
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002430The data from the oFFs chunk can be retrieved in several convenient
2431forms:
2432
2433 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002434
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002435 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002436
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002437 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002438
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002439 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
2440
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002441 Each of these returns 0 [signifying "unknown" if both
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002442 x and y are 0] if the data is not present or if the
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002443 chunk is present but the unit is the pixel. The
2444 remark about inexact inch conversions applies here
2445 as well, because a value in inches can't always be
2446 converted to microns and back without some loss
2447 of precision.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002448
John Bowlercb0b2962011-05-12 21:48:29 -05002449For more information, see the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002450PNG specification for chunk contents. Be careful with trusting
2451rowbytes, as some of the transformations could increase the space
2452needed to hold a row (expand, filler, gray_to_rgb, etc.).
2453See png_read_update_info(), below.
2454
2455A quick word about text_ptr and num_text. PNG stores comments in
2456keyword/text pairs, one pair per chunk, with no limit on the number
2457of text chunks, and a 2^31 byte limit on their size. While there are
2458suggested keywords, there is no requirement to restrict the use to these
2459strings. It is strongly suggested that keywords and text be sensible
2460to humans (that's the point), so don't use abbreviations. Non-printing
2461symbols are not allowed. See the PNG specification for more details.
2462There is also no requirement to have text after the keyword.
2463
2464Keywords should be limited to 79 Latin-1 characters without leading or
2465trailing spaces, but non-consecutive spaces are allowed within the
2466keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002467The text_ptr is an array of png_text structures, each holding a
2468pointer to a language string, a pointer to a keyword and a pointer to
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002469a text string. The text string, language code, and translated
2470keyword may be empty or NULL pointers. The keyword/text
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002471pairs are put into the array in the order that they are received.
2472However, some or all of the text chunks may be after the image, so, to
2473make sure you have read all the text chunks, don't mess with these
2474until after you read the stuff after the image. This will be
2475mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002476
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002477.SS Input transformations
2478
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002479After you've read the header information, you can set up the library
2480to handle any special transformations of the image data. The various
2481ways to transform the data will be described in the order that they
2482should occur. This is important, as some of these change the color
2483type and/or bit depth of the data, and some others only work on
John Bowlercb0b2962011-05-12 21:48:29 -05002484certain color types and bit depths.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002485
John Bowlercb0b2962011-05-12 21:48:29 -05002486Transformations you request are ignored if they don't have any meaning for a
2487particular input data format. However some transformations can have an effect
2488as a result of a previous transformation. If you specify a contradictory set of
2489transformations, for example both adding and removing the alpha channel, you
2490cannot predict the final result.
2491
2492The color used for the transparency values should be supplied in the same
2493format/depth as the current image data. It is stored in the same format/depth
2494as the image data in a tRNS chunk, so this is what libpng expects for this data.
2495
2496The color used for the background value depends on the need_expand argument as
2497described below.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002498
2499Data will be decoded into the supplied row buffers packed into bytes
2500unless the library has been told to transform it into another format.
2501For example, 4 bit/pixel paletted or grayscale data will be returned
25022 pixels/byte with the leftmost pixel in the high-order bits of the
2503byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002504in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2505is called to insert filler bytes, either before or after each RGB triplet.
250616-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002507byte of the color value first, unless png_set_scale_16() is called to
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06002508transform it to regular RGB RGB triplets, or png_set_filler() or
2509png_set_add alpha() is called to insert filler bytes, either before or
2510after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002511be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2512or png_set_scale_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002513
2514The following code transforms grayscale images of less than 8 to 8 bits,
2515changes paletted images to RGB, and adds a full alpha channel if there is
2516transparency information in a tRNS chunk. This is most useful on
2517grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2518viewing application that wishes to treat all images in the same way.
2519
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002520 if (color_type == PNG_COLOR_TYPE_PALETTE)
2521 png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002522
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002523 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002524 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2525
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002526 if (color_type == PNG_COLOR_TYPE_GRAY &&
2527 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2528
2529The first two functions are actually aliases for png_set_expand(), added
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002530in libpng version 1.0.4, with the function names expanded to improve code
2531readability. In some future version they may actually do different
2532things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002533
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06002534As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2535added. It expands the sample depth without changing tRNS to alpha.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002536
John Bowler63d059a2011-02-12 09:03:44 -06002537As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002538png_set_expand(); however, the resultant channels have 16 bits rather than 8.
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002539Use this when the output color or gray channels are made linear to avoid fairly
John Bowler63d059a2011-02-12 09:03:44 -06002540severe accuracy loss.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002541
John Bowler63d059a2011-02-12 09:03:44 -06002542 if (bit_depth < 16)
2543 png_set_expand_16(png_ptr);
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06002544
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002545PNG can have files with 16 bits per channel. If you only can handle
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -050025468 bits per channel, this will strip the pixels down to 8-bit.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002547
2548 if (bit_depth == 16)
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002549#if PNG_LIBPNG_VER >= 10504
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002550 png_set_scale_16(png_ptr);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002551#else
2552 png_set_strip_16(png_ptr);
2553#endif
2554
2555(The more accurate "png_set_scale_16()" API became available in libpng version
25561.5.4).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002557
John Bowlercb0b2962011-05-12 21:48:29 -05002558If you need to process the alpha channel on the image separately from the image
2559data (for example if you convert it to a bitmap mask) it is possible to have
2560libpng strip the channel leaving just RGB or gray data:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002561
2562 if (color_type & PNG_COLOR_MASK_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002563 png_set_strip_alpha(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002564
John Bowlercb0b2962011-05-12 21:48:29 -05002565If you strip the alpha channel you need to find some other way of dealing with
2566the information. If, instead, you want to convert the image to an opaque
2567version with no alpha channel use png_set_background; see below.
John Bowler63d059a2011-02-12 09:03:44 -06002568
2569As of libpng version 1.5.2, almost all useful expansions are supported, the
Glenn Randers-Pehrsoncd116fa2011-05-17 06:56:50 -05002570major ommissions are conversion of grayscale to indexed images (which can be
2571done trivially in the application) and conversion of indexed to grayscale (which
John Bowler63d059a2011-02-12 09:03:44 -06002572can be done by a trivial manipulation of the palette.)
2573
2574In the following table, the 01 means grayscale with depth<8, 31 means
2575indexed with depth<8, other numerals represent the color type, "T" means
2576the tRNS chunk is present, A means an alpha channel is present, and O
2577means tRNS or alpha is present but all pixels in the image are opaque.
2578
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002579 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
John Bowler63d059a2011-02-12 09:03:44 -06002580 TO
2581 01 - [G] - - - - - - - - - - - - -
2582 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
2583 0 1 G + . . G G G G G G B B GB GB
2584 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
2585 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
2586 2 C P C C C + . . C - - CB CB B B
2587 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
2588 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
2589 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
2590 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
2591 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
2592 4A lA G A T T GA GT GT GA GT GT + BA G GBA
2593 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
2594 6A CA PA CA C C A T tT PA P P C CBA + BA
2595 6O CA PBA CA C C A tT T PA P P CBA C BA +
2596
2597Within the matrix,
2598 "+" identifies entries where 'from' and 'to' are the same.
2599 "-" means the transformation is not supported.
2600 "." means nothing is necessary (a tRNS chunk can just be ignored).
2601 "t" means the transformation is obtained by png_set_tRNS.
2602 "A" means the transformation is obtained by png_set_add_alpha().
2603 "X" means the transformation is obtained by png_set_expand().
2604 "1" means the transformation is obtained by
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002605 png_set_expand_gray_1_2_4_to_8() (and by png_set_expand()
2606 if there is no transparency in the original or the final
2607 format).
John Bowler63d059a2011-02-12 09:03:44 -06002608 "C" means the transformation is obtained by png_set_gray_to_rgb().
Glenn Randers-Pehrsonc36074e2011-05-16 09:08:51 -05002609 "G" means the transformation is obtained by png_set_rgb_to_gray().
John Bowler63d059a2011-02-12 09:03:44 -06002610 "P" means the transformation is obtained by
2611 png_set_expand_palette_to_rgb().
2612 "p" means the transformation is obtained by png_set_packing().
2613 "Q" means the transformation is obtained by png_set_quantize().
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002614 "T" means the transformation is obtained by
2615 png_set_tRNS_to_alpha().
2616 "B" means the transformation is obtained by
2617 png_set_background(), or png_strip_alpha().
John Bowler63d059a2011-02-12 09:03:44 -06002618
2619When an entry has multiple transforms listed all are required to cause the
2620right overall transformation. When two transforms are separated by a comma
2621either will do the job. When transforms are enclosed in [] the transform should
2622do the job but this is currently unimplemented - a different format will result
2623if the suggested transformations are used.
2624
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002625In PNG files, the alpha channel in an image
2626is the level of opacity. If you need the alpha channel in an image to
2627be the level of transparency instead of opacity, you can invert the
2628alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2629fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2630images) is fully transparent, with
2631
2632 png_set_invert_alpha(png_ptr);
2633
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002634PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2635they can, resulting in, for example, 8 pixels per byte for 1 bit
2636files. This code expands to 1 pixel per byte without changing the
2637values of the pixels:
2638
2639 if (bit_depth < 8)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002640 png_set_packing(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002641
2642PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
2643stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002644higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2645to 8 bits/sample in the range [0, 255]). However, it is also possible
2646to convert the PNG pixel data back to the original bit depth of the
2647image. This call reduces the pixels back down to the original bit depth:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002648
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05002649 png_color_8p sig_bit;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002650
2651 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002652 png_set_shift(png_ptr, sig_bit);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002653
2654PNG files store 3-color pixels in red, green, blue order. This code
2655changes the storage of the pixels to blue, green, red:
2656
2657 if (color_type == PNG_COLOR_TYPE_RGB ||
2658 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002659 png_set_bgr(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002660
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002661PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2662into 4 or 8 bytes for windowing systems that need them in this format:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002663
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002664 if (color_type == PNG_COLOR_TYPE_RGB)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002665 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002666
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002667where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002668either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2669you want the filler before the RGB or after. This transformation
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002670does not affect images that already have full alpha channels. To add an
2671opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2672will generate RGBA pixels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002673
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002674Note that png_set_filler() does not change the color type. If you want
2675to do that, you can add a true alpha channel with
2676
2677 if (color_type == PNG_COLOR_TYPE_RGB ||
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002678 color_type == PNG_COLOR_TYPE_GRAY)
2679 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002680
2681where "filler" contains the alpha value to assign to each pixel.
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06002682This function was added in libpng-1.2.7.
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002683
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002684If you are reading an image with an alpha channel, and you need the
2685data as ARGB instead of the normal PNG format RGBA:
2686
2687 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002688 png_set_swap_alpha(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002689
2690For some uses, you may want a grayscale image to be represented as
2691RGB. This code will do that conversion:
2692
2693 if (color_type == PNG_COLOR_TYPE_GRAY ||
2694 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002695 png_set_gray_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002696
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002697Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002698with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002699
2700 if (color_type == PNG_COLOR_TYPE_RGB ||
2701 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002702 png_set_rgb_to_gray(png_ptr, error_action,
2703 double red_weight, double green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002704
2705 error_action = 1: silently do the conversion
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002706
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002707 error_action = 2: issue a warning if the original
2708 image has any pixel where
2709 red != green or red != blue
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002710
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002711 error_action = 3: issue an error and abort the
2712 conversion if the original
2713 image has any pixel where
2714 red != green or red != blue
2715
John Bowlercb0b2962011-05-12 21:48:29 -05002716 red_weight: weight of red component
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002717
John Bowlercb0b2962011-05-12 21:48:29 -05002718 green_weight: weight of green component
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002719 If either weight is negative, default
John Bowlercb0b2962011-05-12 21:48:29 -05002720 weights are used.
2721
2722In the corresponding fixed point API the red_weight and green_weight values are
2723simply scaled by 100,000:
2724
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06002725 png_set_rgb_to_gray(png_ptr, error_action,
2726 png_fixed_point red_weight,
John Bowlercb0b2962011-05-12 21:48:29 -05002727 png_fixed_point green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002728
2729If you have set error_action = 1 or 2, you can
2730later check whether the image really was gray, after processing
2731the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2732It will return a png_byte that is zero if the image was gray or
John Bowlercb0b2962011-05-12 21:48:29 -050027331 if there were any non-gray pixels. Background and sBIT data
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002734will be silently converted to grayscale, using the green channel
John Bowlercb0b2962011-05-12 21:48:29 -05002735data for sBIT, regardless of the error_action setting.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002736
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002737The default values come from the PNG file cHRM chunk if present; otherwise, the
John Bowlercb0b2962011-05-12 21:48:29 -05002738defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2739space, as recommended in the Charles Poynton's Colour FAQ,
2740<http://www.poynton.com/>, in section 9:
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002741
John Bowlercb0b2962011-05-12 21:48:29 -05002742 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002743
Glenn Randers-Pehrson6c988972011-07-29 12:31:16 -05002744 Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
2745
2746Previous versions of this document, 1998 through 2002, recommended a slightly
2747different formula:
2748
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002749 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2750
Glenn Randers-Pehrson6c988972011-07-29 12:31:16 -05002751Libpng uses an integer approximation:
2752
2753 Y = (6968 * R + 23434 * G + 2366 * B)/32768
2754
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002755The calculation is done in a linear colorspace, if the image gamma
Glenn Randers-Pehrson9962b842011-01-24 00:12:14 -06002756can be determined.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002757
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002758The png_set_background() function has been described already; it tells libpng to
John Bowlercb0b2962011-05-12 21:48:29 -05002759composite images with alpha or simple transparency against the supplied
2760background color. For compatibility with versions of libpng earlier than
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05002761libpng-1.5.4 it is recommended that you call the function after reading the file
John Bowlercb0b2962011-05-12 21:48:29 -05002762header, even if you don't want to use the color in a bKGD chunk, if one exists.
2763
2764If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2765you may use this color, or supply another color more suitable for
2766the current display (e.g., the background color from a web page). You
2767need to tell libpng how the color is represented, both the format of the
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002768component values in the color (the number of bits) and the gamma encoding of the
John Bowlercb0b2962011-05-12 21:48:29 -05002769color. The function takes two arguments, background_gamma_mode and need_expand
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002770to convey this information, however only two combinations are likely to be
2771useful:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002772
Glenn Randers-Pehrsoncb47e202011-07-10 06:55:14 -05002773 png_color_16 my_background;
2774 png_color_16p image_background;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002775
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002776 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002777 png_set_background(png_ptr, image_background,
John Bowlercb0b2962011-05-12 21:48:29 -05002778 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002779 else
Glenn Randers-Pehrsoncb47e202011-07-10 06:55:14 -05002780 png_set_background(png_ptr, &my_background,
John Bowlercb0b2962011-05-12 21:48:29 -05002781 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002782
John Bowlercb0b2962011-05-12 21:48:29 -05002783The second call was described above - my_background is in the format of the
2784final, display, output produced by libpng. Because you now know the format of
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05002785the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2786output and to retain palette images (the palette colors will be modified
2787appropriately and the tRNS chunk removed.) However, if you are doing this,
2788take great care not to ask for transformations without checking first that
2789they apply!
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002790
John Bowlercb0b2962011-05-12 21:48:29 -05002791In the first call the background color has the original bit depth and color type
2792of the PNG file. So, for palette images the color is supplied as a palette
2793index and for low bit greyscale images the color is a reduced bit value in
2794image_background->gray.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002795
John Bowlercb0b2962011-05-12 21:48:29 -05002796If you didn't call png_set_gamma() before reading the file header, for example
2797if you need your code to remain compatible with older versions of libpng prior
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05002798to libpng-1.5.4, this is the place to call it.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002799
John Bowlercb0b2962011-05-12 21:48:29 -05002800Do not call it if you called png_set_alpha_mode(); doing so will damage the
2801settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
2802supported then you can certainly do png_set_gamma() before reading the PNG
2803header.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002804
Glenn Randers-Pehrsonc7822512011-05-07 21:23:43 -05002805This API unconditionally sets the screen and file gamma values, so it will
2806override the value in the PNG file unless it is called before the PNG file
2807reading starts. For this reason you must always call it with the PNG file
2808value when you call it in this position:
2809
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002810 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
2811 png_set_gamma(png_ptr, screen_gamma, file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002812
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002813 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002814 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002815
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002816If you need to reduce an RGB file to a paletted file, or if a paletted
2817file has more entries then will fit on your screen, png_set_quantize()
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -05002818will do that. Note that this is a simple match quantization that merely
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002819finds the closest color available. This should work fairly well with
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002820optimized palettes, but fairly badly with linear color cubes. If you
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002821pass a palette that is larger than maximum_colors, the file will
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002822reduce the number of colors in the palette so it will fit into
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002823maximum_colors. If there is a histogram, libpng will use it to make
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002824more intelligent choices when reducing the palette. If there is no
2825histogram, it may not do as good a job.
2826
2827 if (color_type & PNG_COLOR_MASK_COLOR)
2828 {
2829 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002830 PNG_INFO_PLTE))
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002831 {
2832 png_uint_16p histogram = NULL;
2833
2834 png_get_hIST(png_ptr, info_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002835 &histogram);
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002836 png_set_quantize(png_ptr, palette, num_palette,
2837 max_screen_colors, histogram, 1);
2838 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002839
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002840 else
2841 {
2842 png_color std_color_cube[MAX_SCREEN_COLORS] =
2843 { ... colors ... };
2844
2845 png_set_quantize(png_ptr, std_color_cube,
2846 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2847 NULL,0);
2848 }
2849 }
2850
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002851PNG files describe monochrome as black being zero and white being one.
2852The following code will reverse this (make black be one and white be
2853zero):
2854
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05002855 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2856 png_set_invert_mono(png_ptr);
2857
2858This function can also be used to invert grayscale and gray-alpha images:
2859
2860 if (color_type == PNG_COLOR_TYPE_GRAY ||
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002861 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002862 png_set_invert_mono(png_ptr);
2863
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05002864PNG files store 16-bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002865ie. most significant bits first). This code changes the storage to the
2866other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002867way PCs store them):
2868
2869 if (bit_depth == 16)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002870 png_set_swap(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002871
2872If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2873need to change the order the pixels are packed into bytes, you can use:
2874
2875 if (bit_depth < 8)
2876 png_set_packswap(png_ptr);
2877
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002878Finally, you can write your own transformation function if none of
2879the existing ones meets your needs. This is done by setting a callback
2880with
2881
2882 png_set_read_user_transform_fn(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002883 read_transform_fn);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002884
2885You must supply the function
2886
Glenn Randers-Pehrson93215672011-02-13 19:42:19 -06002887 void read_transform_fn(png_structp png_ptr, png_row_infop
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002888 row_info, png_bytep data)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002889
2890See pngtest.c for a working example. Your function will be called
John Bowlerf19abd62011-01-22 18:29:24 -06002891after all of the other transformations have been processed. Take care with
2892interlaced images if you do the interlace yourself - the width of the row is the
2893width in 'row_info', not the overall image width.
2894
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002895If supported, libpng provides two information routines that you can use to find
John Bowlerf19abd62011-01-22 18:29:24 -06002896where you are in processing the image:
2897
2898 png_get_current_pass_number(png_structp png_ptr);
2899 png_get_current_row_number(png_structp png_ptr);
2900
2901Don't try using these outside a transform callback - firstly they are only
2902supported if user transforms are supported, secondly they may well return
2903unexpected results unless the row is actually being processed at the moment they
2904are called.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002905
John Bowlercd113452011-02-16 06:15:13 -06002906With interlaced
2907images the value returned is the row in the input sub-image image. Use
2908PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2909find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2910
2911The discussion of interlace handling above contains more information on how to
2912use these values.
2913
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002914You can also set up a pointer to a user structure for use by your
2915callback function, and you can inform libpng that your transform
2916function will change the number of channels or bit depth with the
2917function
2918
2919 png_set_user_transform_info(png_ptr, user_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002920 user_depth, user_channels);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002921
2922The user's application, not libpng, is responsible for allocating and
2923freeing any memory required for the user structure.
2924
2925You can retrieve the pointer via the function
2926png_get_user_transform_ptr(). For example:
2927
2928 voidp read_user_transform_ptr =
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002929 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002930
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002931The last thing to handle is interlacing; this is covered in detail below,
2932but you must call the function here if you want libpng to handle expansion
2933of the interlaced image.
2934
2935 number_of_passes = png_set_interlace_handling(png_ptr);
2936
2937After setting the transformations, libpng can update your png_info
2938structure to reflect any transformations you've requested with this
Glenn Randers-Pehrson968c2312011-09-26 16:35:22 -05002939call.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002940
2941 png_read_update_info(png_ptr, info_ptr);
2942
Glenn Randers-Pehrson968c2312011-09-26 16:35:22 -05002943This is most useful to update the info structure's rowbytes
2944field so you can use it to allocate your image memory. This function
2945will also update your palette with the correct screen_gamma and
2946background if these have been given with the calls above. You may
2947only call png_read_update_info() once with a particular info_ptr.
2948
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002949After you call png_read_update_info(), you can allocate any
2950memory you need to hold the image. The row data is simply
2951raw byte data for all forms of images. As the actual allocation
2952varies among applications, no example will be given. If you
2953are allocating one large chunk, you will need to build an
2954array of pointers to each row, as it will be needed for some
2955of the functions below.
2956
Glenn Randers-Pehrson968c2312011-09-26 16:35:22 -05002957Remember: Before you call png_read_update_info(), the png_get_*()
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002958functions return the values corresponding to the original PNG image.
2959After you call png_read_update_info the values refer to the image
2960that libpng will output. Consequently you must call all the png_set_
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002961functions before you call png_read_update_info(). This is particularly
2962important for png_set_interlace_handling() - if you are going to call
2963png_read_update_info() you must call png_set_interlace_handling() before
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002964it unless you want to receive interlaced output.
2965
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002966.SS Reading image data
2967
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002968After you've allocated memory, you can read the image data.
2969The simplest way to do this is in one function call. If you are
2970allocating enough memory to hold the whole image, you can just
2971call png_read_image() and libpng will read in all the image data
2972and put it in the memory area supplied. You will need to pass in
2973an array of pointers to each row.
2974
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002975This function automatically handles interlacing, so you don't
2976need to call png_set_interlace_handling() (unless you call
2977png_read_update_info()) or call this function multiple times, or any
2978of that other stuff necessary with png_read_rows().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002979
2980 png_read_image(png_ptr, row_pointers);
2981
2982where row_pointers is:
2983
2984 png_bytep row_pointers[height];
2985
2986You can point to void or char or whatever you use for pixels.
2987
2988If you don't want to read in the whole image at once, you can
2989use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002990interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002991
2992 png_read_rows(png_ptr, row_pointers, NULL,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002993 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002994
2995where row_pointers is the same as in the png_read_image() call.
2996
2997If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002998a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002999
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003000 png_bytep row_pointer = row;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003001 png_read_row(png_ptr, row_pointer, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003002
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003003If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
3004get somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003005interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
3006a somewhat complicated 2D interlace scheme, known as Adam7, that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003007breaks down an image into seven smaller images of varying size, based
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003008on an 8x8 grid. This number is defined (from libpng 1.5) as
3009PNG_INTERLACE_ADAM7_PASSES in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003010
3011libpng can fill out those images or it can give them to you "as is".
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003012It is almost always better to have libpng handle the interlacing for you.
3013If you want the images filled out, there are two ways to do that. The one
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003014mentioned in the PNG specification is to expand each pixel to cover
3015those pixels that have not been read yet (the "rectangle" method).
3016This results in a blocky image for the first pass, which gradually
3017smooths out as more pixels are read. The other method is the "sparkle"
3018method, where pixels are drawn only in their final locations, with the
3019rest of the image remaining whatever colors they were initialized to
3020before the start of the read. The first method usually looks better,
3021but tends to be slower, as there are more pixels to put in the rows.
3022
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003023If, as is likely, you want libpng to expand the images, call this before
3024calling png_start_read_image() or png_read_update_info():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003025
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003026 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003027 number_of_passes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003028 = png_set_interlace_handling(png_ptr);
3029
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003030This will return the number of passes needed. Currently, this is seven,
3031but may change if another interlace type is added. This function can be
3032called even if the file is not interlaced, where it will return one pass.
3033You then need to read the whole image 'number_of_passes' times. Each time
3034will distribute the pixels from the current pass to the correct place in
3035the output image, so you need to supply the same rows to png_read_rows in
3036each pass.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05003037
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003038If you are not going to display the image after each pass, but are
3039going to wait until the entire image is read in, use the sparkle
3040effect. This effect is faster and the end result of either method
3041is exactly the same. If you are planning on displaying the image
3042after each pass, the "rectangle" effect is generally considered the
3043better looking one.
3044
3045If you only want the "sparkle" effect, just call png_read_rows() as
3046normal, with the third parameter NULL. Make sure you make pass over
3047the image number_of_passes times, and you don't change the data in the
3048rows between calls. You can change the locations of the data, just
3049not the data. Each pass only writes the pixels appropriate for that
3050pass, and assumes the data from previous passes is still valid.
3051
3052 png_read_rows(png_ptr, row_pointers, NULL,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003053 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003054
3055If you only want the first effect (the rectangles), do the same as
3056before except pass the row buffer in the third parameter, and leave
3057the second parameter NULL.
3058
3059 png_read_rows(png_ptr, NULL, row_pointers,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003060 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003061
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003062If you don't want libpng to handle the interlacing details, just call
3063png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
3064Each of the images is a valid image by itself, however you will almost
3065certainly need to distribute the pixels from each sub-image to the
3066correct place. This is where everything gets very tricky.
3067
3068If you want to retrieve the separate images you must pass the correct
3069number of rows to each successive call of png_read_rows(). The calculation
3070gets pretty complicated for small images, where some sub-images may
3071not even exist because either their width or height ends up zero.
3072libpng provides two macros to help you in 1.5 and later versions:
3073
3074 png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
3075 png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
3076
3077Respectively these tell you the width and height of the sub-image
3078corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
3079this can be confusing because the specification refers to the same passes
3080as 1 to 7! Be careful, you must check both the width and height before
3081calling png_read_rows() and not call it for that pass if either is zero.
3082
3083You can, of course, read each sub-image row by row. If you want to
3084produce optimal code to make a pixel-by-pixel transformation of an
3085interlaced image this is the best approach; read each row of each pass,
3086transform it, and write it out to a new interlaced image.
3087
3088If you want to de-interlace the image yourself libpng provides further
3089macros to help that tell you where to place the pixels in the output image.
3090Because the interlacing scheme is rectangular - sub-image pixels are always
3091arranged on a rectangular grid - all you need to know for each pass is the
3092starting column and row in the output image of the first pixel plus the
3093spacing between each pixel. As of libpng 1.5 there are four macros to
3094retrieve this information:
3095
3096 png_uint_32 x = PNG_PASS_START_COL(pass);
3097 png_uint_32 y = PNG_PASS_START_ROW(pass);
3098 png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
3099 png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
3100
3101These allow you to write the obvious loop:
3102
3103 png_uint_32 input_y = 0;
3104 png_uint_32 output_y = PNG_PASS_START_ROW(pass);
3105
3106 while (output_y < output_image_height)
3107 {
3108 png_uint_32 input_x = 0;
3109 png_uint_32 output_x = PNG_PASS_START_COL(pass);
3110
3111 while (output_x < output_image_width)
3112 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003113 image[output_y][output_x] =
3114 subimage[pass][input_y][input_x++];
3115
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003116 output_x += xStep;
3117 }
3118
3119 ++input_y;
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003120 output_y += yStep;
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003121 }
3122
3123Notice that the steps between successive output rows and columns are
3124returned as shifts. This is possible because the pixels in the subimages
3125are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
3126image. In practice you may need to directly calculate the output coordinate
3127given an input coordinate. libpng provides two further macros for this
3128purpose:
3129
3130 png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
3131 png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
3132
3133Finally a pair of macros are provided to tell you if a particular image
3134row or column appears in a given pass:
3135
3136 int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
3137 int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
3138
3139Bear in mind that you will probably also need to check the width and height
3140of the pass in addition to the above to be sure the pass even exists!
3141
3142With any luck you are convinced by now that you don't want to do your own
3143interlace handling. In reality normally the only good reason for doing this
3144is if you are processing PNG files on a pixel-by-pixel basis and don't want
3145to load the whole file into memory when it is interlaced.
3146
3147libpng includes a test program, pngvalid, that illustrates reading and
3148writing of interlaced images. If you can't get interlacing to work in your
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05003149code and don't want to leave it to libpng (the recommended approach), see
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003150how pngvalid.c does it.
3151
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003152.SS Finishing a sequential read
3153
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003154After you are finished reading the image through the
3155low-level interface, you can finish reading the file. If you are
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003156interested in comments or time, which may be stored either before or
3157after the image data, you should pass the separate png_info struct if
3158you want to keep the comments from before and after the image
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003159separate.
3160
3161 png_infop end_info = png_create_info_struct(png_ptr);
3162
3163 if (!end_info)
3164 {
3165 png_destroy_read_struct(&png_ptr, &info_ptr,
3166 (png_infopp)NULL);
3167 return (ERROR);
3168 }
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003169
3170 png_read_end(png_ptr, end_info);
3171
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003172If you are not interested, you should still call png_read_end()
3173but you can pass NULL, avoiding the need to create an end_info structure.
3174
3175 png_read_end(png_ptr, (png_infop)NULL);
3176
Glenn Randers-Pehrson99778e12011-04-20 17:43:52 -05003177If you don't call png_read_end(), then your file pointer will be
3178left pointing to the first chunk after the last IDAT, which is probably
3179not what you want if you expect to read something beyond the end of
3180the PNG datastream.
3181
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003182When you are done, you can free all memory allocated by libpng like this:
3183
3184 png_destroy_read_struct(&png_ptr, &info_ptr,
3185 &end_info);
3186
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003187or, if you didn't create an end_info structure,
3188
3189 png_destroy_read_struct(&png_ptr, &info_ptr,
3190 (png_infopp)NULL);
3191
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003192It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003193point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003194
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003195 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003196
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003197 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003198 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003199 more of
3200 PNG_FREE_PLTE, PNG_FREE_TRNS,
3201 PNG_FREE_HIST, PNG_FREE_ICCP,
3202 PNG_FREE_PCAL, PNG_FREE_ROWS,
3203 PNG_FREE_SCAL, PNG_FREE_SPLT,
3204 PNG_FREE_TEXT, PNG_FREE_UNKN,
3205 or simply PNG_FREE_ALL
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003206
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003207 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003208 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003209
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003210This function may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003211already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003212by the user and not by libpng, and will in those cases do nothing.
3213The "seq" parameter is ignored if only one item of the selected data
3214type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3215are allowed for the data type identified in the mask, such as text or
3216sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003217
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003218The default behavior is only to free data that was allocated internally
3219by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003220or so that it will free data that was allocated by the user with png_malloc()
3221or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003222
3223 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003224
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003225 freer - one of
3226 PNG_DESTROY_WILL_FREE_DATA
3227 PNG_SET_WILL_FREE_DATA
3228 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003229
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003230 mask - which data elements are affected
3231 same choices as in png_free_data()
3232
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003233This function only affects data that has already been allocated.
3234You can call this function after reading the PNG data but before calling
3235any png_set_*() functions, to control whether the user or the png_set_*()
3236function is responsible for freeing any existing data that might be present,
3237and again after the png_set_*() functions to control whether the user
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003238or png_destroy_*() is supposed to free the data. When the user assumes
3239responsibility for libpng-allocated data, the application must use
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003240png_free() to free it, and when the user transfers responsibility to libpng
3241for data that the user has allocated, the user must have used png_malloc()
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05003242or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003243
3244If you allocated your row_pointers in a single block, as suggested above in
3245the description of the high level read interface, you must not transfer
3246responsibility for freeing it to the png_set_rows or png_read_destroy function,
3247because they would also try to free the individual row_pointers[i].
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003248
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003249If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3250separately, do not transfer responsibility for freeing text_ptr to libpng,
3251because when libpng fills a png_text structure it combines these members with
3252the key member, and png_free_data() will free only text_ptr.key. Similarly,
3253if you transfer responsibility for free'ing text_ptr from libpng to your
3254application, your application must not separately free those members.
3255
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003256The png_free_data() function will turn off the "valid" flag for anything
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003257it frees. If you need to turn the flag off for a chunk that was freed by
3258your application instead of by libpng, you can use
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003259
3260 png_set_invalid(png_ptr, info_ptr, mask);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003261
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003262 mask - identifies the chunks to be made invalid,
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003263 containing the bitwise OR of one or
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06003264 more of
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003265 PNG_INFO_gAMA, PNG_INFO_sBIT,
3266 PNG_INFO_cHRM, PNG_INFO_PLTE,
3267 PNG_INFO_tRNS, PNG_INFO_bKGD,
3268 PNG_INFO_hIST, PNG_INFO_pHYs,
3269 PNG_INFO_oFFs, PNG_INFO_tIME,
3270 PNG_INFO_pCAL, PNG_INFO_sRGB,
3271 PNG_INFO_iCCP, PNG_INFO_sPLT,
3272 PNG_INFO_sCAL, PNG_INFO_IDAT
3273
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003274For a more compact example of reading a PNG image, see the file example.c.
3275
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003276.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003277
3278The progressive reader is slightly different then the non-progressive
3279reader. Instead of calling png_read_info(), png_read_rows(), and
3280png_read_end(), you make one call to png_process_data(), which calls
3281callbacks when it has the info, a row, or the end of the image. You
3282set up these callbacks with png_set_progressive_read_fn(). You don't
3283have to worry about the input/output functions of libpng, as you are
3284giving the library the data directly in png_process_data(). I will
3285assume that you have read the section on reading PNG files above,
3286so I will only highlight the differences (although I will show
3287all of the code).
3288
3289png_structp png_ptr;
3290png_infop info_ptr;
3291
3292 /* An example code fragment of how you would
3293 initialize the progressive reader in your
3294 application. */
3295 int
3296 initialize_png_reader()
3297 {
3298 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003299 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003300 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003301
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003302 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003303 return (ERROR);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003304
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003305 info_ptr = png_create_info_struct(png_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003306
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003307 if (!info_ptr)
3308 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003309 png_destroy_read_struct(&png_ptr,
3310 (png_infopp)NULL, (png_infopp)NULL);
3311 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003312 }
3313
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003314 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003315 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003316 png_destroy_read_struct(&png_ptr, &info_ptr,
3317 (png_infopp)NULL);
3318 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003319 }
3320
3321 /* This one's new. You can provide functions
3322 to be called when the header info is valid,
3323 when each row is completed, and when the image
3324 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003325 you can specify NULL parameters. Even when all
3326 three functions are NULL, you need to call
3327 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003328 any struct as the user_ptr (cast to a void pointer
3329 for the function call), and retrieve the pointer
3330 from inside the callbacks using the function
3331
3332 png_get_progressive_ptr(png_ptr);
3333
3334 which will return a void pointer, which you have
3335 to cast appropriately.
3336 */
3337 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
3338 info_callback, row_callback, end_callback);
3339
3340 return 0;
3341 }
3342
3343 /* A code fragment that you call as you receive blocks
3344 of data */
3345 int
3346 process_data(png_bytep buffer, png_uint_32 length)
3347 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003348 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003349 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003350 png_destroy_read_struct(&png_ptr, &info_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003351 (png_infopp)NULL);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003352 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003353 }
3354
3355 /* This one's new also. Simply give it a chunk
3356 of data from the file stream (in order, of
3357 course). On machines with segmented memory
3358 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003359 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003360 of 4K. Although you can give it much less if
3361 necessary (I assume you can give it chunks of
3362 1 byte, I haven't tried less then 256 bytes
3363 yet). When this function returns, you may
3364 want to display any rows that were generated
3365 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003366 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003367 */
3368 png_process_data(png_ptr, info_ptr, buffer, length);
John Bowlerf19abd62011-01-22 18:29:24 -06003369
3370 /* At this point you can call png_process_data_skip if
3371 you want to handle data the library will skip yourself;
3372 it simply returns the number of bytes to skip (and stops
3373 libpng skipping that number of bytes on the next
3374 png_process_data call).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003375 return 0;
3376 }
3377
3378 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003379 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003380 has been supplied so all of the header has been
3381 read.
3382 */
3383 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003384 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003385 {
3386 /* Do any setup here, including setting any of
3387 the transformations mentioned in the Reading
3388 PNG files section. For now, you _must_ call
3389 either png_start_read_image() or
3390 png_read_update_info() after all the
3391 transformations are set (even if you don't set
3392 any). You may start getting rows before
3393 png_process_data() returns, so this is your
3394 last chance to prepare for that.
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003395
3396 This is where you turn on interlace handling,
3397 assuming you don't want to do it yourself.
John Bowlerf19abd62011-01-22 18:29:24 -06003398
3399 If you need to you can stop the processing of
3400 your original input data at this point by calling
3401 png_process_data_pause. This returns the number
3402 of unprocessed bytes from the last png_process_data
3403 call - it is up to you to ensure that the next call
3404 sees these bytes again. If you don't want to bother
3405 with this you can get libpng to cache the unread
3406 bytes by setting the 'save' parameter (see png.h) but
3407 then libpng will have to copy the data internally.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003408 */
3409 }
3410
3411 /* This function is called when each row of image
3412 data is complete */
3413 void
3414 row_callback(png_structp png_ptr, png_bytep new_row,
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05003415 png_uint_32 row_num, int pass)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003416 {
3417 /* If the image is interlaced, and you turned
3418 on the interlace handler, this function will
3419 be called for every row in every pass. Some
3420 of these rows will not be changed from the
3421 previous pass. When the row is not changed,
3422 the new_row variable will be NULL. The rows
3423 and passes are called in order, so you don't
3424 really need the row_num and pass, but I'm
3425 supplying them because it may make your life
3426 easier.
3427
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003428 If you did not turn on interlace handling then
3429 the callback is called for each row of each
3430 sub-image when the image is interlaced. In this
3431 case 'row_num' is the row in the sub-image, not
3432 the row in the output image as it is in all other
3433 cases.
3434
3435 For the non-NULL rows of interlaced images when
3436 you have switched on libpng interlace handling,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003437 you must call png_progressive_combine_row()
3438 passing in the row and the old row. You can
3439 call this function for NULL rows (it will just
3440 return) and for non-interlaced images (it just
3441 does the memcpy for you) if it will make the
3442 code easier. Thus, you can just do this for
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003443 all cases if you switch on interlace handling;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003444 */
3445
3446 png_progressive_combine_row(png_ptr, old_row,
3447 new_row);
3448
3449 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05003450 previously for the row. Note that the first
3451 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003452 the old row, so the rows do not have to be
3453 initialized. After the first pass (and only
3454 for interlaced images), you will have to pass
3455 the current row, and the function will combine
3456 the old row and the new row.
John Bowlerf19abd62011-01-22 18:29:24 -06003457
3458 You can also call png_process_data_pause in this
3459 callback - see above.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003460 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003461 }
3462
3463 void
3464 end_callback(png_structp png_ptr, png_infop info)
3465 {
3466 /* This function is called after the whole image
3467 has been read, including any chunks after the
3468 image (up to and including the IEND). You
3469 will usually have the same info chunk as you
3470 had in the header, although some data may have
3471 been added to the comments and time fields.
3472
3473 Most people won't do much here, perhaps setting
3474 a flag that marks the image as finished.
3475 */
3476 }
3477
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003478
3479
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003480.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003481
3482Much of this is very similar to reading. However, everything of
3483importance is repeated here, so you won't have to constantly look
3484back up in the reading section to understand writing.
3485
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003486.SS Setup
3487
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003488You will want to do the I/O initialization before you get into libpng,
3489so if it doesn't work, you don't have anything to undo. If you are not
3490using the standard I/O functions, you will need to replace them with
3491custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003492
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003493 FILE *fp = fopen(file_name, "wb");
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003494
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003495 if (!fp)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003496 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003497
3498Next, png_struct and png_info need to be allocated and initialized.
3499As these can be both relatively large, you may not want to store these
3500on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003501will want to check if they return NULL. If you are also reading,
3502you won't want to name your read structure and your write structure
3503both "png_ptr"; you can call them anything you like, such as
3504"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003505
3506 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003507 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003508 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003509
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003510 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003511 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003512
3513 png_infop info_ptr = png_create_info_struct(png_ptr);
3514 if (!info_ptr)
3515 {
3516 png_destroy_write_struct(&png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003517 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003518 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003519 }
3520
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003521If you want to use your own memory allocation routines,
3522define PNG_USER_MEM_SUPPORTED and use
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003523png_create_write_struct_2() instead of png_create_write_struct():
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003524
3525 png_structp png_ptr = png_create_write_struct_2
3526 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3527 user_error_fn, user_warning_fn, (png_voidp)
3528 user_mem_ptr, user_malloc_fn, user_free_fn);
3529
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003530After you have these structures, you will need to set up the
3531error handling. When libpng encounters an error, it expects to
3532longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003533setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003534write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003535the png_jmpbuf(png_ptr) every time you enter a new routine that will
3536call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003537for your compiler for more information on setjmp/longjmp. See
3538the discussion on libpng error handling in the Customizing Libpng
3539section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003540
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003541 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003542 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003543 png_destroy_write_struct(&png_ptr, &info_ptr);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003544 fclose(fp);
3545 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003546 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003547 ...
3548 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003549
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003550If you would rather avoid the complexity of setjmp/longjmp issues,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05003551you can compile libpng with PNG_NO_SETJMP, in which case
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003552errors will result in a call to PNG_ABORT() which defaults to abort().
3553
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05003554You can #define PNG_ABORT() to a function that does something
3555more useful than abort(), as long as your function does not
3556return.
3557
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003558Now you need to set up the output code. The default for libpng is to
3559use the C function fwrite(). If you use this, you will need to pass a
3560valid FILE * in the function png_init_io(). Be sure that the file is
3561opened in binary mode. Again, if you wish to handle writing data in
3562another way, see the discussion on libpng I/O handling in the Customizing
3563Libpng section below.
3564
3565 png_init_io(png_ptr, fp);
3566
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05003567If you are embedding your PNG into a datastream such as MNG, and don't
3568want libpng to write the 8-byte signature, or if you have already
3569written the signature in your application, use
3570
3571 png_set_sig_bytes(png_ptr, 8);
3572
3573to inform libpng that it should not write a signature.
3574
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003575.SS Write callbacks
3576
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003577At this point, you can set up a callback function that will be
3578called after each row has been written, which you can use to control
3579a progress meter or the like. It's demonstrated in pngtest.c.
3580You must supply a function
3581
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06003582 void write_row_callback(png_structp png_ptr, png_uint_32 row,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003583 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003584 {
3585 /* put your code here */
3586 }
3587
3588(You can give it another name that you like instead of "write_row_callback")
3589
3590To inform libpng about your function, use
3591
3592 png_set_write_status_fn(png_ptr, write_row_callback);
3593
John Bowler59010e52011-02-16 06:16:31 -06003594When this function is called the row has already been completely processed and
3595it has also been written out. The 'row' and 'pass' refer to the next row to be
3596handled. For the
3597non-interlaced case the row that was just handled is simply one less than the
3598passed in row number, and pass will always be 0. For the interlaced case the
3599same applies unless the row value is 0, in which case the row just handled was
3600the last one from one of the preceding passes. Because interlacing may skip a
3601pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3602need to know what the last pass is record (row,pass) from the callback and use
3603the last recorded value each time.
3604
3605As with the user transform you can find the output row using the
3606PNG_ROW_FROM_PASS_ROW macro.
3607
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003608You now have the option of modifying how the compression library will
3609run. The following functions are mainly for testing, but may be useful
3610in some cases, like if you need to write PNG files extremely fast and
3611are willing to give up some compression, or if you want to get the
3612maximum possible compression at the expense of slower writing. If you
3613have no special needs in this area, let the library do what it wants by
3614not calling this function at all, as it has been tuned to deliver a good
3615speed/compression ratio. The second parameter to png_set_filter() is
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003616the filter method, for which the only valid values are 0 (as of the
3617July 1999 PNG specification, version 1.2) or 64 (if you are writing
3618a PNG datastream that is to be embedded in a MNG datastream). The third
3619parameter is a flag that indicates which filter type(s) are to be tested
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003620for each scanline. See the PNG specification for details on the specific
3621filter types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003622
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003623
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003624 /* turn on or off filtering, and/or choose
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003625 specific filters. You can use either a single
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003626 PNG_FILTER_VALUE_NAME or the bitwise OR of one
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003627 or more PNG_FILTER_NAME masks.
3628 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003629 png_set_filter(png_ptr, 0,
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003630 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
3631 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
3632 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003633 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003634 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3635 PNG_ALL_FILTERS);
3636
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003637If an application wants to start and stop using particular filters during
3638compression, it should start out with all of the filters (to ensure that
3639the previous row of pixels will be stored in case it's needed later),
3640and then add and remove them after the start of compression.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003641
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003642If you are writing a PNG datastream that is to be embedded in a MNG
3643datastream, the second parameter can be either 0 or 64.
3644
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003645The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003646library, and should mostly be ignored unless you really know what you are
3647doing. The only generally useful call is png_set_compression_level()
3648which changes how much time zlib spends on trying to compress the image
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003649data. See the Compression Library (zlib.h and algorithm.txt, distributed
3650with zlib) for details on the compression levels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003651
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06003652 #include zlib.h
3653
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003654 /* Set the zlib compression level */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003655 png_set_compression_level(png_ptr,
3656 Z_BEST_COMPRESSION);
3657
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003658 /* Set other zlib parameters for compressing IDAT */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003659 png_set_compression_mem_level(png_ptr, 8);
3660 png_set_compression_strategy(png_ptr,
3661 Z_DEFAULT_STRATEGY);
3662 png_set_compression_window_bits(png_ptr, 15);
3663 png_set_compression_method(png_ptr, 8);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003664 png_set_compression_buffer_size(png_ptr, 8192)
3665
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003666 /* Set zlib parameters for text compression
3667 * If you don't call these, the parameters
3668 * fall back on those defined for IDAT chunks
3669 */
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05003670 png_set_text_compression_mem_level(png_ptr, 8);
3671 png_set_text_compression_strategy(png_ptr,
3672 Z_DEFAULT_STRATEGY);
3673 png_set_text_compression_window_bits(png_ptr, 15);
3674 png_set_text_compression_method(png_ptr, 8);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003675
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003676.SS Setting the contents of info for output
3677
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003678You now need to fill in the png_info structure with all the data you
3679wish to write before the actual image. Note that the only thing you
3680are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003681chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003682the latest PNG specification for more information on that. If you
3683wish to write them before the image, fill them in now, and flag that
3684data as being valid. If you want to wait until after the data, don't
3685fill them until png_write_end(). For all the fields in png_info and
3686their data types, see png.h. For explanations of what the fields
3687contain, see the PNG specification.
3688
3689Some of the more important parts of the png_info are:
3690
3691 png_set_IHDR(png_ptr, info_ptr, width, height,
3692 bit_depth, color_type, interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003693 compression_type, filter_method)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003694
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003695 width - holds the width of the image
3696 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003697
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003698 height - holds the height of the image
3699 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003700
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003701 bit_depth - holds the bit depth of one of the
3702 image channels.
3703 (valid values are 1, 2, 4, 8, 16
3704 and depend also on the
3705 color_type. See also significant
3706 bits (sBIT) below).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003707
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003708 color_type - describes which color/alpha
3709 channels are present.
3710 PNG_COLOR_TYPE_GRAY
3711 (bit depths 1, 2, 4, 8, 16)
3712 PNG_COLOR_TYPE_GRAY_ALPHA
3713 (bit depths 8, 16)
3714 PNG_COLOR_TYPE_PALETTE
3715 (bit depths 1, 2, 4, 8)
3716 PNG_COLOR_TYPE_RGB
3717 (bit_depths 8, 16)
3718 PNG_COLOR_TYPE_RGB_ALPHA
3719 (bit_depths 8, 16)
3720
3721 PNG_COLOR_MASK_PALETTE
3722 PNG_COLOR_MASK_COLOR
3723 PNG_COLOR_MASK_ALPHA
3724
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003725 interlace_type - PNG_INTERLACE_NONE or
3726 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003727
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003728 compression_type - (must be
3729 PNG_COMPRESSION_TYPE_DEFAULT)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003730
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003731 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
3732 or, if you are writing a PNG to
3733 be embedded in a MNG datastream,
3734 can also be
3735 PNG_INTRAPIXEL_DIFFERENCING)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003736
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003737If you call png_set_IHDR(), the call must appear before any of the
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05003738other png_set_*() functions, because they might require access to some of
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003739the IHDR settings. The remaining png_set_*() functions can be called
3740in any order.
3741
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003742If you wish, you can reset the compression_type, interlace_type, or
3743filter_method later by calling png_set_IHDR() again; if you do this, the
3744width, height, bit_depth, and color_type must be the same in each call.
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05003745
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003746 png_set_PLTE(png_ptr, info_ptr, palette,
3747 num_palette);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003748
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003749 palette - the palette for the file
3750 (array of png_color)
3751 num_palette - number of entries in the palette
3752
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003753 png_set_gAMA(png_ptr, info_ptr, file_gamma);
3754 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003755
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003756 file_gamma - the gamma at which the image was
3757 created (PNG_INFO_gAMA)
3758
3759 int_file_gamma - 100,000 times the gamma at which
3760 the image was created
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003761
John Bowlerbbd17bd2011-08-25 17:48:18 -05003762 png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y,
3763 green_x, green_y, blue_x, blue_y)
3764 png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,
3765 green_Y, green_Z, blue_X, blue_Y, blue_Z)
3766 png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,
3767 int_red_x, int_red_y, int_green_x, int_green_y,
3768 int_blue_x, int_blue_y)
3769 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,
3770 int_red_Z, int_green_X, int_green_Y, int_green_Z,
3771 int_blue_X, int_blue_Y, int_blue_Z)
3772
3773 {white,red,green,blue}_{x,y}
3774 A color space encoding specified using the chromaticities
3775 of the end points and the white point.
3776
3777 {red,green,blue}_{X,Y,Z}
3778 A color space encoding specified using the encoding end
3779 points - the CIE tristimulus specification of the intended
3780 color of the red, green and blue channels in the PNG RGB
3781 data. The white point is simply the sum of the three end
3782 points.
3783
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003784 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003785
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003786 srgb_intent - the rendering intent
3787 (PNG_INFO_sRGB) The presence of
3788 the sRGB chunk means that the pixel
3789 data is in the sRGB color space.
3790 This chunk also implies specific
3791 values of gAMA and cHRM. Rendering
3792 intent is the CSS-1 property that
3793 has been defined by the International
3794 Color Consortium
3795 (http://www.color.org).
3796 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06003797 PNG_sRGB_INTENT_SATURATION,
3798 PNG_sRGB_INTENT_PERCEPTUAL,
3799 PNG_sRGB_INTENT_ABSOLUTE, or
3800 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003801
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003802
3803 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
3804 srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003805
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003806 srgb_intent - the rendering intent
3807 (PNG_INFO_sRGB) The presence of the
3808 sRGB chunk means that the pixel
3809 data is in the sRGB color space.
3810 This function also causes gAMA and
3811 cHRM chunks with the specific values
3812 that are consistent with sRGB to be
3813 written.
3814
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003815 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003816 profile, proflen);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003817
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003818 name - The profile name.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003819
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003820 compression_type - The compression type; always
3821 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
3822 You may give NULL to this argument to
3823 ignore it.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003824
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003825 profile - International Color Consortium color
3826 profile data. May contain NULs.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003827
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003828 proflen - length of profile data in bytes.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003829
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003830 png_set_sBIT(png_ptr, info_ptr, sig_bit);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003831
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003832 sig_bit - the number of significant bits for
3833 (PNG_INFO_sBIT) each of the gray, red,
3834 green, and blue channels, whichever are
3835 appropriate for the given color type
3836 (png_color_16)
3837
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05003838 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3839 num_trans, trans_color);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003840
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05003841 trans_alpha - array of alpha (transparency)
3842 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003843
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003844 num_trans - number of transparent entries
3845 (PNG_INFO_tRNS)
3846
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003847 trans_color - graylevel or color sample values
3848 (in order red, green, blue) of the
3849 single transparent color for
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003850 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003851
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003852 png_set_hIST(png_ptr, info_ptr, hist);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003853
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003854 hist - histogram of palette (array of
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003855 png_uint_16) (PNG_INFO_hIST)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003856
3857 png_set_tIME(png_ptr, info_ptr, mod_time);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003858
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003859 mod_time - time image was last modified
3860 (PNG_VALID_tIME)
3861
3862 png_set_bKGD(png_ptr, info_ptr, background);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003863
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05003864 background - background color (of type
3865 png_color_16p) (PNG_VALID_bKGD)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003866
3867 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003868
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003869 text_ptr - array of png_text holding image
3870 comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003871
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003872 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003873 on "text" PNG_TEXT_COMPRESSION_NONE
3874 PNG_TEXT_COMPRESSION_zTXt
3875 PNG_ITXT_COMPRESSION_NONE
3876 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003877 text_ptr[i].key - keyword for comment. Must contain
3878 1-79 characters.
3879 text_ptr[i].text - text comments for current
3880 keyword. Can be NULL or empty.
3881 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003882 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003883 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003884 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003885 text_ptr[i].lang - language of comment (NULL or
3886 empty for unknown).
3887 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
3888 or empty for unknown).
Glenn Randers-Pehrson680da022011-11-21 17:05:41 -06003889
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05003890 Note that the itxt_length, lang, and lang_key
Glenn Randers-Pehrson680da022011-11-21 17:05:41 -06003891 members of the text_ptr structure only exist when the
3892 library is built with iTXt chunk support. Prior to
3893 libpng-1.4.0 the library was built by default without
3894 iTXt support. Also note that when iTXt is supported,
3895 they contain NULL pointers when the "compression"
3896 field contains PNG_TEXT_COMPRESSION_NONE or
3897 PNG_TEXT_COMPRESSION_zTXt.
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05003898
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003899 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003900
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003901 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3902 num_spalettes);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003903
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003904 palette_ptr - array of png_sPLT_struct structures
3905 to be added to the list of palettes
3906 in the info structure.
3907 num_spalettes - number of palette structures to be
3908 added.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003909
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003910 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
3911 unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003912
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003913 offset_x - positive offset from the left
3914 edge of the screen
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003915
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003916 offset_y - positive offset from the top
3917 edge of the screen
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003918
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003919 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
3920
3921 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
3922 unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003923
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003924 res_x - pixels/unit physical resolution
3925 in x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003926
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003927 res_y - pixels/unit physical resolution
3928 in y direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003929
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003930 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003931 PNG_RESOLUTION_METER
3932
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003933 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003934
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003935 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003936
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003937 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003938
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003939 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003940 (width and height are doubles)
3941
3942 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003943
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003944 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003945
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003946 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003947 expressed as a string
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003948
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003949 height - height of a pixel in physical scale units
3950 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003951
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003952 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
3953 num_unknowns)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003954
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003955 unknowns - array of png_unknown_chunk
3956 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003957 unknowns[i].name - name of unknown chunk
3958 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003959 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003960 unknowns[i].location - position to write chunk in file
3961 0: do not write chunk
3962 PNG_HAVE_IHDR: before PLTE
3963 PNG_HAVE_PLTE: before IDAT
3964 PNG_AFTER_IDAT: after IDAT
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003965
3966The "location" member is set automatically according to
3967what part of the output file has already been written.
3968You can change its value after calling png_set_unknown_chunks()
3969as demonstrated in pngtest.c. Within each of the "locations",
3970the chunks are sequenced according to their position in the
3971structure (that is, the value of "i", which is the order in which
3972the chunk was either read from the input file or defined with
3973png_set_unknown_chunks).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003974
3975A quick word about text and num_text. text is an array of png_text
3976structures. num_text is the number of valid structures in the array.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003977Each png_text structure holds a language code, a keyword, a text value,
3978and a compression type.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003979
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003980The compression types have the same valid numbers as the compression
3981types of the image data. Currently, the only valid number is zero.
3982However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003983images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003984text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003985Because tEXt and zTXt chunks don't have a language field, if you
3986specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3987any language code or translated keyword will not be written out.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003988
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003989Until text gets around a few hundred bytes, it is not worth compressing it.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003990After the text has been written out to the file, the compression type
3991is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3992so that it isn't written out again at the end (in case you are calling
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003993png_write_end() with the same struct).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003994
3995The keywords that are given in the PNG Specification are:
3996
3997 Title Short (one line) title or
3998 caption for image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003999
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004000 Author Name of image's creator
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004001
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004002 Description Description of image (possibly long)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004003
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004004 Copyright Copyright notice
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004005
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004006 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004007 (usually RFC 1123 format, see below)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004008
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004009 Software Software used to create the image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004010
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004011 Disclaimer Legal disclaimer
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004012
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004013 Warning Warning of nature of content
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004014
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004015 Source Device used to create the image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004016
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004017 Comment Miscellaneous comment; conversion
4018 from other image format
4019
4020The keyword-text pairs work like this. Keywords should be short
4021simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004022keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004023on keywords. You can repeat keywords in a file. You can even write
4024some text before the image and some after. For example, you may want
4025to put a description of the image before the image, but leave the
4026disclaimer until after, so viewers working over modem connections
4027don't have to wait for the disclaimer to go over the modem before
4028they start seeing the image. Finally, keywords should be full
4029words, not abbreviations. Keywords and text are in the ISO 8859-1
4030(Latin-1) character set (a superset of regular ASCII) and can not
4031contain NUL characters, and should not contain control or other
4032unprintable characters. To make the comments widely readable, stick
4033with basic ASCII, and avoid machine specific character set extensions
4034like the IBM-PC character set. The keyword must be present, but
4035you can leave off the text string on non-compressed pairs.
4036Compressed pairs must have a text string, as only the text string
4037is compressed anyway, so the compression would be meaningless.
4038
4039PNG supports modification time via the png_time structure. Two
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004040conversion routines are provided, png_convert_from_time_t() for
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004041time_t and png_convert_from_struct_tm() for struct tm. The
4042time_t routine uses gmtime(). You don't have to use either of
4043these, but if you wish to fill in the png_time structure directly,
4044you should provide the time in universal time (GMT) if possible
4045instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004046year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004047that months start with 1.
4048
4049If you want to store the time of the original image creation, you should
4050use a plain tEXt chunk with the "Creation Time" keyword. This is
4051necessary because the "creation time" of a PNG image is somewhat vague,
4052depending on whether you mean the PNG file, the time the image was
4053created in a non-PNG format, a still photo from which the image was
4054scanned, or possibly the subject matter itself. In order to facilitate
4055machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004056tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004057although this isn't a requirement. Unlike the tIME chunk, the
4058"Creation Time" tEXt chunk is not expected to be automatically changed
4059by the software. To facilitate the use of RFC 1123 dates, a function
4060png_convert_to_rfc1123(png_timep) is provided to convert from PNG
4061time to an RFC 1123 format string.
4062
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004063.SS Writing unknown chunks
4064
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004065You can use the png_set_unknown_chunks function to queue up chunks
4066for writing. You give it a chunk name, raw data, and a size; that's
4067all there is to it. The chunks will be written by the next following
4068png_write_info_before_PLTE, png_write_info, or png_write_end function.
4069Any chunks previously read into the info structure's unknown-chunk
4070list will also be written out in a sequence that satisfies the PNG
4071specification's ordering rules.
4072
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004073.SS The high-level write interface
4074
4075At this point there are two ways to proceed; through the high-level
4076write interface, or through a sequence of low-level write operations.
4077You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004078in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004079transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004080
4081 PNG_TRANSFORM_IDENTITY No transformation
4082 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004083 PNG_TRANSFORM_PACKSWAP Change order of packed
4084 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004085 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004086 PNG_TRANSFORM_SHIFT Normalize pixels to the
4087 sBIT depth
4088 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
4089 to BGRA
4090 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
4091 to AG
4092 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
4093 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004094 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson1eb14e92008-12-10 07:14:45 -06004095 PNG_TRANSFORM_STRIP_FILLER Strip out filler
4096 bytes (deprecated).
4097 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
4098 filler bytes
4099 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
4100 filler bytes
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004101
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004102If you have valid image data in the info structure (you can use
4103png_set_rows() to put image data in the info structure), simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004104
4105 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
4106
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004107where png_transforms is an integer containing the bitwise OR of some set of
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004108transformation flags. This call is equivalent to png_write_info(),
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004109followed the set of transformations indicated by the transform mask,
4110then png_write_image(), and finally png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004111
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004112(The final parameter of this call is not yet used. Someday it might point
4113to transformation parameters required by some future output transform.)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004114
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05004115You must use png_transforms and not call any png_set_transform() functions
4116when you use png_write_png().
4117
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004118.SS The low-level write interface
4119
4120If you are going the low-level route instead, you are now ready to
4121write all the file information up to the actual image data. You do
4122this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004123
4124 png_write_info(png_ptr, info_ptr);
4125
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004126Note that there is one transformation you may need to do before
4127png_write_info(). In PNG files, the alpha channel in an image is the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004128level of opacity. If your data is supplied as a level of transparency,
4129you can invert the alpha channel before you write it, so that 0 is
4130fully transparent and 255 (in 8-bit or paletted images) or 65535
4131(in 16-bit images) is fully opaque, with
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004132
4133 png_set_invert_alpha(png_ptr);
4134
4135This must appear before png_write_info() instead of later with the
4136other transformations because in the case of paletted images the tRNS
4137chunk data has to be inverted before the tRNS chunk is written. If
4138your image is not a paletted image, the tRNS data (which in such cases
4139represents a single color to be rendered as transparent) won't need to
4140be changed, and you can safely do this transformation after your
4141png_write_info() call.
4142
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06004143If you need to write a private chunk that you want to appear before
4144the PLTE chunk when PLTE is present, you can write the PNG info in
4145two steps, and insert code to write your own chunk between them:
4146
4147 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004148 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06004149 png_write_info(png_ptr, info_ptr);
4150
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004151After you've written the file information, you can set up the library
4152to handle any special transformations of the image data. The various
4153ways to transform the data will be described in the order that they
4154should occur. This is important, as some of these change the color
4155type and/or bit depth of the data, and some others only work on
4156certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004157checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004158make sure to only enable a transformation if it will be valid for the
4159data. For example, don't swap red and blue on grayscale data.
4160
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004161PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06004162the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004163to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
4164bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004165
4166 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
4167
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004168where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004169PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
4170is stored XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004171
4172PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
4173they can, resulting in, for example, 8 pixels per byte for 1 bit files.
4174If the data is supplied at 1 pixel per byte, use this code, which will
4175correctly pack the pixels into a single byte:
4176
4177 png_set_packing(png_ptr);
4178
4179PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
4180data is of another bit depth, you can write an sBIT chunk into the
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004181file so that decoders can recover the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004182
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004183 /* Set the true bit depth of the image data */
4184 if (color_type & PNG_COLOR_MASK_COLOR)
4185 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004186 sig_bit.red = true_bit_depth;
4187 sig_bit.green = true_bit_depth;
4188 sig_bit.blue = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004189 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004190
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004191 else
4192 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004193 sig_bit.gray = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004194 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004195
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004196 if (color_type & PNG_COLOR_MASK_ALPHA)
4197 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004198 sig_bit.alpha = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004199 }
4200
4201 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
4202
4203If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004204one 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 -06004205this will scale the values to appear to be the correct bit depth as
4206is required by PNG.
4207
4208 png_set_shift(png_ptr, &sig_bit);
4209
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05004210PNG files store 16-bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004211ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004212supplied the other way (little-endian, i.e. least significant bits
4213first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004214
4215 if (bit_depth > 8)
4216 png_set_swap(png_ptr);
4217
4218If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
4219need to change the order the pixels are packed into bytes, you can use:
4220
4221 if (bit_depth < 8)
4222 png_set_packswap(png_ptr);
4223
4224PNG files store 3 color pixels in red, green, blue order. This code
4225would be used if they are supplied as blue, green, red:
4226
4227 png_set_bgr(png_ptr);
4228
4229PNG files describe monochrome as black being zero and white being
4230one. This code would be used if the pixels are supplied with this reversed
4231(black being one and white being zero):
4232
4233 png_set_invert_mono(png_ptr);
4234
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004235Finally, you can write your own transformation function if none of
4236the existing ones meets your needs. This is done by setting a callback
4237with
4238
4239 png_set_write_user_transform_fn(png_ptr,
4240 write_transform_fn);
4241
4242You must supply the function
4243
Glenn Randers-Pehrson93215672011-02-13 19:42:19 -06004244 void write_transform_fn(png_structp png_ptr, png_row_infop
4245 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004246
4247See pngtest.c for a working example. Your function will be called
John Bowlerf19abd62011-01-22 18:29:24 -06004248before any of the other transformations are processed. If supported
4249libpng also supplies an information routine that may be called from
4250your callback:
4251
4252 png_get_current_row_number(png_ptr);
John Bowlercd113452011-02-16 06:15:13 -06004253 png_get_current_pass_number(png_ptr);
John Bowlerf19abd62011-01-22 18:29:24 -06004254
John Bowlercd113452011-02-16 06:15:13 -06004255This returns the current row passed to the transform. With interlaced
4256images the value returned is the row in the input sub-image image. Use
4257PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
4258find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
4259
4260The discussion of interlace handling above contains more information on how to
4261use these values.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004262
4263You can also set up a pointer to a user structure for use by your
4264callback function.
4265
4266 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
4267
4268The user_channels and user_depth parameters of this function are ignored
4269when writing; you can set them to zero as shown.
4270
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004271You can retrieve the pointer via the function png_get_user_transform_ptr().
4272For example:
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004273
4274 voidp write_user_transform_ptr =
4275 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004276
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004277It is possible to have libpng flush any pending output, either manually,
4278or automatically after a certain number of lines have been written. To
4279flush the output stream a single time call:
4280
4281 png_write_flush(png_ptr);
4282
4283and to have libpng flush the output stream periodically after a certain
4284number of scanlines have been written, call:
4285
4286 png_set_flush(png_ptr, nrows);
4287
4288Note that the distance between rows is from the last time png_write_flush()
4289was called, or the first row of the image if it has never been called.
4290So if you write 50 lines, and then png_set_flush 25, it will flush the
4291output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004292png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004293If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004294RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004295may be acceptable for real-time applications). Infrequent flushing will
4296only degrade the compression performance by a few percent over images
4297that do not use flushing.
4298
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004299.SS Writing the image data
4300
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004301That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004302The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004303whole image in memory, you can just call png_write_image() and libpng
4304will write the image. You will need to pass in an array of pointers to
4305each row. This function automatically handles interlacing, so you don't
4306need to call png_set_interlace_handling() or call this function multiple
4307times, or any of that other stuff necessary with png_write_rows().
4308
4309 png_write_image(png_ptr, row_pointers);
4310
4311where row_pointers is:
4312
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004313 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004314
4315You can point to void or char or whatever you use for pixels.
4316
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004317If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004318use png_write_rows() instead. If the file is not interlaced,
4319this is simple:
4320
4321 png_write_rows(png_ptr, row_pointers,
4322 number_of_rows);
4323
4324row_pointers is the same as in the png_write_image() call.
4325
4326If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004327a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004328
4329 png_bytep row_pointer = row;
4330
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004331 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004332
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004333When the file is interlaced, things can get a good deal more complicated.
4334The only currently (as of the PNG Specification version 1.2, dated July
43351999) defined interlacing scheme for PNG files is the "Adam7" interlace
4336scheme, that breaks down an image into seven smaller images of varying
4337size. libpng will build these images for you, or you can do them
4338yourself. If you want to build them yourself, see the PNG specification
4339for details of which pixels to write when.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004340
4341If you don't want libpng to handle the interlacing details, just
4342use png_set_interlace_handling() and call png_write_rows() the
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004343correct number of times to write all the sub-images
4344(png_set_interlace_handling() returns the number of sub-images.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004345
4346If you want libpng to build the sub-images, call this before you start
4347writing any rows:
4348
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004349 number_of_passes = png_set_interlace_handling(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004350
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004351This will return the number of passes needed. Currently, this is seven,
4352but may change if another interlace type is added.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004353
4354Then write the complete image number_of_passes times.
4355
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004356 png_write_rows(png_ptr, row_pointers, number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004357
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004358Think carefully before you write an interlaced image. Typically code that
4359reads such images reads all the image data into memory, uncompressed, before
4360doing any processing. Only code that can display an image on the fly can
4361take advantage of the interlacing and even then the image has to be exactly
4362the correct size for the output device, because scaling an image requires
4363adjacent pixels and these are not available until all the passes have been
4364read.
4365
4366If you do write an interlaced image you will hardly ever need to handle
4367the interlacing yourself. Call png_set_interlace_handling() and use the
4368approach described above.
4369
4370The only time it is conceivable that you will really need to write an
4371interlaced image pass-by-pass is when you have read one pass by pass and
4372made some pixel-by-pixel transformation to it, as described in the read
4373code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
4374to determine the size of each sub-image in turn and simply write the rows
4375you obtained from the read code.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004376
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004377.SS Finishing a sequential write
4378
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004379After you are finished writing the image, you should finish writing
4380the file. If you are interested in writing comments or time, you should
4381pass an appropriately filled png_info pointer. If you are not interested,
4382you can pass NULL.
4383
4384 png_write_end(png_ptr, info_ptr);
4385
4386When you are done, you can free all memory used by libpng like this:
4387
4388 png_destroy_write_struct(&png_ptr, &info_ptr);
4389
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004390It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05004391point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004392
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004393 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004394
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004395 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004396 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004397 more of
4398 PNG_FREE_PLTE, PNG_FREE_TRNS,
4399 PNG_FREE_HIST, PNG_FREE_ICCP,
4400 PNG_FREE_PCAL, PNG_FREE_ROWS,
4401 PNG_FREE_SCAL, PNG_FREE_SPLT,
4402 PNG_FREE_TEXT, PNG_FREE_UNKN,
4403 or simply PNG_FREE_ALL
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004404
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004405 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004406 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004407
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05004408This function may be safely called when the relevant storage has
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004409already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004410by the user and not by libpng, and will in those cases do nothing.
4411The "seq" parameter is ignored if only one item of the selected data
4412type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
4413are allowed for the data type identified in the mask, such as text or
4414sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004415
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004416If you allocated data such as a palette that you passed in to libpng
4417with png_set_*, you must not free it until just before the call to
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004418png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004419
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004420The default behavior is only to free data that was allocated internally
4421by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004422or so that it will free data that was allocated by the user with png_malloc()
4423or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004424
4425 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004426
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004427 freer - one of
4428 PNG_DESTROY_WILL_FREE_DATA
4429 PNG_SET_WILL_FREE_DATA
4430 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004431
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004432 mask - which data elements are affected
4433 same choices as in png_free_data()
4434
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004435For example, to transfer responsibility for some data from a read structure
4436to a write structure, you could use
4437
4438 png_data_freer(read_ptr, read_info_ptr,
4439 PNG_USER_WILL_FREE_DATA,
4440 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004441
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004442 png_data_freer(write_ptr, write_info_ptr,
4443 PNG_DESTROY_WILL_FREE_DATA,
4444 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4445
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004446thereby briefly reassigning responsibility for freeing to the user but
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004447immediately afterwards reassigning it once more to the write_destroy
4448function. Having done this, it would then be safe to destroy the read
4449structure and continue to use the PLTE, tRNS, and hIST data in the write
4450structure.
4451
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004452This function only affects data that has already been allocated.
4453You can call this function before calling after the png_set_*() functions
4454to control whether the user or png_destroy_*() is supposed to free the data.
4455When the user assumes responsibility for libpng-allocated data, the
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004456application must use
4457png_free() to free it, and when the user transfers responsibility to libpng
4458for data that the user has allocated, the user must have used png_malloc()
4459or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004460
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004461If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
4462separately, do not transfer responsibility for freeing text_ptr to libpng,
4463because when libpng fills a png_text structure it combines these members with
4464the key member, and png_free_data() will free only text_ptr.key. Similarly,
4465if you transfer responsibility for free'ing text_ptr from libpng to your
4466application, your application must not separately free those members.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004467For a more compact example of writing a PNG image, see the file example.c.
4468
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004469.SH V. Simplified API
4470
4471The simplified API, which became available in libpng-1.6.0, hides the details
4472of both libpng and the PNG file format itself.
4473It allows PNG files to be read into a very limited number of
4474in-memory bitmap formats or to be written from the same formats. If these
4475formats do not accomodate your needs then you can, and should, use the more
4476sophisticated APIs above - these support a wide variety of in-memory formats
4477and a wide variety of sophisticated transformations to those formats as well
4478as a wide variety of APIs to manipulate ancilliary information.
4479
4480To read a PNG file using the simplified API:
4481
4482 1) Declare a 'png_image' structure (see below) on the
4483 stack and memset() it to all zero.
4484
4485 2) Call the appropriate png_image_begin_read... function.
4486
4487 3) Set the png_image 'format' member to the required
4488 format and allocate a buffer for the image.
4489
4490 4) Call png_image_finish_read to read the image into
4491 your buffer.
4492
4493There are no restrictions on the format of the PNG input itself; all valid
4494color types, bit depths, and interlace methods are acceptable, and the
4495input image is transformed as necessary to the requested in-memory format
4496during the png_image_finish_read() step.
4497
4498To write a PNG file using the simplified API:
4499
4500 1) Declare a 'png_image' structure on the stack and memset()
4501 it to all zero.
4502
4503 2) Initialize the members of the structure that describe the
4504 image, setting the 'format' member to the format of the
4505 image in memory.
4506
4507 3) Call the appropriate png_image_write... function with a
4508 pointer to the image to write the PNG data.
4509
4510png_image is a structure that describes the in-memory format of an image
4511when it is being read or define the in-memory format of an image that you
4512need to write. The "png_image" structure contains the following members:
4513
4514 png_uint_32 width Image width in pixels (columns)
4515 png_uint_32 height Image height in pixels (rows)
4516 png_uint_32 format Image format as defined below
4517 png_uint_32 flags A bit mask containing informational flags
4518 png_controlp opaque Initialize to NULL, free with png_image_free
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004519 png_const_bytep colormap A pointer to the application color-map
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004520 png_uint_32 warning_or_error;
4521 char message[64];
4522
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004523In the event of an error or warning the following field wrning_or_error
4524field will be set to a non-zero value and the 'message' field will contain
4525a '\0' terminated string with the libpng error or warning message. If both
4526warnings and an error were encountered, only the error is recorded. If there
4527are multiple warnings, only the first one is recorded.
4528
4529The upper 30 bits of this value are reserved; the low two bits contain
4530a two bit code such that a value more than 1 indicates a failure in the API
4531just called:
4532
4533 0 - no warning or error
4534 1 - warning
4535 2 - error
4536 3 - error preceded by warning
4537
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004538The pixels (samples) of the image have one to four channels whose components
4539have original values in the range 0 to 1.0:
4540
4541 1: A single gray or luminance channel (G).
4542 2: A gray/luminance channel and an alpha channel (GA).
4543 3: Three red, green, blue color channels (RGB).
4544 4: Three color channels and an alpha channel (RGBA).
4545
4546The channels are encoded in one of two ways:
4547
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004548 a) As a small integer, value 0..255, contained in a single byte. For the
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004549alpha channel the original value is simply value/255. For the color or
4550luminance channels the value is encoded according to the sRGB specification
4551and matches the 8-bit format expected by typical display devices.
4552
4553The color/gray channels are not scaled (pre-multiplied) by the alpha
4554channel and are suitable for passing to color management software.
4555
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004556 b) As a value in the range 0..65535, contained in a 2-byte integer. All
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004557channels can be converted to the original value by dividing by 65535; all
4558channels are linear. Color channels use the RGB encoding (RGB end-points) of
4559the sRGB specification. This encoding is identified by the
4560PNG_FORMAT_FLAG_LINEAR flag below.
4561
4562When an alpha channel is present it is expected to denote pixel coverage
4563of the color or luminance channels and is returned as an associated alpha
4564channel: the color/gray channels are scaled (pre-multiplied) by the alpha
4565value.
4566
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004567When a color-mapped image is used as a result of calling
4568png_image_read_colormap or png_image_write_colormap the channels are encoded
4569in the color-map and the descriptions above apply to the color-map entries.
4570The image data is encoded as small integers, value 0..255, that index the
4571entries in the color-map. One integer (one byte) is stored for each pixel.
4572
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004573PNG_FORMAT_*
4574
4575The #defines to be used in png_image::format. Each #define identifies a
4576particular layout of channel data and, if present, alpha values. There are
4577separate defines for each of the two channel encodings.
4578
4579A format is built up using single bit flag values. Not all combinations are
4580valid: use the bit flag values below for testing a format returned by the
4581read APIs, but set formats from the derived values.
4582
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004583When reading or writing color-mapped images the format should be set to the
4584format of the entries in the color-map then png_image_{read,write}_colormap
4585called to read or write the color-map and set the format correctly for the
4586image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!
4587
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004588NOTE: libpng can be built with particular features disabled, if you see
4589compiler errors because the definition of one of the following flags has been
4590compiled out it is because libpng does not have the required support. It is
4591possible, however, for the libpng configuration to enable the format on just
4592read or just write; in that case you may see an error at run time. You can
4593guard against this by checking for the definition of:
4594
4595 PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED
4596
4597 PNG_FORMAT_FLAG_ALPHA 0x01 format with an alpha channel
4598 PNG_FORMAT_FLAG_COLOR 0x02 color format: otherwise grayscale
4599 PNG_FORMAT_FLAG_LINEAR 0x04 png_uint_16 channels else png_byte
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004600 PNG_FORMAT_FLAG_COLORMAP 0x08 libpng use only
4601 PNG_FORMAT_FLAG_BGR 0x10 BGR colors, else order is RGB
4602 PNG_FORMAT_FLAG_AFIRST 0x20 alpha channel comes first
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004603
4604Supported formats are as follows. Future versions of libpng may support more
4605formats; for compatibility with older versions simply check if the format
4606macro is defined using #ifdef. These defines describe the in-memory layout
4607of the components of the pixels of the image.
4608
4609First the single byte formats:
4610
4611 PNG_FORMAT_GRAY 0
4612 PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA
4613 PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)
4614 PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR
4615 PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)
4616 PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)
4617 PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)
4618 PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)
4619 PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)
4620
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004621Then the linear 2-byte formats. When naming these "Y" is used to
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004622indicate a luminance (gray) channel. The component order within the pixel
4623is always the same - there is no provision for swapping the order of the
4624components in the linear format.
4625
4626 PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR
4627 PNG_FORMAT_LINEAR_Y_ALPHA
4628 (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)
4629 PNG_FORMAT_LINEAR_RGB
4630 (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)
4631 PNG_FORMAT_LINEAR_RGB_ALPHA
4632 (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|
4633 PNG_FORMAT_FLAG_ALPHA)
4634
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004635Color-mapped formats are obtained by calling png_image_{read,write}_colormap,
4636as appropriate after setting png_image::format to the format of the color-map
4637to be read or written. Applications may check the value of
4638PNG_FORMAT_FLAG_COLORMAP to see if they have called the colormap API. The
4639format of the color-map may be extracted using the following macro.
4640
4641 PNG_FORMAT_OF_COLORMAP(fmt) ((fmt) & ~PNG_FORMAT_FLAG_COLORMAP)
4642
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004643PNG_IMAGE macros
4644
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004645These are convenience macros to derive information from a png_image
4646structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the
4647actual image sample values - either the entries in the color-map or the
4648pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values
4649for the pixels and will always return 1 after a call to
4650png_image_{read,write}_colormap. The remaining macros return information
4651about the rows in the image and the complete image.
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004652
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004653NOTE: All the macros that take a png_image::format parameter are compile time
4654constants if the format parameter is, itself, a constant. Therefore these
4655macros can be used in array declarations and case labels where required.
4656Similarly the macros are also pre-processor constants (sizeof is not used) so
4657they can be used in #if tests.
4658
4659First the information about the samples.
4660
4661 PNG_IMAGE_SAMPLE_CHANNELS(fmt)
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004662 Returns the total number of channels in a given format: 1..4
4663
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004664 PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)
4665 Returns the size in bytes of a single component of a pixel or color-map
4666 entry (as appropriate) in the image.
4667
Glenn Randers-Pehrson612d52a2012-02-03 21:14:33 -06004668 PNG_IMAGE_SAMPLE_SIZE(fmt)
4669 This is the size of the sample data for one sample. If the image is
4670 color-mapped it is the size of one color-map entry (and image pixels are
4671 one byte in size), otherwise it is the size of one image pixel.
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004672
Glenn Randers-Pehrson612d52a2012-02-03 21:14:33 -06004673 PNG_IMAGE_COLORMAP_SIZE(fmt)
4674 The size of the color-map required by the format; this is the size of the
4675 color-map buffer passed to the png_image_{read,write}_colormap APIs, it is
4676 a fixed number determined by the format so can easily be allocated on the
4677 stack if necessary.
4678
4679Corresponding information about the pixels
4680
4681 PNG_IMAGE_PIXEL_(test,fmt)
4682
4683 PNG_IMAGE_PIXEL_CHANNELS(fmt)
4684 The number of separate channels (components) in a pixel; 1 for a
4685 color-mapped image.
4686
4687 PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\
4688 The size, in bytes, of each component in a pixel; 1 for a color-mapped
4689 image.
Glenn Randers-Pehrsone7b4d262012-01-24 07:33:26 -06004690
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004691 PNG_IMAGE_PIXEL_SIZE(fmt)
Glenn Randers-Pehrson612d52a2012-02-03 21:14:33 -06004692 The size, in bytes, of a complete pixel; 1 for a color-mapped image.
4693
4694Information about the whole row, or whole image
4695
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004696 PNG_IMAGE_ROW_STRIDE(image)
Glenn Randers-Pehrson612d52a2012-02-03 21:14:33 -06004697 Returns the total number of components in a single row of the image; this
4698 is the minimum 'row stride', the minimum count of components between each
4699 row. For a color-mapped image this is the minimum number of bytes in a
4700 row.
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004701
4702 PNG_IMAGE_BUFFER_SIZE(image, row_stride)
Glenn Randers-Pehrson612d52a2012-02-03 21:14:33 -06004703 Returns the size, in bytes, of an image buffer given a png_image and a row
4704 stride - the number of components to leave space for in each row.
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004705
Glenn Randers-Pehrson612d52a2012-02-03 21:14:33 -06004706 PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB == 0x01
4707 This indicates the the RGB values of the in-memory bitmap do not
4708 correspond to the red, green and blue end-points defined by sRGB.
4709
4710 PNG_IMAGE_FLAG_COLORMAP == 0x02
4711 The PNG is color-mapped. If this flag is set png_image_read_colormap
4712 can be used without further loss of image information. If it is not set
4713 png_image_read_colormap will cause significant loss if the image has any
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004714
4715READ APIs
4716
4717 The png_image passed to the read APIs must have been initialized by setting
4718 the png_controlp field 'opaque' to NULL (or, better, memset the whole thing.)
4719
4720 int png_image_begin_read_from_file( png_imagep image,
4721 const char *file_name)
4722
4723 The named file is opened for read and the image header
4724 is filled in from the PNG header in the file.
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004725
4726 int png_image_begin_read_from_stdio (png_imagep image,
4727 FILE* file)
4728
4729 The PNG header is read from the stdio FILE object.
4730
4731 int png_image_begin_read_from_memory(png_imagep image,
4732 png_const_voidp memory, png_size_t size)
4733
4734 The PNG header is read from the given memory buffer.
4735
4736 int png_image_finish_read(png_imagep image,
4737 png_colorp background, void *buffer, png_int_32 row_stride));
4738
4739 Finish reading the image into the supplied buffer and
4740 clean up the png_image structure.
4741
4742 row_stride is the step, in png_byte or png_uint_16 units
4743 as appropriate, between adjacent rows. A positive stride
4744 indicates that the top-most row is first in the buffer -
4745 the normal top-down arrangement. A negative stride
4746 indicates that the bottom-most row is first in the buffer.
4747
4748 background need only be supplied if an alpha channel must
4749 be removed from a png_byte format and the removal is to be
4750 done by compositing on a solid color; otherwise it may be
4751 NULL and any composition will be done directly onto the
4752 buffer. The value is an sRGB color to use for the
4753 background, for grayscale output the green channel is used.
4754
4755 For linear output removing the alpha channel is always done
4756 by compositing on black.
4757
4758 void png_image_free(png_imagep image)
4759
4760 Free any data allocated by libpng in image->opaque,
4761 setting the pointer to NULL. May be called at any time
4762 after the structure is initialized.
4763
Glenn Randers-Pehrson5578c372012-02-04 10:31:38 -06004764When the simplified API needs to convert between sRGB and linear colorspaces,
4765the actual sRGB transfer curve defined in the sRGB specification (see the
4766article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
4767approximation used elsewhere in libpng.
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06004768
4769WRITE APIS
4770
4771For write you must initialize a png_image structure to describe the image to
4772be written:
4773
4774 opaque: must be initialized to NULL
4775 width: image width in pixels
4776 height: image height in rows
4777 format: the format of the data you wish to write
4778 flags: set to 0 unless one of the defined flags applies; set
4779 PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images
4780 where the RGB values do not correspond to the colors in sRGB.
4781
4782 int png_image_write_to_file, (png_imagep image,
4783 const char *file, int convert_to_8bit, const void *buffer,
4784 png_int_32 row_stride));
4785
4786 Write the image to the named file.
4787
4788 int png_image_write_to_stdio(png_imagep image, FILE *file,
4789 int convert_to_8_bit, const void *buffer, png_int_32 row_stride)
4790
4791 Write the image to the given (FILE*).
4792
4793With all write APIs if image is in one of the linear formats with
4794(png_uint_16) data then setting convert_to_8_bit will cause the output to be
4795a (png_byte) PNG gamma encoded according to the sRGB specification, otherwise
4796a 16-bit linear encoded PNG file is written.
4797
4798With all APIs row_stride is handled as in the read APIs - it is the spacing
4799from one row to the next in component sized units (float) and if negative
4800indicates a bottom-up row layout in the buffer.
4801
4802Note that the write API does not support interlacing, sub-8-bit pixels,
4803and indexed (paletted) images.
4804
4805.SH VI. Modifying/Customizing libpng
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004806
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004807There are two issues here. The first is changing how libpng does
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004808standard things like memory allocation, input/output, and error handling.
4809The second deals with more complicated things like adding new chunks,
4810adding new transformations, and generally changing how libpng works.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004811Both of those are compile-time issues; that is, they are generally
4812determined at the time the code is written, and there is rarely a need
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004813to provide the user with a means of changing them.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004814
4815Memory allocation, input/output, and error handling
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004816
4817All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004818goes through callbacks that are user-settable. The default routines are
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004819in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004820these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004821
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004822Memory allocation is done through the functions png_malloc(), png_calloc(),
4823and png_free(). These currently just call the standard C functions.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05004824png_calloc() calls png_malloc() and then clears the newly
4825allocated memory to zero. There is limited support for certain systems
4826with segmented memory architectures and the types of pointers declared by
4827png.h match this; you will have to use appropriate pointers in your
4828application. Since it is
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004829unlikely that the method of handling memory allocation on a platform
4830will change between applications, these functions must be modified in
4831the library at compile time. If you prefer to use a different method
4832of allocating and freeing data, you can use png_create_read_struct_2() or
4833png_create_write_struct_2() to register your own functions as described
4834above. These functions also provide a void pointer that can be retrieved
4835via
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004836
4837 mem_ptr=png_get_mem_ptr(png_ptr);
4838
4839Your replacement memory functions must have prototypes as follows:
4840
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004841 png_voidp malloc_fn(png_structp png_ptr,
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004842 png_alloc_size_t size);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004843
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004844 void free_fn(png_structp png_ptr, png_voidp ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004845
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004846Your malloc_fn() must return NULL in case of failure. The png_malloc()
4847function will normally call png_error() if it receives a NULL from the
4848system memory allocator or from your replacement malloc_fn().
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05004849
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004850Your free_fn() will never be called with a NULL ptr, since libpng's
4851png_free() checks for NULL before calling free_fn().
4852
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004853Input/Output in libpng is done through png_read() and png_write(),
4854which currently just call fread() and fwrite(). The FILE * is stored in
4855png_struct and is initialized via png_init_io(). If you wish to change
4856the method of I/O, the library supplies callbacks that you can set
4857through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004858time, instead of calling the png_init_io() function. These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004859also provide a void pointer that can be retrieved via the function
4860png_get_io_ptr(). For example:
4861
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004862 png_set_read_fn(png_structp read_ptr,
4863 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004864
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004865 png_set_write_fn(png_structp write_ptr,
4866 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004867 png_flush_ptr output_flush_fn);
4868
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004869 voidp read_io_ptr = png_get_io_ptr(read_ptr);
4870 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004871
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004872The replacement I/O functions must have prototypes as follows:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004873
4874 void user_read_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05004875 png_bytep data, png_size_t length);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004876
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004877 void user_write_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05004878 png_bytep data, png_size_t length);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004879
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004880 void user_flush_data(png_structp png_ptr);
4881
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004882The user_read_data() function is responsible for detecting and
4883handling end-of-data errors.
4884
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004885Supplying NULL for the read, write, or flush functions sets them back
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004886to using the default C stream functions, which expect the io_ptr to
4887point to a standard *FILE structure. It is probably a mistake
4888to use NULL for one of write_data_fn and output_flush_fn but not both
4889of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4890It is an error to read from a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004891
4892Error handling in libpng is done through png_error() and png_warning().
4893Errors handled through png_error() are fatal, meaning that png_error()
4894should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004895setjmp() and longjmp() (unless you have compiled libpng with
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05004896PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
Glenn Randers-Pehrson60988072010-04-13 22:11:06 -05004897but you could change this to do things like exit() if you should wish,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05004898as long as your function does not return.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004899
4900On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004901to print a warning message, and then control returns to the calling code.
4902By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004903fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
4904(because you don't want the messages) or PNG_NO_STDIO defined (because
4905fprintf() isn't available). If you wish to change the behavior of the error
4906functions, you will need to set up your own message callbacks. These
4907functions are normally supplied at the time that the png_struct is created.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004908It is also possible to redirect errors and warnings to your own replacement
4909functions after png_create_*_struct() has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004910
4911 png_set_error_fn(png_structp png_ptr,
4912 png_voidp error_ptr, png_error_ptr error_fn,
4913 png_error_ptr warning_fn);
4914
4915 png_voidp error_ptr = png_get_error_ptr(png_ptr);
4916
4917If NULL is supplied for either error_fn or warning_fn, then the libpng
4918default function will be used, calling fprintf() and/or longjmp() if a
4919problem is encountered. The replacement error functions should have
4920parameters as follows:
4921
4922 void user_error_fn(png_structp png_ptr,
4923 png_const_charp error_msg);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004924
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004925 void user_warning_fn(png_structp png_ptr,
4926 png_const_charp warning_msg);
4927
4928The motivation behind using setjmp() and longjmp() is the C++ throw and
4929catch exception handling methods. This makes the code much easier to write,
4930as there is no need to check every return code of every function call.
4931However, there are some uncertainties about the status of local variables
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004932after a longjmp, so the user may want to be careful about doing anything
4933after setjmp returns non-zero besides returning itself. Consult your
4934compiler documentation for more details. For an alternative approach, you
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004935may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4936which is illustrated in pngvalid.c and in contrib/visupng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004937
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004938.SS Custom chunks
4939
4940If you need to read or write custom chunks, you may need to get deeper
4941into the libpng code. The library now has mechanisms for storing
4942and writing chunks of unknown type; you can even declare callbacks
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06004943for custom chunks. However, this may not be good enough if the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004944library code itself needs to know about interactions between your
4945chunk and existing `intrinsic' chunks.
4946
4947If you need to write a new intrinsic chunk, first read the PNG
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004948specification. Acquire a first level of understanding of how it works.
4949Pay particular attention to the sections that describe chunk names,
4950and look at how other chunks were designed, so you can do things
4951similarly. Second, check out the sections of libpng that read and
4952write chunks. Try to find a chunk that is similar to yours and use
4953it as a template. More details can be found in the comments inside
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004954the code. It is best to handle private or unknown chunks in a generic method,
4955via callback functions, instead of by modifying libpng functions. This
4956is illustrated in pngtest.c, which uses a callback function to handle a
4957private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4958libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004959
4960If you wish to write your own transformation for the data, look through
4961the part of the code that does the transformations, and check out some of
4962the simpler ones to get an idea of how they work. Try to find a similar
4963transformation to the one you want to add and copy off of it. More details
4964can be found in the comments inside the code itself.
4965
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05004966.SS Configuring for 16-bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004967
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004968You will want to look into zconf.h to tell zlib (and thus libpng) that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004969it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004970won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004971
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004972.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004973
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004974For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004975have to limit zlib's memory usage via a png_set_compression_mem_level()
4976call. See zlib.h or zconf.h in the zlib library for more information.
4977
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004978.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004979
4980Libpng's support for medium model has been tested on most of the popular
4981compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4982defined, and FAR gets defined to far in pngconf.h, and you should be
4983all set. Everything in the library (except for zlib's structure) is
4984expecting far data. You must use the typedefs with the p or pp on
4985the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004986note that the rows of data are defined as png_bytepp, which is
4987an "unsigned char far * far *".
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004988
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004989.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004990
4991You will need to write new error and warning functions that use the GUI
4992interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004993warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004994in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004995They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004996you may also have to change the memory allocators (png_malloc, etc.).
4997
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004998.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004999
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05005000All includes for libpng are in pngconf.h. If you need to add, change
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05005001or delete an include, this is the place to do it.
5002The includes that are not needed outside libpng are placed in pngpriv.h,
5003which is only used by the routines inside libpng itself.
5004The files in libpng proper only include pngpriv.h and png.h, which
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005005%14%in turn includes pngconf.h.
5006in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
5007As of libpng-1.5.0, pngpriv.h also includes three other private header
5008files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
5009that previously appeared in the public headers.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005010
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06005011.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005012
5013There are special functions to configure the compression. Perhaps the
5014most useful one changes the compression level, which currently uses
5015input compression values in the range 0 - 9. The library normally
5016uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
5017have shown that for a large majority of images, compression values in
5018the range 3-6 compress nearly as well as higher levels, and do so much
5019faster. For online applications it may be desirable to have maximum speed
5020(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
5021specify no compression (Z_NO_COMPRESSION = 0), but this would create
5022files larger than just storing the raw bitmap. You can specify the
5023compression level by calling:
5024
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06005025 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005026 png_set_compression_level(png_ptr, level);
5027
5028Another useful one is to reduce the memory level used by the library.
5029The memory level defaults to 8, but it can be lowered if you are
5030short on memory (running DOS, for example, where you only have 640K).
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005031Note that the memory level does have an effect on compression; among
5032other things, lower levels will result in sections of incompressible
5033data being emitted in smaller stored blocks, with a correspondingly
5034larger relative overhead of up to 15% in the worst case.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005035
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06005036 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005037 png_set_compression_mem_level(png_ptr, level);
5038
5039The other functions are for configuring zlib. They are not recommended
5040for normal use and may result in writing an invalid PNG file. See
5041zlib.h for more information on what these mean.
5042
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06005043 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005044 png_set_compression_strategy(png_ptr,
5045 strategy);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005046
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005047 png_set_compression_window_bits(png_ptr,
5048 window_bits);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005049
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005050 png_set_compression_method(png_ptr, method);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005051
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05005052 png_set_compression_buffer_size(png_ptr, size);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005053
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005054As of libpng version 1.5.4, additional APIs became
5055available to set these separately for non-IDAT
5056compressed chunks such as zTXt, iTXt, and iCCP:
5057
5058 #include zlib.h
5059 #if PNG_LIBPNG_VER <= 10504
5060 png_set_text_compression_level(png_ptr, level);
5061
5062 png_set_text_compression_mem_level(png_ptr, level);
5063
5064 png_set_text_compression_strategy(png_ptr,
5065 strategy);
5066
5067 png_set_text_compression_window_bits(png_ptr,
5068 window_bits);
5069
5070 png_set_text_compression_method(png_ptr, method);
5071 #endif
5072
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06005073.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005074
5075If you want to control whether libpng uses filtering or not, which
5076filters are used, and how it goes about picking row filters, you
5077can call one of these functions. The selection and configuration
5078of row filters can have a significant impact on the size and
5079encoding speed and a somewhat lesser impact on the decoding speed
5080of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06005081images (with and without alpha), but not for paletted images nor
5082for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005083
5084The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005085currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005086parameter sets which filter(s), if any, should be used for each
5087scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
5088to turn filtering on and off, respectively.
5089
5090Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
5091PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05005092ORed together with '|' to specify one or more filters to use.
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005093These filters are described in more detail in the PNG specification.
5094If you intend to change the filter type during the course of writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005095the image, you should start with flags set for all of the filters
5096you intend to use so that libpng can initialize its internal
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005097structures appropriately for all of the filter types. (Note that this
5098means the first row must always be adaptively filtered, because libpng
5099currently does not allocate the filter buffers until png_write_row()
5100is called for the first time.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005101
5102 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005103 PNG_FILTER_UP | PNG_FILTER_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05005104 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05005105
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005106 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
5107 filters);
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005108 The second parameter can also be
5109 PNG_INTRAPIXEL_DIFFERENCING if you are
5110 writing a PNG to be embedded in a MNG
5111 datastream. This parameter must be the
5112 same as the value of filter_method used
5113 in png_set_IHDR().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005114
5115It is also possible to influence how libpng chooses from among the
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005116available filters. This is done in one or both of two ways - by
5117telling it how important it is to keep the same filter for successive
5118rows, and by telling it the relative computational costs of the filters.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005119
5120 double weights[3] = {1.5, 1.3, 1.1},
5121 costs[PNG_FILTER_VALUE_LAST] =
5122 {1.0, 1.3, 1.3, 1.5, 1.7};
5123
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005124 png_set_filter_heuristics(png_ptr,
5125 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005126 weights, costs);
5127
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06005128The weights are multiplying factors that indicate to libpng that the
5129row filter should be the same for successive rows unless another row filter
5130is that many times better than the previous filter. In the above example,
5131if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005132"sum of absolute differences" 1.5 x 1.3 times higher than other filters
5133and still be chosen, while the NONE filter could have a sum 1.1 times
5134higher than other filters and still be chosen. Unspecified weights are
5135taken to be 1.0, and the specified weights should probably be declining
5136like those above in order to emphasize recent filters over older filters.
5137
5138The filter costs specify for each filter type a relative decoding cost
5139to be considered when selecting row filters. This means that filters
5140with higher costs are less likely to be chosen over filters with lower
5141costs, unless their "sum of absolute differences" is that much smaller.
5142The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005143the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005144size.
5145
5146Note that the numbers above were invented purely for this example and
5147are given only to help explain the function usage. Little testing has
5148been done to find optimum values for either the costs or the weights.
5149
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06005150.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005151
5152There are a bunch of #define's in pngconf.h that control what parts of
5153libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05005154never going to use a capability, you can change the #define to #undef
5155before recompiling libpng and save yourself code and data space, or
5156you can turn off individual capabilities with defines that begin with
5157PNG_NO_.
5158
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005159In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
5160
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05005161You can also turn all of the transforms and ancillary chunk capabilities
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05005162off en masse with compiler directives that define
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05005163PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
5164or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005165along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06005166want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
5167transformations but still leave the library fully capable of reading
5168and writing PNG files with all known public chunks. Use of the
5169PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
5170that is incapable of reading or writing ancillary chunks. If you are
5171not using the progressive reading capability, you can turn that off
5172with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
5173capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005174
5175All the reading and writing specific code are in separate files, so the
5176linker should only grab the files it needs. However, if you want to
5177make sure, or if you are building a stand alone library, all the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005178reading files start with "pngr" and all the writing files start with "pngw".
5179The files that don't match either (like png.c, pngtrans.c, etc.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005180are used for both reading and writing, and always need to be included.
5181The progressive reader is in pngpread.c
5182
5183If you are creating or distributing a dynamically linked library (a .so
5184or DLL file), you should not remove or disable any parts of the library,
5185as this will cause applications linked with different versions of the
5186library to fail if they call functions not available in your library.
5187The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06005188those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005189
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06005190.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005191
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06005192The macro definition PNG_DEBUG can be used to request debugging
5193printout. Set it to an integer value in the range 0 to 3. Higher
5194numbers result in increasing amounts of debugging information. The
5195information is printed to the "stderr" file, unless another file
5196name is specified in the PNG_DEBUG_FILE macro definition.
5197
5198When PNG_DEBUG > 0, the following functions (macros) become available:
5199
5200 png_debug(level, message)
5201 png_debug1(level, message, p1)
5202 png_debug2(level, message, p1, p2)
5203
5204in which "level" is compared to PNG_DEBUG to decide whether to print
5205the message, "message" is the formatted string to be printed,
5206and p1 and p2 are parameters that are to be embedded in the string
5207according to printf-style formatting directives. For example,
5208
5209 png_debug1(2, "foo=%d\n", foo);
5210
5211is expanded to
5212
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005213 if (PNG_DEBUG > 2)
5214 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06005215
5216When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
5217can still use PNG_DEBUG to control your own debugging:
5218
5219 #ifdef PNG_DEBUG
5220 fprintf(stderr, ...
5221 #endif
5222
5223When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
5224having level = 0 will be printed. There aren't any such statements in
5225this version of libpng, but if you insert some they will be printed.
5226
Glenn Randers-Pehrson5bffd6c2012-01-31 22:21:32 -06005227.SS Prepending a prefix to exported symbols
5228
5229Starting with libpng-1.6.0, you can configure libpng (when using the
5230"configure" script) to prefix all exported symbols by means of the
5231configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
5232string beginning with a letter and containing only uppercase
5233and lowercase letters, digits, and the underscore (i.e., a C language
5234identifier). This creates a set of macros in pnglibconf.h, so this is
5235transparent to applications; their function calls get transformed by
5236the macros to use the modified names.
5237
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005238.SH VII. MNG support
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06005239
5240The MNG specification (available at http://www.libpng.org/pub/mng) allows
5241certain extensions to PNG for PNG images that are embedded in MNG datastreams.
5242Libpng can support some of these extensions. To enable them, use the
5243png_permit_mng_features() function:
5244
5245 feature_set = png_permit_mng_features(png_ptr, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005246
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05005247 mask is a png_uint_32 containing the bitwise OR of the
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06005248 features you want to enable. These include
5249 PNG_FLAG_MNG_EMPTY_PLTE
5250 PNG_FLAG_MNG_FILTER_64
5251 PNG_ALL_MNG_FEATURES
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005252
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05005253 feature_set is a png_uint_32 that is the bitwise AND of
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06005254 your mask with the set of MNG features that is
5255 supported by the version of libpng that you are using.
5256
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06005257It is an error to use this function when reading or writing a standalone
5258PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
Glenn Randers-Pehrsonf05f8032000-12-23 14:27:39 -06005259in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
5260and the MHDR and MEND chunks. Libpng does not provide support for these
5261or any other MNG chunks; your application must provide its own support for
5262them. You may wish to consider using libmng (available at
5263http://www.libmng.com) instead.
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06005264
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005265.SH VIII. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005266
5267It should be noted that versions of libpng later than 0.96 are not
5268distributed by the original libpng author, Guy Schalnat, nor by
5269Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
5270distributed versions 0.89 through 0.96, but rather by another member
5271of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
5272still alive and well, but they have moved on to other things.
5273
5274The old libpng functions png_read_init(), png_write_init(),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05005275png_info_init(), png_read_destroy(), and png_write_destroy() have been
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05005276moved to PNG_INTERNAL in version 0.95 to discourage their use. These
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005277functions will be removed from libpng version 1.4.0.
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05005278
5279The preferred method of creating and initializing the libpng structures is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005280via the png_create_read_struct(), png_create_write_struct(), and
5281png_create_info_struct() because they isolate the size of the structures
5282from the application, allow version error checking, and also allow the
5283use of custom error handling routines during the initialization, which
5284the old functions do not. The functions png_read_destroy() and
5285png_write_destroy() do not actually free the memory that libpng
5286allocated for these structs, but just reset the data structures, so they
5287can be used instead of png_destroy_read_struct() and
5288png_destroy_write_struct() if you feel there is too much system overhead
5289allocating and freeing the png_struct for each image read.
5290
5291Setting the error callbacks via png_set_message_fn() before
5292png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06005293because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005294to fail if the png_ptr was not initialized to zero. It is still possible
5295to set the error callbacks AFTER png_read_init(), or to change them with
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05005296png_set_error_fn(), which is essentially the same function, but with a new
5297name to force compilation errors with applications that try to use the old
5298method.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005299
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05005300Starting with version 1.0.7, you can find out which version of the library
5301you are using at run-time:
5302
5303 png_uint_32 libpng_vn = png_access_version_number();
5304
5305The number libpng_vn is constructed from the major version, minor
5306version with leading zero, and release number with leading zero,
5307(e.g., libpng_vn for version 1.0.7 is 10007).
5308
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05005309Note that this function does not take a png_ptr, so you can call it
5310before you've created one.
5311
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05005312You can also check which version of png.h you used when compiling your
5313application:
5314
5315 png_uint_32 application_vn = PNG_LIBPNG_VER;
5316
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005317.SH IX. Changes to Libpng from version 1.0.x to 1.2.x
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005318
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005319Support for user memory management was enabled by default. To
5320accomplish this, the functions png_create_read_struct_2(),
5321png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
5322png_malloc_default(), and png_free_default() were added.
5323
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -06005324Support for the iTXt chunk has been enabled by default as of
5325version 1.2.41.
5326
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005327Support for certain MNG features was enabled.
5328
5329Support for numbered error messages was added. However, we never got
5330around to actually numbering the error messages. The function
5331png_set_strip_error_numbers() was added (Note: the prototype for this
5332function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
5333builds of libpng-1.2.15. It was restored in libpng-1.2.36).
5334
5335The png_malloc_warn() function was added at libpng-1.2.3. This issues
5336a png_warning and returns NULL instead of aborting when it fails to
5337acquire the requested memory allocation.
5338
5339Support for setting user limits on image width and height was enabled
5340by default. The functions png_set_user_limits(), png_get_user_width_max(),
5341and png_get_user_height_max() were added at libpng-1.2.6.
5342
5343The png_set_add_alpha() function was added at libpng-1.2.7.
5344
5345The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
5346Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
5347tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
5348deprecated.
5349
5350A number of macro definitions in support of runtime selection of
5351assembler code features (especially Intel MMX code support) were
5352added at libpng-1.2.0:
5353
5354 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
5355 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
5356 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
5357 PNG_ASM_FLAG_MMX_READ_INTERLACE
5358 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
5359 PNG_ASM_FLAG_MMX_READ_FILTER_UP
5360 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
5361 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
5362 PNG_ASM_FLAGS_INITIALIZED
5363 PNG_MMX_READ_FLAGS
5364 PNG_MMX_FLAGS
5365 PNG_MMX_WRITE_FLAGS
5366 PNG_MMX_FLAGS
5367
5368We added the following functions in support of runtime
5369selection of assembler code features:
5370
5371 png_get_mmx_flagmask()
5372 png_set_mmx_thresholds()
5373 png_get_asm_flags()
5374 png_get_mmx_bitdepth_threshold()
5375 png_get_mmx_rowbytes_threshold()
5376 png_set_asm_flags()
5377
5378We replaced all of these functions with simple stubs in libpng-1.2.20,
5379when the Intel assembler code was removed due to a licensing issue.
5380
Glenn Randers-Pehrson3d893a02009-08-31 13:32:46 -05005381These macros are deprecated:
5382
5383 PNG_READ_TRANSFORMS_NOT_SUPPORTED
5384 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
5385 PNG_NO_SEQUENTIAL_READ_SUPPORTED
5386 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
5387 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
5388 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
5389
5390They have been replaced, respectively, by:
5391
5392 PNG_NO_READ_TRANSFORMS
5393 PNG_NO_PROGRESSIVE_READ
5394 PNG_NO_SEQUENTIAL_READ
5395 PNG_NO_WRITE_TRANSFORMS
5396 PNG_NO_READ_ANCILLARY_CHUNKS
5397 PNG_NO_WRITE_ANCILLARY_CHUNKS
5398
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005399PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
5400deprecated since libpng-1.0.16 and libpng-1.2.6.
5401
5402The function
5403 png_check_sig(sig, num)
5404was replaced with
5405 !png_sig_cmp(sig, 0, num)
5406It has been deprecated since libpng-0.90.
5407
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005408The function
5409 png_set_gray_1_2_4_to_8()
5410which also expands tRNS to alpha was replaced with
5411 png_set_expand_gray_1_2_4_to_8()
5412which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005413
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005414.SH X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
Glenn Randers-Pehrsond740c842009-11-04 19:01:54 -06005415
5416Private libpng prototypes and macro definitions were moved from
5417png.h and pngconf.h into a new pngpriv.h header file.
5418
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005419Functions png_set_benign_errors(), png_benign_error(), and
5420png_chunk_benign_error() were added.
5421
5422Support for setting the maximum amount of memory that the application
5423will allocate for reading chunks was added, as a security measure.
5424The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
5425were added to the library.
5426
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06005427We implemented support for I/O states by adding png_ptr member io_state
5428and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005429
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05005430We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
5431input transforms.
5432
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05005433Checking for and reporting of errors in the IHDR chunk is more thorough.
5434
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005435Support for global arrays was removed, to improve thread safety.
5436
5437Some obsolete/deprecated macros and functions have been removed.
5438
5439Typecasted NULL definitions such as
5440 #define png_voidp_NULL (png_voidp)NULL
5441were eliminated. If you used these in your application, just use
5442NULL instead.
5443
5444The png_struct and info_struct members "trans" and "trans_values" were
5445changed to "trans_alpha" and "trans_color", respectively.
5446
5447The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005448were removed.
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005449
5450The PNG_1_0_X and PNG_1_2_X macros were eliminated.
5451
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05005452The PNG_LEGACY_SUPPORTED macro was eliminated.
5453
5454Many WIN32_WCE #ifdefs were removed.
5455
5456The functions png_read_init(info_ptr), png_write_init(info_ptr),
5457png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
5458have been removed. They have been deprecated since libpng-0.95.
5459
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005460The png_permit_empty_plte() was removed. It has been deprecated
5461since libpng-1.0.9. Use png_permit_mng_features() instead.
5462
5463We removed the obsolete stub functions png_get_mmx_flagmask(),
5464png_set_mmx_thresholds(), png_get_asm_flags(),
5465png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
5466png_set_asm_flags(), and png_mmx_supported()
5467
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005468We removed the obsolete png_check_sig(), png_memcpy_check(), and
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05005469png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
5470and memset(), respectively.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005471
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005472The function png_set_gray_1_2_4_to_8() was removed. It has been
5473deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
5474png_set_expand_gray_1_2_4_to_8() because the former function also
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005475expanded any tRNS chunk to an alpha channel.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005476
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005477Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
5478were added and are used by default instead of the corresponding
5479functions. Unfortunately,
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005480from 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 -06005481function) incorrectly returned a value of type png_uint_32.
5482
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005483We changed the prototype for png_malloc() from
5484 png_malloc(png_structp png_ptr, png_uint_32 size)
5485to
5486 png_malloc(png_structp png_ptr, png_alloc_size_t size)
5487
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005488This also applies to the prototype for the user replacement malloc_fn().
5489
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005490The png_calloc() function was added and is used in place of
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05005491of "png_malloc(); memset();" except in the case in png_read_png()
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005492where the array consists of pointers; in this case a "for" loop is used
5493after the png_malloc() to set the pointers to NULL, to give robust.
5494behavior in case the application runs out of memory part-way through
5495the process.
5496
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005497We changed the prototypes of png_get_compression_buffer_size() and
5498png_set_compression_buffer_size() to work with png_size_t instead of
5499png_uint_32.
5500
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005501Support for numbered error messages was removed by default, since we
5502never got around to actually numbering the error messages. The function
5503png_set_strip_error_numbers() was removed from the library by default.
5504
5505The png_zalloc() and png_zfree() functions are no longer exported.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005506The png_zalloc() function no longer zeroes out the memory that it
5507allocates.
5508
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05005509Support for dithering was disabled by default in libpng-1.4.0, because
Glenn Randers-Pehrson9f1cd702011-04-16 19:40:23 -05005510it has not been well tested and doesn't actually "dither".
5511The code was not
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05005512removed, however, and could be enabled by building libpng with
5513PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
5514was reenabled, but the function was renamed png_set_quantize() to
5515reflect more accurately what it actually does. At the same time,
5516the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005517PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5518was renamed to PNG_READ_QUANTIZE_SUPPORTED.
Glenn Randers-Pehrson60988072010-04-13 22:11:06 -05005519
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005520We removed the trailing '.' from the warning and error messages.
5521
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005522.SH XI. Changes to Libpng from version 1.4.x to 1.5.x
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005523
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005524From 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 -06005525function) incorrectly returned a value of type png_uint_32.
5526
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005527A. Changes that affect users of libpng
5528
5529There are no substantial API changes between the non-deprecated parts of
Glenn Randers-Pehrson5a956a72011-12-22 14:23:37 -06005530the 1.4.5 API and the 1.5.0 API; however the ability to directly access
5531members of the main libpng control structures, png_struct and png_info,
5532deprecated in earlier versions of libpng, has been completely removed from
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005533libpng 1.5.
5534
Glenn Randers-Pehrson5a956a72011-12-22 14:23:37 -06005535We no longer include zlib.h in png.h. The include statement has been moved
5536to pngstruct.h, where it is not accessible by applications. Applications that
5537need access to information in zlib.h will need to add the '#include "zlib.h"'
5538directive. It does not matter whether this is placed prior to or after
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005539the '"#include png.h"' directive.
5540
5541We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
5542png_memcmp(), png_sprintf, and png_memcpy() macros into a private
Glenn Randers-Pehrson5a956a72011-12-22 14:23:37 -06005543header file (pngpriv.h) that is not accessible by applications.
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005544
Glenn Randers-Pehrson9d23b402011-01-08 10:42:01 -06005545In png_get_iCCP, the type of "profile" was changed from png_charpp
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005546to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
Glenn Randers-Pehrson9d23b402011-01-08 10:42:01 -06005547
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005548There are changes of form in png.h, including new and changed macros to
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05005549declare parts of the API. Some API functions with arguments that are
5550pointers to data not modified within the function have been corrected to
5551declare these arguments with PNG_CONST.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005552
5553Much of the internal use of C macros to control the library build has also
5554changed and some of this is visible in the exported header files, in
5555particular the use of macros to control data and API elements visible
5556during application compilation may require significant revision to
5557application code. (It is extremely rare for an application to do this.)
5558
5559Any program that compiled against libpng 1.4 and did not use deprecated
5560features or access internal library structures should compile and work
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -06005561against libpng 1.5, except for the change in the prototype for
5562png_get_iCCP() and png_set_iCCP() API functions mentioned above.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005563
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06005564libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5565interlaced images. The macros return the number of rows and columns in
5566each pass and information that can be used to de-interlace and (if
5567absolutely necessary) interlace an image.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005568
5569libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -06005570the application-provided png_longjmp_ptr on the internal, but application
Glenn Randers-Pehrson33ced442011-04-27 14:58:06 -05005571initialized, longjmp buffer. It is provided as a convenience to avoid
5572the need to use the png_jmpbuf macro, which had the unnecessary side
5573effect of resetting the internal png_longjmp_ptr value.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005574
5575libpng 1.5.0 includes a complete fixed point API. By default this is
5576present along with the corresponding floating point API. In general the
5577fixed point API is faster and smaller than the floating point one because
5578the PNG file format used fixed point, not floating point. This applies
5579even if the library uses floating point in internal calculations. A new
5580macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5581uses floating point arithmetic (the default) or fixed point arithmetic
5582internally for performance critical calculations such as gamma correction.
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005583In some cases, the gamma calculations may produce slightly different
5584results. This has changed the results in png_rgb_to_gray and in alpha
5585composition (png_set_background for example). This applies even if the
5586original image was already linear (gamma == 1.0) and, therefore, it is
5587not necessary to linearize the image. This is because libpng has *not*
5588been changed to optimize that case correctly, yet.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005589
5590Fixed point support for the sCAL chunk comes with an important caveat;
5591the sCAL specification uses a decimal encoding of floating point values
5592and the accuracy of PNG fixed point values is insufficient for
5593representation of these values. Consequently a "string" API
5594(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5595arbitrary sCAL chunks in the absence of either the floating point API or
5596internal floating point calculations.
5597
5598Applications no longer need to include the optional distribution header
5599file pngusr.h or define the corresponding macros during application
5600build in order to see the correct variant of the libpng API. From 1.5.0
5601application code can check for the corresponding _SUPPORTED macro:
5602
5603#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
5604 /* code that uses the inch conversion APIs. */
5605#endif
5606
5607This macro will only be defined if the inch conversion functions have been
5608compiled into libpng. The full set of macros, and whether or not support
5609has been compiled in, are available in the header file pnglibconf.h.
5610This header file is specific to the libpng build. Notice that prior to
56111.5.0 the _SUPPORTED macros would always have the default definition unless
5612reset by pngusr.h or by explicit settings on the compiler command line.
5613These settings may produce compiler warnings or errors in 1.5.0 because
5614of macro redefinition.
5615
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005616From 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 -06005617function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
5618is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5619did not exist.)
5620
5621Applications can now choose whether to use these macros or to call the
5622corresponding function by defining PNG_USE_READ_MACROS or
5623PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
5624only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
Glenn Randers-Pehrson95ba4172011-09-08 12:21:42 -05005625will lead to a link failure.
Glenn Randers-Pehrson59fa3e92011-01-06 07:07:06 -06005626
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005627Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05005628when compressing the IDAT data and textual data such as zTXt and iCCP.
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005629In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05005630We added five png_set_text_*() functions for setting the parameters to
5631use with textual data.
5632
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005633Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
John Bowlerb2bee332011-06-10 23:24:58 -05005634option was off by default, and slightly inaccurate scaling occurred.
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05005635This option can no longer be turned off, and the choice of accurate
5636or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5637API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5638chopping.
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05005639
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005640Prior to libpng-1.5.4, the png_set_user_limits() function could only be
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05005641used to reduce the width and height limits from the value of
5642PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5643that it could be used to override them. Now this function will reduce or
5644increase the limits.
John Bowlerb2bee332011-06-10 23:24:58 -05005645
Glenn Randers-Pehrson9eb125e2012-02-24 22:04:53 -06005646Starting in libpng-1.5.10, the user limits can be set en masse with the
5647configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled,
5648a set of "safe" limits is applied in pngpriv.h. These can be overridden by
5649application calls to png_set_user_limits(), png_set_user_chunk_cache_max(),
5650and/or png_set_user_malloc_max() that increase or decrease the limits. Also,
5651in libpng-1.5.10 the default width and height limits were increased
5652from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the
5653limits are now
5654 default safe
5655 png_user_width_max 0x7fffffff 1,000,000
5656 png_user_height_max 0x7fffffff 1,000,000
5657 png_user_chunk_cache_max 0 (unlimited) 128
5658 png_user_chunk_malloc_max 0 (unlimited) 8,000,000
5659
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005660B. Changes to the build and configuration of libpng
5661
5662Details of internal changes to the library code can be found in the CHANGES
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005663file and in the GIT repository logs. These will be of no concern to the vast
5664majority of library users or builders, however the few who configure libpng
5665to a non-default feature set may need to change how this is done.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005666
5667There should be no need for library builders to alter build scripts if
5668these use the distributed build support - configure or the makefiles -
5669however users of the makefiles may care to update their build scripts
5670to build pnglibconf.h where the corresponding makefile does not do so.
5671
5672Building libpng with a non-default configuration has changed completely.
5673The old method using pngusr.h should still work correctly even though the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005674way pngusr.h is used in the build has been changed; however, library
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005675builders will probably want to examine the changes to take advantage of
5676new capabilities and to simplify their build system.
5677
5678B.1 Specific changes to library configuration capabilities
5679
5680The library now supports a complete fixed point implementation and can
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005681thus be used on systems that have no floating point support or very
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005682limited or slow support. Previously gamma correction, an essential part
5683of complete PNG support, required reasonably fast floating point.
5684
5685As part of this the choice of internal implementation has been made
5686independent of the choice of fixed versus floating point APIs and all the
5687missing fixed point APIs have been implemented.
5688
5689The exact mechanism used to control attributes of API functions has
5690changed. A single set of operating system independent macro definitions
5691is used and operating system specific directives are defined in
5692pnglibconf.h
5693
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005694As part of this the mechanism used to choose procedure call standards on
5695those systems that allow a choice has been changed. At present this only
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005696affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005697running on Intel processors. As before, PNGAPI is defined where required
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005698to control the exported API functions; however, two new macros, PNGCBAPI
5699and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5700(PNGCAPI) for functions that must match a C library prototype (currently
5701only png_longjmp_ptr, which must match the C longjmp function.) The new
5702approach is documented in pngconf.h
5703
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005704Despite these changes, libpng 1.5.0 only supports the native C function
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005705calling standard on those platforms tested so far (__cdecl on Microsoft
5706Windows). This is because the support requirements for alternative
5707calling conventions seem to no longer exist. Developers who find it
5708necessary to set PNG_API_RULE to 1 should advise the mailing list
5709(png-mng-implement) of this and library builders who use Openwatcom and
5710therefore set PNG_API_RULE to 2 should also contact the mailing list.
5711
5712A new test program, pngvalid, is provided in addition to pngtest.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005713pngvalid validates the arithmetic accuracy of the gamma correction
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005714calculations and includes a number of validations of the file format.
5715A subset of the full range of tests is run when "make check" is done
5716(in the 'configure' build.) pngvalid also allows total allocated memory
5717usage to be evaluated and performs additional memory overwrite validation.
5718
5719Many changes to individual feature macros have been made. The following
5720are the changes most likely to be noticed by library builders who
5721configure libpng:
5722
57231) All feature macros now have consistent naming:
5724
5725#define PNG_NO_feature turns the feature off
5726#define PNG_feature_SUPPORTED turns the feature on
5727
5728pnglibconf.h contains one line for each feature macro which is either:
5729
5730#define PNG_feature_SUPPORTED
5731
5732if the feature is supported or:
5733
5734/*#undef PNG_feature_SUPPORTED*/
5735
5736if it is not. Library code consistently checks for the 'SUPPORTED' macro.
Glenn Randers-Pehrsond0797f52011-07-12 10:28:02 -05005737It does not, and libpng applications should not, check for the 'NO' macro
5738which will not normally be defined even if the feature is not supported.
5739The 'NO' macros are only used internally for setting or not setting the
5740corresponding 'SUPPORTED' macros.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005741
5742Compatibility with the old names is provided as follows:
5743
5744PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5745
5746And the following definitions disable the corresponding feature:
5747
5748PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5749PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5750PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5751PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5752PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5753PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5754
5755Library builders should remove use of the above, inconsistent, names.
5756
57572) Warning and error message formatting was previously conditional on
5758the STDIO feature. The library has been changed to use the
5759CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5760the library no longer uses the printf(3) functions, even though the
5761default read/write implementations use (FILE) style stdio.h functions.
5762
57633) Three feature macros now control the fixed/floating point decisions:
5764
5765PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5766
5767PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5768practice these are normally required internally anyway (because the PNG
5769file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5770merely stops the function from being exported.
5771
5772PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5773point implementation or the fixed point one. Typically the fixed point
5774implementation is larger and slower than the floating point implementation
5775on a system that supports floating point, however it may be faster on a
5776system which lacks floating point hardware and therefore uses a software
5777emulation.
5778
57794) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
5780functions to read and write ints to be disabled independently of
5781PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5782even though the default is to use the macros - this allows applications
5783to choose at app buildtime whether or not to use macros (previously
5784impossible because the functions weren't in the default build.)
5785
5786B.2 Changes to the configuration mechanism
5787
5788Prior to libpng-1.5.0 library builders who needed to configure libpng
5789had either to modify the exported pngconf.h header file to add system
5790specific configuration or had to write feature selection macros into
5791pngusr.h and cause this to be included into pngconf.h by defining
5792PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5793application built without PNG_USER_CONFIG defined would see the
5794unmodified, default, libpng API and thus would probably fail to link.
5795
5796These mechanisms still work in the configure build and in any makefile
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005797build that builds pnglibconf.h, although the feature selection macros
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005798have changed somewhat as described above. In 1.5.0, however, pngusr.h is
5799processed only once, when the exported header file pnglibconf.h is built.
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005800pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005801build of pnglibconf.h and it is never included in an application build.
5802
5803The rarely used alternative of adding a list of feature macros to the
5804CFLAGS setting in the build also still works, however the macros will be
5805copied to pnglibconf.h and this may produce macro redefinition warnings
5806when the individual C files are compiled.
5807
5808All configuration now only works if pnglibconf.h is built from
5809scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
5810(the original author of awk) maintains C source code of that awk and this
5811and all known later implementations (often called by subtly different
5812names - nawk and gawk for example) are adequate to build pnglibconf.h.
5813The Sun Microsystems (now Oracle) program 'awk' is an earlier version
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005814and does not work; this may also apply to other systems that have a
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005815functioning awk called 'nawk'.
5816
5817Configuration options are now documented in scripts/pnglibconf.dfa. This
5818file also includes dependency information that ensures a configuration is
5819consistent; that is, if a feature is switched off dependent features are
5820also removed. As a recommended alternative to using feature macros in
5821pngusr.h a system builder may also define equivalent options in pngusr.dfa
5822(or, indeed, any file) and add that to the configuration by setting
5823DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
5824how to do this, and a case where pngusr.h is still required.
5825
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005826.SH XII. Changes to Libpng from version 1.5.x to 1.6.x
5827
5828A "simplified API" has been added (see documentation in png.h and a simple
5829example in contrib/examples/pngtopng.c)
Glenn Randers-Pehrson5a956a72011-12-22 14:23:37 -06005830
Glenn Randers-Pehrson5bffd6c2012-01-31 22:21:32 -06005831Starting with libpng-1.6.0, you can configure libpng to prefix all exported
5832symbols.
5833
Glenn Randers-Pehrson5a956a72011-12-22 14:23:37 -06005834We no longer include string.h in png.h. The include statement has been moved
5835to pngpriv.h, where it is not accessible by applications. Applications that
5836need access to information in string.h must add an '#include "string.h"'
5837directive. It does not matter whether this is placed prior to or after
5838the '"#include png.h"' directive.
5839
5840The following API are now DEPRECATED:
5841 png_info_init_3()
5842 png_convert_to_rfc1123() which has been replaced
5843 with png_convert_to_rfc1123_buffer()
5844 png_malloc_default()
5845 png_free_default()
5846
5847The following has been removed:
5848 png_get_io_chunk_name(), which has been replaced
5849 with png_get_io_chunk_type(). The new
5850 function returns a 32-bit integer instead of
5851 a string.
5852
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005853.SH XIII. Detecting libpng
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05005854
5855The png_get_io_ptr() function has been present since libpng-0.88, has never
5856changed, and is unaffected by conditional compilation macros. It is the
5857best choice for use in configure scripts for detecting the presence of any
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05005858libpng version since 0.88. In an autoconf "configure.in" you could use
5859
5860 AC_CHECK_LIB(png, png_get_io_ptr, ...
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05005861
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005862.SH XV. Source code repository
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005863
5864Since about February 2009, version 1.2.34, libpng has been under "git" source
5865control. The git repository was built from old libpng-x.y.z.tar.gz files
5866going back to version 0.70. You can access the git repository (read only)
5867at
5868
5869 git://libpng.git.sourceforge.net/gitroot/libpng
5870
5871or you can browse it via "gitweb" at
5872
5873 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
5874
5875Patches can be sent to glennrp at users.sourceforge.net or to
5876png-mng-implement at lists.sourceforge.net or you can upload them to
5877the libpng bug tracker at
5878
5879 http://libpng.sourceforge.net
5880
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005881We also accept patches built from the tar or zip distributions, and
5882simple verbal discriptions of bug fixes, reported either to the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005883SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5884mailing list, or directly to glennrp.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005885
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005886.SH XV. Coding style
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005887
5888Our coding style is similar to the "Allman" style, with curly
5889braces on separate lines:
5890
5891 if (condition)
5892 {
5893 action;
5894 }
5895
5896 else if (another condition)
5897 {
5898 another action;
5899 }
5900
5901The braces can be omitted from simple one-line actions:
5902
5903 if (condition)
5904 return (0);
5905
5906We use 3-space indentation, except for continued statements which
5907are usually indented the same as the first line of the statement
5908plus four more spaces.
5909
Glenn Randers-Pehrson5ade7ed2009-09-30 15:11:49 -05005910For macro definitions we use 2-space indentation, always leaving the "#"
5911in the first column.
5912
5913 #ifndef PNG_NO_FEATURE
5914 # ifndef PNG_FEATURE_SUPPORTED
5915 # define PNG_FEATURE_SUPPORTED
5916 # endif
5917 #endif
5918
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005919Comments appear with the leading "/*" at the same indentation as
5920the statement that follows the comment:
5921
5922 /* Single-line comment */
5923 statement;
5924
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005925 /* This is a multiple-line
5926 * comment.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005927 */
5928 statement;
5929
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005930Very short comments can be placed after the end of the statement
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005931to which they pertain:
5932
5933 statement; /* comment */
5934
5935We don't use C++ style ("//") comments. We have, however,
5936used them in the past in some now-abandoned MMX assembler
5937code.
5938
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05005939Functions and their curly braces are not indented, and
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005940exported functions are marked with PNGAPI:
5941
5942 /* This is a public function that is visible to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005943 * application programmers. It does thus-and-so.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005944 */
5945 void PNGAPI
5946 png_exported_function(png_ptr, png_info, foo)
5947 {
5948 body;
5949 }
5950
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005951The prototypes for all exported functions appear in png.h,
5952above the comment that says
5953
5954 /* Maintainer: Put new public prototypes here ... */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005955
5956We mark all non-exported functions with "/* PRIVATE */"":
5957
5958 void /* PRIVATE */
5959 png_non_exported_function(png_ptr, png_info, foo)
5960 {
5961 body;
5962 }
5963
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005964The prototypes for non-exported functions (except for those in
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05005965pngtest) appear in
5966pngpriv.h
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005967above the comment that says
5968
5969 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005970
Glenn Randers-Pehrsoncbbe9a52011-01-29 16:12:11 -06005971To avoid polluting the global namespace, the names of all exported
5972functions and variables begin with "png_", and all publicly visible C
5973preprocessor macros begin with "PNG_". We request that applications that
5974use libpng *not* begin any of their own symbols with either of these strings.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005975
5976We put a space after each comma and after each semicolon
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005977in "for" statements, and we put spaces before and after each
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005978C binary operator and after "for" or "while", and before
5979"?". We don't put a space between a typecast and the expression
5980being cast, nor do we put one between a function name and the
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005981left parenthesis that follows it:
5982
5983 for (i = 2; i > 0; --i)
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05005984 y[i] = a(x) + (int)b;
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005985
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05005986We prefer #ifdef and #ifndef to #if defined() and if !defined()
5987when there is only one macro being tested.
5988
Glenn Randers-Pehrson8db19982011-10-27 16:17:24 -05005989We prefer to express integers that are used as bit masks in hex format,
5990with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
5991
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05005992We do not use the TAB character for indentation in the C sources.
5993
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06005994Lines do not exceed 80 characters.
5995
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06005996Other rules can be inferred by inspecting the libpng source.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005997
Glenn Randers-Pehrson0501c1c2012-01-11 14:00:52 -06005998.SH XVI. Y2K Compliance in libpng
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005999
Glenn Randers-Pehrsonfaf38ee2012-02-26 21:11:25 -06006000February 27, 2012
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006001
6002Since the PNG Development group is an ad-hoc body, we can't make
6003an official declaration.
6004
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05006005This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06006006upward through 1.6.0beta15 are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05006007versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006008
6009Libpng only has three year fields. One is a 2-byte unsigned integer that
6010will hold years up to 65535. The other two hold the date in text
6011format, and will hold years up to 9999.
6012
6013The integer is
6014 "png_uint_16 year" in png_time_struct.
6015
6016The strings are
6017 "png_charp time_buffer" in png_struct and
6018 "near_time_buffer", which is a local character string in png.c.
6019
6020There are seven time-related functions:
6021
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06006022 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006023 (formerly png_convert_to_rfc_1152() in error)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06006024 png_convert_from_struct_tm() in pngwrite.c, called
6025 in pngwrite.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006026 png_convert_from_time_t() in pngwrite.c
6027 png_get_tIME() in pngget.c
6028 png_handle_tIME() in pngrutil.c, called in pngread.c
6029 png_set_tIME() in pngset.c
6030 png_write_tIME() in pngwutil.c, called in pngwrite.c
6031
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06006032All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006033png_convert_from_time_t() function calls gmtime() to convert from system
6034clock time, which returns (year - 1900), which we properly convert to
6035the full 4-digit year. There is a possibility that applications using
6036libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05006037function, or that they are incorrectly passing only a 2-digit year
6038instead of "year - 1900" into the png_convert_from_struct_tm() function,
6039but this is not under our control. The libpng documentation has always
6040stated that it works with 4-digit years, and the APIs have been
6041documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006042
6043The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
6044integer to hold the year, and can hold years as large as 65535.
6045
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05006046zlib, upon which libpng depends, is also Y2K compliant. It contains
6047no date-related code.
6048
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06006049
6050 Glenn Randers-Pehrson
6051 libpng maintainer
6052 PNG Development Group
6053
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006054.SH NOTE
6055
6056Note about libpng version numbers:
6057
6058Due to various miscommunications, unforeseen code incompatibilities
6059and occasional factors outside the authors' control, version numbering
6060on the library has not always been consistent and straightforward.
6061The following table summarizes matters since version 0.89c, which was
6062the first widely used release:
6063
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06006064 source png.h png.h shared-lib
6065 version string int version
6066 ------- ------ ----- ----------
6067 0.89c ("beta 3") 0.89 89 1.0.89
6068 0.90 ("beta 4") 0.90 90 0.90
6069 0.95 ("beta 5") 0.95 95 0.95
6070 0.96 ("beta 6") 0.96 96 0.96
6071 0.97b ("beta 7") 1.00.97 97 1.0.1
6072 0.97c 0.97 97 2.0.97
6073 0.98 0.98 98 2.0.98
6074 0.99 0.99 98 2.0.99
6075 0.99a-m 0.99 99 2.0.99
6076 1.00 1.00 100 2.1.0
6077 1.0.0 1.0.0 100 2.1.0
6078 1.0.0 (from here on, the 100 2.1.0
6079 1.0.1 png.h string is 10001 2.1.0
6080 1.0.1a-e identical to the 10002 from here on, the
6081 1.0.2 source version) 10002 shared library is 2.V
6082 1.0.2a-b 10003 where V is the source
6083 1.0.1 10001 code version except as
6084 1.0.1a-e 10002 2.1.0.1a-e noted.
6085 1.0.2 10002 2.1.0.2
6086 1.0.2a-b 10003 2.1.0.2a-b
6087 1.0.3 10003 2.1.0.3
6088 1.0.3a-d 10004 2.1.0.3a-d
6089 1.0.4 10004 2.1.0.4
6090 1.0.4a-f 10005 2.1.0.4a-f
6091 1.0.5 (+ 2 patches) 10005 2.1.0.5
6092 1.0.5a-d 10006 2.1.0.5a-d
6093 1.0.5e-r 10100 2.1.0.5e-r
6094 1.0.5s-v 10006 2.1.0.5s-v
6095 1.0.6 (+ 3 patches) 10006 2.1.0.6
6096 1.0.6d-g 10007 2.1.0.6d-g
6097 1.0.6h 10007 10.6h
6098 1.0.6i 10007 10.6i
6099 1.0.6j 10007 2.1.0.6j
Glenn Randers-Pehrson25467032011-01-28 11:58:40 -06006100 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06006101 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
6102 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
6103 1.0.7 1 10007 2.1.0.7
6104 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
6105 1.0.8rc1 1 10008 2.1.0.8rc1
6106 1.0.8 1 10008 2.1.0.8
6107 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
6108 1.0.9rc1 1 10009 2.1.0.9rc1
6109 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
6110 1.0.9rc2 1 10009 2.1.0.9rc2
6111 1.0.9 1 10009 2.1.0.9
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06006112 1.0.10beta1 1 10010 2.1.0.10beta1
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06006113 1.0.10rc1 1 10010 2.1.0.10rc1
Glenn Randers-Pehrson13cfbac2001-03-30 06:42:28 -06006114 1.0.10 1 10010 2.1.0.10
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -05006115 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05006116 1.0.11rc1 1 10011 2.1.0.11rc1
Glenn Randers-Pehrson32835392001-04-27 08:29:32 -05006117 1.0.11 1 10011 2.1.0.11
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05006118 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
6119 1.0.12rc1 2 10012 2.1.0.12rc1
6120 1.0.12 2 10012 2.1.0.12
6121 1.1.0a-f - 10100 2.1.1.0a-f abandoned
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05006122 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
Glenn Randers-Pehrson5a0be342001-10-18 20:55:13 -05006123 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
6124 1.2.0rc1 3 10200 3.1.2.0rc1
6125 1.2.0 3 10200 3.1.2.0
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -06006126 1.2.1beta-4 3 10201 3.1.2.1beta1-4
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -06006127 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
6128 1.2.1 3 10201 3.1.2.1
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -06006129 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
Glenn Randers-Pehrsonfcbd7872002-04-07 16:35:38 -05006130 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
6131 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
6132 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05006133 1.0.13 10 10013 10.so.0.1.0.13
6134 1.2.2 12 10202 12.so.0.1.2.2
Glenn Randers-Pehrson22f28962002-05-13 18:17:09 -05006135 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
6136 1.2.3 12 10203 12.so.0.1.2.3
Glenn Randers-Pehrsond020e9d2002-06-28 09:34:00 -05006137 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -05006138 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
Glenn Randers-Pehrson484a8a12002-07-07 19:15:20 -05006139 1.0.14 10 10014 10.so.0.1.0.14
6140 1.2.4 13 10204 12.so.0.1.2.4
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05006141 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
6142 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05006143 1.0.15 10 10015 10.so.0.1.0.15
6144 1.2.5 13 10205 12.so.0.1.2.5
6145 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
Glenn Randers-Pehrson37f116a2004-08-15 07:15:39 -05006146 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
6147 1.0.16 10 10016 10.so.0.1.0.16
6148 1.2.6 13 10206 12.so.0.1.2.6
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05006149 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05006150 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
6151 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
Glenn Randers-Pehrson250dfe12004-09-11 21:19:54 -05006152 1.0.17 10 10017 12.so.0.1.0.17
6153 1.2.7 13 10207 12.so.0.1.2.7
Glenn Randers-Pehrson40936072004-11-20 11:18:40 -06006154 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
Glenn Randers-Pehrson584b96e2004-11-29 15:08:00 -06006155 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
6156 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06006157 1.0.18 10 10018 12.so.0.1.0.18
6158 1.2.8 13 10208 12.so.0.1.2.8
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06006159 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -06006160 1.2.9beta4-11 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrson3a512032006-03-31 05:29:33 -06006161 1.2.9rc1 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsona7d0c942006-04-14 06:22:52 -05006162 1.2.9 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05006163 1.2.10beta1-7 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -05006164 1.2.10rc1-2 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson86dc9812006-05-10 07:27:44 -05006165 1.2.10 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05006166 1.4.0beta1-6 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05006167 1.2.11beta1-4 13 10210 12.so.0.11[.0]
Glenn Randers-Pehrson3424ee72006-07-12 13:33:47 -05006168 1.4.0beta7-8 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrson701dbaa2006-11-17 09:36:54 -06006169 1.2.11 13 10211 12.so.0.11[.0]
6170 1.2.12 13 10212 12.so.0.12[.0]
6171 1.4.0beta9-14 14 10400 14.so.0.0[.0]
6172 1.2.13 13 10213 12.so.0.13[.0]
Glenn Randers-Pehrson97a9b482008-10-25 20:03:28 -05006173 1.4.0beta15-36 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsonfa028102009-10-10 06:15:21 -05006174 1.4.0beta37-87 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson733da8c2009-10-30 00:00:15 -05006175 1.4.0rc01 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06006176 1.4.0beta88-109 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson67a83db2010-01-01 18:26:18 -06006177 1.4.0rc02-08 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsondbcfb712009-12-25 14:24:18 -06006178 1.4.0 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06006179 1.4.1beta01-03 14 10401 14.so.14.1[.0]
6180 1.4.1rc01 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06006181 1.4.1beta04-12 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrsonaaf377c2010-03-08 11:20:30 -06006182 1.4.1 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrson5b3d5542010-06-18 21:55:53 -05006183 1.4.2 14 10402 14.so.14.2[.0]
6184 1.4.3 14 10403 14.so.14.3[.0]
Glenn Randers-Pehrson2776d5e2010-11-21 15:18:02 -06006185 1.4.4 14 10404 14.so.14.4[.0]
Glenn Randers-Pehrsonfd20a5a2010-12-27 08:53:08 -06006186 1.5.0beta01-58 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrson64b863c2011-01-04 09:57:06 -06006187 1.5.0rc01-07 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrsonf5ea1b72011-01-06 06:42:51 -06006188 1.5.0 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrsonef123cc2011-01-28 15:20:34 -06006189 1.5.1beta01-11 15 10501 15.so.15.1[.0]
Glenn Randers-Pehrson3d3aae12011-02-02 22:58:27 -06006190 1.5.1rc01-02 15 10501 15.so.15.1[.0]
6191 1.5.1 15 10501 15.so.15.1[.0]
Glenn Randers-Pehrsonf3dd1cc2011-03-18 22:02:20 -05006192 1.5.2beta01-03 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrson77fd0832011-03-24 08:59:48 -05006193 1.5.2rc01-03 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrsondcc35052011-03-31 11:23:49 -05006194 1.5.2 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrson36edbb52011-06-03 07:15:04 -05006195 1.5.3beta01-10 15 10503 15.so.15.3[.0]
Glenn Randers-Pehrsonfb278732011-06-10 20:43:39 -05006196 1.5.3rc01-02 15 10503 15.so.15.3[.0]
Glenn Randers-Pehrson413138a2011-06-13 22:07:37 -05006197 1.5.3beta11 15 10503 15.so.15.3[.0]
6198 1.5.3 [omitted]
Glenn Randers-Pehrson9daf91e2011-06-22 23:10:36 -05006199 1.5.4beta01-08 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrson78bb9da2011-06-30 18:59:45 -05006200 1.5.4rc01 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrsond404b6d2011-07-07 06:24:57 -05006201 1.5.4 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrson3c2ae602011-09-09 06:02:09 -05006202 1.5.5beta01-08 15 10505 15.so.15.5[.0]
6203 1.5.5rc01 15 10505 15.so.15.5[.0]
Glenn Randers-Pehrson3e2263a2011-09-22 08:40:32 -05006204 1.5.5 15 10505 15.so.15.5[.0]
Glenn Randers-Pehrson93254f62011-10-26 08:36:21 -05006205 1.5.6beta01-07 15 10506 15.so.15.6[.0]
Glenn Randers-Pehrsonbc6726b2011-11-02 22:43:00 -05006206 1.5.6rc01-03 15 10506 15.so.15.6[.0]
6207 1.5.6 15 10506 15.so.15.6[.0]
Glenn Randers-Pehrson36251d32011-11-17 21:14:34 -06006208 1.5.7beta01-05 15 10507 15.so.15.7[.0]
Glenn Randers-Pehrsonb74fb4e2011-12-21 08:37:46 -06006209 1.5.7rc01-03 15 10507 15.so.15.7[.0]
6210 1.5.7 15 10507 15.so.15.7[.0]
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06006211 1.6.0beta01-15 16 10600 16.so.16.0[.0]
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006212
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06006213Henceforth the source version will match the shared-library minor
6214and patch numbers; the shared-library major version number will be
6215used for changes in backward compatibility, as it is intended. The
6216PNG_PNGLIB_VER macro, which is not used within libpng but is available
6217for applications, is an unsigned integer of the form xyyzz corresponding
6218to the source version x.y.z (leading zeros in y and z). Beta versions
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06006219were given the previous public release number plus a letter, until
6220version 1.0.6j; from then on they were given the upcoming public
6221release number plus "betaNN" or "rcN".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06006222
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006223.SH "SEE ALSO"
Glenn Randers-Pehrson4e763f12010-03-03 10:45:50 -06006224.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
Glenn Randers-Pehrson7fb32a82010-03-03 09:47:49 -06006225
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06006226.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006227.IR libpng :
6228.IP
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05006229http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06006230http://www.libpng.org/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006231
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06006232.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006233.IR zlib :
6234.IP
6235(generally) at the same location as
6236.I libpng
6237or at
6238.br
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06006239ftp://ftp.info-zip.org/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006240
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06006241.LP
6242.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006243.IP
6244(generally) at the same location as
6245.I libpng
6246or at
6247.br
6248ftp://ds.internic.net/rfc/rfc2083.txt
6249.br
6250or (as a W3C Recommendation) at
6251.br
6252http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006253
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06006254.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006255In the case of any inconsistency between the PNG specification
6256and this library, the specification takes precedence.
6257
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006258.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006259This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06006260<glennrp at users.sourceforge.net>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006261
6262The contributing authors would like to thank all those who helped
6263with testing, bug fixes, and patience. This wouldn't have been
6264possible without all of you.
6265
6266Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06006267
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06006268Libpng version 1.6.0beta15 - February 27, 2012:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006269Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06006270Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006271
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006272Supported by the PNG development group
6273.br
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06006274png-mng-implement at lists.sf.net
6275(subscription required; visit
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -06006276png-mng-implement at lists.sourceforge.net (subscription required; visit
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06006277https://lists.sourceforge.net/lists/listinfo/png-mng-implement
6278to subscribe).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006279
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006280.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006281
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06006282(This copy of the libpng notices is provided for your convenience. In case of
6283any discrepancy between this copy and the notices in the file png.h that is
6284included in the libpng distribution, the latter shall prevail.)
6285
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006286If you modify libpng you may insert additional notices immediately following
6287this sentence.
6288
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05006289This code is released under the libpng license.
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05006290
Glenn Randers-Pehrsonb7e32052012-02-26 21:32:02 -06006291libpng versions 1.2.6, August 15, 2004, through 1.6.0beta15, February 27, 2012, are
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05006292Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05006293distributed according to the same disclaimer and license as libpng-1.2.5
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05006294with the following individual added to the list of Contributing Authors
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05006295
6296 Cosmin Truta
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05006297
6298libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06006299Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson32fc5ce2000-07-24 06:34:14 -05006300distributed according to the same disclaimer and license as libpng-1.0.6
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006301with the following individuals added to the list of Contributing Authors
6302
6303 Simon-Pierre Cadieux
6304 Eric S. Raymond
6305 Gilles Vollant
6306
6307and with the following additions to the disclaimer:
6308
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06006309 There is no warranty against interference with your
6310 enjoyment of the library or against infringement.
6311 There is no warranty that our efforts or the library
6312 will fulfill any of your particular purposes or needs.
6313 This library is provided with all faults, and the entire
6314 risk of satisfactory quality, performance, accuracy, and
6315 effort is with the user.
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006316
6317libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
6318Copyright (c) 1998, 1999 Glenn Randers-Pehrson
6319Distributed according to the same disclaimer and license as libpng-0.96,
6320with the following individuals added to the list of Contributing Authors:
6321
6322 Tom Lane
6323 Glenn Randers-Pehrson
6324 Willem van Schaik
6325
6326libpng versions 0.89, June 1996, through 0.96, May 1997, are
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05006327Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006328Distributed according to the same disclaimer and license as libpng-0.88,
6329with the following individuals added to the list of Contributing Authors:
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05006330
6331 John Bowler
6332 Kevin Bracey
6333 Sam Bushell
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05006334 Magnus Holmgren
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05006335 Greg Roelofs
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006336 Tom Tanner
6337
6338libpng versions 0.5, May 1995, through 0.88, January 1996, are
6339Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
6340
6341For the purposes of this copyright and license, "Contributing Authors"
6342is defined as the following set of individuals:
6343
6344 Andreas Dilger
6345 Dave Martindale
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05006346 Guy Eric Schalnat
6347 Paul Schmidt
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05006348 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06006349
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006350The PNG Reference Library is supplied "AS IS". The Contributing Authors
6351and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006352including, without limitation, the warranties of merchantability and of
6353fitness for any purpose. The Contributing Authors and Group 42, Inc.
6354assume no liability for direct, indirect, incidental, special, exemplary,
6355or consequential damages, which may result from the use of the PNG
6356Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06006357
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006358Permission is hereby granted to use, copy, modify, and distribute this
6359source code, or portions hereof, for any purpose, without fee, subject
6360to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006361
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -050063621. The origin of this source code must not be misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006363
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060063642. Altered versions must be plainly marked as such and
6365 must not be misrepresented as being the original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006366
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060063673. This Copyright notice may not be removed or altered from
6368 any source or altered source distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006369
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006370The Contributing Authors and Group 42, Inc. specifically permit, without
6371fee, and encourage the use of this source code as a component to
6372supporting the PNG file format in commercial products. If you use this
6373source code in a product, acknowledgment is not required but would be
6374appreciated.
6375
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006376
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05006377A "png_get_copyright" function is available, for convenient use in "about"
6378boxes and the like:
6379
6380 printf("%s",png_get_copyright(NULL));
6381
6382Also, the PNG logo (in PNG format, of course) is supplied in the
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -05006383files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05006384
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006385Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05006386certification mark of the Open Source Initiative.
6387
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006388Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06006389glennrp at users.sourceforge.net
Glenn Randers-Pehrsonfaf38ee2012-02-26 21:11:25 -06006390February 27, 2012
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05006391
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06006392.\" end of man page
6393