blob: dab4e9313f84b513be2cdeccc8dc8c1b0d12205d [file] [log] [blame]
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001.TH LIBPNG 3 "July 26, 2011"
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06002.SH NAME
Glenn Randers-Pehrsone9ef47f2011-07-14 08:18:24 -05003libpng \- Portable Network Graphics (PNG) Reference Library 1.5.5beta03
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06004.SH SYNOPSIS
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -05005\fI\fB
6
7\fB#include <png.h>\fP
8
9\fI\fB
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060010
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -050011\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
12
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050013\fI\fB
14
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -050015\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
16
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050017\fI\fB
18
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060019\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
20
21\fI\fB
22
23\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
24
25\fI\fB
26
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -050027\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
28
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050029\fI\fB
30
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050031\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060032
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050033\fI\fB
34
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050035\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060036
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050037\fI\fB
38
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050039\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060040
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050041\fI\fB
42
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050043\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060044
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050045\fI\fB
46
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050047\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -060048
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050049\fI\fB
50
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050051\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060052
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050053\fI\fB
54
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060055\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050056
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050057\fI\fB
58
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060059\fBpng_structp png_create_read_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050060
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050061\fI\fB
62
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -060063\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050064
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050065\fI\fB
66
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060067\fBpng_structp png_create_write_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
68
69\fI\fB
70
71\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050072
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050073\fI\fB
74
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050075\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
76
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050077\fI\fB
78
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050079\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
80
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050081\fI\fB
82
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050083\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
84
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050085\fI\fB
86
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -060087\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
88
89\fI\fB
90
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050091\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
92
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050093\fI\fB
94
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050095\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
96
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -050097\fI\fB
98
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060099\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
100
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500101\fI\fB
102
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600103\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500104
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500105\fI\fB
106
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600107\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600108
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500109\fI\fB
110
John Bowler0a5c9c02011-01-22 17:36:34 -0600111\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500112
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500113\fI\fB
114
John Bowler0a5c9c02011-01-22 17:36:34 -0600115\fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500116
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500117\fI\fB
118
John Bowler0a5c9c02011-01-22 17:36:34 -0600119\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500120
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500121\fI\fB
122
John Bowler0a5c9c02011-01-22 17:36:34 -0600123\fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500124
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500125\fI\fB
126
John Bowler0a5c9c02011-01-22 17:36:34 -0600127\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600128
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500129\fI\fB
130
John Bowler0a5c9c02011-01-22 17:36:34 -0600131\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500132
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500133\fI\fB
134
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600135\fI\fB
136
John Bowler0a5c9c02011-01-22 17:36:34 -0600137\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 -0600138
139\fI\fB
140
John Bowler0a5c9c02011-01-22 17:36:34 -0600141\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 -0500142
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500143\fI\fB
144
John Bowler0a5c9c02011-01-22 17:36:34 -0600145\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500146
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500147\fI\fB
148
John Bowler0a5c9c02011-01-22 17:36:34 -0600149\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 -0500150
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500151\fI\fB
152
John Bowler0a5c9c02011-01-22 17:36:34 -0600153\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500154
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500155\fI\fB
156
John Bowlerf19abd62011-01-22 18:29:24 -0600157\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP
158
159\fI\fB
160
161\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
162
163\fI\fB
164
John Bowler0a5c9c02011-01-22 17:36:34 -0600165\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500166
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500167\fI\fB
168
John Bowler0a5c9c02011-01-22 17:36:34 -0600169\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 -0500170
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500171\fI\fB
172
John Bowler0a5c9c02011-01-22 17:36:34 -0600173\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 -0500174
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500175\fI\fB
176
John Bowler0a5c9c02011-01-22 17:36:34 -0600177\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 -0600178
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500179\fI\fB
180
John Bowler0a5c9c02011-01-22 17:36:34 -0600181\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600182
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500183\fI\fB
184
John Bowler0a5c9c02011-01-22 17:36:34 -0600185\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500186
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500187\fI\fB
188
John Bowler0a5c9c02011-01-22 17:36:34 -0600189\fBpng_uint_32 png_get_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 -0500190
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500191\fI\fB
192
John Bowler0a5c9c02011-01-22 17:36:34 -0600193\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 -0600194
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500195\fI\fB
196
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500197\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
198
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500199\fI\fB
200
John Bowler0a5c9c02011-01-22 17:36:34 -0600201\fBpng_uint_32 png_get_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 -0500202
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500203\fI\fB
204
John Bowler0a5c9c02011-01-22 17:36:34 -0600205\fBpng_uint_32 png_get_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 -0500206
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500207\fI\fB
208
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500209\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
210
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500211\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600212
John Bowler0a5c9c02011-01-22 17:36:34 -0600213\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 -0500214
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500215\fI\fB
216
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600217\fBpng_const_bytep png_get_io_chunk_name (png_structp \fIpng_ptr\fP\fB);\fP
218
219\fI\fB
220
John Bowler0a5c9c02011-01-22 17:36:34 -0600221\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -0600222
223\fI\fB
224
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500225\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
226
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500227\fI\fB
228
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -0600229\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
230
231\fI\fB
232
John Bowler0a5c9c02011-01-22 17:36:34 -0600233\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600234
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500235\fI\fB
236
John Bowler0a5c9c02011-01-22 17:36:34 -0600237\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500238
239\fI\fB
240
John Bowler0a5c9c02011-01-22 17:36:34 -0600241\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 -0500242
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500243\fI\fB
244
John Bowler0a5c9c02011-01-22 17:36:34 -0600245\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 -0500246
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500247\fI\fB
248
John Bowler0a5c9c02011-01-22 17:36:34 -0600249\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 -0500250
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500251\fI\fB
252
John Bowler0a5c9c02011-01-22 17:36:34 -0600253\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 -0500254
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500255\fI\fB
256
John Bowler0a5c9c02011-01-22 17:36:34 -0600257\fBpng_uint_32 png_get_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 -0600258
259\fI\fB
260
John Bowler0a5c9c02011-01-22 17:36:34 -0600261\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 -0500262
263\fI\fB
264
John Bowler0a5c9c02011-01-22 17:36:34 -0600265\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 -0600266
267\fI\fB
268
John Bowler0a5c9c02011-01-22 17:36:34 -0600269\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 -0500270
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500271\fI\fB
272
John Bowler0a5c9c02011-01-22 17:36:34 -0600273\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500274
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500275\fI\fB
276
John Bowler0a5c9c02011-01-22 17:36:34 -0600277\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 -0500278
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500279\fI\fB
280
John Bowler0a5c9c02011-01-22 17:36:34 -0600281\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr)
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500282
John Bowler0a5c9c02011-01-22 17:36:34 -0600283\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500284
285\fI\fB
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500286
John Bowler0a5c9c02011-01-22 17:36:34 -0600287\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 -0600288
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500289\fI\fB
290
John Bowler0a5c9c02011-01-22 17:36:34 -0600291\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 -0500292
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500293\fI\fB
294
John Bowler0a5c9c02011-01-22 17:36:34 -0600295\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 -0500296
297\fI\fB
298
John Bowler0a5c9c02011-01-22 17:36:34 -0600299\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 -0500300
301\fI\fB
302
John Bowler0a5c9c02011-01-22 17:36:34 -0600303\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 -0500304
305\fI\fB
306
John Bowler0a5c9c02011-01-22 17:36:34 -0600307\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 -0500308
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500309\fI\fB
310
John Bowler0a5c9c02011-01-22 17:36:34 -0600311\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 -0600312
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500313\fI\fB
314
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600315\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 -0500316
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500317\fI\fB
318
John Bowler0a5c9c02011-01-22 17:36:34 -0600319\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 -0500320
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500321\fI\fB
322
John Bowler0a5c9c02011-01-22 17:36:34 -0600323\fBpng_uint_32 png_get_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 -0500324
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500325\fI\fB
326
John Bowler0a5c9c02011-01-22 17:36:34 -0600327\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 -0500328
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500329\fI\fB
330
331\fB/* This function is really an inline macro. \fI*/
332
333\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
334
335\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600336
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -0600337\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 -0600338
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500339\fI\fB
340
341\fB/* This function is really an inline macro. \fI*/
342
343\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
344
345\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600346
John Bowler0a5c9c02011-01-22 17:36:34 -0600347\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 -0600348
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500349\fI\fB
350
John Bowler0a5c9c02011-01-22 17:36:34 -0600351\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600352
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500353\fI\fB
354
John Bowler0a5c9c02011-01-22 17:36:34 -0600355\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500356
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500357\fI\fB
358
John Bowler0a5c9c02011-01-22 17:36:34 -0600359\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500360
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500361\fI\fB
362
John Bowler0a5c9c02011-01-22 17:36:34 -0600363\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500364
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500365\fI\fB
366
John Bowler0a5c9c02011-01-22 17:36:34 -0600367\fBpng_uint_32 png_get_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 -0500368
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500369\fI\fB
370
John Bowler0a5c9c02011-01-22 17:36:34 -0600371\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 -0500372
373\fI\fB
374
John Bowler0a5c9c02011-01-22 17:36:34 -0600375\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 -0500376
377\fI\fB
378
John Bowler0a5c9c02011-01-22 17:36:34 -0600379\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 -0500380
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500381\fI\fB
382
John Bowler0a5c9c02011-01-22 17:36:34 -0600383\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 -0500384
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500385\fI\fB
386
John Bowler0a5c9c02011-01-22 17:36:34 -0600387\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 -0600388
389\fI\fB
390
John Bowler0a5c9c02011-01-22 17:36:34 -0600391\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 -0500392
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500393\fI\fB
394
John Bowler0a5c9c02011-01-22 17:36:34 -0600395\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 -0500396
397\fI\fB
398
John Bowler0a5c9c02011-01-22 17:36:34 -0600399\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 -0500400
401\fI\fB
402
John Bowler0a5c9c02011-01-22 17:36:34 -0600403\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 -0500404
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500405\fI\fB
406
John Bowler0a5c9c02011-01-22 17:36:34 -0600407\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 -0500408
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500409\fI\fB
410
John Bowler0a5c9c02011-01-22 17:36:34 -0600411\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 -0600412
413\fI\fB
414
John Bowler0a5c9c02011-01-22 17:36:34 -0600415\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 -0500416
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500417\fI\fB
418
Glenn Randers-Pehrsonc1bfe682002-03-06 22:08:00 -0600419\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
420
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500421\fI\fB
422
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600423\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
424
425\fI\fB
426
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500427\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 -0500428
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500429\fI\fB
430
Glenn Randers-Pehrsonf98726a2010-02-19 09:54:53 -0600431\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
432
433\fI\fB
434
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500435\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 -0500436
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500437\fI\fB
438
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600439\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
440
441\fI\fB
442
443\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
444
445\fI\fB
446
447\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 -0500448
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500449\fI\fB
450
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500451\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
452
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500453\fI\fB
454
John Bowlerf19abd62011-01-22 18:29:24 -0600455\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
456
457\fI\fB
458
459\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
460
461\fI\fB
462
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500463\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
464
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500465\fI\fB
466
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500467\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
468
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500469\fI\fB
470
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500471\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
472
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500473\fI\fB
474
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500475\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
476
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500477\fI\fB
478
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600479\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 -0600480
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500481\fI\fB
482
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500483\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
484
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500485\fI\fB
486
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500487\fBvoid png_read_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
488
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500489\fI\fB
490
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500491\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
492
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500493\fI\fB
494
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600495\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
496
497\fI\fB
498
499\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 -0500500
501\fI\fB
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600502
503\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
504
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500505\fI\fB
506
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -0600507\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
508
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500509\fI\fB
510
511\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
512
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500513\fI\fB
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -0500514
Glenn Randers-Pehrsonc7822512011-05-07 21:23:43 -0500515\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP
516
517\fI\fB
518
519\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
520
521\fI\fB
522
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500523\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
524
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500525\fI\fB
526
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500527\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
528
529\fI\fB
530
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600531\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
532
533\fI\fB
534
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500535\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
536
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500537\fI\fB
538
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500539\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
540
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500541\fI\fB
542
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500543\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
544
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500545\fI\fB
546
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600547\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
548
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500549\fI\fB
550
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -0500551\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
552
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500553\fI\fB
554
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500555\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
556
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500557\fI\fB
558
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500559\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
560
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500561\fI\fB
562
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500563\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
564
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500565\fI\fB
566
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500567\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 -0600568
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500569\fI\fB
570
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500571\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 -0600572
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500573\fI\fB
574
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500575\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 -0600576
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500577\fI\fB
578
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500579\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 -0600580
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500581\fI\fB
582
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -0600583\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsonc85f5f62011-02-13 05:56:07 -0600584
585\fI\fB
586
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -0600587\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600588
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500589\fI\fB
590
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600591\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 -0600592
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500593\fI\fB
594
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500595\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 -0600596
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500597\fI\fB
598
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500599\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 -0600600
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500601\fI\fB
602
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500603\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 -0500604
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500605\fI\fB
606
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500607\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
608
609\fI\fB
610
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500611\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600612
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500613\fI\fB
614
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500615\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 -0600616
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500617\fI\fB
618
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500619\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
620
621\fI\fB
622
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500623\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600624
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500625\fI\fB
626
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600627\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
628
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500629\fI\fB
630
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600631\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600632
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500633\fI\fB
634
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500635\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600636
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500637\fI\fB
638
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500639\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 -0600640
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500641\fI\fB
642
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -0600643\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 -0600644
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500645\fI\fB
646
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500647\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600648
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500649\fI\fB
650
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -0500651\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
652
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500653\fI\fB
654
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500655\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600656
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500657\fI\fB
658
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500659\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600660
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500661\fI\fB
662
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500663\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 -0600664
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500665\fI\fB
666
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600667\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 -0600668
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500669\fI\fB
670
Glenn Randers-Pehrson1e6ed732009-11-20 22:06:56 -0600671\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
672
673\fI\fB
674
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600675\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
676
677\fI\fB
678
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600679\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
680
681\fI\fB
682
683\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 -0600684
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500685\fI\fB
686
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500687\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 -0600688
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500689\fI\fB
690
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500691\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600692
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500693\fI\fB
694
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500695\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600696
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500697\fI\fB
698
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600699\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600700
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500701\fI\fB
702
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500703\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 -0600704
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500705\fI\fB
706
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500707\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 -0600708
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500709\fI\fB
710
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500711\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 -0600712
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500713\fI\fB
714
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500715\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 -0600716
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500717\fI\fB
718
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -0500719\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
720
721\fI\fB
722
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500723\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 -0600724
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500725\fI\fB
726
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500727\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 -0600728
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500729\fI\fB
730
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600731\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
732
733\fI\fB
734
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500735\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 -0600736
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500737\fI\fB
738
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600739\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
740
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500741\fI\fB
742
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500743\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 -0600744
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500745\fI\fB
746
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600747\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
748
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500749\fI\fB
750
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500751\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 -0600752
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500753\fI\fB
754
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -0500755\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
756
757\fI\fB
758
759\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
760
761\fI\fB
762
763\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
764
765\fI\fB
766
Glenn Randers-Pehrsonc4a82142011-06-18 00:44:08 -0500767\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
768
769\fI\fB
770
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500771\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 -0600772
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500773\fI\fB
774
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500775\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 -0600776
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500777\fI\fB
778
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600779\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 -0600780
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500781\fI\fB
782
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600783\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 -0600784
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500785\fI\fB
786
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -0600787\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 -0600788
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500789\fI\fB
790
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500791\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600792
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500793\fI\fB
794
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500795\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600796
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500797\fI\fB
798
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600799\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
800
801\fI\fB
802
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500803\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600804
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500805\fI\fB
806
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500807\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600808
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500809\fI\fB
810
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500811\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 -0600812
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500813\fI\fB
814
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -0500815\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
816
817\fI\fB
818
819\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
820
821\fI\fB
822
823\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
824
825\fI\fB
826
827\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
828
829\fI\fB
830
831\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
832
833\fI\fB
834
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500835\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 -0600836
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500837\fI\fB
838
Glenn Randers-Pehrsonf3c51e42011-01-15 10:25:25 -0600839\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 -0500840
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500841\fI\fB
842
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600843\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600844
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500845\fI\fB
846
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600847\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
848
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500849\fI\fB
850
Glenn Randers-Pehrsonbb98bcb2011-01-22 16:27:39 -0600851\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 -0600852
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500853\fI\fB
854
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500855\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
856
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500857\fI\fB
858
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500859\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 -0600860
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500861\fI\fB
862
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500863\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 -0600864
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500865\fI\fB
866
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500867\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 -0600868
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500869\fI\fB
870
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500871\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 -0600872
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500873\fI\fB
874
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500875\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 -0600876
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500877\fI\fB
878
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500879\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600880
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500881\fI\fB
882
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500883\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 -0600884
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500885\fI\fB
886
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500887\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 -0600888
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500889\fI\fB
890
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500891\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 -0600892
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500893\fI\fB
894
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500895\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600896
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500897\fI\fB
898
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500899\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 -0600900
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500901\fI\fB
902
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500903\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 -0600904
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500905\fI\fB
906
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500907\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600908
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500909\fI\fB
910
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500911\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 -0600912
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500913\fI\fB
914
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500915\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 -0600916
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500917\fI\fB
918
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600919\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
920
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500921\fI\fB
922
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600923\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 -0600924
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500925\fI\fB
926
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500927\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 -0600928
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500929\fI\fB
930
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500931\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 -0600932
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500933\fI\fB
934
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500935\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
936
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500937\fI\fB
938
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500939\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
940
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500941\fI\fB
942
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500943\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
944
Glenn Randers-Pehrsonad81d712009-07-30 15:39:00 -0500945\fI\fB
946
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600947.SH DESCRIPTION
948The
949.I libpng
950library supports encoding, decoding, and various manipulations of
951the Portable Network Graphics (PNG) format image files. It uses the
952.IR zlib(3)
953compression library.
Glenn Randers-Pehrson557b2562010-10-17 12:55:04 -0500954Following is a copy of the libpng-manual.txt file that accompanies libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600955.SH LIBPNG.TXT
Glenn Randers-Pehrson557b2562010-10-17 12:55:04 -0500956libpng-manual.txt - A description on how to use and modify libpng
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600957
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -0500958 libpng version 1.5.5beta03 - July 26, 2011
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600959 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -0600960 <glennrp at users.sourceforge.net>
Glenn Randers-Pehrson9f45c8e2011-01-15 19:35:03 -0600961 Copyright (c) 1998-2011 Glenn Randers-Pehrson
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -0500962
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -0500963 This document is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -0500964 For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -0500965 and license in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600966
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500967 Based on:
968
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -0500969 libpng versions 0.97, January 1998, through 1.5.5beta03 - July 26, 2011
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500970 Updated and distributed by Glenn Randers-Pehrson
Glenn Randers-Pehrson9f45c8e2011-01-15 19:35:03 -0600971 Copyright (c) 1998-2011 Glenn Randers-Pehrson
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600972
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600973 libpng 1.0 beta 6 version 0.96 May 28, 1997
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600974 Updated and distributed by Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600975 Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600976
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600977 libpng 1.0 beta 2 - version 0.88 January 26, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600978 For conditions of distribution and use, see copyright
979 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600980 Schalnat, Group 42, Inc.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600981
982 Updated/rewritten per request in the libpng FAQ
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600983 Copyright (c) 1995, 1996 Frank J. T. Wojcik
984 December 18, 1995 & January 20, 1996
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600985
986.SH I. Introduction
987
988This file describes how to use and modify the PNG reference library
989(known as libpng) for your own use. There are five sections to this
990file: introduction, structures, reading, writing, and modification and
991configuration notes for various special platforms. In addition to this
992file, example.c is a good starting point for using the library, as
993it is heavily commented and should include everything most people
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600994will need. We assume that libpng is already installed; see the
995INSTALL file for instructions on how to install libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600996
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -0500997For examples of libpng usage, see the files "example.c", "pngtest.c",
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -0600998and the files in the "contrib" directory, all of which are included in
999the libpng distribution.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001000
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001001Libpng was written as a companion to the PNG specification, as a way
1002of reducing the amount of time and effort it takes to support the PNG
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001003file format in application programs.
1004
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001005The PNG specification (second edition), November 2003, is available as
1006a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
1007<http://www.w3.org/TR/2003/REC-PNG-20031110/
1008The W3C and ISO documents have identical technical content.
1009
1010The PNG-1.2 specification is available at
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001011<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
1012to the PNG specification (second edition) but has some additional material.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001013
1014The PNG-1.0 specification is available
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001015as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001016W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
1017
1018Some additional chunks are described in the special-purpose public chunks
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001019documents at <http://www.libpng.org/pub/png/documents/>.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001020
1021Other information
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001022about PNG, and the latest version of libpng, can be found at the PNG home
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001023page, <http://www.libpng.org/pub/png/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001024
1025Most users will not have to modify the library significantly; advanced
1026users may want to modify it more. All attempts were made to make it as
1027complete as possible, while keeping the code easy to understand.
1028Currently, this library only supports C. Support for other languages
1029is being considered.
1030
1031Libpng has been designed to handle multiple sessions at one time,
1032to be easily modifiable, to be portable to the vast majority of
1033machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
1034to use. The ultimate goal of libpng is to promote the acceptance of
1035the PNG file format in whatever way possible. While there is still
1036work to be done (see the TODO file), libpng should cover the
1037majority of the needs of its users.
1038
1039Libpng uses zlib for its compression and decompression of PNG files.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001040Further information about zlib, and the latest version of zlib, can
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001041be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001042The zlib compression utility is a general purpose utility that is
1043useful for more than PNG files, and can be used without libpng.
1044See the documentation delivered with zlib for more details.
1045You can usually find the source files for the zlib utility wherever you
1046find the libpng source files.
1047
1048Libpng is thread safe, provided the threads are using different
1049instances of the structures. Each thread should have its own
1050png_struct and png_info instances, and thus its own image.
1051Libpng does not protect itself against two threads using the
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05001052same instance of a structure.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001053
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001054.SH II. Structures
1055
1056There are two main structures that are important to libpng, png_struct
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001057and png_info. Both are internal structures that are no longer exposed
1058in the libpng interface (as of libpng 1.5.0).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001059
1060The png_info structure is designed to provide information about the
1061PNG file. At one time, the fields of png_info were intended to be
1062directly accessible to the user. However, this tended to cause problems
1063with applications using dynamically loaded libraries, and as a result
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001064a set of interface functions for png_info (the png_get_*() and png_set_*()
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001065functions) was developed, and direct access to the png_info fields was
1066deprecated..
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001067
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001068The png_struct structure is the object used by the library to decode a
1069single image. As of 1.5.0 this structure is also not exposed.
1070
1071Almost all libpng APIs require a pointer to a png_struct as the first argument.
1072Many (in particular the png_set and png_get APIs) also require a pointer
1073to png_info as the second argument. Some application visible macros
1074defined in png.h designed for basic data access (reading and writing
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001075integers in the PNG format) don't take a png_info pointer, but it's almost
1076always safe to assume that a (png_struct*) has to be passed to call an API
1077function.
1078
1079You can have more than one png_info structure associated with an image,
1080as illustrated in pngtest.c, one for information valid prior to the
1081IDAT chunks and another (called "end_info" below) for things after them.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001082
1083The png.h header file is an invaluable reference for programming with libpng.
1084And while I'm on the topic, make sure you include the libpng header file:
1085
1086#include <png.h>
1087
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001088and also (as of libpng-1.5.0) the zlib header file, if you need it:
1089
1090#include <zlib.h>
1091
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001092.SS Types
1093
1094The png.h header file defines a number of integral types used by the
1095APIs. Most of these are fairly obvious; for example types corresponding
1096to integers of particular sizes and types for passing color values.
1097
1098One exception is how non-integral numbers are handled. For application
1099convenience most APIs that take such numbers have C (double) arguments,
1100however internally PNG, and libpng, use 32 bit signed integers and encode
1101the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
1102macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
1103which is simply (png_int_32).
1104
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001105All APIs that take (double) arguments also have a matching API that
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001106takes the corresponding fixed point integer arguments. The fixed point
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001107API has the same name as the floating point one with "_fixed" appended.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001108The actual range of values permitted in the APIs is frequently less than
1109the full range of (png_fixed_point) (-21474 to +21474). When APIs require
1110a non-negative argument the type is recorded as png_uint_32 above. Consult
1111the header file and the text below for more information.
1112
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001113Special care must be take with sCAL chunk handling because the chunk itself
1114uses non-integral values encoded as strings containing decimal floating point
1115numbers. See the comments in the header file.
1116
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001117.SS Configuration
1118
1119The main header file function declarations are frequently protected by C
1120preprocessing directives of the form:
1121
1122 #ifdef PNG_feature_SUPPORTED
1123 declare-function
1124 #endif
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001125 ...
1126 #ifdef PNG_feature_SUPPORTED
1127 use-function
1128 #endif
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05001129
1130The library can be built without support for these APIs, although a
1131standard build will have all implemented APIs. Application programs
1132should check the feature macros before using an API for maximum
1133portability. From libpng 1.5.0 the feature macros set during the build
1134of libpng are recorded in the header file "pnglibconf.h" and this file
1135is always included by png.h.
1136
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001137If you don't need to change the library configuration from the default, skip to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001138the next section ("Reading").
1139
1140Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
1141of the build project files in the 'projects' directory simply copy
1142scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
1143systems do not permit easy auto-configuration of the library - they only
1144support the default configuration.
1145
1146The easiest way to make minor changes to the libpng configuration when
1147auto-configuration is supported is to add definitions to the command line
1148using (typically) CPPFLAGS. For example:
1149
1150CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
1151
1152will change the internal libpng math implementation for gamma correction and
1153other arithmetic calculations to fixed point, avoiding the need for fast
1154floating point support. The result can be seen in the generated pnglibconf.h -
1155make sure it contains the changed feature macro setting.
1156
1157If you need to make more extensive configuration changes - more than one or two
1158feature macro settings - you can either add -DPNG_USER_CONFIG to the build
1159command line and put a list of feature macro settings in pngusr.h or you can set
1160DFA_XTRA (a makefile variable) to a file containing the same information in the
1161form of 'option' settings.
1162
1163A. Changing pnglibconf.h
1164
1165A variety of methods exist to build libpng. Not all of these support
1166reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
1167rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
1168
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001169Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
1170pnglibconf.h and changing the lines defining the supported features, paying
1171very close attention to the 'option' information in scripts/pnglibconf.dfa
1172that describes those features and their requirements. This is easy to get
1173wrong.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001174
1175B. Configuration using DFA_XTRA
1176
1177Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
1178variant such as 'nawk' or 'gawk', is available. The configure build will
1179automatically find an appropriate awk and build pnglibconf.h.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001180The scripts/pnglibconf.mak file contains a set of make rules for doing the
1181same thing if configure is not used, and many of the makefiles in the scripts
1182directory use this approach.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001183
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001184When rebuilding simply write a new file containing changed options and set
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001185DFA_XTRA to the name of this file. This causes the build to append the new file
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001186to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
1187of the following forms:
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001188
1189everything = off
1190
1191This turns all optional features off. Include it at the start of pngusr.dfa to
1192make it easier to build a minimal configuration. You will need to turn at least
1193some features on afterward to enable either reading or writing code, or both.
1194
1195option feature on
1196option feature off
1197
1198Enable or disable a single feature. This will automatically enable other
1199features required by a feature that is turned on or disable other features that
1200require a feature which is turned off. Conflicting settings will cause an error
1201message to be emitted by awk.
1202
1203setting feature default value
1204
1205Changes the default value of setting 'feature' to 'value'. There are a small
1206number of settings listed at the top of pnglibconf.h, they are documented in the
1207source code. Most of these values have performance implications for the library
1208but most of them have no visible effect on the API. Some can also be overridden
1209from the API.
1210
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001211This method of building a customized pnglibconf.h is illustrated in
1212contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
1213pngusr.dfa in these directories.
1214
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001215C. Configuration using PNG_USR_CONFIG
1216
1217If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
1218pngusr.h will automatically be included before the options in
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001219scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
1220macro definitions turning features on or off or setting settings.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06001221
1222Apart from the global setting "everything = off" all the options listed above
1223can be set using macros in pngusr.h:
1224
1225#define PNG_feature_SUPPORTED
1226
1227is equivalent to:
1228
1229option feature on
1230
1231#define PNG_NO_feature
1232
1233is equivalent to:
1234
1235option feature off
1236
1237#define PNG_feature value
1238
1239is equivalent to:
1240
1241setting feature default value
1242
1243Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
1244pngusr file you supply override the contents of scripts/pnglibconf.dfa
1245
1246If confusing or incomprehensible behavior results it is possible to
1247examine the intermediate file pnglibconf.dfn to find the full set of
1248dependency information for each setting and option. Simply locate the
1249feature in the file and read the C comments that precede it.
1250
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05001251This method is also illustrated in the contrib/pngminim/* makefiles and
1252pngusr.h.
1253
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001254.SH III. Reading
1255
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001256We'll now walk you through the possible functions to call when reading
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001257in a PNG file sequentially, briefly explaining the syntax and purpose
1258of each one. See example.c and png.h for more detail. While
1259progressive reading is covered in the next section, you will still
1260need some of the functions discussed in this section to read a PNG
1261file.
1262
1263.SS Setup
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001264
1265You will want to do the I/O initialization(*) before you get into libpng,
1266so if it doesn't work, you don't have much to undo. Of course, you
1267will also want to insure that you are, in fact, dealing with a PNG
1268file. Libpng provides a simple check to see if a file is a PNG file.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05001269To use it, pass in the first 1 to 8 bytes of the file to the function
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05001270png_sig_cmp(), and it will return 0 (false) if the bytes match the
1271corresponding bytes of the PNG signature, or nonzero (true) otherwise.
1272Of course, the more bytes you pass in, the greater the accuracy of the
1273prediction.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001274
1275If you are intending to keep the file pointer open for use in libpng,
1276you must ensure you don't read more than 8 bytes from the beginning
1277of the file, and you also have to make a call to png_set_sig_bytes_read()
1278with the number of bytes you read from the beginning. Libpng will
1279then only check the bytes (if any) that your program didn't read.
1280
1281(*): If you are not using the standard I/O functions, you will need
1282to replace them with custom functions. See the discussion under
1283Customizing libpng.
1284
1285
1286 FILE *fp = fopen(file_name, "rb");
1287 if (!fp)
1288 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001289 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001290 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001291
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001292 fread(header, 1, number, fp);
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06001293 is_png = !png_sig_cmp(header, 0, number);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001294
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001295 if (!is_png)
1296 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001297 return (NOT_PNG);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001298 }
1299
1300
1301Next, png_struct and png_info need to be allocated and initialized. In
1302order to ensure that the size of these structures is correct even with a
1303dynamically linked libpng, there are functions to initialize and
1304allocate the structures. We also pass the library version, optional
1305pointers to error handling functions, and a pointer to a data struct for
1306use by the error functions, if necessary (the pointer and functions can
1307be NULL if the default error handlers are to be used). See the section
1308on Changes to Libpng below regarding the old initialization functions.
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001309The structure allocation functions quietly return NULL if they fail to
1310create the structure, so your application should check for that.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001311
1312 png_structp png_ptr = png_create_read_struct
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001313 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001314 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001315
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001316 if (!png_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001317 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001318
1319 png_infop info_ptr = png_create_info_struct(png_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001320
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001321 if (!info_ptr)
1322 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001323 png_destroy_read_struct(&png_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001324 (png_infopp)NULL, (png_infopp)NULL);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001325 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001326 }
1327
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001328If you want to use your own memory allocation routines,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001329use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001330png_create_read_struct_2() instead of png_create_read_struct():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001331
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001332 png_structp png_ptr = png_create_read_struct_2
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05001333 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001334 user_error_fn, user_warning_fn, (png_voidp)
1335 user_mem_ptr, user_malloc_fn, user_free_fn);
1336
1337The error handling routines passed to png_create_read_struct()
1338and the memory alloc/free routines passed to png_create_struct_2()
1339are only necessary if you are not using the libpng supplied error
1340handling and memory alloc/free functions.
1341
1342When libpng encounters an error, it expects to longjmp back
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001343to your routine. Therefore, you will need to call setjmp and pass
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001344your png_jmpbuf(png_ptr). If you read the file from different
John Bowlere6dc85b2011-04-27 14:47:15 -05001345routines, you will need to update the longjmp buffer every time you enter
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001346a new routine that will call a png_*() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001347
1348See your documentation of setjmp/longjmp for your compiler for more
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001349information on setjmp/longjmp. See the discussion on libpng error
1350handling in the Customizing Libpng section below for more information
1351on the libpng error handling. If an error occurs, and libpng longjmp's
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001352back to your setjmp, you will want to call png_destroy_read_struct() to
1353free any memory.
1354
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001355 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001356 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001357 png_destroy_read_struct(&png_ptr, &info_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001358 &end_info);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001359 fclose(fp);
1360 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001361 }
1362
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05001363Pass (png_infopp)NULL instead of &end_info if you didn't create
1364an end_info structure.
1365
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001366If you would rather avoid the complexity of setjmp/longjmp issues,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05001367you can compile libpng with PNG_NO_SETJMP, in which case
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001368errors will result in a call to PNG_ABORT() which defaults to abort().
1369
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05001370You can #define PNG_ABORT() to a function that does something
1371more useful than abort(), as long as your function does not
1372return.
1373
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001374Now you need to set up the input code. The default for libpng is to
1375use the C function fread(). If you use this, you will need to pass a
1376valid FILE * in the function png_init_io(). Be sure that the file is
1377opened in binary mode. If you wish to handle reading data in another
1378way, you need not call the png_init_io() function, but you must then
1379implement the libpng I/O methods discussed in the Customizing Libpng
1380section below.
1381
1382 png_init_io(png_ptr, fp);
1383
1384If you had previously opened the file and read any of the signature from
1385the beginning in order to see if this was a PNG file, you need to let
1386libpng know that there are some bytes missing from the start of the file.
1387
1388 png_set_sig_bytes(png_ptr, number);
1389
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001390You can change the zlib compression buffer size to be used while
1391reading compressed data with
1392
1393 png_set_compression_buffer_size(png_ptr, buffer_size);
1394
1395where the default size is 8192 bytes. Note that the buffer size
1396is changed immediately and the buffer is reallocated immediately,
1397instead of setting a flag to be acted upon later.
1398
Glenn Randers-Pehrson9dd1cdf2011-01-06 21:42:36 -06001399If you want CRC errors to be handled in a different manner than
1400the default, use
1401
1402 png_set_crc_action(png_ptr, crit_action, ancil_action);
1403
1404The values for png_set_crc_action() say how libpng is to handle CRC errors in
1405ancillary and critical chunks, and whether to use the data contained
1406therein. Note that it is impossible to "discard" data in a critical
1407chunk.
1408
1409Choices for (int) crit_action are
1410 PNG_CRC_DEFAULT 0 error/quit
1411 PNG_CRC_ERROR_QUIT 1 error/quit
1412 PNG_CRC_WARN_USE 3 warn/use data
1413 PNG_CRC_QUIET_USE 4 quiet/use data
1414 PNG_CRC_NO_CHANGE 5 use the current value
1415
1416Choices for (int) ancil_action are
1417 PNG_CRC_DEFAULT 0 error/quit
1418 PNG_CRC_ERROR_QUIT 1 error/quit
1419 PNG_CRC_WARN_DISCARD 2 warn/discard data
1420 PNG_CRC_WARN_USE 3 warn/use data
1421 PNG_CRC_QUIET_USE 4 quiet/use data
1422 PNG_CRC_NO_CHANGE 5 use the current value
1423
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001424.SS Setting up callback code
1425
1426You can set up a callback function to handle any unknown chunks in the
1427input stream. You must supply the function
1428
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06001429 read_chunk_callback(png_structp png_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001430 png_unknown_chunkp chunk);
1431 {
1432 /* The unknown chunk structure contains your
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001433 chunk data, along with similar data for any other
1434 unknown chunks: */
1435
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001436 png_byte name[5];
1437 png_byte *data;
1438 png_size_t size;
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001439
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001440 /* Note that libpng has already taken care of
1441 the CRC handling */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001442
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001443 /* put your code here. Search for your chunk in the
1444 unknown chunk structure, process it, and return one
1445 of the following: */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001446
1447 return (-n); /* chunk had an error */
1448 return (0); /* did not recognize */
1449 return (n); /* success */
1450 }
1451
1452(You can give your function another name that you like instead of
1453"read_chunk_callback")
1454
1455To inform libpng about your function, use
1456
1457 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1458 read_chunk_callback);
1459
1460This names not only the callback function, but also a user pointer that
1461you can retrieve with
1462
1463 png_get_user_chunk_ptr(png_ptr);
1464
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001465If you call the png_set_read_user_chunk_fn() function, then all unknown
1466chunks will be saved when read, in case your callback function will need
1467one or more of them. This behavior can be changed with the
1468png_set_keep_unknown_chunks() function, described below.
1469
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001470At this point, you can set up a callback function that will be
1471called after each row has been read, which you can use to control
1472a progress meter or the like. It's demonstrated in pngtest.c.
1473You must supply a function
1474
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06001475 void read_row_callback(png_structp png_ptr,
1476 png_uint_32 row, int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001477 {
1478 /* put your code here */
1479 }
1480
1481(You can give it another name that you like instead of "read_row_callback")
1482
1483To inform libpng about your function, use
1484
1485 png_set_read_status_fn(png_ptr, read_row_callback);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001486
John Bowler59010e52011-02-16 06:16:31 -06001487When this function is called the row has already been completely processed and
1488the 'row' and 'pass' refer to the next row to be handled. For the
1489non-interlaced case the row that was just handled is simply one less than the
1490passed in row number, and pass will always be 0. For the interlaced case the
1491same applies unless the row value is 0, in which case the row just handled was
1492the last one from one of the preceding passes. Because interlacing may skip a
1493pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1494need to know what the last pass is record (row,pass) from the callback and use
1495the last recorded value each time.
1496
1497As with the user transform you can find the output row using the
1498PNG_ROW_FROM_PASS_ROW macro.
1499
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001500.SS Unknown-chunk handling
1501
1502Now you get to set the way the library processes unknown chunks in the
1503input PNG stream. Both known and unknown chunks will be read. Normal
1504behavior is that known chunks will be parsed into information in
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001505various info_ptr members while unknown chunks will be discarded. This
1506behavior can be wasteful if your application will never use some known
1507chunk types. To change this, you can call:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001508
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001509 png_set_keep_unknown_chunks(png_ptr, keep,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001510 chunk_list, num_chunks);
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001511 keep - 0: default unknown chunk handling
1512 1: ignore; do not keep
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001513 2: keep only if safe-to-copy
1514 3: keep even if unsafe-to-copy
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001515
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001516 You can use these definitions:
1517 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1518 PNG_HANDLE_CHUNK_NEVER 1
1519 PNG_HANDLE_CHUNK_IF_SAFE 2
1520 PNG_HANDLE_CHUNK_ALWAYS 3
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001521
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001522 chunk_list - list of chunks affected (a byte string,
1523 five bytes per chunk, NULL or '\0' if
1524 num_chunks is 0)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001525
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001526 num_chunks - number of chunks affected; if 0, all
Glenn Randers-Pehrsondff799e2004-08-07 21:42:49 -05001527 unknown chunks are affected. If nonzero,
1528 only the chunks in the list are affected
1529
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001530Unknown chunks declared in this way will be saved as raw data onto a
1531list of png_unknown_chunk structures. If a chunk that is normally
1532known to libpng is named in the list, it will be handled as unknown,
1533according to the "keep" directive. If a chunk is named in successive
1534instances of png_set_keep_unknown_chunks(), the final instance will
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05001535take precedence. The IHDR and IEND chunks should not be named in
1536chunk_list; if they are, libpng will process them normally anyway.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001537If you know that your application will never make use of some particular
1538chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001539
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001540Here is an example of the usage of png_set_keep_unknown_chunks(),
1541where the private "vpAg" chunk will later be processed by a user chunk
1542callback function:
1543
1544 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1545
1546 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1547 png_byte unused_chunks[]=
1548 {
1549 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1550 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1551 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1552 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1553 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1554 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1555 };
1556 #endif
1557
1558 ...
1559
1560 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1561 /* ignore all unknown chunks: */
1562 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001563
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001564 /* except for vpAg: */
1565 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001566
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001567 /* also ignore unused known chunks: */
1568 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1569 (int)sizeof(unused_chunks)/5);
1570 #endif
1571
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001572.SS User limits
1573
1574The PNG specification allows the width and height of an image to be as
1575large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1576Since very few applications really need to process such large images,
1577we have imposed an arbitrary 1-million limit on rows and columns.
1578Larger images will be rejected immediately with a png_error() call. If
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05001579you wish to change this limit, you can use
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001580
1581 png_set_user_limits(png_ptr, width_max, height_max);
1582
1583to set your own limits, or use width_max = height_max = 0x7fffffffL
1584to allow all valid dimensions (libpng may reject some very large images
1585anyway because of potential buffer overflow conditions).
1586
1587You should put this statement after you create the PNG structure and
1588before calling png_read_info(), png_read_png(), or png_process_data().
Glenn Randers-Pehrsoncc277082011-06-10 21:17:34 -05001589
1590When writing a PNG datastream, put this statement before calling
1591png_write_info() or png_write_png().
1592
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001593If you need to retrieve the limits that are being applied, use
1594
1595 width_max = png_get_user_width_max(png_ptr);
1596 height_max = png_get_user_height_max(png_ptr);
1597
1598The PNG specification sets no limit on the number of ancillary chunks
1599allowed in a PNG datastream. You can impose a limit on the total number
1600of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1601
1602 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1603
1604where 0x7fffffffL means unlimited. You can retrieve this limit with
1605
1606 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1607
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05001608This limit also applies to the number of buffers that can be allocated
1609by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1610
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001611You can also set a limit on the amount of memory that a compressed chunk
1612other than IDAT can occupy, with
1613
1614 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1615
1616and you can retrieve the limit with
1617
1618 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1619
1620Any chunks that would cause either of these limits to be exceeded will
1621be ignored.
1622
John Bowlercb0b2962011-05-12 21:48:29 -05001623.SS Information about your system
1624
1625If you intend to display the PNG or to incorporate it in other image data you
1626need to tell libpng information about your display or drawing surface so that
1627libpng can convert the values in the image to match the display.
1628
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001629From libpng-1.5.4 this information can be set before reading the PNG file
John Bowlercb0b2962011-05-12 21:48:29 -05001630header. In earlier versions png_set_gamma() existed but behaved incorrectly if
1631called before the PNG file header had been read and png_set_alpha_mode() did not
1632exist.
1633
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001634If you need to support versions prior to libpng-1.5.4 test the version number
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001635as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1636described in the appropriate manual page.
John Bowlercb0b2962011-05-12 21:48:29 -05001637
1638You give libpng the encoding expected by your system expressed as a 'gamma'
1639value. You can also specify a default encoding for the PNG file in
1640case the required information is missing from the file. By default libpng
1641assumes that the PNG data matches your system, to keep this default call:
1642
1643 png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
1644
1645or you can use the fixed point equivalent:
1646
1647 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
1648
1649If you don't know the gamma for you system it is probably 2.2 - a good
1650approximation to the IEC standard for display systems (sRGB). If images are
1651too contrasty or washed out you got the value wrong - check your system
1652documentation!
1653
1654Many systems permit the system gamma to be changed via a lookup table in the
1655display driver, a few systems, including older Macs, change the response by
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001656default. As of 1.5.4 three special values are available to handle common
John Bowlercb0b2962011-05-12 21:48:29 -05001657situations:
1658
1659 PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
1660 standard. This matches almost all systems.
1661 PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6)
1662 Apple Macintosh system with the default settings.
1663 PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
1664 system expects data with no gamma encoding.
1665
1666You would use the linear (unencoded) value if you need to process the pixel
1667values further because this avoids the need to decode and reencode each
1668component value whenever arithmetic is performed. A lot of graphics software
1669uses linear values for this reason, often with higher precision component values
1670to preserve overall accuracy.
1671
1672The second thing you may need to tell libpng about is how your system handles
1673alpha channel information. Some, but not all, PNG files contain an alpha
1674channel. To display these files correctly you need to compose the data onto a
1675suitable background, as described in the PNG specification.
1676
1677Libpng only supports composing onto a single color (using png_set_background;
1678see below.) Otherwise you must do the composition yourself and, in this case,
1679you may need to call png_set_alpha_mode:
1680
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001681#if PNG_LIBPNG_VER >= 10504
John Bowlercb0b2962011-05-12 21:48:29 -05001682 png_set_alpha_mode(png_ptr, mode, screen_gamma);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05001683#endif
John Bowlercb0b2962011-05-12 21:48:29 -05001684
1685The screen_gamma value is the same as the argument to png_set_gamma, however how
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001686it affects the output depends on the mode. png_set_alpha_mode() sets the file
John Bowlercb0b2962011-05-12 21:48:29 -05001687gamma default to 1/screen_gamma, so normally you don't need to call
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001688png_set_gamma. If you need different defaults call png_set_gamma() before
1689png_set_alpha_mode() - if you call it after it will override the settings made
1690by png_set_alpha_mode().
John Bowlercb0b2962011-05-12 21:48:29 -05001691
1692The mode is as follows:
1693
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001694 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
1695green and blue, or gray, components are gamma encoded color
1696values and are not premultiplied by the alpha value. The
1697alpha value is a linear measure of the contribution of the
1698pixel to the corresponding final output pixel.
John Bowlercb0b2962011-05-12 21:48:29 -05001699
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001700You should normally use this format if you intend to perform
1701color correction on the color values; most, maybe all, color
1702correction software has no handling for the alpha channel and,
1703anyway, the math to handle pre-multiplied component values is
1704unnecessarily complex.
John Bowlercb0b2962011-05-12 21:48:29 -05001705
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001706Before you do any arithmetic on the component values you need
1707to remove the gamma encoding and multiply out the alpha
1708channel. See the PNG specification for more detail. It is
1709important to note that when an image with an alpha channel is
1710scaled, linear encoded, pre-multiplied component values must
1711be used!
John Bowlercb0b2962011-05-12 21:48:29 -05001712
1713The remaining modes assume you don't need to do any further color correction or
1714that if you do your color correction software knows all about alpha (it
1715probably doesn't!)
1716
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001717 PNG_ALPHA_STANDARD: The data libpng produces is encoded in the standard way
1718assumed by most correctly written graphics software.
1719The gamma encoding will be removed by libpng and the
1720linear component values will be pre-multiplied by the
1721alpha channel.
John Bowlercb0b2962011-05-12 21:48:29 -05001722
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001723With this format the final image must be re-encoded to
1724match the display gamma before the image is displayed.
1725If your system doesn't do that, yet still seems to
1726perform arithmetic on the pixels without decoding them,
1727it is broken - check out the modes below.
John Bowlercb0b2962011-05-12 21:48:29 -05001728
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001729With PNG_ALPHA_STANDARD libpng always produces linear
1730component values, whatever screen_gamma you supply. The
1731screen_gamma value is, however, used as a default for
1732the file gamma if the PNG file has no gamma information.
John Bowlercb0b2962011-05-12 21:48:29 -05001733
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001734If you call png_set_gamma() after png_set_alpha_mode() you
1735will override the linear encoding. Instead the
1736pre-multiplied pixel values will be gamma encoded but
1737the alpha channel will still be linear. This may
1738actually match the requirements of some broken software,
1739but it is unlikely.
John Bowlercb0b2962011-05-12 21:48:29 -05001740
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001741While linear 8-bit data is often used it has
1742insufficient precision for any image with a reasonable
1743dynamic range. To avoid problems, and if your software
1744supports it, use png_set_expand_16() to force all
1745components to 16 bits.
John Bowlercb0b2962011-05-12 21:48:29 -05001746
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001747 PNG_ALPHA_OPTIMIZED: This mode is the same as PNG_ALPHA_STANDARD except that
1748completely opaque pixels are gamma encoded according to
1749the screen_gamma value. Pixels with alpha less than 1.0
1750will still have linear components.
John Bowlercb0b2962011-05-12 21:48:29 -05001751
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001752Use this format if you have control over your
1753compositing software and do don't do other arithmetic
1754(such as scaling) on the data you get from libpng. Your
1755compositing software can simply copy opaque pixels to
1756the output but still has linear values for the
1757non-opaque pixels.
John Bowlercb0b2962011-05-12 21:48:29 -05001758
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001759In normal compositing, where the alpha channel encodes
1760partial pixel coverage (as opposed to broad area
1761translucency), the inaccuracies of the 8-bit
1762representation of non-opaque pixels are irrelevant.
John Bowlercb0b2962011-05-12 21:48:29 -05001763
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001764You can also try this format if your software is broken;
1765it might look better.
John Bowlercb0b2962011-05-12 21:48:29 -05001766
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001767 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD however all component values,
1768including the alpha channel are gamma encoded. This is
1769an appropriate format to try if your software, or more
1770likely hardware, is totally broken: if it performs
1771linear arithmetic directly on gamma encoded values.
John Bowlercb0b2962011-05-12 21:48:29 -05001772
1773In most cases of broken software or hardware the bug in the final display
1774manifests as a subtle halo around composited parts of the image. You may not
1775even perceive this as a halo; the composited part of the image may simply appear
1776separate from the background, as though it had been cut out of paper and pasted
1777on afterward.
1778
1779If 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 -05001780them, there are three recommended ways of using png_set_alpha_mode():
John Bowlercb0b2962011-05-12 21:48:29 -05001781
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001782 png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
1783 screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001784
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001785You can do color correction on the result (libpng does not currently
1786support color correction internally.) When you handle the alpha channel
1787you need to undo the gamma encoding and multiply out the alpha.
1788
1789 png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
1790 screen_gamma);
John Bowlercb0b2962011-05-12 21:48:29 -05001791 png_set_expand_16(png_ptr);
John Bowlercb0b2962011-05-12 21:48:29 -05001792
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001793If you are using the high level interface don't call png_set_expand_16();
1794instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
John Bowlercb0b2962011-05-12 21:48:29 -05001795
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001796With this mode you can't do color correction, but you can do arithmetic,
1797including composition and scaling, on the data without further processing.
1798
1799 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1800 screen_gamma);
1801
1802You can avoid the expansion to 16-bit components with this mode, but you
1803lose the ability to scale the image or perform other linear arithmetic.
1804All you can do is compose the result onto a matching output. Since this
1805mode is libpng specific you also need to write your own composition
1806software.
John Bowlercb0b2962011-05-12 21:48:29 -05001807
1808If you don't need, or can't handle, the alpha channel you can call
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001809png_set_background() to remove it by compositing against a fixed color. Don't
1810call png_set_strip_alpha() to do this - it will leave spurious pixel values in
John Bowlercb0b2962011-05-12 21:48:29 -05001811transparent parts of this image.
1812
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05001813 png_set_background(png_ptr, &background_color,
1814 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
John Bowlercb0b2962011-05-12 21:48:29 -05001815
1816The background_color is an RGB or grayscale value according to the data format
1817libpng will produce for you. Because you don't yet know the format of the PNG
1818file if you call png_set_background at this point you must arrange for the
1819format produced by libpng to always have 8-bit or 16-bit components and then
1820store the color as an 8-bit or 16-bit color as appropriate. The color contains
1821separate gray and RGB component values, so you can let libpng produce gray or
1822RGB output according to the input format, but low bit depth grayscale images
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05001823must always be converted to at least 8-bit format. (Even though low bit depth
John Bowlercb0b2962011-05-12 21:48:29 -05001824grayscale images can't have an alpha channel they can have a transparent
1825color!)
1826
1827You set the transforms you need later, either as flags to the high level
1828interface or libpng API calls for the low level interface. For reference the
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001829settings and API calls required are:
John Bowlercb0b2962011-05-12 21:48:29 -05001830
18318-bit values:
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001832 PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
1833 png_set_expand(png_ptr); png_set_scale_16(png_ptr);
John Bowlercb0b2962011-05-12 21:48:29 -05001834
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001835 If you must get exactly the same inaccurate results
1836 produced by default in versions prior to libpng-1.5.4,
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001837 use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001838 instead.
1839
John Bowlercb0b2962011-05-12 21:48:29 -0500184016-bit values:
1841 PNG_TRANSFORM_EXPAND_16
1842 png_set_expand_16(png_ptr);
1843
1844In either case palette image data will be expanded to RGB. If you just want
1845color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1846to the list.
1847
1848Calling png_set_background before the PNG file header is read will not work
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001849prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
John Bowlercb0b2962011-05-12 21:48:29 -05001850errors it is therefore much safer to call png_set_background after the head has
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05001851been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
John Bowlercb0b2962011-05-12 21:48:29 -05001852used with the high level interface.
1853
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001854.SS The high-level read interface
1855
1856At this point there are two ways to proceed; through the high-level
1857read interface, or through a sequence of low-level read operations.
1858You can use the high-level interface if (a) you are willing to read
1859the entire image into memory, and (b) the input transformations
1860you want to do are limited to the following set:
1861
1862 PNG_TRANSFORM_IDENTITY No transformation
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05001863 PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
1864 8-bit accurately
1865 PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
1866 8-bit less accurately
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001867 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001868 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1869 samples to bytes
1870 PNG_TRANSFORM_PACKSWAP Change order of packed
1871 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001872 PNG_TRANSFORM_EXPAND Perform set_expand()
1873 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001874 PNG_TRANSFORM_SHIFT Normalize pixels to the
1875 sBIT depth
1876 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1877 to BGRA
1878 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1879 to AG
1880 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1881 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001882 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05001883 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1884 to RGB (or GA to RGBA)
John Bowlera9b34192011-05-08 19:46:51 -05001885 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001886
1887(This excludes setting a background color, doing gamma transformation,
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05001888quantizing, and setting filler.) If this is the case, simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001889
1890 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1891
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06001892where png_transforms is an integer containing the bitwise OR of some
1893set of transformation flags. This call is equivalent to png_read_info(),
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001894followed the set of transformations indicated by the transform mask,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001895then png_read_image(), and finally png_read_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001896
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001897(The final parameter of this call is not yet used. Someday it might point
1898to transformation parameters required by some future input transform.)
1899
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05001900You must use png_transforms and not call any png_set_transform() functions
1901when you use png_read_png().
1902
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001903After you have called png_read_png(), you can retrieve the image data
1904with
1905
1906 row_pointers = png_get_rows(png_ptr, info_ptr);
1907
1908where row_pointers is an array of pointers to the pixel data for each row:
1909
1910 png_bytep row_pointers[height];
1911
1912If you know your image size and pixel size ahead of time, you can allocate
1913row_pointers prior to calling png_read_png() with
1914
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001915 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001916 png_error (png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001917 "Image is too tall to process in memory");
1918
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001919 if (width > PNG_UINT_32_MAX/pixel_size)
1920 png_error (png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001921 "Image is too wide to process in memory");
1922
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001923 row_pointers = png_malloc(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001924 height*png_sizeof(png_bytep));
1925
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05001926 for (int i=0; i<height, i++)
1927 row_pointers[i]=NULL; /* security precaution */
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001928
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001929 for (int i=0; i<height, i++)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06001930 row_pointers[i]=png_malloc(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001931 width*pixel_size);
1932
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06001933 png_set_rows(png_ptr, info_ptr, &row_pointers);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001934
1935Alternatively you could allocate your image in one big block and define
1936row_pointers[i] to point into the proper places in your block.
1937
1938If you use png_set_rows(), the application is responsible for freeing
1939row_pointers (and row_pointers[i], if they were separately allocated).
1940
1941If you don't allocate row_pointers ahead of time, png_read_png() will
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001942do it, and it'll be free'ed by libpng when you call png_destroy_*().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001943
1944.SS The low-level read interface
1945
1946If you are going the low-level route, you are now ready to read all
1947the file information up to the actual image data. You do this with a
1948call to png_read_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001949
1950 png_read_info(png_ptr, info_ptr);
1951
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001952This will process all chunks up to but not including the image data.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001953
John Bowlercb0b2962011-05-12 21:48:29 -05001954This also copies some of the data from the PNG file into the decode structure
1955for use in later transformations. Important information copied in is:
1956
19571) The PNG file gamma from the gAMA chunk. This overwrites the default value
1958provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1959
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -050019602) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
John Bowlercb0b2962011-05-12 21:48:29 -05001961damages the information provided by an earlier call to png_set_background
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05001962resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
John Bowlercb0b2962011-05-12 21:48:29 -05001963
19643) The number of significant bits in each component value. Libpng uses this to
1965optimize gamma handling by reducing the internal lookup table sizes.
1966
19674) The transparent color information from a tRNS chunk. This can be modified by
1968a later call to png_set_tRNS.
1969
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001970.SS Querying the info structure
1971
1972Functions are used to get the information from the info_ptr once it
1973has been read. Note that these fields may not be completely filled
1974in until png_read_end() has read the chunk data following the image.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001975
1976 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1977 &bit_depth, &color_type, &interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06001978 &compression_type, &filter_method);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001979
1980 width - holds the width of the image
1981 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001982
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001983 height - holds the height of the image
1984 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001985
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001986 bit_depth - holds the bit depth of one of the
1987 image channels. (valid values are
1988 1, 2, 4, 8, 16 and depend also on
1989 the color_type. See also
1990 significant bits (sBIT) below).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06001991
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001992 color_type - describes which color/alpha channels
1993 are present.
1994 PNG_COLOR_TYPE_GRAY
1995 (bit depths 1, 2, 4, 8, 16)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001996 PNG_COLOR_TYPE_GRAY_ALPHA
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001997 (bit depths 8, 16)
1998 PNG_COLOR_TYPE_PALETTE
1999 (bit depths 1, 2, 4, 8)
2000 PNG_COLOR_TYPE_RGB
2001 (bit_depths 8, 16)
2002 PNG_COLOR_TYPE_RGB_ALPHA
2003 (bit_depths 8, 16)
2004
2005 PNG_COLOR_MASK_PALETTE
2006 PNG_COLOR_MASK_COLOR
2007 PNG_COLOR_MASK_ALPHA
2008
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002009 interlace_type - (PNG_INTERLACE_NONE or
2010 PNG_INTERLACE_ADAM7)
2011
2012 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
2013 for PNG 1.0)
2014
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06002015 filter_method - (must be PNG_FILTER_TYPE_BASE
2016 for PNG 1.0, and can also be
2017 PNG_INTRAPIXEL_DIFFERENCING if
2018 the PNG datastream is embedded in
2019 a MNG-1.0 datastream)
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002020
2021 Any or all of interlace_type, compression_type, or
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002022 filter_method can be NULL if you are
2023 not interested in their values.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002024
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002025 Note that png_get_IHDR() returns 32-bit data into
2026 the application's width and height variables.
2027 This is an unsafe situation if these are 16-bit
2028 variables. In such situations, the
2029 png_get_image_width() and png_get_image_height()
2030 functions described below are safer.
2031
2032 width = png_get_image_width(png_ptr,
2033 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002034
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002035 height = png_get_image_height(png_ptr,
2036 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002037
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002038 bit_depth = png_get_bit_depth(png_ptr,
2039 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002040
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002041 color_type = png_get_color_type(png_ptr,
2042 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002043
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002044 interlace_type = png_get_interlace_type(png_ptr,
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002045 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002046
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002047 compression_type = png_get_compression_type(png_ptr,
2048 info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002049
Glenn Randers-Pehrson2cb633b2011-01-21 08:31:29 -06002050 filter_method = png_get_filter_type(png_ptr,
Glenn Randers-Pehrson0bfb58f2009-09-30 23:07:22 -05002051 info_ptr);
2052
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002053 channels = png_get_channels(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002054
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002055 channels - number of channels of info for the
2056 color type (valid values are 1 (GRAY,
2057 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
2058 4 (RGB_ALPHA or RGB + filler byte))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002059
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002060 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002061
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002062 rowbytes - number of bytes needed to hold a row
2063
2064 signature = png_get_signature(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002065
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002066 signature - holds the signature read from the
2067 file (if any). The data is kept in
2068 the same offset it would be if the
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002069 whole signature were read (i.e. if an
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002070 application had already read in 4
2071 bytes of signature before starting
2072 libpng, the remaining 4 bytes would
2073 be in signature[4] through signature[7]
2074 (see png_set_sig_bytes())).
2075
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002076These are also important, but their validity depends on whether the chunk
2077has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
2078png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
2079data has been read, or zero if it is missing. The parameters to the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002080png_get_<chunk> are set directly if they are simple data types, or a
2081pointer into the info_ptr is returned for any complex types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002082
2083 png_get_PLTE(png_ptr, info_ptr, &palette,
2084 &num_palette);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002085
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002086 palette - the palette for the file
2087 (array of png_color)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002088
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002089 num_palette - number of entries in the palette
2090
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002091 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
Glenn Randers-Pehrson27742382011-01-27 09:37:34 -06002092 png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002093
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002094 file_gamma - the gamma at which the file is
2095 written (PNG_INFO_gAMA)
2096
2097 int_file_gamma - 100,000 times the gamma at which the
2098 file is written
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002099
2100 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002101
Glenn Randers-Pehrson27742382011-01-27 09:37:34 -06002102 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002103 The presence of the sRGB chunk
2104 means that the pixel data is in the
2105 sRGB color space. This chunk also
2106 implies specific values of gAMA and
2107 cHRM.
2108
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002109 png_get_iCCP(png_ptr, info_ptr, &name,
2110 &compression_type, &profile, &proflen);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002111
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002112 name - The profile name.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002113
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002114 compression_type - The compression type; always
2115 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2116 You may give NULL to this argument to
2117 ignore it.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002118
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002119 profile - International Color Consortium color
2120 profile data. May contain NULs.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002121
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06002122 proflen - length of profile data in bytes.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002123
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002124 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002125
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002126 sig_bit - the number of significant bits for
2127 (PNG_INFO_sBIT) each of the gray,
2128 red, green, and blue channels,
2129 whichever are appropriate for the
2130 given color type (png_color_16)
2131
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002132 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
2133 &num_trans, &trans_color);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002134
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05002135 trans_alpha - array of alpha (transparency)
2136 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002137
Glenn Randers-Pehrsonf3c51e42011-01-15 10:25:25 -06002138 num_trans - number of transparent entries
2139 (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002140
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05002141 trans_color - graylevel or color sample values of
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05002142 the single transparent color for
2143 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002144
2145 png_get_hIST(png_ptr, info_ptr, &hist);
2146 (PNG_INFO_hIST)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002147
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002148 hist - histogram of palette (array of
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002149 png_uint_16)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002150
2151 png_get_tIME(png_ptr, info_ptr, &mod_time);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002152
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002153 mod_time - time image was last modified
2154 (PNG_VALID_tIME)
2155
2156 png_get_bKGD(png_ptr, info_ptr, &background);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002157
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002158 background - background color (of type
2159 png_color_16p) (PNG_VALID_bKGD)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002160 valid 16-bit red, green and blue
2161 values, regardless of color_type
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002162
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002163 num_comments = png_get_text(png_ptr, info_ptr,
2164 &text_ptr, &num_text);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002165
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06002166 num_comments - number of comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002167
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002168 text_ptr - array of png_text holding image
2169 comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002170
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002171 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002172 on "text" PNG_TEXT_COMPRESSION_NONE
2173 PNG_TEXT_COMPRESSION_zTXt
2174 PNG_ITXT_COMPRESSION_NONE
2175 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002176
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002177 text_ptr[i].key - keyword for comment. Must contain
2178 1-79 characters.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002179
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002180 text_ptr[i].text - text comments for current
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05002181 keyword. Can be empty.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002182
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002183 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002184 after decompression, 0 for iTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002185
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002186 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002187 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002188
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002189 text_ptr[i].lang - language of comment (empty
2190 string for unknown).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002191
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -06002192 text_ptr[i].lang_key - keyword in UTF-8
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002193 (empty string for unknown).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002194
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002195 Note that the itxt_length, lang, and lang_key
2196 members of the text_ptr structure only exist
2197 when the library is built with iTXt chunk support.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002198 Prior to libpng-1.4.0, the default build was
2199 was without iTXt chunk support.
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05002200
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002201 num_text - number of comments (same as
2202 num_comments; you can put NULL here
2203 to avoid the duplication)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002204
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002205 Note while png_set_text() will accept text, language,
2206 and translated keywords that can be NULL pointers, the
2207 structure returned by png_get_text will always contain
2208 regular zero-terminated C strings. They might be
2209 empty strings but they will never be NULL pointers.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002210
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002211 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
2212 &palette_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002213
2214 num_spalettes - number of sPLT chunks read.
2215
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002216 palette_ptr - array of palette structures holding
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002217 contents of one or more sPLT chunks
2218 read.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002219
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002220 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002221 &unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002222
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002223 offset_x - positive offset from the left edge
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002224 of the screen (can be negative)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002225
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002226 offset_y - positive offset from the top edge
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002227 of the screen (can be negative)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002228
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002229 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2230
2231 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002232 &unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002233
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002234 res_x - pixels/unit physical resolution in
2235 x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002236
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002237 res_y - pixels/unit physical resolution in
2238 x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002239
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002240 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002241 PNG_RESOLUTION_METER
2242
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002243 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
2244 &height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002245
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002246 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002247
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002248 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002249
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002250 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002251 (width and height are doubles)
2252
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002253 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
2254 &height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002255
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002256 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002257
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002258 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002259 (expressed as a string)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002260
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002261 height - height of a pixel in physical scale units
2262 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002263
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002264 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
2265 info_ptr, &unknowns)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002266
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002267 unknowns - array of png_unknown_chunk
2268 structures holding unknown chunks
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002269
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002270 unknowns[i].name - name of unknown chunk
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002271
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002272 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002273
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002274 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002275
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002276 unknowns[i].location - position of chunk in file
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002277
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002278 The value of "i" corresponds to the order in which the
2279 chunks were read from the PNG file or inserted with the
2280 png_set_unknown_chunks() function.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002281
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002282 The value of "location" is a bitwise "or" of
2283
2284 PNG_HAVE_IHDR (0x01)
2285 PNG_HAVE_PLTE (0x02)
2286 PNG_AFTER_IDAT (0x08)
2287
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002288The data from the pHYs chunk can be retrieved in several convenient
2289forms:
2290
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002291 res_x = png_get_x_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002292 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002293
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002294 res_y = png_get_y_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002295 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002296
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002297 res_x_and_y = png_get_pixels_per_meter(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002298 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002299
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002300 res_x = png_get_x_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002301 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002302
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002303 res_y = png_get_y_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002304 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002305
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002306 res_x_and_y = png_get_pixels_per_inch(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002307 info_ptr)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002308
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002309 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002310 info_ptr)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002311
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002312 Each of these returns 0 [signifying "unknown"] if
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002313 the data is not present or if res_x is 0;
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002314 res_x_and_y is 0 if res_x != res_y
2315
2316 Note that because of the way the resolutions are
2317 stored internally, the inch conversions won't
2318 come out to exactly even number. For example,
2319 72 dpi is stored as 0.28346 pixels/meter, and
2320 when this is retrieved it is 71.9988 dpi, so
2321 be sure to round the returned value appropriately
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002322 if you want to display a reasonable-looking result.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002323
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002324The data from the oFFs chunk can be retrieved in several convenient
2325forms:
2326
2327 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002328
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002329 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002330
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002331 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002332
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002333 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
2334
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002335 Each of these returns 0 [signifying "unknown" if both
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06002336 x and y are 0] if the data is not present or if the
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002337 chunk is present but the unit is the pixel. The
2338 remark about inexact inch conversions applies here
2339 as well, because a value in inches can't always be
2340 converted to microns and back without some loss
2341 of precision.
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002342
John Bowlercb0b2962011-05-12 21:48:29 -05002343For more information, see the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002344PNG specification for chunk contents. Be careful with trusting
2345rowbytes, as some of the transformations could increase the space
2346needed to hold a row (expand, filler, gray_to_rgb, etc.).
2347See png_read_update_info(), below.
2348
2349A quick word about text_ptr and num_text. PNG stores comments in
2350keyword/text pairs, one pair per chunk, with no limit on the number
2351of text chunks, and a 2^31 byte limit on their size. While there are
2352suggested keywords, there is no requirement to restrict the use to these
2353strings. It is strongly suggested that keywords and text be sensible
2354to humans (that's the point), so don't use abbreviations. Non-printing
2355symbols are not allowed. See the PNG specification for more details.
2356There is also no requirement to have text after the keyword.
2357
2358Keywords should be limited to 79 Latin-1 characters without leading or
2359trailing spaces, but non-consecutive spaces are allowed within the
2360keyword. It is possible to have the same keyword any number of times.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002361The text_ptr is an array of png_text structures, each holding a
2362pointer to a language string, a pointer to a keyword and a pointer to
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002363a text string. The text string, language code, and translated
2364keyword may be empty or NULL pointers. The keyword/text
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06002365pairs are put into the array in the order that they are received.
2366However, some or all of the text chunks may be after the image, so, to
2367make sure you have read all the text chunks, don't mess with these
2368until after you read the stuff after the image. This will be
2369mentioned again below in the discussion that goes with png_read_end().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002370
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002371.SS Input transformations
2372
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002373After you've read the header information, you can set up the library
2374to handle any special transformations of the image data. The various
2375ways to transform the data will be described in the order that they
2376should occur. This is important, as some of these change the color
2377type and/or bit depth of the data, and some others only work on
John Bowlercb0b2962011-05-12 21:48:29 -05002378certain color types and bit depths.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002379
John Bowlercb0b2962011-05-12 21:48:29 -05002380Transformations you request are ignored if they don't have any meaning for a
2381particular input data format. However some transformations can have an effect
2382as a result of a previous transformation. If you specify a contradictory set of
2383transformations, for example both adding and removing the alpha channel, you
2384cannot predict the final result.
2385
2386The color used for the transparency values should be supplied in the same
2387format/depth as the current image data. It is stored in the same format/depth
2388as the image data in a tRNS chunk, so this is what libpng expects for this data.
2389
2390The color used for the background value depends on the need_expand argument as
2391described below.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002392
2393Data will be decoded into the supplied row buffers packed into bytes
2394unless the library has been told to transform it into another format.
2395For example, 4 bit/pixel paletted or grayscale data will be returned
23962 pixels/byte with the leftmost pixel in the high-order bits of the
2397byte, unless png_set_packing() is called. 8-bit RGB data will be stored
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002398in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2399is called to insert filler bytes, either before or after each RGB triplet.
240016-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002401byte of the color value first, unless png_set_scale_16() is called to
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06002402transform it to regular RGB RGB triplets, or png_set_filler() or
2403png_set_add alpha() is called to insert filler bytes, either before or
2404after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002405be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2406or png_set_scale_16().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002407
2408The following code transforms grayscale images of less than 8 to 8 bits,
2409changes paletted images to RGB, and adds a full alpha channel if there is
2410transparency information in a tRNS chunk. This is most useful on
2411grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2412viewing application that wishes to treat all images in the same way.
2413
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002414 if (color_type == PNG_COLOR_TYPE_PALETTE)
2415 png_set_palette_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002416
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002417 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002418 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2419
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002420 if (color_type == PNG_COLOR_TYPE_GRAY &&
2421 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2422
2423The first two functions are actually aliases for png_set_expand(), added
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002424in libpng version 1.0.4, with the function names expanded to improve code
2425readability. In some future version they may actually do different
2426things.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002427
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06002428As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2429added. It expands the sample depth without changing tRNS to alpha.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002430
John Bowler63d059a2011-02-12 09:03:44 -06002431As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002432png_set_expand(); however, the resultant channels have 16 bits rather than 8.
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002433Use this when the output color or gray channels are made linear to avoid fairly
John Bowler63d059a2011-02-12 09:03:44 -06002434severe accuracy loss.
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05002435
John Bowler63d059a2011-02-12 09:03:44 -06002436 if (bit_depth < 16)
2437 png_set_expand_16(png_ptr);
Glenn Randers-Pehrson1ce08362006-03-08 23:35:59 -06002438
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002439PNG can have files with 16 bits per channel. If you only can handle
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -050024408 bits per channel, this will strip the pixels down to 8-bit.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002441
2442 if (bit_depth == 16)
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002443#if PNG_LIBPNG_VER >= 10504
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05002444 png_set_scale_16(png_ptr);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002445#else
2446 png_set_strip_16(png_ptr);
2447#endif
2448
2449(The more accurate "png_set_scale_16()" API became available in libpng version
24501.5.4).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002451
John Bowlercb0b2962011-05-12 21:48:29 -05002452If you need to process the alpha channel on the image separately from the image
2453data (for example if you convert it to a bitmap mask) it is possible to have
2454libpng strip the channel leaving just RGB or gray data:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002455
2456 if (color_type & PNG_COLOR_MASK_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002457 png_set_strip_alpha(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002458
John Bowlercb0b2962011-05-12 21:48:29 -05002459If you strip the alpha channel you need to find some other way of dealing with
2460the information. If, instead, you want to convert the image to an opaque
2461version with no alpha channel use png_set_background; see below.
John Bowler63d059a2011-02-12 09:03:44 -06002462
2463As of libpng version 1.5.2, almost all useful expansions are supported, the
Glenn Randers-Pehrsoncd116fa2011-05-17 06:56:50 -05002464major ommissions are conversion of grayscale to indexed images (which can be
2465done trivially in the application) and conversion of indexed to grayscale (which
John Bowler63d059a2011-02-12 09:03:44 -06002466can be done by a trivial manipulation of the palette.)
2467
2468In the following table, the 01 means grayscale with depth<8, 31 means
2469indexed with depth<8, other numerals represent the color type, "T" means
2470the tRNS chunk is present, A means an alpha channel is present, and O
2471means tRNS or alpha is present but all pixels in the image are opaque.
2472
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06002473 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
John Bowler63d059a2011-02-12 09:03:44 -06002474 TO
2475 01 - [G] - - - - - - - - - - - - -
2476 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
2477 0 1 G + . . G G G G G G B B GB GB
2478 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
2479 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
2480 2 C P C C C + . . C - - CB CB B B
2481 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
2482 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
2483 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
2484 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
2485 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
2486 4A lA G A T T GA GT GT GA GT GT + BA G GBA
2487 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
2488 6A CA PA CA C C A T tT PA P P C CBA + BA
2489 6O CA PBA CA C C A tT T PA P P CBA C BA +
2490
2491Within the matrix,
2492 "+" identifies entries where 'from' and 'to' are the same.
2493 "-" means the transformation is not supported.
2494 "." means nothing is necessary (a tRNS chunk can just be ignored).
2495 "t" means the transformation is obtained by png_set_tRNS.
2496 "A" means the transformation is obtained by png_set_add_alpha().
2497 "X" means the transformation is obtained by png_set_expand().
2498 "1" means the transformation is obtained by
2499 png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() if there
2500 is no transparency in the original or the final format).
2501 "C" means the transformation is obtained by png_set_gray_to_rgb().
Glenn Randers-Pehrsonc36074e2011-05-16 09:08:51 -05002502 "G" means the transformation is obtained by png_set_rgb_to_gray().
John Bowler63d059a2011-02-12 09:03:44 -06002503 "P" means the transformation is obtained by
2504 png_set_expand_palette_to_rgb().
2505 "p" means the transformation is obtained by png_set_packing().
2506 "Q" means the transformation is obtained by png_set_quantize().
2507 "T" means the transformation is obtained by png_set_tRNS_to_alpha().
2508 "B" means the transformation is obtained by png_set_background(), or
2509 png_strip_alpha().
John Bowler63d059a2011-02-12 09:03:44 -06002510
2511When an entry has multiple transforms listed all are required to cause the
2512right overall transformation. When two transforms are separated by a comma
2513either will do the job. When transforms are enclosed in [] the transform should
2514do the job but this is currently unimplemented - a different format will result
2515if the suggested transformations are used.
2516
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002517In PNG files, the alpha channel in an image
2518is the level of opacity. If you need the alpha channel in an image to
2519be the level of transparency instead of opacity, you can invert the
2520alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2521fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2522images) is fully transparent, with
2523
2524 png_set_invert_alpha(png_ptr);
2525
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002526PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2527they can, resulting in, for example, 8 pixels per byte for 1 bit
2528files. This code expands to 1 pixel per byte without changing the
2529values of the pixels:
2530
2531 if (bit_depth < 8)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002532 png_set_packing(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002533
2534PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
2535stored in a PNG image have been "scaled" or "shifted" up to the next
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06002536higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2537to 8 bits/sample in the range [0, 255]). However, it is also possible
2538to convert the PNG pixel data back to the original bit depth of the
2539image. This call reduces the pixels back down to the original bit depth:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002540
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05002541 png_color_8p sig_bit;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002542
2543 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002544 png_set_shift(png_ptr, sig_bit);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002545
2546PNG files store 3-color pixels in red, green, blue order. This code
2547changes the storage of the pixels to blue, green, red:
2548
2549 if (color_type == PNG_COLOR_TYPE_RGB ||
2550 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002551 png_set_bgr(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002552
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002553PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2554into 4 or 8 bytes for windowing systems that need them in this format:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002555
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002556 if (color_type == PNG_COLOR_TYPE_RGB)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002557 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002558
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05002559where "filler" is the 8 or 16-bit number to fill with, and the location is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002560either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2561you want the filler before the RGB or after. This transformation
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05002562does not affect images that already have full alpha channels. To add an
2563opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2564will generate RGBA pixels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002565
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002566Note that png_set_filler() does not change the color type. If you want
2567to do that, you can add a true alpha channel with
2568
2569 if (color_type == PNG_COLOR_TYPE_RGB ||
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002570 color_type == PNG_COLOR_TYPE_GRAY)
2571 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002572
2573where "filler" contains the alpha value to assign to each pixel.
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -06002574This function was added in libpng-1.2.7.
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05002575
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002576If you are reading an image with an alpha channel, and you need the
2577data as ARGB instead of the normal PNG format RGBA:
2578
2579 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002580 png_set_swap_alpha(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002581
2582For some uses, you may want a grayscale image to be represented as
2583RGB. This code will do that conversion:
2584
2585 if (color_type == PNG_COLOR_TYPE_GRAY ||
2586 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002587 png_set_gray_to_rgb(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002588
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002589Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002590with alpha.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002591
2592 if (color_type == PNG_COLOR_TYPE_RGB ||
2593 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
John Bowlercb0b2962011-05-12 21:48:29 -05002594 png_set_rgb_to_gray(png_ptr, error_action, double red_weight,
2595 double green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002596
2597 error_action = 1: silently do the conversion
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002598
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002599 error_action = 2: issue a warning if the original
2600 image has any pixel where
2601 red != green or red != blue
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002602
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002603 error_action = 3: issue an error and abort the
2604 conversion if the original
2605 image has any pixel where
2606 red != green or red != blue
2607
John Bowlercb0b2962011-05-12 21:48:29 -05002608 red_weight: weight of red component
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002609
John Bowlercb0b2962011-05-12 21:48:29 -05002610 green_weight: weight of green component
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002611 If either weight is negative, default
John Bowlercb0b2962011-05-12 21:48:29 -05002612 weights are used.
2613
2614In the corresponding fixed point API the red_weight and green_weight values are
2615simply scaled by 100,000:
2616
2617 png_set_rgb_to_gray(png_ptr, error_action, png_fixed_point red_weight,
2618 png_fixed_point green_weight);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002619
2620If you have set error_action = 1 or 2, you can
2621later check whether the image really was gray, after processing
2622the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2623It will return a png_byte that is zero if the image was gray or
John Bowlercb0b2962011-05-12 21:48:29 -050026241 if there were any non-gray pixels. Background and sBIT data
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002625will be silently converted to grayscale, using the green channel
John Bowlercb0b2962011-05-12 21:48:29 -05002626data for sBIT, regardless of the error_action setting.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002627
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002628The default values come from the PNG file cHRM chunk if present; otherwise, the
John Bowlercb0b2962011-05-12 21:48:29 -05002629defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2630space, as recommended in the Charles Poynton's Colour FAQ,
2631<http://www.poynton.com/>, in section 9:
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002632
John Bowlercb0b2962011-05-12 21:48:29 -05002633 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002634
2635 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2636
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002637The calculation is done in a linear colorspace, if the image gamma
Glenn Randers-Pehrson9962b842011-01-24 00:12:14 -06002638can be determined.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002639
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002640The png_set_background() function has been described already; it tells libpng to
John Bowlercb0b2962011-05-12 21:48:29 -05002641composite images with alpha or simple transparency against the supplied
2642background color. For compatibility with versions of libpng earlier than
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05002643libpng-1.5.4 it is recommended that you call the function after reading the file
John Bowlercb0b2962011-05-12 21:48:29 -05002644header, even if you don't want to use the color in a bKGD chunk, if one exists.
2645
2646If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2647you may use this color, or supply another color more suitable for
2648the current display (e.g., the background color from a web page). You
2649need to tell libpng how the color is represented, both the format of the
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002650component values in the color (the number of bits) and the gamma encoding of the
John Bowlercb0b2962011-05-12 21:48:29 -05002651color. The function takes two arguments, background_gamma_mode and need_expand
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05002652to convey this information, however only two combinations are likely to be
2653useful:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002654
Glenn Randers-Pehrsoncb47e202011-07-10 06:55:14 -05002655 png_color_16 my_background;
2656 png_color_16p image_background;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002657
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05002658 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002659 png_set_background(png_ptr, image_background,
John Bowlercb0b2962011-05-12 21:48:29 -05002660 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002661 else
Glenn Randers-Pehrsoncb47e202011-07-10 06:55:14 -05002662 png_set_background(png_ptr, &my_background,
John Bowlercb0b2962011-05-12 21:48:29 -05002663 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002664
John Bowlercb0b2962011-05-12 21:48:29 -05002665The second call was described above - my_background is in the format of the
2666final, display, output produced by libpng. Because you now know the format of
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05002667the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2668output and to retain palette images (the palette colors will be modified
2669appropriately and the tRNS chunk removed.) However, if you are doing this,
2670take great care not to ask for transformations without checking first that
2671they apply!
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002672
John Bowlercb0b2962011-05-12 21:48:29 -05002673In the first call the background color has the original bit depth and color type
2674of the PNG file. So, for palette images the color is supplied as a palette
2675index and for low bit greyscale images the color is a reduced bit value in
2676image_background->gray.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002677
John Bowlercb0b2962011-05-12 21:48:29 -05002678If you didn't call png_set_gamma() before reading the file header, for example
2679if you need your code to remain compatible with older versions of libpng prior
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05002680to libpng-1.5.4, this is the place to call it.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05002681
John Bowlercb0b2962011-05-12 21:48:29 -05002682Do not call it if you called png_set_alpha_mode(); doing so will damage the
2683settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
2684supported then you can certainly do png_set_gamma() before reading the PNG
2685header.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002686
Glenn Randers-Pehrsonc7822512011-05-07 21:23:43 -05002687This API unconditionally sets the screen and file gamma values, so it will
2688override the value in the PNG file unless it is called before the PNG file
2689reading starts. For this reason you must always call it with the PNG file
2690value when you call it in this position:
2691
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06002692 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
2693 png_set_gamma(png_ptr, screen_gamma, file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002694
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002695 else
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06002696 png_set_gamma(png_ptr, screen_gamma, 0.45455);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002697
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002698If you need to reduce an RGB file to a paletted file, or if a paletted
2699file has more entries then will fit on your screen, png_set_quantize()
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -05002700will do that. Note that this is a simple match quantization that merely
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002701finds the closest color available. This should work fairly well with
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002702optimized palettes, but fairly badly with linear color cubes. If you
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002703pass a palette that is larger than maximum_colors, the file will
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002704reduce the number of colors in the palette so it will fit into
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002705maximum_colors. If there is a histogram, libpng will use it to make
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002706more intelligent choices when reducing the palette. If there is no
2707histogram, it may not do as good a job.
2708
2709 if (color_type & PNG_COLOR_MASK_COLOR)
2710 {
2711 if (png_get_valid(png_ptr, info_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002712 PNG_INFO_PLTE))
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002713 {
2714 png_uint_16p histogram = NULL;
2715
2716 png_get_hIST(png_ptr, info_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002717 &histogram);
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002718 png_set_quantize(png_ptr, palette, num_palette,
2719 max_screen_colors, histogram, 1);
2720 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002721
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05002722 else
2723 {
2724 png_color std_color_cube[MAX_SCREEN_COLORS] =
2725 { ... colors ... };
2726
2727 png_set_quantize(png_ptr, std_color_cube,
2728 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2729 NULL,0);
2730 }
2731 }
2732
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002733PNG files describe monochrome as black being zero and white being one.
2734The following code will reverse this (make black be one and white be
2735zero):
2736
Glenn Randers-Pehrson1ea0ff32001-08-07 22:25:59 -05002737 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2738 png_set_invert_mono(png_ptr);
2739
2740This function can also be used to invert grayscale and gray-alpha images:
2741
2742 if (color_type == PNG_COLOR_TYPE_GRAY ||
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002743 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002744 png_set_invert_mono(png_ptr);
2745
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05002746PNG files store 16-bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002747ie. most significant bits first). This code changes the storage to the
2748other way (little-endian, i.e. least significant bits first, the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002749way PCs store them):
2750
2751 if (bit_depth == 16)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002752 png_set_swap(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002753
2754If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2755need to change the order the pixels are packed into bytes, you can use:
2756
2757 if (bit_depth < 8)
2758 png_set_packswap(png_ptr);
2759
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002760Finally, you can write your own transformation function if none of
2761the existing ones meets your needs. This is done by setting a callback
2762with
2763
2764 png_set_read_user_transform_fn(png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002765 read_transform_fn);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002766
2767You must supply the function
2768
Glenn Randers-Pehrson93215672011-02-13 19:42:19 -06002769 void read_transform_fn(png_structp png_ptr, png_row_infop
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002770 row_info, png_bytep data)
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002771
2772See pngtest.c for a working example. Your function will be called
John Bowlerf19abd62011-01-22 18:29:24 -06002773after all of the other transformations have been processed. Take care with
2774interlaced images if you do the interlace yourself - the width of the row is the
2775width in 'row_info', not the overall image width.
2776
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05002777If supported, libpng provides two information routines that you can use to find
John Bowlerf19abd62011-01-22 18:29:24 -06002778where you are in processing the image:
2779
2780 png_get_current_pass_number(png_structp png_ptr);
2781 png_get_current_row_number(png_structp png_ptr);
2782
2783Don't try using these outside a transform callback - firstly they are only
2784supported if user transforms are supported, secondly they may well return
2785unexpected results unless the row is actually being processed at the moment they
2786are called.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002787
John Bowlercd113452011-02-16 06:15:13 -06002788With interlaced
2789images the value returned is the row in the input sub-image image. Use
2790PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2791find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2792
2793The discussion of interlace handling above contains more information on how to
2794use these values.
2795
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002796You can also set up a pointer to a user structure for use by your
2797callback function, and you can inform libpng that your transform
2798function will change the number of channels or bit depth with the
2799function
2800
2801 png_set_user_transform_info(png_ptr, user_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002802 user_depth, user_channels);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002803
2804The user's application, not libpng, is responsible for allocating and
2805freeing any memory required for the user structure.
2806
2807You can retrieve the pointer via the function
2808png_get_user_transform_ptr(). For example:
2809
2810 voidp read_user_transform_ptr =
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002811 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002812
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002813The last thing to handle is interlacing; this is covered in detail below,
2814but you must call the function here if you want libpng to handle expansion
2815of the interlaced image.
2816
2817 number_of_passes = png_set_interlace_handling(png_ptr);
2818
2819After setting the transformations, libpng can update your png_info
2820structure to reflect any transformations you've requested with this
2821call. This is most useful to update the info structure's rowbytes
2822field so you can use it to allocate your image memory. This function
2823will also update your palette with the correct screen_gamma and
2824background if these have been given with the calls above.
2825
2826 png_read_update_info(png_ptr, info_ptr);
2827
2828After you call png_read_update_info(), you can allocate any
2829memory you need to hold the image. The row data is simply
2830raw byte data for all forms of images. As the actual allocation
2831varies among applications, no example will be given. If you
2832are allocating one large chunk, you will need to build an
2833array of pointers to each row, as it will be needed for some
2834of the functions below.
2835
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002836Remember: Before you call png_read_update_info(), the png_get_
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002837functions return the values corresponding to the original PNG image.
2838After you call png_read_update_info the values refer to the image
2839that libpng will output. Consequently you must call all the png_set_
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002840functions before you call png_read_update_info(). This is particularly
2841important for png_set_interlace_handling() - if you are going to call
2842png_read_update_info() you must call png_set_interlace_handling() before
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002843it unless you want to receive interlaced output.
2844
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06002845.SS Reading image data
2846
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002847After you've allocated memory, you can read the image data.
2848The simplest way to do this is in one function call. If you are
2849allocating enough memory to hold the whole image, you can just
2850call png_read_image() and libpng will read in all the image data
2851and put it in the memory area supplied. You will need to pass in
2852an array of pointers to each row.
2853
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06002854This function automatically handles interlacing, so you don't
2855need to call png_set_interlace_handling() (unless you call
2856png_read_update_info()) or call this function multiple times, or any
2857of that other stuff necessary with png_read_rows().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002858
2859 png_read_image(png_ptr, row_pointers);
2860
2861where row_pointers is:
2862
2863 png_bytep row_pointers[height];
2864
2865You can point to void or char or whatever you use for pixels.
2866
2867If you don't want to read in the whole image at once, you can
2868use png_read_rows() instead. If there is no interlacing (check
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002869interlace_type == PNG_INTERLACE_NONE), this is simple:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002870
2871 png_read_rows(png_ptr, row_pointers, NULL,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002872 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002873
2874where row_pointers is the same as in the png_read_image() call.
2875
2876If you are doing this just one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002877a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002878
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06002879 png_bytep row_pointer = row;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05002880 png_read_row(png_ptr, row_pointer, NULL);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002881
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05002882If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2883get somewhat harder. The only current (PNG Specification version 1.2)
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002884interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
2885a somewhat complicated 2D interlace scheme, known as Adam7, that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002886breaks down an image into seven smaller images of varying size, based
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002887on an 8x8 grid. This number is defined (from libpng 1.5) as
2888PNG_INTERLACE_ADAM7_PASSES in png.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002889
2890libpng can fill out those images or it can give them to you "as is".
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002891It is almost always better to have libpng handle the interlacing for you.
2892If you want the images filled out, there are two ways to do that. The one
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002893mentioned in the PNG specification is to expand each pixel to cover
2894those pixels that have not been read yet (the "rectangle" method).
2895This results in a blocky image for the first pass, which gradually
2896smooths out as more pixels are read. The other method is the "sparkle"
2897method, where pixels are drawn only in their final locations, with the
2898rest of the image remaining whatever colors they were initialized to
2899before the start of the read. The first method usually looks better,
2900but tends to be slower, as there are more pixels to put in the rows.
2901
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002902If, as is likely, you want libpng to expand the images, call this before
2903calling png_start_read_image() or png_read_update_info():
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002904
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06002905 if (interlace_type == PNG_INTERLACE_ADAM7)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002906 number_of_passes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002907 = png_set_interlace_handling(png_ptr);
2908
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002909This will return the number of passes needed. Currently, this is seven,
2910but may change if another interlace type is added. This function can be
2911called even if the file is not interlaced, where it will return one pass.
2912You then need to read the whole image 'number_of_passes' times. Each time
2913will distribute the pixels from the current pass to the correct place in
2914the output image, so you need to supply the same rows to png_read_rows in
2915each pass.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05002916
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002917If you are not going to display the image after each pass, but are
2918going to wait until the entire image is read in, use the sparkle
2919effect. This effect is faster and the end result of either method
2920is exactly the same. If you are planning on displaying the image
2921after each pass, the "rectangle" effect is generally considered the
2922better looking one.
2923
2924If you only want the "sparkle" effect, just call png_read_rows() as
2925normal, with the third parameter NULL. Make sure you make pass over
2926the image number_of_passes times, and you don't change the data in the
2927rows between calls. You can change the locations of the data, just
2928not the data. Each pass only writes the pixels appropriate for that
2929pass, and assumes the data from previous passes is still valid.
2930
2931 png_read_rows(png_ptr, row_pointers, NULL,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002932 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002933
2934If you only want the first effect (the rectangles), do the same as
2935before except pass the row buffer in the third parameter, and leave
2936the second parameter NULL.
2937
2938 png_read_rows(png_ptr, NULL, row_pointers,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002939 number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06002940
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002941If you don't want libpng to handle the interlacing details, just call
2942png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
2943Each of the images is a valid image by itself, however you will almost
2944certainly need to distribute the pixels from each sub-image to the
2945correct place. This is where everything gets very tricky.
2946
2947If you want to retrieve the separate images you must pass the correct
2948number of rows to each successive call of png_read_rows(). The calculation
2949gets pretty complicated for small images, where some sub-images may
2950not even exist because either their width or height ends up zero.
2951libpng provides two macros to help you in 1.5 and later versions:
2952
2953 png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
2954 png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
2955
2956Respectively these tell you the width and height of the sub-image
2957corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
2958this can be confusing because the specification refers to the same passes
2959as 1 to 7! Be careful, you must check both the width and height before
2960calling png_read_rows() and not call it for that pass if either is zero.
2961
2962You can, of course, read each sub-image row by row. If you want to
2963produce optimal code to make a pixel-by-pixel transformation of an
2964interlaced image this is the best approach; read each row of each pass,
2965transform it, and write it out to a new interlaced image.
2966
2967If you want to de-interlace the image yourself libpng provides further
2968macros to help that tell you where to place the pixels in the output image.
2969Because the interlacing scheme is rectangular - sub-image pixels are always
2970arranged on a rectangular grid - all you need to know for each pass is the
2971starting column and row in the output image of the first pixel plus the
2972spacing between each pixel. As of libpng 1.5 there are four macros to
2973retrieve this information:
2974
2975 png_uint_32 x = PNG_PASS_START_COL(pass);
2976 png_uint_32 y = PNG_PASS_START_ROW(pass);
2977 png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
2978 png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
2979
2980These allow you to write the obvious loop:
2981
2982 png_uint_32 input_y = 0;
2983 png_uint_32 output_y = PNG_PASS_START_ROW(pass);
2984
2985 while (output_y < output_image_height)
2986 {
2987 png_uint_32 input_x = 0;
2988 png_uint_32 output_x = PNG_PASS_START_COL(pass);
2989
2990 while (output_x < output_image_width)
2991 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002992 image[output_y][output_x] =
2993 subimage[pass][input_y][input_x++];
2994
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06002995 output_x += xStep;
2996 }
2997
2998 ++input_y;
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06002999 output_y += yStep;
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003000 }
3001
3002Notice that the steps between successive output rows and columns are
3003returned as shifts. This is possible because the pixels in the subimages
3004are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
3005image. In practice you may need to directly calculate the output coordinate
3006given an input coordinate. libpng provides two further macros for this
3007purpose:
3008
3009 png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
3010 png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
3011
3012Finally a pair of macros are provided to tell you if a particular image
3013row or column appears in a given pass:
3014
3015 int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
3016 int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
3017
3018Bear in mind that you will probably also need to check the width and height
3019of the pass in addition to the above to be sure the pass even exists!
3020
3021With any luck you are convinced by now that you don't want to do your own
3022interlace handling. In reality normally the only good reason for doing this
3023is if you are processing PNG files on a pixel-by-pixel basis and don't want
3024to load the whole file into memory when it is interlaced.
3025
3026libpng includes a test program, pngvalid, that illustrates reading and
3027writing of interlaced images. If you can't get interlacing to work in your
3028code and don't want to leave it to libpng (the recommended approach) see
3029how pngvalid.c does it.
3030
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003031.SS Finishing a sequential read
3032
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06003033After you are finished reading the image through the
3034low-level interface, you can finish reading the file. If you are
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003035interested in comments or time, which may be stored either before or
3036after the image data, you should pass the separate png_info struct if
3037you want to keep the comments from before and after the image
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003038separate.
3039
3040 png_infop end_info = png_create_info_struct(png_ptr);
3041
3042 if (!end_info)
3043 {
3044 png_destroy_read_struct(&png_ptr, &info_ptr,
3045 (png_infopp)NULL);
3046 return (ERROR);
3047 }
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003048
3049 png_read_end(png_ptr, end_info);
3050
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003051If you are not interested, you should still call png_read_end()
3052but you can pass NULL, avoiding the need to create an end_info structure.
3053
3054 png_read_end(png_ptr, (png_infop)NULL);
3055
Glenn Randers-Pehrson99778e12011-04-20 17:43:52 -05003056If you don't call png_read_end(), then your file pointer will be
3057left pointing to the first chunk after the last IDAT, which is probably
3058not what you want if you expect to read something beyond the end of
3059the PNG datastream.
3060
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003061When you are done, you can free all memory allocated by libpng like this:
3062
3063 png_destroy_read_struct(&png_ptr, &info_ptr,
3064 &end_info);
3065
Glenn Randers-Pehrson20786be2011-04-20 22:20:40 -05003066or, if you didn't create an end_info structure,
3067
3068 png_destroy_read_struct(&png_ptr, &info_ptr,
3069 (png_infopp)NULL);
3070
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003071It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003072point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003073
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003074 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003075
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003076 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003077 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003078 more of
3079 PNG_FREE_PLTE, PNG_FREE_TRNS,
3080 PNG_FREE_HIST, PNG_FREE_ICCP,
3081 PNG_FREE_PCAL, PNG_FREE_ROWS,
3082 PNG_FREE_SCAL, PNG_FREE_SPLT,
3083 PNG_FREE_TEXT, PNG_FREE_UNKN,
3084 or simply PNG_FREE_ALL
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003085
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003086 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003087 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003088
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003089This function may be safely called when the relevant storage has
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06003090already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003091by the user and not by libpng, and will in those cases do nothing.
3092The "seq" parameter is ignored if only one item of the selected data
3093type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3094are allowed for the data type identified in the mask, such as text or
3095sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003096
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003097The default behavior is only to free data that was allocated internally
3098by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003099or so that it will free data that was allocated by the user with png_malloc()
3100or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003101
3102 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003103
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003104 freer - one of
3105 PNG_DESTROY_WILL_FREE_DATA
3106 PNG_SET_WILL_FREE_DATA
3107 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003108
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003109 mask - which data elements are affected
3110 same choices as in png_free_data()
3111
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003112This function only affects data that has already been allocated.
3113You can call this function after reading the PNG data but before calling
3114any png_set_*() functions, to control whether the user or the png_set_*()
3115function is responsible for freeing any existing data that might be present,
3116and again after the png_set_*() functions to control whether the user
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003117or png_destroy_*() is supposed to free the data. When the user assumes
3118responsibility for libpng-allocated data, the application must use
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003119png_free() to free it, and when the user transfers responsibility to libpng
3120for data that the user has allocated, the user must have used png_malloc()
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05003121or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003122
3123If you allocated your row_pointers in a single block, as suggested above in
3124the description of the high level read interface, you must not transfer
3125responsibility for freeing it to the png_set_rows or png_read_destroy function,
3126because they would also try to free the individual row_pointers[i].
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003127
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003128If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3129separately, do not transfer responsibility for freeing text_ptr to libpng,
3130because when libpng fills a png_text structure it combines these members with
3131the key member, and png_free_data() will free only text_ptr.key. Similarly,
3132if you transfer responsibility for free'ing text_ptr from libpng to your
3133application, your application must not separately free those members.
3134
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003135The png_free_data() function will turn off the "valid" flag for anything
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003136it frees. If you need to turn the flag off for a chunk that was freed by
3137your application instead of by libpng, you can use
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003138
3139 png_set_invalid(png_ptr, info_ptr, mask);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003140
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003141 mask - identifies the chunks to be made invalid,
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003142 containing the bitwise OR of one or
Glenn Randers-Pehrsond56aca72000-11-23 11:51:42 -06003143 more of
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05003144 PNG_INFO_gAMA, PNG_INFO_sBIT,
3145 PNG_INFO_cHRM, PNG_INFO_PLTE,
3146 PNG_INFO_tRNS, PNG_INFO_bKGD,
3147 PNG_INFO_hIST, PNG_INFO_pHYs,
3148 PNG_INFO_oFFs, PNG_INFO_tIME,
3149 PNG_INFO_pCAL, PNG_INFO_sRGB,
3150 PNG_INFO_iCCP, PNG_INFO_sPLT,
3151 PNG_INFO_sCAL, PNG_INFO_IDAT
3152
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003153For a more compact example of reading a PNG image, see the file example.c.
3154
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003155.SS Reading PNG files progressively
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003156
3157The progressive reader is slightly different then the non-progressive
3158reader. Instead of calling png_read_info(), png_read_rows(), and
3159png_read_end(), you make one call to png_process_data(), which calls
3160callbacks when it has the info, a row, or the end of the image. You
3161set up these callbacks with png_set_progressive_read_fn(). You don't
3162have to worry about the input/output functions of libpng, as you are
3163giving the library the data directly in png_process_data(). I will
3164assume that you have read the section on reading PNG files above,
3165so I will only highlight the differences (although I will show
3166all of the code).
3167
3168png_structp png_ptr;
3169png_infop info_ptr;
3170
3171 /* An example code fragment of how you would
3172 initialize the progressive reader in your
3173 application. */
3174 int
3175 initialize_png_reader()
3176 {
3177 png_ptr = png_create_read_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003178 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003179 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003180
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003181 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003182 return (ERROR);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003183
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003184 info_ptr = png_create_info_struct(png_ptr);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003185
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003186 if (!info_ptr)
3187 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003188 png_destroy_read_struct(&png_ptr,
3189 (png_infopp)NULL, (png_infopp)NULL);
3190 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003191 }
3192
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003193 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003194 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003195 png_destroy_read_struct(&png_ptr, &info_ptr,
3196 (png_infopp)NULL);
3197 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003198 }
3199
3200 /* This one's new. You can provide functions
3201 to be called when the header info is valid,
3202 when each row is completed, and when the image
3203 is finished. If you aren't using all functions,
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003204 you can specify NULL parameters. Even when all
3205 three functions are NULL, you need to call
3206 png_set_progressive_read_fn(). You can use
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003207 any struct as the user_ptr (cast to a void pointer
3208 for the function call), and retrieve the pointer
3209 from inside the callbacks using the function
3210
3211 png_get_progressive_ptr(png_ptr);
3212
3213 which will return a void pointer, which you have
3214 to cast appropriately.
3215 */
3216 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
3217 info_callback, row_callback, end_callback);
3218
3219 return 0;
3220 }
3221
3222 /* A code fragment that you call as you receive blocks
3223 of data */
3224 int
3225 process_data(png_bytep buffer, png_uint_32 length)
3226 {
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003227 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003228 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003229 png_destroy_read_struct(&png_ptr, &info_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003230 (png_infopp)NULL);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003231 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003232 }
3233
3234 /* This one's new also. Simply give it a chunk
3235 of data from the file stream (in order, of
3236 course). On machines with segmented memory
3237 models machines, don't give it any more than
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003238 64K. The library seems to run fine with sizes
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003239 of 4K. Although you can give it much less if
3240 necessary (I assume you can give it chunks of
3241 1 byte, I haven't tried less then 256 bytes
3242 yet). When this function returns, you may
3243 want to display any rows that were generated
3244 in the row callback if you don't already do
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003245 so there.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003246 */
3247 png_process_data(png_ptr, info_ptr, buffer, length);
John Bowlerf19abd62011-01-22 18:29:24 -06003248
3249 /* At this point you can call png_process_data_skip if
3250 you want to handle data the library will skip yourself;
3251 it simply returns the number of bytes to skip (and stops
3252 libpng skipping that number of bytes on the next
3253 png_process_data call).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003254 return 0;
3255 }
3256
3257 /* This function is called (as set by
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003258 png_set_progressive_read_fn() above) when enough data
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003259 has been supplied so all of the header has been
3260 read.
3261 */
3262 void
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003263 info_callback(png_structp png_ptr, png_infop info)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003264 {
3265 /* Do any setup here, including setting any of
3266 the transformations mentioned in the Reading
3267 PNG files section. For now, you _must_ call
3268 either png_start_read_image() or
3269 png_read_update_info() after all the
3270 transformations are set (even if you don't set
3271 any). You may start getting rows before
3272 png_process_data() returns, so this is your
3273 last chance to prepare for that.
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003274
3275 This is where you turn on interlace handling,
3276 assuming you don't want to do it yourself.
John Bowlerf19abd62011-01-22 18:29:24 -06003277
3278 If you need to you can stop the processing of
3279 your original input data at this point by calling
3280 png_process_data_pause. This returns the number
3281 of unprocessed bytes from the last png_process_data
3282 call - it is up to you to ensure that the next call
3283 sees these bytes again. If you don't want to bother
3284 with this you can get libpng to cache the unread
3285 bytes by setting the 'save' parameter (see png.h) but
3286 then libpng will have to copy the data internally.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003287 */
3288 }
3289
3290 /* This function is called when each row of image
3291 data is complete */
3292 void
3293 row_callback(png_structp png_ptr, png_bytep new_row,
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05003294 png_uint_32 row_num, int pass)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003295 {
3296 /* If the image is interlaced, and you turned
3297 on the interlace handler, this function will
3298 be called for every row in every pass. Some
3299 of these rows will not be changed from the
3300 previous pass. When the row is not changed,
3301 the new_row variable will be NULL. The rows
3302 and passes are called in order, so you don't
3303 really need the row_num and pass, but I'm
3304 supplying them because it may make your life
3305 easier.
3306
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003307 If you did not turn on interlace handling then
3308 the callback is called for each row of each
3309 sub-image when the image is interlaced. In this
3310 case 'row_num' is the row in the sub-image, not
3311 the row in the output image as it is in all other
3312 cases.
3313
3314 For the non-NULL rows of interlaced images when
3315 you have switched on libpng interlace handling,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003316 you must call png_progressive_combine_row()
3317 passing in the row and the old row. You can
3318 call this function for NULL rows (it will just
3319 return) and for non-interlaced images (it just
3320 does the memcpy for you) if it will make the
3321 code easier. Thus, you can just do this for
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003322 all cases if you switch on interlace handling;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003323 */
3324
3325 png_progressive_combine_row(png_ptr, old_row,
3326 new_row);
3327
3328 /* where old_row is what was displayed for
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -05003329 previously for the row. Note that the first
3330 pass (pass == 0, really) will completely cover
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003331 the old row, so the rows do not have to be
3332 initialized. After the first pass (and only
3333 for interlaced images), you will have to pass
3334 the current row, and the function will combine
3335 the old row and the new row.
John Bowlerf19abd62011-01-22 18:29:24 -06003336
3337 You can also call png_process_data_pause in this
3338 callback - see above.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003339 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003340 }
3341
3342 void
3343 end_callback(png_structp png_ptr, png_infop info)
3344 {
3345 /* This function is called after the whole image
3346 has been read, including any chunks after the
3347 image (up to and including the IEND). You
3348 will usually have the same info chunk as you
3349 had in the header, although some data may have
3350 been added to the comments and time fields.
3351
3352 Most people won't do much here, perhaps setting
3353 a flag that marks the image as finished.
3354 */
3355 }
3356
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05003357
3358
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003359.SH IV. Writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003360
3361Much of this is very similar to reading. However, everything of
3362importance is repeated here, so you won't have to constantly look
3363back up in the reading section to understand writing.
3364
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003365.SS Setup
3366
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003367You will want to do the I/O initialization before you get into libpng,
3368so if it doesn't work, you don't have anything to undo. If you are not
3369using the standard I/O functions, you will need to replace them with
3370custom writing functions. See the discussion under Customizing libpng.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003371
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003372 FILE *fp = fopen(file_name, "wb");
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003373
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003374 if (!fp)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003375 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003376
3377Next, png_struct and png_info need to be allocated and initialized.
3378As these can be both relatively large, you may not want to store these
3379on the stack, unless you have stack space to spare. Of course, you
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003380will want to check if they return NULL. If you are also reading,
3381you won't want to name your read structure and your write structure
3382both "png_ptr"; you can call them anything you like, such as
3383"read_ptr" and "write_ptr". Look at pngtest.c, for example.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003384
3385 png_structp png_ptr = png_create_write_struct
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05003386 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003387 user_error_fn, user_warning_fn);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003388
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003389 if (!png_ptr)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003390 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003391
3392 png_infop info_ptr = png_create_info_struct(png_ptr);
3393 if (!info_ptr)
3394 {
3395 png_destroy_write_struct(&png_ptr,
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003396 (png_infopp)NULL);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003397 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003398 }
3399
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003400If you want to use your own memory allocation routines,
3401define PNG_USER_MEM_SUPPORTED and use
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003402png_create_write_struct_2() instead of png_create_write_struct():
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05003403
3404 png_structp png_ptr = png_create_write_struct_2
3405 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3406 user_error_fn, user_warning_fn, (png_voidp)
3407 user_mem_ptr, user_malloc_fn, user_free_fn);
3408
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003409After you have these structures, you will need to set up the
3410error handling. When libpng encounters an error, it expects to
3411longjmp() back to your routine. Therefore, you will need to call
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003412setjmp() and pass the png_jmpbuf(png_ptr). If you
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003413write the file from different routines, you will need to update
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003414the png_jmpbuf(png_ptr) every time you enter a new routine that will
3415call a png_*() function. See your documentation of setjmp/longjmp
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003416for your compiler for more information on setjmp/longjmp. See
3417the discussion on libpng error handling in the Customizing Libpng
3418section below for more information on the libpng error handling.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003419
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06003420 if (setjmp(png_jmpbuf(png_ptr)))
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003421 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003422 png_destroy_write_struct(&png_ptr, &info_ptr);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05003423 fclose(fp);
3424 return (ERROR);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003425 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003426 ...
3427 return;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003428
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003429If you would rather avoid the complexity of setjmp/longjmp issues,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05003430you can compile libpng with PNG_NO_SETJMP, in which case
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003431errors will result in a call to PNG_ABORT() which defaults to abort().
3432
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05003433You can #define PNG_ABORT() to a function that does something
3434more useful than abort(), as long as your function does not
3435return.
3436
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003437Now you need to set up the output code. The default for libpng is to
3438use the C function fwrite(). If you use this, you will need to pass a
3439valid FILE * in the function png_init_io(). Be sure that the file is
3440opened in binary mode. Again, if you wish to handle writing data in
3441another way, see the discussion on libpng I/O handling in the Customizing
3442Libpng section below.
3443
3444 png_init_io(png_ptr, fp);
3445
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05003446If you are embedding your PNG into a datastream such as MNG, and don't
3447want libpng to write the 8-byte signature, or if you have already
3448written the signature in your application, use
3449
3450 png_set_sig_bytes(png_ptr, 8);
3451
3452to inform libpng that it should not write a signature.
3453
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003454.SS Write callbacks
3455
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003456At this point, you can set up a callback function that will be
3457called after each row has been written, which you can use to control
3458a progress meter or the like. It's demonstrated in pngtest.c.
3459You must supply a function
3460
Glenn Randers-Pehrson81ce8892011-01-24 08:04:37 -06003461 void write_row_callback(png_structp png_ptr, png_uint_32 row,
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003462 int pass);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06003463 {
3464 /* put your code here */
3465 }
3466
3467(You can give it another name that you like instead of "write_row_callback")
3468
3469To inform libpng about your function, use
3470
3471 png_set_write_status_fn(png_ptr, write_row_callback);
3472
John Bowler59010e52011-02-16 06:16:31 -06003473When this function is called the row has already been completely processed and
3474it has also been written out. The 'row' and 'pass' refer to the next row to be
3475handled. For the
3476non-interlaced case the row that was just handled is simply one less than the
3477passed in row number, and pass will always be 0. For the interlaced case the
3478same applies unless the row value is 0, in which case the row just handled was
3479the last one from one of the preceding passes. Because interlacing may skip a
3480pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3481need to know what the last pass is record (row,pass) from the callback and use
3482the last recorded value each time.
3483
3484As with the user transform you can find the output row using the
3485PNG_ROW_FROM_PASS_ROW macro.
3486
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003487You now have the option of modifying how the compression library will
3488run. The following functions are mainly for testing, but may be useful
3489in some cases, like if you need to write PNG files extremely fast and
3490are willing to give up some compression, or if you want to get the
3491maximum possible compression at the expense of slower writing. If you
3492have no special needs in this area, let the library do what it wants by
3493not calling this function at all, as it has been tuned to deliver a good
3494speed/compression ratio. The second parameter to png_set_filter() is
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003495the filter method, for which the only valid values are 0 (as of the
3496July 1999 PNG specification, version 1.2) or 64 (if you are writing
3497a PNG datastream that is to be embedded in a MNG datastream). The third
3498parameter is a flag that indicates which filter type(s) are to be tested
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003499for each scanline. See the PNG specification for details on the specific
3500filter types.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003501
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003502
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003503 /* turn on or off filtering, and/or choose
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003504 specific filters. You can use either a single
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003505 PNG_FILTER_VALUE_NAME or the bitwise OR of one
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003506 or more PNG_FILTER_NAME masks.
3507 */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003508 png_set_filter(png_ptr, 0,
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003509 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
3510 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
3511 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05003512 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003513 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3514 PNG_ALL_FILTERS);
3515
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06003516If an application wants to start and stop using particular filters during
3517compression, it should start out with all of the filters (to ensure that
3518the previous row of pixels will be stored in case it's needed later),
3519and then add and remove them after the start of compression.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003520
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003521If you are writing a PNG datastream that is to be embedded in a MNG
3522datastream, the second parameter can be either 0 or 64.
3523
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003524The png_set_compression_*() functions interface to the zlib compression
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003525library, and should mostly be ignored unless you really know what you are
3526doing. The only generally useful call is png_set_compression_level()
3527which changes how much time zlib spends on trying to compress the image
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003528data. See the Compression Library (zlib.h and algorithm.txt, distributed
3529with zlib) for details on the compression levels.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003530
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06003531 #include zlib.h
3532
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003533 /* Set the zlib compression level */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003534 png_set_compression_level(png_ptr,
3535 Z_BEST_COMPRESSION);
3536
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003537 /* Set other zlib parameters for compressing IDAT */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003538 png_set_compression_mem_level(png_ptr, 8);
3539 png_set_compression_strategy(png_ptr,
3540 Z_DEFAULT_STRATEGY);
3541 png_set_compression_window_bits(png_ptr, 15);
3542 png_set_compression_method(png_ptr, 8);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003543 png_set_compression_buffer_size(png_ptr, 8192)
3544
Glenn Randers-Pehrsona45f47c2011-04-01 15:31:26 -05003545 /* Set zlib parameters for text compression
3546 * If you don't call these, the parameters
3547 * fall back on those defined for IDAT chunks
3548 */
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05003549 png_set_text_compression_mem_level(png_ptr, 8);
3550 png_set_text_compression_strategy(png_ptr,
3551 Z_DEFAULT_STRATEGY);
3552 png_set_text_compression_window_bits(png_ptr, 15);
3553 png_set_text_compression_method(png_ptr, 8);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003554
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003555.SS Setting the contents of info for output
3556
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003557You now need to fill in the png_info structure with all the data you
3558wish to write before the actual image. Note that the only thing you
3559are allowed to write after the image is the text chunks and the time
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05003560chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003561the latest PNG specification for more information on that. If you
3562wish to write them before the image, fill them in now, and flag that
3563data as being valid. If you want to wait until after the data, don't
3564fill them until png_write_end(). For all the fields in png_info and
3565their data types, see png.h. For explanations of what the fields
3566contain, see the PNG specification.
3567
3568Some of the more important parts of the png_info are:
3569
3570 png_set_IHDR(png_ptr, info_ptr, width, height,
3571 bit_depth, color_type, interlace_type,
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003572 compression_type, filter_method)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003573
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003574 width - holds the width of the image
3575 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003576
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003577 height - holds the height of the image
3578 in pixels (up to 2^31).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003579
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003580 bit_depth - holds the bit depth of one of the
3581 image channels.
3582 (valid values are 1, 2, 4, 8, 16
3583 and depend also on the
3584 color_type. See also significant
3585 bits (sBIT) below).
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003586
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003587 color_type - describes which color/alpha
3588 channels are present.
3589 PNG_COLOR_TYPE_GRAY
3590 (bit depths 1, 2, 4, 8, 16)
3591 PNG_COLOR_TYPE_GRAY_ALPHA
3592 (bit depths 8, 16)
3593 PNG_COLOR_TYPE_PALETTE
3594 (bit depths 1, 2, 4, 8)
3595 PNG_COLOR_TYPE_RGB
3596 (bit_depths 8, 16)
3597 PNG_COLOR_TYPE_RGB_ALPHA
3598 (bit_depths 8, 16)
3599
3600 PNG_COLOR_MASK_PALETTE
3601 PNG_COLOR_MASK_COLOR
3602 PNG_COLOR_MASK_ALPHA
3603
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003604 interlace_type - PNG_INTERLACE_NONE or
3605 PNG_INTERLACE_ADAM7
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003606
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003607 compression_type - (must be
3608 PNG_COMPRESSION_TYPE_DEFAULT)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003609
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06003610 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
3611 or, if you are writing a PNG to
3612 be embedded in a MNG datastream,
3613 can also be
3614 PNG_INTRAPIXEL_DIFFERENCING)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003615
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003616If you call png_set_IHDR(), the call must appear before any of the
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05003617other png_set_*() functions, because they might require access to some of
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05003618the IHDR settings. The remaining png_set_*() functions can be called
3619in any order.
3620
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003621If you wish, you can reset the compression_type, interlace_type, or
3622filter_method later by calling png_set_IHDR() again; if you do this, the
3623width, height, bit_depth, and color_type must be the same in each call.
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05003624
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003625 png_set_PLTE(png_ptr, info_ptr, palette,
3626 num_palette);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003627
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003628 palette - the palette for the file
3629 (array of png_color)
3630 num_palette - number of entries in the palette
3631
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003632 png_set_gAMA(png_ptr, info_ptr, file_gamma);
3633 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003634
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003635 file_gamma - the gamma at which the image was
3636 created (PNG_INFO_gAMA)
3637
3638 int_file_gamma - 100,000 times the gamma at which
3639 the image was created
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003640
3641 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003642
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003643 srgb_intent - the rendering intent
3644 (PNG_INFO_sRGB) The presence of
3645 the sRGB chunk means that the pixel
3646 data is in the sRGB color space.
3647 This chunk also implies specific
3648 values of gAMA and cHRM. Rendering
3649 intent is the CSS-1 property that
3650 has been defined by the International
3651 Color Consortium
3652 (http://www.color.org).
3653 It can be one of
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06003654 PNG_sRGB_INTENT_SATURATION,
3655 PNG_sRGB_INTENT_PERCEPTUAL,
3656 PNG_sRGB_INTENT_ABSOLUTE, or
3657 PNG_sRGB_INTENT_RELATIVE.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003658
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003659
3660 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
3661 srgb_intent);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003662
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003663 srgb_intent - the rendering intent
3664 (PNG_INFO_sRGB) The presence of the
3665 sRGB chunk means that the pixel
3666 data is in the sRGB color space.
3667 This function also causes gAMA and
3668 cHRM chunks with the specific values
3669 that are consistent with sRGB to be
3670 written.
3671
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003672 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003673 profile, proflen);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003674
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003675 name - The profile name.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003676
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003677 compression_type - The compression type; always
3678 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
3679 You may give NULL to this argument to
3680 ignore it.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003681
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003682 profile - International Color Consortium color
3683 profile data. May contain NULs.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003684
Glenn Randers-Pehrson4a5a1ec2011-01-15 11:43:28 -06003685 proflen - length of profile data in bytes.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003686
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003687 png_set_sBIT(png_ptr, info_ptr, sig_bit);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003688
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003689 sig_bit - the number of significant bits for
3690 (PNG_INFO_sBIT) each of the gray, red,
3691 green, and blue channels, whichever are
3692 appropriate for the given color type
3693 (png_color_16)
3694
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05003695 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3696 num_trans, trans_color);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003697
Glenn Randers-Pehrson866b62a2009-08-08 16:33:14 -05003698 trans_alpha - array of alpha (transparency)
3699 entries for palette (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003700
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003701 num_trans - number of transparent entries
3702 (PNG_INFO_tRNS)
3703
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05003704 trans_color - graylevel or color sample values
3705 (in order red, green, blue) of the
3706 single transparent color for
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05003707 non-paletted images (PNG_INFO_tRNS)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003708
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003709 png_set_hIST(png_ptr, info_ptr, hist);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003710
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003711 hist - histogram of palette (array of
Glenn Randers-Pehrson8d0bc0f2011-01-25 22:15:58 -06003712 png_uint_16) (PNG_INFO_hIST)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003713
3714 png_set_tIME(png_ptr, info_ptr, mod_time);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003715
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003716 mod_time - time image was last modified
3717 (PNG_VALID_tIME)
3718
3719 png_set_bKGD(png_ptr, info_ptr, background);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003720
Glenn Randers-Pehrsonab389792011-07-09 19:35:22 -05003721 background - background color (of type
3722 png_color_16p) (PNG_VALID_bKGD)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003723
3724 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003725
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003726 text_ptr - array of png_text holding image
3727 comments
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003728
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003729 text_ptr[i].compression - type of compression used
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003730 on "text" PNG_TEXT_COMPRESSION_NONE
3731 PNG_TEXT_COMPRESSION_zTXt
3732 PNG_ITXT_COMPRESSION_NONE
3733 PNG_ITXT_COMPRESSION_zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003734 text_ptr[i].key - keyword for comment. Must contain
3735 1-79 characters.
3736 text_ptr[i].text - text comments for current
3737 keyword. Can be NULL or empty.
3738 text_ptr[i].text_length - length of text string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003739 after decompression, 0 for iTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003740 text_ptr[i].itxt_length - length of itxt string,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003741 after decompression, 0 for tEXt/zTXt
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003742 text_ptr[i].lang - language of comment (NULL or
3743 empty for unknown).
3744 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
3745 or empty for unknown).
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05003746 Note that the itxt_length, lang, and lang_key
3747 members of the text_ptr structure only exist
3748 when the library is built with iTXt chunk support.
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003749 Prior to libpng-1.4.0 the library was built by default
3750 without iTXt support.
Glenn Randers-Pehrson8f5846f2009-10-31 21:31:08 -05003751
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003752 num_text - number of comments
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003753
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003754 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3755 num_spalettes);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003756
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003757 palette_ptr - array of png_sPLT_struct structures
3758 to be added to the list of palettes
3759 in the info structure.
3760 num_spalettes - number of palette structures to be
3761 added.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003762
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003763 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
3764 unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003765
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003766 offset_x - positive offset from the left
3767 edge of the screen
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003768
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003769 offset_y - positive offset from the top
3770 edge of the screen
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003771
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003772 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
3773
3774 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
3775 unit_type);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003776
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003777 res_x - pixels/unit physical resolution
3778 in x direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003779
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003780 res_y - pixels/unit physical resolution
3781 in y direction
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003782
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003783 unit_type - PNG_RESOLUTION_UNKNOWN,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003784 PNG_RESOLUTION_METER
3785
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003786 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003787
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003788 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003789
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003790 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003791
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003792 height - height of a pixel in physical scale units
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003793 (width and height are doubles)
3794
3795 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003796
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003797 unit - physical scale units (an integer)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003798
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003799 width - width of a pixel in physical scale units
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003800 expressed as a string
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003801
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003802 height - height of a pixel in physical scale units
3803 (width and height are strings like "2.54")
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003804
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003805 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
3806 num_unknowns)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003807
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003808 unknowns - array of png_unknown_chunk
3809 structures holding unknown chunks
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003810 unknowns[i].name - name of unknown chunk
3811 unknowns[i].data - data of unknown chunk
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -05003812 unknowns[i].size - size of unknown chunk's data
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003813 unknowns[i].location - position to write chunk in file
3814 0: do not write chunk
3815 PNG_HAVE_IHDR: before PLTE
3816 PNG_HAVE_PLTE: before IDAT
3817 PNG_AFTER_IDAT: after IDAT
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003818
3819The "location" member is set automatically according to
3820what part of the output file has already been written.
3821You can change its value after calling png_set_unknown_chunks()
3822as demonstrated in pngtest.c. Within each of the "locations",
3823the chunks are sequenced according to their position in the
3824structure (that is, the value of "i", which is the order in which
3825the chunk was either read from the input file or defined with
3826png_set_unknown_chunks).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003827
3828A quick word about text and num_text. text is an array of png_text
3829structures. num_text is the number of valid structures in the array.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003830Each png_text structure holds a language code, a keyword, a text value,
3831and a compression type.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003832
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003833The compression types have the same valid numbers as the compression
3834types of the image data. Currently, the only valid number is zero.
3835However, you can store text either compressed or uncompressed, unlike
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003836images, which always have to be compressed. So if you don't want the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003837text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05003838Because tEXt and zTXt chunks don't have a language field, if you
3839specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3840any language code or translated keyword will not be written out.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003841
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05003842Until text gets around a few hundred bytes, it is not worth compressing it.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003843After the text has been written out to the file, the compression type
3844is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3845so that it isn't written out again at the end (in case you are calling
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003846png_write_end() with the same struct).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003847
3848The keywords that are given in the PNG Specification are:
3849
3850 Title Short (one line) title or
3851 caption for image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003852
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003853 Author Name of image's creator
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003854
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003855 Description Description of image (possibly long)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003856
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003857 Copyright Copyright notice
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003858
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003859 Creation Time Time of original image creation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003860 (usually RFC 1123 format, see below)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003861
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003862 Software Software used to create the image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003863
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003864 Disclaimer Legal disclaimer
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003865
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003866 Warning Warning of nature of content
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003867
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003868 Source Device used to create the image
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06003869
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003870 Comment Miscellaneous comment; conversion
3871 from other image format
3872
3873The keyword-text pairs work like this. Keywords should be short
3874simple descriptions of what the comment is about. Some typical
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003875keywords are found in the PNG specification, as is some recommendations
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003876on keywords. You can repeat keywords in a file. You can even write
3877some text before the image and some after. For example, you may want
3878to put a description of the image before the image, but leave the
3879disclaimer until after, so viewers working over modem connections
3880don't have to wait for the disclaimer to go over the modem before
3881they start seeing the image. Finally, keywords should be full
3882words, not abbreviations. Keywords and text are in the ISO 8859-1
3883(Latin-1) character set (a superset of regular ASCII) and can not
3884contain NUL characters, and should not contain control or other
3885unprintable characters. To make the comments widely readable, stick
3886with basic ASCII, and avoid machine specific character set extensions
3887like the IBM-PC character set. The keyword must be present, but
3888you can leave off the text string on non-compressed pairs.
3889Compressed pairs must have a text string, as only the text string
3890is compressed anyway, so the compression would be meaningless.
3891
3892PNG supports modification time via the png_time structure. Two
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003893conversion routines are provided, png_convert_from_time_t() for
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003894time_t and png_convert_from_struct_tm() for struct tm. The
3895time_t routine uses gmtime(). You don't have to use either of
3896these, but if you wish to fill in the png_time structure directly,
3897you should provide the time in universal time (GMT) if possible
3898instead of your local time. Note that the year number is the full
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06003899year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003900that months start with 1.
3901
3902If you want to store the time of the original image creation, you should
3903use a plain tEXt chunk with the "Creation Time" keyword. This is
3904necessary because the "creation time" of a PNG image is somewhat vague,
3905depending on whether you mean the PNG file, the time the image was
3906created in a non-PNG format, a still photo from which the image was
3907scanned, or possibly the subject matter itself. In order to facilitate
3908machine-readable dates, it is recommended that the "Creation Time"
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06003909tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003910although this isn't a requirement. Unlike the tIME chunk, the
3911"Creation Time" tEXt chunk is not expected to be automatically changed
3912by the software. To facilitate the use of RFC 1123 dates, a function
3913png_convert_to_rfc1123(png_timep) is provided to convert from PNG
3914time to an RFC 1123 format string.
3915
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003916.SS Writing unknown chunks
3917
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06003918You can use the png_set_unknown_chunks function to queue up chunks
3919for writing. You give it a chunk name, raw data, and a size; that's
3920all there is to it. The chunks will be written by the next following
3921png_write_info_before_PLTE, png_write_info, or png_write_end function.
3922Any chunks previously read into the info structure's unknown-chunk
3923list will also be written out in a sequence that satisfies the PNG
3924specification's ordering rules.
3925
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003926.SS The high-level write interface
3927
3928At this point there are two ways to proceed; through the high-level
3929write interface, or through a sequence of low-level write operations.
3930You can use the high-level interface if your image data is present
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05003931in the info structure. All defined output
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06003932transformations are permitted, enabled by the following masks.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003933
3934 PNG_TRANSFORM_IDENTITY No transformation
3935 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003936 PNG_TRANSFORM_PACKSWAP Change order of packed
3937 pixels to LSB first
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003938 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06003939 PNG_TRANSFORM_SHIFT Normalize pixels to the
3940 sBIT depth
3941 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
3942 to BGRA
3943 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
3944 to AG
3945 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
3946 to transparency
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003947 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
Glenn Randers-Pehrson1eb14e92008-12-10 07:14:45 -06003948 PNG_TRANSFORM_STRIP_FILLER Strip out filler
3949 bytes (deprecated).
3950 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
3951 filler bytes
3952 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
3953 filler bytes
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003954
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05003955If you have valid image data in the info structure (you can use
3956png_set_rows() to put image data in the info structure), simply do this:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003957
3958 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
3959
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05003960where png_transforms is an integer containing the bitwise OR of some set of
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003961transformation flags. This call is equivalent to png_write_info(),
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003962followed the set of transformations indicated by the transform mask,
3963then png_write_image(), and finally png_write_end().
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003964
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05003965(The final parameter of this call is not yet used. Someday it might point
3966to transformation parameters required by some future output transform.)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003967
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05003968You must use png_transforms and not call any png_set_transform() functions
3969when you use png_write_png().
3970
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003971.SS The low-level write interface
3972
3973If you are going the low-level route instead, you are now ready to
3974write all the file information up to the actual image data. You do
3975this with a call to png_write_info().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06003976
3977 png_write_info(png_ptr, info_ptr);
3978
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003979Note that there is one transformation you may need to do before
3980png_write_info(). In PNG files, the alpha channel in an image is the
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06003981level of opacity. If your data is supplied as a level of transparency,
3982you can invert the alpha channel before you write it, so that 0 is
3983fully transparent and 255 (in 8-bit or paletted images) or 65535
3984(in 16-bit images) is fully opaque, with
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06003985
3986 png_set_invert_alpha(png_ptr);
3987
3988This must appear before png_write_info() instead of later with the
3989other transformations because in the case of paletted images the tRNS
3990chunk data has to be inverted before the tRNS chunk is written. If
3991your image is not a paletted image, the tRNS data (which in such cases
3992represents a single color to be rendered as transparent) won't need to
3993be changed, and you can safely do this transformation after your
3994png_write_info() call.
3995
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06003996If you need to write a private chunk that you want to appear before
3997the PLTE chunk when PLTE is present, you can write the PNG info in
3998two steps, and insert code to write your own chunk between them:
3999
4000 png_write_info_before_PLTE(png_ptr, info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004001 png_set_unknown_chunks(png_ptr, info_ptr, ...);
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06004002 png_write_info(png_ptr, info_ptr);
4003
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004004After you've written the file information, you can set up the library
4005to handle any special transformations of the image data. The various
4006ways to transform the data will be described in the order that they
4007should occur. This is important, as some of these change the color
4008type and/or bit depth of the data, and some others only work on
4009certain color types and bit depths. Even though each transformation
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004010checks to see if it has data that it can do something with, you should
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004011make sure to only enable a transformation if it will be valid for the
4012data. For example, don't swap red and blue on grayscale data.
4013
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004014PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
Glenn Randers-Pehrson68ea2432000-04-01 21:10:05 -06004015the library to strip input data that has 4 or 8 bytes per pixel down
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004016to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
4017bytes per pixel).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004018
4019 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
4020
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004021where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004022PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
4023is stored XRGB or RGBX.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004024
4025PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
4026they can, resulting in, for example, 8 pixels per byte for 1 bit files.
4027If the data is supplied at 1 pixel per byte, use this code, which will
4028correctly pack the pixels into a single byte:
4029
4030 png_set_packing(png_ptr);
4031
4032PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
4033data is of another bit depth, you can write an sBIT chunk into the
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004034file so that decoders can recover the original data if desired.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004035
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004036 /* Set the true bit depth of the image data */
4037 if (color_type & PNG_COLOR_MASK_COLOR)
4038 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004039 sig_bit.red = true_bit_depth;
4040 sig_bit.green = true_bit_depth;
4041 sig_bit.blue = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004042 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004043
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004044 else
4045 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004046 sig_bit.gray = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004047 }
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004048
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004049 if (color_type & PNG_COLOR_MASK_ALPHA)
4050 {
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004051 sig_bit.alpha = true_bit_depth;
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004052 }
4053
4054 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
4055
4056If the data is stored in the row buffer in a bit depth other than
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004057one 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 -06004058this will scale the values to appear to be the correct bit depth as
4059is required by PNG.
4060
4061 png_set_shift(png_ptr, &sig_bit);
4062
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05004063PNG files store 16-bit pixels in network byte order (big-endian,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004064ie. most significant bits first). This code would be used if they are
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004065supplied the other way (little-endian, i.e. least significant bits
4066first, the way PCs store them):
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004067
4068 if (bit_depth > 8)
4069 png_set_swap(png_ptr);
4070
4071If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
4072need to change the order the pixels are packed into bytes, you can use:
4073
4074 if (bit_depth < 8)
4075 png_set_packswap(png_ptr);
4076
4077PNG files store 3 color pixels in red, green, blue order. This code
4078would be used if they are supplied as blue, green, red:
4079
4080 png_set_bgr(png_ptr);
4081
4082PNG files describe monochrome as black being zero and white being
4083one. This code would be used if the pixels are supplied with this reversed
4084(black being one and white being zero):
4085
4086 png_set_invert_mono(png_ptr);
4087
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004088Finally, you can write your own transformation function if none of
4089the existing ones meets your needs. This is done by setting a callback
4090with
4091
4092 png_set_write_user_transform_fn(png_ptr,
4093 write_transform_fn);
4094
4095You must supply the function
4096
Glenn Randers-Pehrson93215672011-02-13 19:42:19 -06004097 void write_transform_fn(png_structp png_ptr, png_row_infop
4098 row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004099
4100See pngtest.c for a working example. Your function will be called
John Bowlerf19abd62011-01-22 18:29:24 -06004101before any of the other transformations are processed. If supported
4102libpng also supplies an information routine that may be called from
4103your callback:
4104
4105 png_get_current_row_number(png_ptr);
John Bowlercd113452011-02-16 06:15:13 -06004106 png_get_current_pass_number(png_ptr);
John Bowlerf19abd62011-01-22 18:29:24 -06004107
John Bowlercd113452011-02-16 06:15:13 -06004108This returns the current row passed to the transform. With interlaced
4109images the value returned is the row in the input sub-image image. Use
4110PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
4111find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
4112
4113The discussion of interlace handling above contains more information on how to
4114use these values.
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004115
4116You can also set up a pointer to a user structure for use by your
4117callback function.
4118
4119 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
4120
4121The user_channels and user_depth parameters of this function are ignored
4122when writing; you can set them to zero as shown.
4123
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004124You can retrieve the pointer via the function png_get_user_transform_ptr().
4125For example:
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004126
4127 voidp write_user_transform_ptr =
4128 png_get_user_transform_ptr(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06004129
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004130It is possible to have libpng flush any pending output, either manually,
4131or automatically after a certain number of lines have been written. To
4132flush the output stream a single time call:
4133
4134 png_write_flush(png_ptr);
4135
4136and to have libpng flush the output stream periodically after a certain
4137number of scanlines have been written, call:
4138
4139 png_set_flush(png_ptr, nrows);
4140
4141Note that the distance between rows is from the last time png_write_flush()
4142was called, or the first row of the image if it has never been called.
4143So if you write 50 lines, and then png_set_flush 25, it will flush the
4144output on the next scanline, and every 25 lines thereafter, unless
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004145png_write_flush() is called before 25 more lines have been written.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004146If nrows is too small (less than about 10 lines for a 640 pixel wide
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004147RGB image) the image compression may decrease noticeably (although this
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004148may be acceptable for real-time applications). Infrequent flushing will
4149only degrade the compression performance by a few percent over images
4150that do not use flushing.
4151
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004152.SS Writing the image data
4153
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004154That's it for the transformations. Now you can write the image data.
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004155The simplest way to do this is in one function call. If you have the
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004156whole image in memory, you can just call png_write_image() and libpng
4157will write the image. You will need to pass in an array of pointers to
4158each row. This function automatically handles interlacing, so you don't
4159need to call png_set_interlace_handling() or call this function multiple
4160times, or any of that other stuff necessary with png_write_rows().
4161
4162 png_write_image(png_ptr, row_pointers);
4163
4164where row_pointers is:
4165
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004166 png_byte *row_pointers[height];
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004167
4168You can point to void or char or whatever you use for pixels.
4169
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05004170If you don't want to write the whole image at once, you can
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004171use png_write_rows() instead. If the file is not interlaced,
4172this is simple:
4173
4174 png_write_rows(png_ptr, row_pointers,
4175 number_of_rows);
4176
4177row_pointers is the same as in the png_write_image() call.
4178
4179If you are just writing one row at a time, you can do this with
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004180a single row_pointer instead of an array of row_pointers:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004181
4182 png_bytep row_pointer = row;
4183
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06004184 png_write_row(png_ptr, row_pointer);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004185
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004186When the file is interlaced, things can get a good deal more complicated.
4187The only currently (as of the PNG Specification version 1.2, dated July
41881999) defined interlacing scheme for PNG files is the "Adam7" interlace
4189scheme, that breaks down an image into seven smaller images of varying
4190size. libpng will build these images for you, or you can do them
4191yourself. If you want to build them yourself, see the PNG specification
4192for details of which pixels to write when.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004193
4194If you don't want libpng to handle the interlacing details, just
4195use png_set_interlace_handling() and call png_write_rows() the
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004196correct number of times to write all the sub-images
4197(png_set_interlace_handling() returns the number of sub-images.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004198
4199If you want libpng to build the sub-images, call this before you start
4200writing any rows:
4201
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004202 number_of_passes = png_set_interlace_handling(png_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004203
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004204This will return the number of passes needed. Currently, this is seven,
4205but may change if another interlace type is added.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004206
4207Then write the complete image number_of_passes times.
4208
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004209 png_write_rows(png_ptr, row_pointers, number_of_rows);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004210
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06004211Think carefully before you write an interlaced image. Typically code that
4212reads such images reads all the image data into memory, uncompressed, before
4213doing any processing. Only code that can display an image on the fly can
4214take advantage of the interlacing and even then the image has to be exactly
4215the correct size for the output device, because scaling an image requires
4216adjacent pixels and these are not available until all the passes have been
4217read.
4218
4219If you do write an interlaced image you will hardly ever need to handle
4220the interlacing yourself. Call png_set_interlace_handling() and use the
4221approach described above.
4222
4223The only time it is conceivable that you will really need to write an
4224interlaced image pass-by-pass is when you have read one pass by pass and
4225made some pixel-by-pixel transformation to it, as described in the read
4226code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
4227to determine the size of each sub-image in turn and simply write the rows
4228you obtained from the read code.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004229
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004230.SS Finishing a sequential write
4231
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004232After you are finished writing the image, you should finish writing
4233the file. If you are interested in writing comments or time, you should
4234pass an appropriately filled png_info pointer. If you are not interested,
4235you can pass NULL.
4236
4237 png_write_end(png_ptr, info_ptr);
4238
4239When you are done, you can free all memory used by libpng like this:
4240
4241 png_destroy_write_struct(&png_ptr, &info_ptr);
4242
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004243It is also possible to individually free the info_ptr members that
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05004244point to libpng-allocated storage with the following function:
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004245
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004246 png_free_data(png_ptr, info_ptr, mask, seq)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004247
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004248 mask - identifies data to be freed, a mask
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004249 containing the bitwise OR of one or
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004250 more of
4251 PNG_FREE_PLTE, PNG_FREE_TRNS,
4252 PNG_FREE_HIST, PNG_FREE_ICCP,
4253 PNG_FREE_PCAL, PNG_FREE_ROWS,
4254 PNG_FREE_SCAL, PNG_FREE_SPLT,
4255 PNG_FREE_TEXT, PNG_FREE_UNKN,
4256 or simply PNG_FREE_ALL
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004257
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004258 seq - sequence number of item to be freed
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004259 (-1 for all items)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004260
Glenn Randers-Pehrsonfc4a1432000-05-17 17:39:34 -05004261This function may be safely called when the relevant storage has
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004262already been freed, or has not yet been allocated, or was allocated
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004263by the user and not by libpng, and will in those cases do nothing.
4264The "seq" parameter is ignored if only one item of the selected data
4265type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
4266are allowed for the data type identified in the mask, such as text or
4267sPLT, only the n'th item in the structure is freed, where n is "seq".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06004268
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004269If you allocated data such as a palette that you passed in to libpng
4270with png_set_*, you must not free it until just before the call to
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004271png_destroy_write_struct().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004272
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004273The default behavior is only to free data that was allocated internally
4274by libpng. This can be changed, so that libpng will not free the data,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004275or so that it will free data that was allocated by the user with png_malloc()
4276or png_zalloc() and passed in via a png_set_*() function, with
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004277
4278 png_data_freer(png_ptr, info_ptr, freer, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004279
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004280 freer - one of
4281 PNG_DESTROY_WILL_FREE_DATA
4282 PNG_SET_WILL_FREE_DATA
4283 PNG_USER_WILL_FREE_DATA
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004284
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004285 mask - which data elements are affected
4286 same choices as in png_free_data()
4287
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004288For example, to transfer responsibility for some data from a read structure
4289to a write structure, you could use
4290
4291 png_data_freer(read_ptr, read_info_ptr,
4292 PNG_USER_WILL_FREE_DATA,
4293 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004294
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004295 png_data_freer(write_ptr, write_info_ptr,
4296 PNG_DESTROY_WILL_FREE_DATA,
4297 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4298
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004299thereby briefly reassigning responsibility for freeing to the user but
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004300immediately afterwards reassigning it once more to the write_destroy
4301function. Having done this, it would then be safe to destroy the read
4302structure and continue to use the PLTE, tRNS, and hIST data in the write
4303structure.
4304
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004305This function only affects data that has already been allocated.
4306You can call this function before calling after the png_set_*() functions
4307to control whether the user or png_destroy_*() is supposed to free the data.
4308When the user assumes responsibility for libpng-allocated data, the
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004309application must use
4310png_free() to free it, and when the user transfers responsibility to libpng
4311for data that the user has allocated, the user must have used png_malloc()
4312or png_zalloc() to allocate it.
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004313
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004314If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
4315separately, do not transfer responsibility for freeing text_ptr to libpng,
4316because when libpng fills a png_text structure it combines these members with
4317the key member, and png_free_data() will free only text_ptr.key. Similarly,
4318if you transfer responsibility for free'ing text_ptr from libpng to your
4319application, your application must not separately free those members.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004320For a more compact example of writing a PNG image, see the file example.c.
4321
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004322.SH V. Modifying/Customizing libpng:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004323
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004324There are two issues here. The first is changing how libpng does
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004325standard things like memory allocation, input/output, and error handling.
4326The second deals with more complicated things like adding new chunks,
4327adding new transformations, and generally changing how libpng works.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004328Both of those are compile-time issues; that is, they are generally
4329determined at the time the code is written, and there is rarely a need
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004330to provide the user with a means of changing them.
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004331
4332Memory allocation, input/output, and error handling
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004333
4334All of the memory allocation, input/output, and error handling in libpng
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -06004335goes through callbacks that are user-settable. The default routines are
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004336in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004337these functions, call the appropriate png_set_*_fn() function.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004338
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004339Memory allocation is done through the functions png_malloc(), png_calloc(),
4340and png_free(). These currently just call the standard C functions.
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05004341png_calloc() calls png_malloc() and then clears the newly
4342allocated memory to zero. There is limited support for certain systems
4343with segmented memory architectures and the types of pointers declared by
4344png.h match this; you will have to use appropriate pointers in your
4345application. Since it is
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004346unlikely that the method of handling memory allocation on a platform
4347will change between applications, these functions must be modified in
4348the library at compile time. If you prefer to use a different method
4349of allocating and freeing data, you can use png_create_read_struct_2() or
4350png_create_write_struct_2() to register your own functions as described
4351above. These functions also provide a void pointer that can be retrieved
4352via
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004353
4354 mem_ptr=png_get_mem_ptr(png_ptr);
4355
4356Your replacement memory functions must have prototypes as follows:
4357
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004358 png_voidp malloc_fn(png_structp png_ptr,
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004359 png_alloc_size_t size);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004360
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004361 void free_fn(png_structp png_ptr, png_voidp ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004362
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05004363Your malloc_fn() must return NULL in case of failure. The png_malloc()
4364function will normally call png_error() if it receives a NULL from the
4365system memory allocator or from your replacement malloc_fn().
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05004366
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004367Your free_fn() will never be called with a NULL ptr, since libpng's
4368png_free() checks for NULL before calling free_fn().
4369
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004370Input/Output in libpng is done through png_read() and png_write(),
4371which currently just call fread() and fwrite(). The FILE * is stored in
4372png_struct and is initialized via png_init_io(). If you wish to change
4373the method of I/O, the library supplies callbacks that you can set
4374through the function png_set_read_fn() and png_set_write_fn() at run
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004375time, instead of calling the png_init_io() function. These functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004376also provide a void pointer that can be retrieved via the function
4377png_get_io_ptr(). For example:
4378
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004379 png_set_read_fn(png_structp read_ptr,
4380 voidp read_io_ptr, png_rw_ptr read_data_fn)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004381
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004382 png_set_write_fn(png_structp write_ptr,
4383 voidp write_io_ptr, png_rw_ptr write_data_fn,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004384 png_flush_ptr output_flush_fn);
4385
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05004386 voidp read_io_ptr = png_get_io_ptr(read_ptr);
4387 voidp write_io_ptr = png_get_io_ptr(write_ptr);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004388
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004389The replacement I/O functions must have prototypes as follows:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004390
4391 void user_read_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05004392 png_bytep data, png_size_t length);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004393
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004394 void user_write_data(png_structp png_ptr,
Glenn Randers-Pehrson837a3d12002-05-10 20:19:58 -05004395 png_bytep data, png_size_t length);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004396
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004397 void user_flush_data(png_structp png_ptr);
4398
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004399The user_read_data() function is responsible for detecting and
4400handling end-of-data errors.
4401
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004402Supplying NULL for the read, write, or flush functions sets them back
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004403to using the default C stream functions, which expect the io_ptr to
4404point to a standard *FILE structure. It is probably a mistake
4405to use NULL for one of write_data_fn and output_flush_fn but not both
4406of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4407It is an error to read from a write stream, and vice versa.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004408
4409Error handling in libpng is done through png_error() and png_warning().
4410Errors handled through png_error() are fatal, meaning that png_error()
4411should never return to its caller. Currently, this is handled via
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004412setjmp() and longjmp() (unless you have compiled libpng with
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05004413PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
Glenn Randers-Pehrson60988072010-04-13 22:11:06 -05004414but you could change this to do things like exit() if you should wish,
Glenn Randers-Pehrson54ac9a92010-04-02 17:06:22 -05004415as long as your function does not return.
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004416
4417On non-fatal errors, png_warning() is called
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004418to print a warning message, and then control returns to the calling code.
4419By default png_error() and png_warning() print a message on stderr via
Glenn Randers-Pehrson38e6e772000-04-09 19:06:13 -05004420fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
4421(because you don't want the messages) or PNG_NO_STDIO defined (because
4422fprintf() isn't available). If you wish to change the behavior of the error
4423functions, you will need to set up your own message callbacks. These
4424functions are normally supplied at the time that the png_struct is created.
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004425It is also possible to redirect errors and warnings to your own replacement
4426functions after png_create_*_struct() has been called by calling:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004427
4428 png_set_error_fn(png_structp png_ptr,
4429 png_voidp error_ptr, png_error_ptr error_fn,
4430 png_error_ptr warning_fn);
4431
4432 png_voidp error_ptr = png_get_error_ptr(png_ptr);
4433
4434If NULL is supplied for either error_fn or warning_fn, then the libpng
4435default function will be used, calling fprintf() and/or longjmp() if a
4436problem is encountered. The replacement error functions should have
4437parameters as follows:
4438
4439 void user_error_fn(png_structp png_ptr,
4440 png_const_charp error_msg);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004441
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004442 void user_warning_fn(png_structp png_ptr,
4443 png_const_charp warning_msg);
4444
4445The motivation behind using setjmp() and longjmp() is the C++ throw and
4446catch exception handling methods. This makes the code much easier to write,
4447as there is no need to check every return code of every function call.
4448However, there are some uncertainties about the status of local variables
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004449after a longjmp, so the user may want to be careful about doing anything
4450after setjmp returns non-zero besides returning itself. Consult your
4451compiler documentation for more details. For an alternative approach, you
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004452may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4453which is illustrated in pngvalid.c and in contrib/visupng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004454
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004455.SS Custom chunks
4456
4457If you need to read or write custom chunks, you may need to get deeper
4458into the libpng code. The library now has mechanisms for storing
4459and writing chunks of unknown type; you can even declare callbacks
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06004460for custom chunks. However, this may not be good enough if the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004461library code itself needs to know about interactions between your
4462chunk and existing `intrinsic' chunks.
4463
4464If you need to write a new intrinsic chunk, first read the PNG
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004465specification. Acquire a first level of understanding of how it works.
4466Pay particular attention to the sections that describe chunk names,
4467and look at how other chunks were designed, so you can do things
4468similarly. Second, check out the sections of libpng that read and
4469write chunks. Try to find a chunk that is similar to yours and use
4470it as a template. More details can be found in the comments inside
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004471the code. It is best to handle private or unknown chunks in a generic method,
4472via callback functions, instead of by modifying libpng functions. This
4473is illustrated in pngtest.c, which uses a callback function to handle a
4474private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4475libpng.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004476
4477If you wish to write your own transformation for the data, look through
4478the part of the code that does the transformations, and check out some of
4479the simpler ones to get an idea of how they work. Try to find a similar
4480transformation to the one you want to add and copy off of it. More details
4481can be found in the comments inside the code itself.
4482
Glenn Randers-Pehrson593fc042011-05-12 22:18:23 -05004483.SS Configuring for 16-bit platforms
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004484
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004485You will want to look into zconf.h to tell zlib (and thus libpng) that
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004486it cannot allocate more then 64K at a time. Even if you can, the memory
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004487won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004488
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004489.SS Configuring for DOS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004490
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004491For DOS users who only have access to the lower 640K, you will
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004492have to limit zlib's memory usage via a png_set_compression_mem_level()
4493call. See zlib.h or zconf.h in the zlib library for more information.
4494
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004495.SS Configuring for Medium Model
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004496
4497Libpng's support for medium model has been tested on most of the popular
4498compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4499defined, and FAR gets defined to far in pngconf.h, and you should be
4500all set. Everything in the library (except for zlib's structure) is
4501expecting far data. You must use the typedefs with the p or pp on
4502the end for pointers (or at least look at them and be careful). Make
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004503note that the rows of data are defined as png_bytepp, which is
4504an "unsigned char far * far *".
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004505
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004506.SS Configuring for gui/windowing platforms:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004507
4508You will need to write new error and warning functions that use the GUI
4509interface, as described previously, and set them to be the error and
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06004510warning functions at the time that png_create_*_struct() is called,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004511in order to have them available during the structure initialization.
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004512They can be changed later via png_set_error_fn(). On some compilers,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004513you may also have to change the memory allocators (png_malloc, etc.).
4514
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004515.SS Configuring for compiler xxx:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004516
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05004517All includes for libpng are in pngconf.h. If you need to add, change
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004518or delete an include, this is the place to do it.
4519The includes that are not needed outside libpng are placed in pngpriv.h,
4520which is only used by the routines inside libpng itself.
4521The files in libpng proper only include pngpriv.h and png.h, which
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004522%14%in turn includes pngconf.h.
4523in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
4524As of libpng-1.5.0, pngpriv.h also includes three other private header
4525files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
4526that previously appeared in the public headers.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004527
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004528.SS Configuring zlib:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004529
4530There are special functions to configure the compression. Perhaps the
4531most useful one changes the compression level, which currently uses
4532input compression values in the range 0 - 9. The library normally
4533uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
4534have shown that for a large majority of images, compression values in
4535the range 3-6 compress nearly as well as higher levels, and do so much
4536faster. For online applications it may be desirable to have maximum speed
4537(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
4538specify no compression (Z_NO_COMPRESSION = 0), but this would create
4539files larger than just storing the raw bitmap. You can specify the
4540compression level by calling:
4541
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06004542 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004543 png_set_compression_level(png_ptr, level);
4544
4545Another useful one is to reduce the memory level used by the library.
4546The memory level defaults to 8, but it can be lowered if you are
4547short on memory (running DOS, for example, where you only have 640K).
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004548Note that the memory level does have an effect on compression; among
4549other things, lower levels will result in sections of incompressible
4550data being emitted in smaller stored blocks, with a correspondingly
4551larger relative overhead of up to 15% in the worst case.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004552
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06004553 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004554 png_set_compression_mem_level(png_ptr, level);
4555
4556The other functions are for configuring zlib. They are not recommended
4557for normal use and may result in writing an invalid PNG file. See
4558zlib.h for more information on what these mean.
4559
Glenn Randers-Pehrson38734ee2011-03-03 06:23:31 -06004560 #include zlib.h
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004561 png_set_compression_strategy(png_ptr,
4562 strategy);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004563
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004564 png_set_compression_window_bits(png_ptr,
4565 window_bits);
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004566
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004567 png_set_compression_method(png_ptr, method);
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004568
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004569 png_set_compression_buffer_size(png_ptr, size);
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004570
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05004571As of libpng version 1.5.4, additional APIs became
4572available to set these separately for non-IDAT
4573compressed chunks such as zTXt, iTXt, and iCCP:
4574
4575 #include zlib.h
4576 #if PNG_LIBPNG_VER <= 10504
4577 png_set_text_compression_level(png_ptr, level);
4578
4579 png_set_text_compression_mem_level(png_ptr, level);
4580
4581 png_set_text_compression_strategy(png_ptr,
4582 strategy);
4583
4584 png_set_text_compression_window_bits(png_ptr,
4585 window_bits);
4586
4587 png_set_text_compression_method(png_ptr, method);
4588 #endif
4589
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004590.SS Controlling row filtering
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004591
4592If you want to control whether libpng uses filtering or not, which
4593filters are used, and how it goes about picking row filters, you
4594can call one of these functions. The selection and configuration
4595of row filters can have a significant impact on the size and
4596encoding speed and a somewhat lesser impact on the decoding speed
4597of an image. Filtering is enabled by default for RGB and grayscale
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004598images (with and without alpha), but not for paletted images nor
4599for any images with bit depths less than 8 bits/pixel.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004600
4601The 'method' parameter sets the main filtering method, which is
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05004602currently only '0' in the PNG 1.2 specification. The 'filters'
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004603parameter sets which filter(s), if any, should be used for each
4604scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
4605to turn filtering on and off, respectively.
4606
4607Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
4608PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05004609ORed together with '|' to specify one or more filters to use.
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004610These filters are described in more detail in the PNG specification.
4611If you intend to change the filter type during the course of writing
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004612the image, you should start with flags set for all of the filters
4613you intend to use so that libpng can initialize its internal
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004614structures appropriately for all of the filter types. (Note that this
4615means the first row must always be adaptively filtered, because libpng
4616currently does not allocate the filter buffers until png_write_row()
4617is called for the first time.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004618
4619 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05004620 PNG_FILTER_UP | PNG_FILTER_AVG |
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004621 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004622
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004623 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
4624 filters);
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06004625 The second parameter can also be
4626 PNG_INTRAPIXEL_DIFFERENCING if you are
4627 writing a PNG to be embedded in a MNG
4628 datastream. This parameter must be the
4629 same as the value of filter_method used
4630 in png_set_IHDR().
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004631
4632It is also possible to influence how libpng chooses from among the
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004633available filters. This is done in one or both of two ways - by
4634telling it how important it is to keep the same filter for successive
4635rows, and by telling it the relative computational costs of the filters.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004636
4637 double weights[3] = {1.5, 1.3, 1.1},
4638 costs[PNG_FILTER_VALUE_LAST] =
4639 {1.0, 1.3, 1.3, 1.5, 1.7};
4640
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05004641 png_set_filter_heuristics(png_ptr,
4642 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004643 weights, costs);
4644
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004645The weights are multiplying factors that indicate to libpng that the
4646row filter should be the same for successive rows unless another row filter
4647is that many times better than the previous filter. In the above example,
4648if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004649"sum of absolute differences" 1.5 x 1.3 times higher than other filters
4650and still be chosen, while the NONE filter could have a sum 1.1 times
4651higher than other filters and still be chosen. Unspecified weights are
4652taken to be 1.0, and the specified weights should probably be declining
4653like those above in order to emphasize recent filters over older filters.
4654
4655The filter costs specify for each filter type a relative decoding cost
4656to be considered when selecting row filters. This means that filters
4657with higher costs are less likely to be chosen over filters with lower
4658costs, unless their "sum of absolute differences" is that much smaller.
4659The costs do not necessarily reflect the exact computational speeds of
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06004660the various filters, since this would unduly influence the final image
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004661size.
4662
4663Note that the numbers above were invented purely for this example and
4664are given only to help explain the function usage. Little testing has
4665been done to find optimum values for either the costs or the weights.
4666
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004667.SS Removing unwanted object code
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004668
4669There are a bunch of #define's in pngconf.h that control what parts of
4670libpng are compiled. All the defines end in _SUPPORTED. If you are
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004671never going to use a capability, you can change the #define to #undef
4672before recompiling libpng and save yourself code and data space, or
4673you can turn off individual capabilities with defines that begin with
4674PNG_NO_.
4675
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004676In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
4677
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004678You can also turn all of the transforms and ancillary chunk capabilities
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05004679off en masse with compiler directives that define
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004680PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
4681or all four,
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004682along with directives to turn on any of the capabilities that you do
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004683want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
4684transformations but still leave the library fully capable of reading
4685and writing PNG files with all known public chunks. Use of the
4686PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
4687that is incapable of reading or writing ancillary chunks. If you are
4688not using the progressive reading capability, you can turn that off
4689with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
4690capability, which you'll still have).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004691
4692All the reading and writing specific code are in separate files, so the
4693linker should only grab the files it needs. However, if you want to
4694make sure, or if you are building a stand alone library, all the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05004695reading files start with "pngr" and all the writing files start with "pngw".
4696The files that don't match either (like png.c, pngtrans.c, etc.)
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004697are used for both reading and writing, and always need to be included.
4698The progressive reader is in pngpread.c
4699
4700If you are creating or distributing a dynamically linked library (a .so
4701or DLL file), you should not remove or disable any parts of the library,
4702as this will cause applications linked with different versions of the
4703library to fail if they call functions not available in your library.
4704The size of the library itself should not be an issue, because only
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004705those sections that are actually used will be loaded into memory.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004706
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06004707.SS Requesting debug printout
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004708
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004709The macro definition PNG_DEBUG can be used to request debugging
4710printout. Set it to an integer value in the range 0 to 3. Higher
4711numbers result in increasing amounts of debugging information. The
4712information is printed to the "stderr" file, unless another file
4713name is specified in the PNG_DEBUG_FILE macro definition.
4714
4715When PNG_DEBUG > 0, the following functions (macros) become available:
4716
4717 png_debug(level, message)
4718 png_debug1(level, message, p1)
4719 png_debug2(level, message, p1, p2)
4720
4721in which "level" is compared to PNG_DEBUG to decide whether to print
4722the message, "message" is the formatted string to be printed,
4723and p1 and p2 are parameters that are to be embedded in the string
4724according to printf-style formatting directives. For example,
4725
4726 png_debug1(2, "foo=%d\n", foo);
4727
4728is expanded to
4729
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004730 if (PNG_DEBUG > 2)
4731 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004732
4733When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
4734can still use PNG_DEBUG to control your own debugging:
4735
4736 #ifdef PNG_DEBUG
4737 fprintf(stderr, ...
4738 #endif
4739
4740When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
4741having level = 0 will be printed. There aren't any such statements in
4742this version of libpng, but if you insert some they will be printed.
4743
Glenn Randers-Pehrson56f63962008-10-06 10:16:17 -05004744.SH VI. MNG support
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06004745
4746The MNG specification (available at http://www.libpng.org/pub/mng) allows
4747certain extensions to PNG for PNG images that are embedded in MNG datastreams.
4748Libpng can support some of these extensions. To enable them, use the
4749png_permit_mng_features() function:
4750
4751 feature_set = png_permit_mng_features(png_ptr, mask)
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004752
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004753 mask is a png_uint_32 containing the bitwise OR of the
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06004754 features you want to enable. These include
4755 PNG_FLAG_MNG_EMPTY_PLTE
4756 PNG_FLAG_MNG_FILTER_64
4757 PNG_ALL_MNG_FEATURES
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004758
Glenn Randers-Pehrsonebd7f9a2006-10-19 09:37:56 -05004759 feature_set is a png_uint_32 that is the bitwise AND of
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -06004760 your mask with the set of MNG features that is
4761 supported by the version of libpng that you are using.
4762
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06004763It is an error to use this function when reading or writing a standalone
4764PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
Glenn Randers-Pehrsonf05f8032000-12-23 14:27:39 -06004765in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
4766and the MHDR and MEND chunks. Libpng does not provide support for these
4767or any other MNG chunks; your application must provide its own support for
4768them. You may wish to consider using libmng (available at
4769http://www.libmng.com) instead.
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -06004770
Glenn Randers-Pehrson8fb550c2009-03-21 08:15:32 -05004771.SH VII. Changes to Libpng from version 0.88
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004772
4773It should be noted that versions of libpng later than 0.96 are not
4774distributed by the original libpng author, Guy Schalnat, nor by
4775Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
4776distributed versions 0.89 through 0.96, but rather by another member
4777of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
4778still alive and well, but they have moved on to other things.
4779
4780The old libpng functions png_read_init(), png_write_init(),
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05004781png_info_init(), png_read_destroy(), and png_write_destroy() have been
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05004782moved to PNG_INTERNAL in version 0.95 to discourage their use. These
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06004783functions will be removed from libpng version 1.4.0.
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05004784
4785The preferred method of creating and initializing the libpng structures is
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004786via the png_create_read_struct(), png_create_write_struct(), and
4787png_create_info_struct() because they isolate the size of the structures
4788from the application, allow version error checking, and also allow the
4789use of custom error handling routines during the initialization, which
4790the old functions do not. The functions png_read_destroy() and
4791png_write_destroy() do not actually free the memory that libpng
4792allocated for these structs, but just reset the data structures, so they
4793can be used instead of png_destroy_read_struct() and
4794png_destroy_write_struct() if you feel there is too much system overhead
4795allocating and freeing the png_struct for each image read.
4796
4797Setting the error callbacks via png_set_message_fn() before
4798png_read_init() as was suggested in libpng-0.88 is no longer supported
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06004799because this caused applications that do not use custom error functions
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004800to fail if the png_ptr was not initialized to zero. It is still possible
4801to set the error callbacks AFTER png_read_init(), or to change them with
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05004802png_set_error_fn(), which is essentially the same function, but with a new
4803name to force compilation errors with applications that try to use the old
4804method.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06004805
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05004806Starting with version 1.0.7, you can find out which version of the library
4807you are using at run-time:
4808
4809 png_uint_32 libpng_vn = png_access_version_number();
4810
4811The number libpng_vn is constructed from the major version, minor
4812version with leading zero, and release number with leading zero,
4813(e.g., libpng_vn for version 1.0.7 is 10007).
4814
4815You can also check which version of png.h you used when compiling your
4816application:
4817
4818 png_uint_32 application_vn = PNG_LIBPNG_VER;
4819
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004820.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06004821
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004822Support for user memory management was enabled by default. To
4823accomplish this, the functions png_create_read_struct_2(),
4824png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
4825png_malloc_default(), and png_free_default() were added.
4826
Glenn Randers-Pehrsond6ea40a2009-11-02 07:32:00 -06004827Support for the iTXt chunk has been enabled by default as of
4828version 1.2.41.
4829
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004830Support for certain MNG features was enabled.
4831
4832Support for numbered error messages was added. However, we never got
4833around to actually numbering the error messages. The function
4834png_set_strip_error_numbers() was added (Note: the prototype for this
4835function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
4836builds of libpng-1.2.15. It was restored in libpng-1.2.36).
4837
4838The png_malloc_warn() function was added at libpng-1.2.3. This issues
4839a png_warning and returns NULL instead of aborting when it fails to
4840acquire the requested memory allocation.
4841
4842Support for setting user limits on image width and height was enabled
4843by default. The functions png_set_user_limits(), png_get_user_width_max(),
4844and png_get_user_height_max() were added at libpng-1.2.6.
4845
4846The png_set_add_alpha() function was added at libpng-1.2.7.
4847
4848The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
4849Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
4850tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
4851deprecated.
4852
4853A number of macro definitions in support of runtime selection of
4854assembler code features (especially Intel MMX code support) were
4855added at libpng-1.2.0:
4856
4857 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
4858 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
4859 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
4860 PNG_ASM_FLAG_MMX_READ_INTERLACE
4861 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
4862 PNG_ASM_FLAG_MMX_READ_FILTER_UP
4863 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
4864 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
4865 PNG_ASM_FLAGS_INITIALIZED
4866 PNG_MMX_READ_FLAGS
4867 PNG_MMX_FLAGS
4868 PNG_MMX_WRITE_FLAGS
4869 PNG_MMX_FLAGS
4870
4871We added the following functions in support of runtime
4872selection of assembler code features:
4873
4874 png_get_mmx_flagmask()
4875 png_set_mmx_thresholds()
4876 png_get_asm_flags()
4877 png_get_mmx_bitdepth_threshold()
4878 png_get_mmx_rowbytes_threshold()
4879 png_set_asm_flags()
4880
4881We replaced all of these functions with simple stubs in libpng-1.2.20,
4882when the Intel assembler code was removed due to a licensing issue.
4883
Glenn Randers-Pehrson3d893a02009-08-31 13:32:46 -05004884These macros are deprecated:
4885
4886 PNG_READ_TRANSFORMS_NOT_SUPPORTED
4887 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
4888 PNG_NO_SEQUENTIAL_READ_SUPPORTED
4889 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
4890 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
4891 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
4892
4893They have been replaced, respectively, by:
4894
4895 PNG_NO_READ_TRANSFORMS
4896 PNG_NO_PROGRESSIVE_READ
4897 PNG_NO_SEQUENTIAL_READ
4898 PNG_NO_WRITE_TRANSFORMS
4899 PNG_NO_READ_ANCILLARY_CHUNKS
4900 PNG_NO_WRITE_ANCILLARY_CHUNKS
4901
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004902PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
4903deprecated since libpng-1.0.16 and libpng-1.2.6.
4904
4905The function
4906 png_check_sig(sig, num)
4907was replaced with
4908 !png_sig_cmp(sig, 0, num)
4909It has been deprecated since libpng-0.90.
4910
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004911The function
4912 png_set_gray_1_2_4_to_8()
4913which also expands tRNS to alpha was replaced with
4914 png_set_expand_gray_1_2_4_to_8()
4915which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004916
Glenn Randers-Pehrsond740c842009-11-04 19:01:54 -06004917.SH IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
4918
4919Private libpng prototypes and macro definitions were moved from
4920png.h and pngconf.h into a new pngpriv.h header file.
4921
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004922Functions png_set_benign_errors(), png_benign_error(), and
4923png_chunk_benign_error() were added.
4924
4925Support for setting the maximum amount of memory that the application
4926will allocate for reading chunks was added, as a security measure.
4927The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
4928were added to the library.
4929
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06004930We implemented support for I/O states by adding png_ptr member io_state
4931and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004932
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004933We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
4934input transforms.
4935
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004936Checking for and reporting of errors in the IHDR chunk is more thorough.
4937
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004938Support for global arrays was removed, to improve thread safety.
4939
4940Some obsolete/deprecated macros and functions have been removed.
4941
4942Typecasted NULL definitions such as
4943 #define png_voidp_NULL (png_voidp)NULL
4944were eliminated. If you used these in your application, just use
4945NULL instead.
4946
4947The png_struct and info_struct members "trans" and "trans_values" were
4948changed to "trans_alpha" and "trans_color", respectively.
4949
4950The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004951were removed.
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004952
4953The PNG_1_0_X and PNG_1_2_X macros were eliminated.
4954
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05004955The PNG_LEGACY_SUPPORTED macro was eliminated.
4956
4957Many WIN32_WCE #ifdefs were removed.
4958
4959The functions png_read_init(info_ptr), png_write_init(info_ptr),
4960png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
4961have been removed. They have been deprecated since libpng-0.95.
4962
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004963The png_permit_empty_plte() was removed. It has been deprecated
4964since libpng-1.0.9. Use png_permit_mng_features() instead.
4965
4966We removed the obsolete stub functions png_get_mmx_flagmask(),
4967png_set_mmx_thresholds(), png_get_asm_flags(),
4968png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
4969png_set_asm_flags(), and png_mmx_supported()
4970
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004971We removed the obsolete png_check_sig(), png_memcpy_check(), and
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05004972png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
4973and memset(), respectively.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004974
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004975The function png_set_gray_1_2_4_to_8() was removed. It has been
4976deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
4977png_set_expand_gray_1_2_4_to_8() because the former function also
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06004978expanded any tRNS chunk to an alpha channel.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004979
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06004980Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
4981were added and are used by default instead of the corresponding
4982functions. Unfortunately,
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06004983from 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 -06004984function) incorrectly returned a value of type png_uint_32.
4985
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05004986We changed the prototype for png_malloc() from
4987 png_malloc(png_structp png_ptr, png_uint_32 size)
4988to
4989 png_malloc(png_structp png_ptr, png_alloc_size_t size)
4990
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06004991This also applies to the prototype for the user replacement malloc_fn().
4992
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004993The png_calloc() function was added and is used in place of
Glenn Randers-Pehrson2be8b642010-07-29 19:09:18 -05004994of "png_malloc(); memset();" except in the case in png_read_png()
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06004995where the array consists of pointers; in this case a "for" loop is used
4996after the png_malloc() to set the pointers to NULL, to give robust.
4997behavior in case the application runs out of memory part-way through
4998the process.
4999
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005000We changed the prototypes of png_get_compression_buffer_size() and
5001png_set_compression_buffer_size() to work with png_size_t instead of
5002png_uint_32.
5003
Glenn Randers-Pehrson45af8192009-12-30 08:37:29 -06005004Support for numbered error messages was removed by default, since we
5005never got around to actually numbering the error messages. The function
5006png_set_strip_error_numbers() was removed from the library by default.
5007
5008The png_zalloc() and png_zfree() functions are no longer exported.
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005009The png_zalloc() function no longer zeroes out the memory that it
5010allocates.
5011
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05005012Support for dithering was disabled by default in libpng-1.4.0, because
Glenn Randers-Pehrson9f1cd702011-04-16 19:40:23 -05005013it has not been well tested and doesn't actually "dither".
5014The code was not
Glenn Randers-Pehrson3cd7cff2010-04-16 19:27:08 -05005015removed, however, and could be enabled by building libpng with
5016PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
5017was reenabled, but the function was renamed png_set_quantize() to
5018reflect more accurately what it actually does. At the same time,
5019the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005020PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5021was renamed to PNG_READ_QUANTIZE_SUPPORTED.
Glenn Randers-Pehrson60988072010-04-13 22:11:06 -05005022
Glenn Randers-Pehrson6a9c2ce2009-03-27 19:30:10 -05005023We removed the trailing '.' from the warning and error messages.
5024
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005025.SH X. Changes to Libpng from version 1.4.x to 1.5.x
5026
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005027From 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 -06005028function) incorrectly returned a value of type png_uint_32.
5029
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005030A. Changes that affect users of libpng
5031
5032There are no substantial API changes between the non-deprecated parts of
5033the 1.4.5 API and the 1.5.0 API, however the ability to directly access
5034the main libpng control structures, png_struct and png_info, deprecated
5035in earlier versions of libpng, has been completely removed from
5036libpng 1.5.
5037
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005038We no longer include zlib.h in png.h. Applications that need access
5039to information in zlib.h will need to add the '#include "zlib.h"'
5040directive. It does not matter whether it is placed prior to or after
5041the '"#include png.h"' directive.
5042
5043We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
5044png_memcmp(), png_sprintf, and png_memcpy() macros into a private
5045header file (pngpriv.h) that is not accessible to applications.
5046
Glenn Randers-Pehrson9d23b402011-01-08 10:42:01 -06005047In png_get_iCCP, the type of "profile" was changed from png_charpp
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005048to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
Glenn Randers-Pehrson9d23b402011-01-08 10:42:01 -06005049
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005050There are changes of form in png.h, including new and changed macros to
5051declare
Glenn Randers-Pehrsonf5ea1b72011-01-06 06:42:51 -06005052parts of the API. Some API functions with arguments that are pointers to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005053data not modified within the function have been corrected to declare
5054these arguments with PNG_CONST.
5055
5056Much of the internal use of C macros to control the library build has also
5057changed and some of this is visible in the exported header files, in
5058particular the use of macros to control data and API elements visible
5059during application compilation may require significant revision to
5060application code. (It is extremely rare for an application to do this.)
5061
5062Any program that compiled against libpng 1.4 and did not use deprecated
5063features or access internal library structures should compile and work
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -06005064against libpng 1.5, except for the change in the prototype for
5065png_get_iCCP() and png_set_iCCP() API functions mentioned above.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005066
Glenn Randers-Pehrson6e974102010-12-19 16:44:22 -06005067libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5068interlaced images. The macros return the number of rows and columns in
5069each pass and information that can be used to de-interlace and (if
5070absolutely necessary) interlace an image.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005071
5072libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
Glenn Randers-Pehrsond08b6bd2011-02-19 15:50:17 -06005073the application-provided png_longjmp_ptr on the internal, but application
Glenn Randers-Pehrson33ced442011-04-27 14:58:06 -05005074initialized, longjmp buffer. It is provided as a convenience to avoid
5075the need to use the png_jmpbuf macro, which had the unnecessary side
5076effect of resetting the internal png_longjmp_ptr value.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005077
5078libpng 1.5.0 includes a complete fixed point API. By default this is
5079present along with the corresponding floating point API. In general the
5080fixed point API is faster and smaller than the floating point one because
5081the PNG file format used fixed point, not floating point. This applies
5082even if the library uses floating point in internal calculations. A new
5083macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5084uses floating point arithmetic (the default) or fixed point arithmetic
5085internally for performance critical calculations such as gamma correction.
Glenn Randers-Pehrson00879b12011-01-15 19:25:34 -06005086In some cases, the gamma calculations may produce slightly different
5087results. This has changed the results in png_rgb_to_gray and in alpha
5088composition (png_set_background for example). This applies even if the
5089original image was already linear (gamma == 1.0) and, therefore, it is
5090not necessary to linearize the image. This is because libpng has *not*
5091been changed to optimize that case correctly, yet.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005092
5093Fixed point support for the sCAL chunk comes with an important caveat;
5094the sCAL specification uses a decimal encoding of floating point values
5095and the accuracy of PNG fixed point values is insufficient for
5096representation of these values. Consequently a "string" API
5097(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5098arbitrary sCAL chunks in the absence of either the floating point API or
5099internal floating point calculations.
5100
5101Applications no longer need to include the optional distribution header
5102file pngusr.h or define the corresponding macros during application
5103build in order to see the correct variant of the libpng API. From 1.5.0
5104application code can check for the corresponding _SUPPORTED macro:
5105
5106#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
5107 /* code that uses the inch conversion APIs. */
5108#endif
5109
5110This macro will only be defined if the inch conversion functions have been
5111compiled into libpng. The full set of macros, and whether or not support
5112has been compiled in, are available in the header file pnglibconf.h.
5113This header file is specific to the libpng build. Notice that prior to
51141.5.0 the _SUPPORTED macros would always have the default definition unless
5115reset by pngusr.h or by explicit settings on the compiler command line.
5116These settings may produce compiler warnings or errors in 1.5.0 because
5117of macro redefinition.
5118
Glenn Randers-Pehrsonc36bb792011-02-12 09:49:07 -06005119From 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 -06005120function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
5121is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5122did not exist.)
5123
5124Applications can now choose whether to use these macros or to call the
5125corresponding function by defining PNG_USE_READ_MACROS or
5126PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
5127only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
5128 will lead to a link failure.
Glenn Randers-Pehrson59fa3e92011-01-06 07:07:06 -06005129
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005130Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05005131when compressing the IDAT data and textual data such as zTXt and iCCP.
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005132In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
Glenn Randers-Pehrson8eb88332011-04-01 00:16:50 -05005133We added five png_set_text_*() functions for setting the parameters to
5134use with textual data.
5135
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005136Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
John Bowlerb2bee332011-06-10 23:24:58 -05005137option was off by default, and slightly inaccurate scaling occurred.
Glenn Randers-Pehrsonfb29e512011-06-17 20:38:24 -05005138This option can no longer be turned off, and the choice of accurate
5139or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5140API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5141chopping.
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05005142
Glenn Randers-Pehrson733b1312011-06-15 13:21:01 -05005143Prior to libpng-1.5.4, the png_set_user_limits() function could only be
Glenn Randers-Pehrson0cb906d2011-06-11 14:22:22 -05005144used to reduce the width and height limits from the value of
5145PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5146that it could be used to override them. Now this function will reduce or
5147increase the limits.
John Bowlerb2bee332011-06-10 23:24:58 -05005148
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005149B. Changes to the build and configuration of libpng
5150
5151Details of internal changes to the library code can be found in the CHANGES
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005152file and in the GIT repository logs. These will be of no concern to the vast
5153majority of library users or builders, however the few who configure libpng
5154to a non-default feature set may need to change how this is done.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005155
5156There should be no need for library builders to alter build scripts if
5157these use the distributed build support - configure or the makefiles -
5158however users of the makefiles may care to update their build scripts
5159to build pnglibconf.h where the corresponding makefile does not do so.
5160
5161Building libpng with a non-default configuration has changed completely.
5162The old method using pngusr.h should still work correctly even though the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005163way pngusr.h is used in the build has been changed; however, library
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005164builders will probably want to examine the changes to take advantage of
5165new capabilities and to simplify their build system.
5166
5167B.1 Specific changes to library configuration capabilities
5168
5169The library now supports a complete fixed point implementation and can
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005170thus be used on systems that have no floating point support or very
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005171limited or slow support. Previously gamma correction, an essential part
5172of complete PNG support, required reasonably fast floating point.
5173
5174As part of this the choice of internal implementation has been made
5175independent of the choice of fixed versus floating point APIs and all the
5176missing fixed point APIs have been implemented.
5177
5178The exact mechanism used to control attributes of API functions has
5179changed. A single set of operating system independent macro definitions
5180is used and operating system specific directives are defined in
5181pnglibconf.h
5182
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005183As part of this the mechanism used to choose procedure call standards on
5184those systems that allow a choice has been changed. At present this only
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005185affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005186running on Intel processors. As before, PNGAPI is defined where required
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005187to control the exported API functions; however, two new macros, PNGCBAPI
5188and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5189(PNGCAPI) for functions that must match a C library prototype (currently
5190only png_longjmp_ptr, which must match the C longjmp function.) The new
5191approach is documented in pngconf.h
5192
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005193Despite these changes, libpng 1.5.0 only supports the native C function
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005194calling standard on those platforms tested so far (__cdecl on Microsoft
5195Windows). This is because the support requirements for alternative
5196calling conventions seem to no longer exist. Developers who find it
5197necessary to set PNG_API_RULE to 1 should advise the mailing list
5198(png-mng-implement) of this and library builders who use Openwatcom and
5199therefore set PNG_API_RULE to 2 should also contact the mailing list.
5200
5201A new test program, pngvalid, is provided in addition to pngtest.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005202pngvalid validates the arithmetic accuracy of the gamma correction
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005203calculations and includes a number of validations of the file format.
5204A subset of the full range of tests is run when "make check" is done
5205(in the 'configure' build.) pngvalid also allows total allocated memory
5206usage to be evaluated and performs additional memory overwrite validation.
5207
5208Many changes to individual feature macros have been made. The following
5209are the changes most likely to be noticed by library builders who
5210configure libpng:
5211
52121) All feature macros now have consistent naming:
5213
5214#define PNG_NO_feature turns the feature off
5215#define PNG_feature_SUPPORTED turns the feature on
5216
5217pnglibconf.h contains one line for each feature macro which is either:
5218
5219#define PNG_feature_SUPPORTED
5220
5221if the feature is supported or:
5222
5223/*#undef PNG_feature_SUPPORTED*/
5224
5225if it is not. Library code consistently checks for the 'SUPPORTED' macro.
Glenn Randers-Pehrsond0797f52011-07-12 10:28:02 -05005226It does not, and libpng applications should not, check for the 'NO' macro
5227which will not normally be defined even if the feature is not supported.
5228The 'NO' macros are only used internally for setting or not setting the
5229corresponding 'SUPPORTED' macros.
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005230
5231Compatibility with the old names is provided as follows:
5232
5233PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5234
5235And the following definitions disable the corresponding feature:
5236
5237PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5238PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5239PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5240PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5241PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5242PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5243
5244Library builders should remove use of the above, inconsistent, names.
5245
52462) Warning and error message formatting was previously conditional on
5247the STDIO feature. The library has been changed to use the
5248CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5249the library no longer uses the printf(3) functions, even though the
5250default read/write implementations use (FILE) style stdio.h functions.
5251
52523) Three feature macros now control the fixed/floating point decisions:
5253
5254PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5255
5256PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5257practice these are normally required internally anyway (because the PNG
5258file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5259merely stops the function from being exported.
5260
5261PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5262point implementation or the fixed point one. Typically the fixed point
5263implementation is larger and slower than the floating point implementation
5264on a system that supports floating point, however it may be faster on a
5265system which lacks floating point hardware and therefore uses a software
5266emulation.
5267
52684) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
5269functions to read and write ints to be disabled independently of
5270PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5271even though the default is to use the macros - this allows applications
5272to choose at app buildtime whether or not to use macros (previously
5273impossible because the functions weren't in the default build.)
5274
5275B.2 Changes to the configuration mechanism
5276
5277Prior to libpng-1.5.0 library builders who needed to configure libpng
5278had either to modify the exported pngconf.h header file to add system
5279specific configuration or had to write feature selection macros into
5280pngusr.h and cause this to be included into pngconf.h by defining
5281PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5282application built without PNG_USER_CONFIG defined would see the
5283unmodified, default, libpng API and thus would probably fail to link.
5284
5285These mechanisms still work in the configure build and in any makefile
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005286build that builds pnglibconf.h, although the feature selection macros
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005287have changed somewhat as described above. In 1.5.0, however, pngusr.h is
5288processed only once, when the exported header file pnglibconf.h is built.
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005289pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005290build of pnglibconf.h and it is never included in an application build.
5291
5292The rarely used alternative of adding a list of feature macros to the
5293CFLAGS setting in the build also still works, however the macros will be
5294copied to pnglibconf.h and this may produce macro redefinition warnings
5295when the individual C files are compiled.
5296
5297All configuration now only works if pnglibconf.h is built from
5298scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
5299(the original author of awk) maintains C source code of that awk and this
5300and all known later implementations (often called by subtly different
5301names - nawk and gawk for example) are adequate to build pnglibconf.h.
5302The Sun Microsystems (now Oracle) program 'awk' is an earlier version
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005303and does not work; this may also apply to other systems that have a
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005304functioning awk called 'nawk'.
5305
5306Configuration options are now documented in scripts/pnglibconf.dfa. This
5307file also includes dependency information that ensures a configuration is
5308consistent; that is, if a feature is switched off dependent features are
5309also removed. As a recommended alternative to using feature macros in
5310pngusr.h a system builder may also define equivalent options in pngusr.dfa
5311(or, indeed, any file) and add that to the configuration by setting
5312DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
5313how to do this, and a case where pngusr.h is still required.
5314
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005315.SH XI. Detecting libpng
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05005316
5317The png_get_io_ptr() function has been present since libpng-0.88, has never
5318changed, and is unaffected by conditional compilation macros. It is the
5319best choice for use in configure scripts for detecting the presence of any
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05005320libpng version since 0.88. In an autoconf "configure.in" you could use
5321
5322 AC_CHECK_LIB(png, png_get_io_ptr, ...
Glenn Randers-Pehrson424c9852009-06-02 13:45:15 -05005323
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005324.SH XII. Source code repository
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005325
5326Since about February 2009, version 1.2.34, libpng has been under "git" source
5327control. The git repository was built from old libpng-x.y.z.tar.gz files
5328going back to version 0.70. You can access the git repository (read only)
5329at
5330
5331 git://libpng.git.sourceforge.net/gitroot/libpng
5332
5333or you can browse it via "gitweb" at
5334
5335 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
5336
5337Patches can be sent to glennrp at users.sourceforge.net or to
5338png-mng-implement at lists.sourceforge.net or you can upload them to
5339the libpng bug tracker at
5340
5341 http://libpng.sourceforge.net
5342
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005343We also accept patches built from the tar or zip distributions, and
5344simple verbal discriptions of bug fixes, reported either to the
Glenn Randers-Pehrsona5e55472011-07-12 10:13:32 -05005345SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5346mailing list, or directly to glennrp.
Glenn Randers-Pehrson7bc25012011-01-21 23:29:09 -06005347
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005348.SH XIII. Coding style
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005349
5350Our coding style is similar to the "Allman" style, with curly
5351braces on separate lines:
5352
5353 if (condition)
5354 {
5355 action;
5356 }
5357
5358 else if (another condition)
5359 {
5360 another action;
5361 }
5362
5363The braces can be omitted from simple one-line actions:
5364
5365 if (condition)
5366 return (0);
5367
5368We use 3-space indentation, except for continued statements which
5369are usually indented the same as the first line of the statement
5370plus four more spaces.
5371
Glenn Randers-Pehrson5ade7ed2009-09-30 15:11:49 -05005372For macro definitions we use 2-space indentation, always leaving the "#"
5373in the first column.
5374
5375 #ifndef PNG_NO_FEATURE
5376 # ifndef PNG_FEATURE_SUPPORTED
5377 # define PNG_FEATURE_SUPPORTED
5378 # endif
5379 #endif
5380
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005381Comments appear with the leading "/*" at the same indentation as
5382the statement that follows the comment:
5383
5384 /* Single-line comment */
5385 statement;
5386
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005387 /* This is a multiple-line
5388 * comment.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005389 */
5390 statement;
5391
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005392Very short comments can be placed after the end of the statement
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005393to which they pertain:
5394
5395 statement; /* comment */
5396
5397We don't use C++ style ("//") comments. We have, however,
5398used them in the past in some now-abandoned MMX assembler
5399code.
5400
Glenn Randers-Pehrsonb5444a12009-06-08 08:36:19 -05005401Functions and their curly braces are not indented, and
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005402exported functions are marked with PNGAPI:
5403
5404 /* This is a public function that is visible to
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005405 * application programmers. It does thus-and-so.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005406 */
5407 void PNGAPI
5408 png_exported_function(png_ptr, png_info, foo)
5409 {
5410 body;
5411 }
5412
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005413The prototypes for all exported functions appear in png.h,
5414above the comment that says
5415
5416 /* Maintainer: Put new public prototypes here ... */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005417
5418We mark all non-exported functions with "/* PRIVATE */"":
5419
5420 void /* PRIVATE */
5421 png_non_exported_function(png_ptr, png_info, foo)
5422 {
5423 body;
5424 }
5425
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005426The prototypes for non-exported functions (except for those in
Glenn Randers-Pehrson5df7edb2009-10-29 23:32:44 -05005427pngtest) appear in
5428pngpriv.h
Glenn Randers-Pehrson416976f2009-07-27 22:16:09 -05005429above the comment that says
5430
5431 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005432
Glenn Randers-Pehrsoncbbe9a52011-01-29 16:12:11 -06005433To avoid polluting the global namespace, the names of all exported
5434functions and variables begin with "png_", and all publicly visible C
5435preprocessor macros begin with "PNG_". We request that applications that
5436use libpng *not* begin any of their own symbols with either of these strings.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005437
5438We put a space after each comma and after each semicolon
Glenn Randers-Pehrson49a56e72010-12-06 20:06:01 -06005439in "for" statements, and we put spaces before and after each
Glenn Randers-Pehrsone4c706a2010-03-06 14:51:54 -06005440C binary operator and after "for" or "while", and before
5441"?". We don't put a space between a typecast and the expression
5442being cast, nor do we put one between a function name and the
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005443left parenthesis that follows it:
5444
5445 for (i = 2; i > 0; --i)
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05005446 y[i] = a(x) + (int)b;
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005447
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05005448We prefer #ifdef and #ifndef to #if defined() and if !defined()
5449when there is only one macro being tested.
5450
Glenn Randers-Pehrson67f3b482009-09-23 11:36:28 -05005451We do not use the TAB character for indentation in the C sources.
5452
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06005453Lines do not exceed 80 characters.
5454
Glenn Randers-Pehrsonf210a052009-11-12 10:02:24 -06005455Other rules can be inferred by inspecting the libpng source.
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005456
Glenn Randers-Pehrson5b40b012010-11-25 07:16:29 -06005457.SH XIV. Y2K Compliance in libpng
Glenn Randers-Pehrson76546822009-05-16 07:25:42 -05005458
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005459July 26, 2011
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005460
5461Since the PNG Development group is an ad-hoc body, we can't make
5462an official declaration.
5463
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005464This is your unofficial assurance that libpng from version 0.71 and
Glenn Randers-Pehrsone9ef47f2011-07-14 08:18:24 -05005465upward through 1.5.5beta03 are Y2K compliant. It is my belief that earlier
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005466versions were also Y2K compliant.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005467
5468Libpng only has three year fields. One is a 2-byte unsigned integer that
5469will hold years up to 65535. The other two hold the date in text
5470format, and will hold years up to 9999.
5471
5472The integer is
5473 "png_uint_16 year" in png_time_struct.
5474
5475The strings are
5476 "png_charp time_buffer" in png_struct and
5477 "near_time_buffer", which is a local character string in png.c.
5478
5479There are seven time-related functions:
5480
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005481 png_convert_to_rfc_1123() in png.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005482 (formerly png_convert_to_rfc_1152() in error)
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005483 png_convert_from_struct_tm() in pngwrite.c, called
5484 in pngwrite.c
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005485 png_convert_from_time_t() in pngwrite.c
5486 png_get_tIME() in pngget.c
5487 png_handle_tIME() in pngrutil.c, called in pngread.c
5488 png_set_tIME() in pngset.c
5489 png_write_tIME() in pngwutil.c, called in pngwrite.c
5490
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005491All appear to handle dates properly in a Y2K environment. The
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005492png_convert_from_time_t() function calls gmtime() to convert from system
5493clock time, which returns (year - 1900), which we properly convert to
5494the full 4-digit year. There is a possibility that applications using
5495libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005496function, or that they are incorrectly passing only a 2-digit year
5497instead of "year - 1900" into the png_convert_from_struct_tm() function,
5498but this is not under our control. The libpng documentation has always
5499stated that it works with 4-digit years, and the APIs have been
5500documented as such.
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005501
5502The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
5503integer to hold the year, and can hold years as large as 65535.
5504
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005505zlib, upon which libpng depends, is also Y2K compliant. It contains
5506no date-related code.
5507
Glenn Randers-Pehrson87544ac1999-01-13 22:06:39 -06005508
5509 Glenn Randers-Pehrson
5510 libpng maintainer
5511 PNG Development Group
5512
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005513.SH NOTE
5514
5515Note about libpng version numbers:
5516
5517Due to various miscommunications, unforeseen code incompatibilities
5518and occasional factors outside the authors' control, version numbering
5519on the library has not always been consistent and straightforward.
5520The following table summarizes matters since version 0.89c, which was
5521the first widely used release:
5522
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005523 source png.h png.h shared-lib
5524 version string int version
5525 ------- ------ ----- ----------
5526 0.89c ("beta 3") 0.89 89 1.0.89
5527 0.90 ("beta 4") 0.90 90 0.90
5528 0.95 ("beta 5") 0.95 95 0.95
5529 0.96 ("beta 6") 0.96 96 0.96
5530 0.97b ("beta 7") 1.00.97 97 1.0.1
5531 0.97c 0.97 97 2.0.97
5532 0.98 0.98 98 2.0.98
5533 0.99 0.99 98 2.0.99
5534 0.99a-m 0.99 99 2.0.99
5535 1.00 1.00 100 2.1.0
5536 1.0.0 1.0.0 100 2.1.0
5537 1.0.0 (from here on, the 100 2.1.0
5538 1.0.1 png.h string is 10001 2.1.0
5539 1.0.1a-e identical to the 10002 from here on, the
5540 1.0.2 source version) 10002 shared library is 2.V
5541 1.0.2a-b 10003 where V is the source
5542 1.0.1 10001 code version except as
5543 1.0.1a-e 10002 2.1.0.1a-e noted.
5544 1.0.2 10002 2.1.0.2
5545 1.0.2a-b 10003 2.1.0.2a-b
5546 1.0.3 10003 2.1.0.3
5547 1.0.3a-d 10004 2.1.0.3a-d
5548 1.0.4 10004 2.1.0.4
5549 1.0.4a-f 10005 2.1.0.4a-f
5550 1.0.5 (+ 2 patches) 10005 2.1.0.5
5551 1.0.5a-d 10006 2.1.0.5a-d
5552 1.0.5e-r 10100 2.1.0.5e-r
5553 1.0.5s-v 10006 2.1.0.5s-v
5554 1.0.6 (+ 3 patches) 10006 2.1.0.6
5555 1.0.6d-g 10007 2.1.0.6d-g
5556 1.0.6h 10007 10.6h
5557 1.0.6i 10007 10.6i
5558 1.0.6j 10007 2.1.0.6j
Glenn Randers-Pehrson25467032011-01-28 11:58:40 -06005559 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005560 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
5561 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
5562 1.0.7 1 10007 2.1.0.7
5563 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
5564 1.0.8rc1 1 10008 2.1.0.8rc1
5565 1.0.8 1 10008 2.1.0.8
5566 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
5567 1.0.9rc1 1 10009 2.1.0.9rc1
5568 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
5569 1.0.9rc2 1 10009 2.1.0.9rc2
5570 1.0.9 1 10009 2.1.0.9
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06005571 1.0.10beta1 1 10010 2.1.0.10beta1
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005572 1.0.10rc1 1 10010 2.1.0.10rc1
Glenn Randers-Pehrson13cfbac2001-03-30 06:42:28 -06005573 1.0.10 1 10010 2.1.0.10
Glenn Randers-Pehrsone1eff582001-04-14 20:15:41 -05005574 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
Glenn Randers-Pehrson82ae3832001-04-20 10:32:10 -05005575 1.0.11rc1 1 10011 2.1.0.11rc1
Glenn Randers-Pehrson32835392001-04-27 08:29:32 -05005576 1.0.11 1 10011 2.1.0.11
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -05005577 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
5578 1.0.12rc1 2 10012 2.1.0.12rc1
5579 1.0.12 2 10012 2.1.0.12
5580 1.1.0a-f - 10100 2.1.1.0a-f abandoned
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05005581 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
Glenn Randers-Pehrson5a0be342001-10-18 20:55:13 -05005582 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
5583 1.2.0rc1 3 10200 3.1.2.0rc1
5584 1.2.0 3 10200 3.1.2.0
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -06005585 1.2.1beta-4 3 10201 3.1.2.1beta1-4
Glenn Randers-Pehrsondb3b88d2001-12-04 06:30:43 -06005586 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
5587 1.2.1 3 10201 3.1.2.1
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -06005588 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
Glenn Randers-Pehrsonfcbd7872002-04-07 16:35:38 -05005589 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
5590 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
5591 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
Glenn Randers-Pehrson4fb046a2002-04-15 09:25:51 -05005592 1.0.13 10 10013 10.so.0.1.0.13
5593 1.2.2 12 10202 12.so.0.1.2.2
Glenn Randers-Pehrson22f28962002-05-13 18:17:09 -05005594 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
5595 1.2.3 12 10203 12.so.0.1.2.3
Glenn Randers-Pehrsond020e9d2002-06-28 09:34:00 -05005596 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -05005597 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
Glenn Randers-Pehrson484a8a12002-07-07 19:15:20 -05005598 1.0.14 10 10014 10.so.0.1.0.14
5599 1.2.4 13 10204 12.so.0.1.2.4
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -05005600 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
5601 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005602 1.0.15 10 10015 10.so.0.1.0.15
5603 1.2.5 13 10205 12.so.0.1.2.5
5604 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
Glenn Randers-Pehrson37f116a2004-08-15 07:15:39 -05005605 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
5606 1.0.16 10 10016 10.so.0.1.0.16
5607 1.2.6 13 10206 12.so.0.1.2.6
Glenn Randers-Pehrson67864af2004-08-28 23:30:07 -05005608 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
Glenn Randers-Pehrson5b779162004-09-04 13:25:08 -05005609 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
5610 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
Glenn Randers-Pehrson250dfe12004-09-11 21:19:54 -05005611 1.0.17 10 10017 12.so.0.1.0.17
5612 1.2.7 13 10207 12.so.0.1.2.7
Glenn Randers-Pehrson40936072004-11-20 11:18:40 -06005613 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
Glenn Randers-Pehrson584b96e2004-11-29 15:08:00 -06005614 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
5615 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06005616 1.0.18 10 10018 12.so.0.1.0.18
5617 1.2.8 13 10208 12.so.0.1.2.8
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06005618 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -06005619 1.2.9beta4-11 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrson3a512032006-03-31 05:29:33 -06005620 1.2.9rc1 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsona7d0c942006-04-14 06:22:52 -05005621 1.2.9 13 10209 12.so.0.9[.0]
Glenn Randers-Pehrsond60b8fa2006-04-20 21:31:14 -05005622 1.2.10beta1-7 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson17218292006-04-20 07:20:46 -05005623 1.2.10rc1-2 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson86dc9812006-05-10 07:27:44 -05005624 1.2.10 13 10210 12.so.0.10[.0]
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -05005625 1.4.0beta1-6 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05005626 1.2.11beta1-4 13 10210 12.so.0.11[.0]
Glenn Randers-Pehrson3424ee72006-07-12 13:33:47 -05005627 1.4.0beta7-8 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrson701dbaa2006-11-17 09:36:54 -06005628 1.2.11 13 10211 12.so.0.11[.0]
5629 1.2.12 13 10212 12.so.0.12[.0]
5630 1.4.0beta9-14 14 10400 14.so.0.0[.0]
5631 1.2.13 13 10213 12.so.0.13[.0]
Glenn Randers-Pehrson97a9b482008-10-25 20:03:28 -05005632 1.4.0beta15-36 14 10400 14.so.0.0[.0]
Glenn Randers-Pehrsonfa028102009-10-10 06:15:21 -05005633 1.4.0beta37-87 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson733da8c2009-10-30 00:00:15 -05005634 1.4.0rc01 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson62ca98e2009-12-20 15:14:57 -06005635 1.4.0beta88-109 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrson67a83db2010-01-01 18:26:18 -06005636 1.4.0rc02-08 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsondbcfb712009-12-25 14:24:18 -06005637 1.4.0 14 10400 14.so.14.0[.0]
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06005638 1.4.1beta01-03 14 10401 14.so.14.1[.0]
5639 1.4.1rc01 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06005640 1.4.1beta04-12 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrsonaaf377c2010-03-08 11:20:30 -06005641 1.4.1 14 10401 14.so.14.1[.0]
Glenn Randers-Pehrson5b3d5542010-06-18 21:55:53 -05005642 1.4.2 14 10402 14.so.14.2[.0]
5643 1.4.3 14 10403 14.so.14.3[.0]
Glenn Randers-Pehrson2776d5e2010-11-21 15:18:02 -06005644 1.4.4 14 10404 14.so.14.4[.0]
Glenn Randers-Pehrsonfd20a5a2010-12-27 08:53:08 -06005645 1.5.0beta01-58 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrson64b863c2011-01-04 09:57:06 -06005646 1.5.0rc01-07 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrsonf5ea1b72011-01-06 06:42:51 -06005647 1.5.0 15 10500 15.so.15.0[.0]
Glenn Randers-Pehrsonef123cc2011-01-28 15:20:34 -06005648 1.5.1beta01-11 15 10501 15.so.15.1[.0]
Glenn Randers-Pehrson3d3aae12011-02-02 22:58:27 -06005649 1.5.1rc01-02 15 10501 15.so.15.1[.0]
5650 1.5.1 15 10501 15.so.15.1[.0]
Glenn Randers-Pehrsonf3dd1cc2011-03-18 22:02:20 -05005651 1.5.2beta01-03 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrson77fd0832011-03-24 08:59:48 -05005652 1.5.2rc01-03 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrsondcc35052011-03-31 11:23:49 -05005653 1.5.2 15 10502 15.so.15.2[.0]
Glenn Randers-Pehrson36edbb52011-06-03 07:15:04 -05005654 1.5.3beta01-10 15 10503 15.so.15.3[.0]
Glenn Randers-Pehrsonfb278732011-06-10 20:43:39 -05005655 1.5.3rc01-02 15 10503 15.so.15.3[.0]
Glenn Randers-Pehrson413138a2011-06-13 22:07:37 -05005656 1.5.3beta11 15 10503 15.so.15.3[.0]
5657 1.5.3 [omitted]
Glenn Randers-Pehrson9daf91e2011-06-22 23:10:36 -05005658 1.5.4beta01-08 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrson78bb9da2011-06-30 18:59:45 -05005659 1.5.4rc01 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrsond404b6d2011-07-07 06:24:57 -05005660 1.5.4 15 10504 15.so.15.4[.0]
Glenn Randers-Pehrsone9ef47f2011-07-14 08:18:24 -05005661 1.5.5beta01-03 15 10505 15.so.15.5[.0]
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005662
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005663Henceforth the source version will match the shared-library minor
5664and patch numbers; the shared-library major version number will be
5665used for changes in backward compatibility, as it is intended. The
5666PNG_PNGLIB_VER macro, which is not used within libpng but is available
5667for applications, is an unsigned integer of the form xyyzz corresponding
5668to the source version x.y.z (leading zeros in y and z). Beta versions
Glenn Randers-Pehrsone1644472001-03-23 05:06:56 -06005669were given the previous public release number plus a letter, until
5670version 1.0.6j; from then on they were given the upcoming public
5671release number plus "betaNN" or "rcN".
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005672
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005673.SH "SEE ALSO"
Glenn Randers-Pehrson4e763f12010-03-03 10:45:50 -06005674.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
Glenn Randers-Pehrson7fb32a82010-03-03 09:47:49 -06005675
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005676.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005677.IR libpng :
5678.IP
Glenn Randers-Pehrsona4981d42004-08-25 22:00:45 -05005679http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06005680http://www.libpng.org/pub/png
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005681
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005682.LP
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005683.IR zlib :
5684.IP
5685(generally) at the same location as
5686.I libpng
5687or at
5688.br
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06005689ftp://ftp.info-zip.org/pub/infozip/zlib
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005690
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005691.LP
5692.IR PNG specification: RFC 2083
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005693.IP
5694(generally) at the same location as
5695.I libpng
5696or at
5697.br
5698ftp://ds.internic.net/rfc/rfc2083.txt
5699.br
5700or (as a W3C Recommendation) at
5701.br
5702http://www.w3.org/TR/REC-png.html
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005703
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06005704.LP
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005705In the case of any inconsistency between the PNG specification
5706and this library, the specification takes precedence.
5707
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005708.SH AUTHORS
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005709This man page: Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06005710<glennrp at users.sourceforge.net>
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005711
5712The contributing authors would like to thank all those who helped
5713with testing, bug fixes, and patience. This wouldn't have been
5714possible without all of you.
5715
5716Thanks to Frank J. T. Wojcik for helping with the documentation.
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06005717
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005718Libpng version 1.5.5beta03 - July 26, 2011:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005719Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06005720Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005721
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005722Supported by the PNG development group
5723.br
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06005724png-mng-implement at lists.sf.net
5725(subscription required; visit
Glenn Randers-Pehrson7b34df32006-02-24 06:30:16 -06005726png-mng-implement at lists.sourceforge.net (subscription required; visit
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06005727https://lists.sourceforge.net/lists/listinfo/png-mng-implement
5728to subscribe).
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005729
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005730.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005731
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -06005732(This copy of the libpng notices is provided for your convenience. In case of
5733any discrepancy between this copy and the notices in the file png.h that is
5734included in the libpng distribution, the latter shall prevail.)
5735
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005736If you modify libpng you may insert additional notices immediately following
5737this sentence.
5738
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05005739This code is released under the libpng license.
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05005740
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005741libpng versions 1.2.6, August 15, 2004, through 1.5.5beta03, July 26, 2011, are
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05005742Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005743distributed according to the same disclaimer and license as libpng-1.2.5
Glenn Randers-Pehrsond029a752004-08-09 21:50:32 -05005744with the following individual added to the list of Contributing Authors
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005745
5746 Cosmin Truta
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05005747
5748libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Glenn Randers-Pehrsonc6de22d2002-02-23 18:55:25 -06005749Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
Glenn Randers-Pehrson32fc5ce2000-07-24 06:34:14 -05005750distributed according to the same disclaimer and license as libpng-1.0.6
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005751with the following individuals added to the list of Contributing Authors
5752
5753 Simon-Pierre Cadieux
5754 Eric S. Raymond
5755 Gilles Vollant
5756
5757and with the following additions to the disclaimer:
5758
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -06005759 There is no warranty against interference with your
5760 enjoyment of the library or against infringement.
5761 There is no warranty that our efforts or the library
5762 will fulfill any of your particular purposes or needs.
5763 This library is provided with all faults, and the entire
5764 risk of satisfactory quality, performance, accuracy, and
5765 effort is with the user.
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005766
5767libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
5768Copyright (c) 1998, 1999 Glenn Randers-Pehrson
5769Distributed according to the same disclaimer and license as libpng-0.96,
5770with the following individuals added to the list of Contributing Authors:
5771
5772 Tom Lane
5773 Glenn Randers-Pehrson
5774 Willem van Schaik
5775
5776libpng versions 0.89, June 1996, through 0.96, May 1997, are
Glenn Randers-Pehrson54a066a1999-09-19 06:04:18 -05005777Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005778Distributed according to the same disclaimer and license as libpng-0.88,
5779with the following individuals added to the list of Contributing Authors:
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005780
5781 John Bowler
5782 Kevin Bracey
5783 Sam Bushell
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005784 Magnus Holmgren
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005785 Greg Roelofs
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005786 Tom Tanner
5787
5788libpng versions 0.5, May 1995, through 0.88, January 1996, are
5789Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
5790
5791For the purposes of this copyright and license, "Contributing Authors"
5792is defined as the following set of individuals:
5793
5794 Andreas Dilger
5795 Dave Martindale
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005796 Guy Eric Schalnat
5797 Paul Schmidt
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005798 Tim Wegner
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06005799
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005800The PNG Reference Library is supplied "AS IS". The Contributing Authors
5801and Group 42, Inc. disclaim all warranties, expressed or implied,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005802including, without limitation, the warranties of merchantability and of
5803fitness for any purpose. The Contributing Authors and Group 42, Inc.
5804assume no liability for direct, indirect, incidental, special, exemplary,
5805or consequential damages, which may result from the use of the PNG
5806Reference Library, even if advised of the possibility of such damage.
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06005807
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005808Permission is hereby granted to use, copy, modify, and distribute this
5809source code, or portions hereof, for any purpose, without fee, subject
5810to the following restrictions:
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005811
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -050058121. The origin of this source code must not be misrepresented.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005813
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060058142. Altered versions must be plainly marked as such and
5815 must not be misrepresented as being the original source.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005816
Glenn Randers-Pehrson19095602001-03-14 07:08:39 -060058173. This Copyright notice may not be removed or altered from
5818 any source or altered source distribution.
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005819
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005820The Contributing Authors and Group 42, Inc. specifically permit, without
5821fee, and encourage the use of this source code as a component to
5822supporting the PNG file format in commercial products. If you use this
5823source code in a product, acknowledgment is not required but would be
5824appreciated.
5825
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005826
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005827A "png_get_copyright" function is available, for convenient use in "about"
5828boxes and the like:
5829
5830 printf("%s",png_get_copyright(NULL));
5831
5832Also, the PNG logo (in PNG format, of course) is supplied in the
Glenn Randers-Pehrsona4d54bd2000-07-14 08:15:12 -05005833files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05005834
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005835Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05005836certification mark of the Open Source Initiative.
5837
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005838Glenn Randers-Pehrson
Glenn Randers-Pehrson5dd2b8e2004-11-24 07:50:16 -06005839glennrp at users.sourceforge.net
Glenn Randers-Pehrson7a287242011-07-26 12:03:11 -05005840July 26, 2011
Glenn Randers-Pehrson3d5a5202000-07-01 15:37:28 -05005841
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005842.\" end of man page
5843