VirtualBox

source: vbox/trunk/src/libs/libpng-1.2.53/libpng.3@ 58276

Last change on this file since 58276 was 58100, checked in by vboxsync, 9 years ago

libpng 1.2.53 export fix

  • Property svn:eol-style set to native
File size: 176.8 KB
Line 
1.TH LIBPNG 3 "February 26, 2015"
2.SH NAME
3libpng \- Portable Network Graphics (PNG) Reference Library 1.2.53
4.SH SYNOPSIS
5\fB
6#include <png.h>\fP
7
8\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
9
10\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
11
12\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
13
14\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
15
16\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
17
18\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
19
20\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
21
22\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
23
24\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
25
26\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
27
28\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
29
30\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
31
32\fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP
33
34\fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP
35
36\fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP
37
38\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
39
40\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
41
42\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
43
44\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
45
46\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
47
48\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
49
50\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
51
52\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
53
54\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
55
56\fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
57
58\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
59
60\fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
61
62\fBpng_uint_32 png_get_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
63
64\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
65
66\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
67
68\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
69
70\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
71
72\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
73
74\fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
75
76\fBpng_uint_32 png_get_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
77
78\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
79
80\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
81
82\fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
83
84\fBpng_uint_32 png_get_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_charpp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
85
86\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
87
88\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
89
90\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
91
92\fB#if !defined(PNG_1_0_X) png_int_32 png_get_int_32 (png_bytep buf); \fI#endif
93
94\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
95
96\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
97
98\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
99
100\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
101
102\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
103
104\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
105
106\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
107
108\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
109
110\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
111
112\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
113
114\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
115
116\fBpng_byte png_get_rgb_to_gray_status (png_structp png_ptr) png_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
117
118\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
119
120\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
121
122\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
123
124\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
125
126\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
127
128\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
129
130\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
131
132\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP
133
134\fB#if !defined(PNG_1_0_X) png_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
135
136\fBpng_uint_32 png_get_uint_31 (png_bytep \fIbuf\fP\fB);\fP
137
138\fBpng_uint_32 png_get_uint_32 (png_bytep buf); \fI#endif
139
140\fBpng_uint_32 png_get_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
141
142\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
143
144\fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP
145
146\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
147
148\fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP
149
150\fBpng_uint_32 png_get_valid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
151
152\fBpng_int_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
153
154\fBpng_int_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
155
156\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
157
158\fBpng_int_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
159
160\fBpng_int_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
161
162\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
163
164\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
165
166\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
167
168\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
169
170\fBDEPRECATED void png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP
171
172\fBDEPRECATED void png_info_init_2 (png_infopp \fP\fIptr_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
173
174\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
175
176\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
177
178\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
179
180\fBpng_voidp png_memcpy_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
181
182\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
183
184\fBpng_voidp png_memset_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
185
186\fBDEPRECATED void png_permit_empty_plte (png_structp \fP\fIpng_ptr\fP\fB, int \fIempty_plte_permitted\fP\fB);\fP
187
188\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
189
190\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
191
192\fBvoid png_read_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_infop \fIend_info_ptr\fP\fB);\fP
193
194\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
195
196\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
197
198\fBDEPRECATED void png_read_init (png_structp \fIpng_ptr\fP\fB);\fP
199
200\fBDEPRECATED void png_read_init_2 (png_structpp \fP\fIptr_ptr\fP\fB, png_const_charp \fP\fIuser_png_ver\fP\fB, png_size_t \fP\fIpng_struct_size\fP\fB, png_size_t \fIpng_info_size\fP\fB);\fP
201
202\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
203
204\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
205
206\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
207
208\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
209
210\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
211
212\fB#if !defined(PNG_1_0_X) png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
213
214\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
215
216\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
217
218\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int flags); \fI#endif
219
220\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
221
222\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
223
224\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
225
226\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
227
228\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
229
230\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
231
232\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
233
234\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
235
236\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
237
238\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
239
240\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
241
242\fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP
243
244\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
245
246\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
247
248\fBvoid png_set_expand_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
249
250\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
251
252\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
253
254\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
255
256\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
257
258\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
259
260\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
261
262\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
263
264\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
265
266\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
267
268\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
269
270\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
271
272\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
273
274\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
275
276\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
277
278\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
279
280\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
281
282\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
283
284\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
285
286\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
287
288\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
289
290\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
291
292\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
293
294\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
295
296\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
297
298\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
299
300\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
301
302\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
303
304\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
305
306\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
307
308\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
309
310\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_fixed_point \fP\fIred\fP\fB, png_fixed_point \fIgreen\fP\fB);\fP
311
312\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
313
314\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
315
316\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
317
318\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
319
320\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
321
322\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
323
324\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
325
326\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
327
328\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
329
330\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
331
332\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
333
334\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
335
336\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
337
338\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
339
340\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_values\fP\fB);\fP
341
342\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
343
344\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
345
346\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
347
348\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
349
350\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
351
352\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
353
354\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
355
356\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
357
358\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
359
360\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
361
362\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
363
364\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
365
366\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
367
368\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
369
370\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
371
372\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
373
374\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
375
376\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
377
378\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
379
380\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
381
382\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
383
384\fBDEPRECATED void png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
385
386\fBDEPRECATED void png_write_init_2 (png_structpp \fP\fIptr_ptr\fP\fB, png_const_charp \fP\fIuser_png_ver\fP\fB, png_size_t \fP\fIpng_struct_size\fP\fB, png_size_t \fIpng_info_size\fP\fB);\fP
387
388\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
389
390\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
391
392\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
393
394\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
395
396\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
397
398\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
399
400\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
401
402.SH DESCRIPTION
403The
404.I libpng
405library supports encoding, decoding, and various manipulations of
406the Portable Network Graphics (PNG) format image files. It uses the
407.IR zlib(3)
408compression library.
409Following is a copy of the libpng.txt file that accompanies libpng.
410.SH LIBPNG.TXT
411libpng.txt - A description on how to use and modify libpng
412
413 libpng version 1.2.53 - February 26, 2015
414 Updated and distributed by Glenn Randers-Pehrson
415 <glennrp at users.sourceforge.net>
416 Copyright (c) 1998-2014 Glenn Randers-Pehrson
417
418 This document is released under the libpng license.
419 For conditions of distribution and use, see the disclaimer
420 and license in png.h
421
422 Based on:
423
424 libpng versions 0.97, January 1998, through 1.2.53 - February 26, 2015
425 Updated and distributed by Glenn Randers-Pehrson
426 Copyright (c) 1998-2014 Glenn Randers-Pehrson
427
428 libpng 1.0 beta 6 version 0.96 May 28, 1997
429 Updated and distributed by Andreas Dilger
430 Copyright (c) 1996, 1997 Andreas Dilger
431
432 libpng 1.0 beta 2 - version 0.88 January 26, 1996
433 For conditions of distribution and use, see copyright
434 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
435 Schalnat, Group 42, Inc.
436
437 Updated/rewritten per request in the libpng FAQ
438 Copyright (c) 1995, 1996 Frank J. T. Wojcik
439 December 18, 1995 & January 20, 1996
440
441.SH I. Introduction
442
443This file describes how to use and modify the PNG reference library
444(known as libpng) for your own use. There are five sections to this
445file: introduction, structures, reading, writing, and modification and
446configuration notes for various special platforms. In addition to this
447file, example.c is a good starting point for using the library, as
448it is heavily commented and should include everything most people
449will need. We assume that libpng is already installed; see the
450INSTALL file for instructions on how to install libpng.
451
452For examples of libpng usage, see the files "example.c", "pngtest.c",
453and the files in the "contrib" directory, all of which are included in
454the libpng distribution.
455
456Libpng was written as a companion to the PNG specification, as a way
457of reducing the amount of time and effort it takes to support the PNG
458file format in application programs.
459
460The PNG specification (second edition), November 2003, is available as
461a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
462<http://www.w3.org/TR/2003/REC-PNG-20031110/
463The W3C and ISO documents have identical technical content.
464
465The PNG-1.2 specification is available at
466<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
467to the PNG specification (second edition) but has some additional material.
468
469The PNG-1.0 specification is available
470as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
471W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
472
473Some additional chunks are described in the special-purpose public chunks
474documents at <http://www.libpng.org/pub/png/documents/>.
475
476Other information
477about PNG, and the latest version of libpng, can be found at the PNG home
478page, <http://www.libpng.org/pub/png/>.
479
480Most users will not have to modify the library significantly; advanced
481users may want to modify it more. All attempts were made to make it as
482complete as possible, while keeping the code easy to understand.
483Currently, this library only supports C. Support for other languages
484is being considered.
485
486Libpng has been designed to handle multiple sessions at one time,
487to be easily modifiable, to be portable to the vast majority of
488machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
489to use. The ultimate goal of libpng is to promote the acceptance of
490the PNG file format in whatever way possible. While there is still
491work to be done (see the TODO file), libpng should cover the
492majority of the needs of its users.
493
494Libpng uses zlib for its compression and decompression of PNG files.
495Further information about zlib, and the latest version of zlib, can
496be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
497The zlib compression utility is a general purpose utility that is
498useful for more than PNG files, and can be used without libpng.
499See the documentation delivered with zlib for more details.
500You can usually find the source files for the zlib utility wherever you
501find the libpng source files.
502
503Libpng is thread safe, provided the threads are using different
504instances of the structures. Each thread should have its own
505png_struct and png_info instances, and thus its own image.
506Libpng does not protect itself against two threads using the
507same instance of a structure.
508
509.SH II. Structures
510
511There are two main structures that are important to libpng, png_struct
512and png_info. The first, png_struct, is an internal structure that
513will not, for the most part, be used by a user except as the first
514variable passed to every libpng function call.
515
516The png_info structure is designed to provide information about the
517PNG file. At one time, the fields of png_info were intended to be
518directly accessible to the user. However, this tended to cause problems
519with applications using dynamically loaded libraries, and as a result
520a set of interface functions for png_info (the png_get_*() and png_set_*()
521functions) was developed. The fields of png_info are still available for
522older applications, but it is suggested that applications use the new
523interfaces if at all possible.
524
525Applications that do make direct access to the members of png_struct (except
526for png_ptr->jmpbuf) must be recompiled whenever the library is updated,
527and applications that make direct access to the members of png_info must
528be recompiled if they were compiled or loaded with libpng version 1.0.6,
529in which the members were in a different order. In version 1.0.7, the
530members of the png_info structure reverted to the old order, as they were
531in versions 0.97c through 1.0.5. Starting with version 2.0.0, both
532structures are going to be hidden, and the contents of the structures will
533only be accessible through the png_get/png_set functions.
534
535The png.h header file is an invaluable reference for programming with libpng.
536And while I'm on the topic, make sure you include the libpng header file:
537
538#include <png.h>
539
540.SH III. Reading
541
542We'll now walk you through the possible functions to call when reading
543in a PNG file sequentially, briefly explaining the syntax and purpose
544of each one. See example.c and png.h for more detail. While
545progressive reading is covered in the next section, you will still
546need some of the functions discussed in this section to read a PNG
547file.
548
549.SS Setup
550
551You will want to do the I/O initialization(*) before you get into libpng,
552so if it doesn't work, you don't have much to undo. Of course, you
553will also want to insure that you are, in fact, dealing with a PNG
554file. Libpng provides a simple check to see if a file is a PNG file.
555To use it, pass in the first 1 to 8 bytes of the file to the function
556png_sig_cmp(), and it will return 0 (false) if the bytes match the
557corresponding bytes of the PNG signature, or nonzero (true) otherwise.
558Of course, the more bytes you pass in, the greater the accuracy of the
559prediction.
560
561If you are intending to keep the file pointer open for use in libpng,
562you must ensure you don't read more than 8 bytes from the beginning
563of the file, and you also have to make a call to png_set_sig_bytes_read()
564with the number of bytes you read from the beginning. Libpng will
565then only check the bytes (if any) that your program didn't read.
566
567(*): If you are not using the standard I/O functions, you will need
568to replace them with custom functions. See the discussion under
569Customizing libpng.
570
571
572 FILE *fp = fopen(file_name, "rb");
573 if (!fp)
574 {
575 return (ERROR);
576 }
577 fread(header, 1, number, fp);
578 is_png = !png_sig_cmp(header, 0, number);
579 if (!is_png)
580 {
581 return (NOT_PNG);
582 }
583
584
585Next, png_struct and png_info need to be allocated and initialized. In
586order to ensure that the size of these structures is correct even with a
587dynamically linked libpng, there are functions to initialize and
588allocate the structures. We also pass the library version, optional
589pointers to error handling functions, and a pointer to a data struct for
590use by the error functions, if necessary (the pointer and functions can
591be NULL if the default error handlers are to be used). See the section
592on Changes to Libpng below regarding the old initialization functions.
593The structure allocation functions quietly return NULL if they fail to
594create the structure, so your application should check for that.
595
596 png_structp png_ptr = png_create_read_struct
597 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
598 user_error_fn, user_warning_fn);
599 if (!png_ptr)
600 return (ERROR);
601
602 png_infop info_ptr = png_create_info_struct(png_ptr);
603 if (!info_ptr)
604 {
605 png_destroy_read_struct(&png_ptr,
606 (png_infopp)NULL, (png_infopp)NULL);
607 return (ERROR);
608 }
609
610 png_infop end_info = png_create_info_struct(png_ptr);
611 if (!end_info)
612 {
613 png_destroy_read_struct(&png_ptr, &info_ptr,
614 (png_infopp)NULL);
615 return (ERROR);
616 }
617
618If you want to use your own memory allocation routines,
619define PNG_USER_MEM_SUPPORTED and use
620png_create_read_struct_2() instead of png_create_read_struct():
621
622 png_structp png_ptr = png_create_read_struct_2
623 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
624 user_error_fn, user_warning_fn, (png_voidp)
625 user_mem_ptr, user_malloc_fn, user_free_fn);
626
627The error handling routines passed to png_create_read_struct()
628and the memory alloc/free routines passed to png_create_struct_2()
629are only necessary if you are not using the libpng supplied error
630handling and memory alloc/free functions.
631
632When libpng encounters an error, it expects to longjmp back
633to your routine. Therefore, you will need to call setjmp and pass
634your png_jmpbuf(png_ptr). If you read the file from different
635routines, you will need to update the jmpbuf field every time you enter
636a new routine that will call a png_*() function.
637
638See your documentation of setjmp/longjmp for your compiler for more
639information on setjmp/longjmp. See the discussion on libpng error
640handling in the Customizing Libpng section below for more information
641on the libpng error handling. If an error occurs, and libpng longjmp's
642back to your setjmp, you will want to call png_destroy_read_struct() to
643free any memory.
644
645 if (setjmp(png_jmpbuf(png_ptr)))
646 {
647 png_destroy_read_struct(&png_ptr, &info_ptr,
648 &end_info);
649 fclose(fp);
650 return (ERROR);
651 }
652
653If you would rather avoid the complexity of setjmp/longjmp issues,
654you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
655errors will result in a call to PNG_ABORT() which defaults to abort().
656
657Now you need to set up the input code. The default for libpng is to
658use the C function fread(). If you use this, you will need to pass a
659valid FILE * in the function png_init_io(). Be sure that the file is
660opened in binary mode. If you wish to handle reading data in another
661way, you need not call the png_init_io() function, but you must then
662implement the libpng I/O methods discussed in the Customizing Libpng
663section below.
664
665 png_init_io(png_ptr, fp);
666
667If you had previously opened the file and read any of the signature from
668the beginning in order to see if this was a PNG file, you need to let
669libpng know that there are some bytes missing from the start of the file.
670
671 png_set_sig_bytes(png_ptr, number);
672
673.SS Setting up callback code
674
675You can set up a callback function to handle any unknown chunks in the
676input stream. You must supply the function
677
678 read_chunk_callback(png_ptr ptr,
679 png_unknown_chunkp chunk);
680 {
681 /* The unknown chunk structure contains your
682 chunk data, along with similar data for any other
683 unknown chunks: */
684
685 png_byte name[5];
686 png_byte *data;
687 png_size_t size;
688
689 /* Note that libpng has already taken care of
690 the CRC handling */
691
692 /* put your code here. Search for your chunk in the
693 unknown chunk structure, process it, and return one
694 of the following: */
695
696 return (\-n); /* chunk had an error */
697 return (0); /* did not recognize */
698 return (n); /* success */
699 }
700
701(You can give your function another name that you like instead of
702"read_chunk_callback")
703
704To inform libpng about your function, use
705
706 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
707 read_chunk_callback);
708
709This names not only the callback function, but also a user pointer that
710you can retrieve with
711
712 png_get_user_chunk_ptr(png_ptr);
713
714If you call the png_set_read_user_chunk_fn() function, then all unknown
715chunks will be saved when read, in case your callback function will need
716one or more of them. This behavior can be changed with the
717png_set_keep_unknown_chunks() function, described below.
718
719At this point, you can set up a callback function that will be
720called after each row has been read, which you can use to control
721a progress meter or the like. It's demonstrated in pngtest.c.
722You must supply a function
723
724 void read_row_callback(png_ptr ptr, png_uint_32 row,
725 int pass);
726 {
727 /* put your code here */
728 }
729
730(You can give it another name that you like instead of "read_row_callback")
731
732To inform libpng about your function, use
733
734 png_set_read_status_fn(png_ptr, read_row_callback);
735
736.SS Unknown-chunk handling
737
738Now you get to set the way the library processes unknown chunks in the
739input PNG stream. Both known and unknown chunks will be read. Normal
740behavior is that known chunks will be parsed into information in
741various info_ptr members while unknown chunks will be discarded. This
742behavior can be wasteful if your application will never use some known
743chunk types. To change this, you can call:
744
745 png_set_keep_unknown_chunks(png_ptr, keep,
746 chunk_list, num_chunks);
747 keep - 0: default unknown chunk handling
748 1: ignore; do not keep
749 2: keep only if safe-to-copy
750 3: keep even if unsafe-to-copy
751 You can use these definitions:
752 PNG_HANDLE_CHUNK_AS_DEFAULT 0
753 PNG_HANDLE_CHUNK_NEVER 1
754 PNG_HANDLE_CHUNK_IF_SAFE 2
755 PNG_HANDLE_CHUNK_ALWAYS 3
756 chunk_list - list of chunks affected (a byte string,
757 five bytes per chunk, NULL or '\0' if
758 num_chunks is 0)
759 num_chunks - number of chunks affected; if 0, all
760 unknown chunks are affected. If nonzero,
761 only the chunks in the list are affected
762
763Unknown chunks declared in this way will be saved as raw data onto a
764list of png_unknown_chunk structures. If a chunk that is normally
765known to libpng is named in the list, it will be handled as unknown,
766according to the "keep" directive. If a chunk is named in successive
767instances of png_set_keep_unknown_chunks(), the final instance will
768take precedence. The IHDR and IEND chunks should not be named in
769chunk_list; if they are, libpng will process them normally anyway.
770
771Here is an example of the usage of png_set_keep_unknown_chunks(),
772where the private "vpAg" chunk will later be processed by a user chunk
773callback function:
774
775 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
776
777 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
778 png_byte unused_chunks[]=
779 {
780 104, 73, 83, 84, (png_byte) '\0', /* hIST */
781 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
782 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
783 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
784 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
785 116, 73, 77, 69, (png_byte) '\0', /* tIME */
786 };
787 #endif
788
789 ...
790
791 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
792 /* ignore all unknown chunks: */
793 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
794 /* except for vpAg: */
795 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
796 /* also ignore unused known chunks: */
797 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
798 (int)sizeof(unused_chunks)/5);
799 #endif
800
801.SS User limits
802
803The PNG specification allows the width and height of an image to be as
804large as 2^(31\-1 (0x7fffffff), or about 2.147 billion rows and columns.
805Since very few applications really need to process such large images,
806we have imposed an arbitrary 1-million limit on rows and columns.
807Larger images will be rejected immediately with a png_error() call. If
808you wish to override this limit, you can use
809
810 png_set_user_limits(png_ptr, width_max, height_max);
811
812to set your own limits, or use width_max = height_max = 0x7fffffffL
813to allow all valid dimensions (libpng may reject some very large images
814anyway because of potential buffer overflow conditions).
815
816You should put this statement after you create the PNG structure and
817before calling png_read_info(), png_read_png(), or png_process_data().
818If you need to retrieve the limits that are being applied, use
819
820 width_max = png_get_user_width_max(png_ptr);
821 height_max = png_get_user_height_max(png_ptr);
822
823The PNG specification sets no limit on the number of ancillary chunks
824allowed in a PNG datastream. You can impose a limit on the total number
825of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
826
827 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
828
829where 0x7fffffffL means unlimited. You can retrieve this limit with
830
831 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
832
833This limit also applies to the number of buffers that can be allocated
834by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
835
836.SS The high-level read interface
837
838At this point there are two ways to proceed; through the high-level
839read interface, or through a sequence of low-level read operations.
840You can use the high-level interface if (a) you are willing to read
841the entire image into memory, and (b) the input transformations
842you want to do are limited to the following set:
843
844 PNG_TRANSFORM_IDENTITY No transformation
845 PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
846 8 bits
847 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
848 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
849 samples to bytes
850 PNG_TRANSFORM_PACKSWAP Change order of packed
851 pixels to LSB first
852 PNG_TRANSFORM_EXPAND Perform set_expand()
853 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
854 PNG_TRANSFORM_SHIFT Normalize pixels to the
855 sBIT depth
856 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
857 to BGRA
858 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
859 to AG
860 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
861 to transparency
862 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
863 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
864 to RGB (or GA to RGBA)
865
866(This excludes setting a background color, doing gamma transformation,
867dithering, and setting filler.) If this is the case, simply do this:
868
869 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
870
871where png_transforms is an integer containing the bitwise OR of some
872set of transformation flags. This call is equivalent to png_read_info(),
873followed the set of transformations indicated by the transform mask,
874then png_read_image(), and finally png_read_end().
875
876(The final parameter of this call is not yet used. Someday it might point
877to transformation parameters required by some future input transform.)
878
879You must use png_transforms and not call any png_set_transform() functions
880when you use png_read_png().
881
882After you have called png_read_png(), you can retrieve the image data
883with
884
885 row_pointers = png_get_rows(png_ptr, info_ptr);
886
887where row_pointers is an array of pointers to the pixel data for each row:
888
889 png_bytep row_pointers[height];
890
891If you know your image size and pixel size ahead of time, you can allocate
892row_pointers prior to calling png_read_png() with
893
894 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
895 png_error (png_ptr,
896 "Image is too tall to process in memory");
897 if (width > PNG_UINT_32_MAX/pixel_size)
898 png_error (png_ptr,
899 "Image is too wide to process in memory");
900 row_pointers = png_malloc(png_ptr,
901 height*png_sizeof(png_bytep));
902 for (int i=0; i<height, i++)
903 row_pointers[i]=NULL; /* security precaution */
904 for (int i=0; i<height, i++)
905 row_pointers[i]=png_malloc(png_ptr,
906 width*pixel_size);
907 png_set_rows(png_ptr, info_ptr, &row_pointers);
908
909Alternatively you could allocate your image in one big block and define
910row_pointers[i] to point into the proper places in your block.
911
912If you use png_set_rows(), the application is responsible for freeing
913row_pointers (and row_pointers[i], if they were separately allocated).
914
915If you don't allocate row_pointers ahead of time, png_read_png() will
916do it, and it'll be free'ed when you call png_destroy_*().
917
918.SS The low-level read interface
919
920If you are going the low-level route, you are now ready to read all
921the file information up to the actual image data. You do this with a
922call to png_read_info().
923
924 png_read_info(png_ptr, info_ptr);
925
926This will process all chunks up to but not including the image data.
927
928.SS Querying the info structure
929
930Functions are used to get the information from the info_ptr once it
931has been read. Note that these fields may not be completely filled
932in until png_read_end() has read the chunk data following the image.
933
934 png_get_IHDR(png_ptr, info_ptr, &width, &height,
935 &bit_depth, &color_type, &interlace_type,
936 &compression_type, &filter_method);
937
938 width - holds the width of the image
939 in pixels (up to 2^31).
940 height - holds the height of the image
941 in pixels (up to 2^31).
942 bit_depth - holds the bit depth of one of the
943 image channels. (valid values are
944 1, 2, 4, 8, 16 and depend also on
945 the color_type. See also
946 significant bits (sBIT) below).
947 color_type - describes which color/alpha channels
948 are present.
949 PNG_COLOR_TYPE_GRAY
950 (bit depths 1, 2, 4, 8, 16)
951 PNG_COLOR_TYPE_GRAY_ALPHA
952 (bit depths 8, 16)
953 PNG_COLOR_TYPE_PALETTE
954 (bit depths 1, 2, 4, 8)
955 PNG_COLOR_TYPE_RGB
956 (bit_depths 8, 16)
957 PNG_COLOR_TYPE_RGB_ALPHA
958 (bit_depths 8, 16)
959
960 PNG_COLOR_MASK_PALETTE
961 PNG_COLOR_MASK_COLOR
962 PNG_COLOR_MASK_ALPHA
963
964 filter_method - (must be PNG_FILTER_TYPE_BASE
965 for PNG 1.0, and can also be
966 PNG_INTRAPIXEL_DIFFERENCING if
967 the PNG datastream is embedded in
968 a MNG-1.0 datastream)
969 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
970 for PNG 1.0)
971 interlace_type - (PNG_INTERLACE_NONE or
972 PNG_INTERLACE_ADAM7)
973
974 Any or all of interlace_type, compression_type, or
975 filter_method can be NULL if you are
976 not interested in their values.
977
978 Note that png_get_IHDR() returns 32-bit data into
979 the application's width and height variables.
980 This is an unsafe situation if these are 16-bit
981 variables. In such situations, the
982 png_get_image_width() and png_get_image_height()
983 functions described below are safer.
984
985 width = png_get_image_width(png_ptr,
986 info_ptr);
987 height = png_get_image_height(png_ptr,
988 info_ptr);
989 bit_depth = png_get_bit_depth(png_ptr,
990 info_ptr);
991 color_type = png_get_color_type(png_ptr,
992 info_ptr);
993 filter_method = png_get_filter_type(png_ptr,
994 info_ptr);
995 compression_type = png_get_compression_type(png_ptr,
996 info_ptr);
997 interlace_type = png_get_interlace_type(png_ptr,
998 info_ptr);
999
1000 channels = png_get_channels(png_ptr, info_ptr);
1001 channels - number of channels of info for the
1002 color type (valid values are 1 (GRAY,
1003 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1004 4 (RGB_ALPHA or RGB + filler byte))
1005 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1006 rowbytes - number of bytes needed to hold a row
1007
1008 signature = png_get_signature(png_ptr, info_ptr);
1009 signature - holds the signature read from the
1010 file (if any). The data is kept in
1011 the same offset it would be if the
1012 whole signature were read (i.e. if an
1013 application had already read in 4
1014 bytes of signature before starting
1015 libpng, the remaining 4 bytes would
1016 be in signature[4] through signature[7]
1017 (see png_set_sig_bytes())).
1018
1019These are also important, but their validity depends on whether the chunk
1020has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1021png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1022data has been read, or zero if it is missing. The parameters to the
1023png_get_<chunk> are set directly if they are simple data types, or a
1024pointer into the info_ptr is returned for any complex types.
1025
1026 png_get_PLTE(png_ptr, info_ptr, &palette,
1027 &num_palette);
1028 palette - the palette for the file
1029 (array of png_color)
1030 num_palette - number of entries in the palette
1031
1032 png_get_gAMA(png_ptr, info_ptr, &gamma);
1033 gamma - the gamma the file is written
1034 at (PNG_INFO_gAMA)
1035
1036 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1037 srgb_intent - the rendering intent (PNG_INFO_sRGB)
1038 The presence of the sRGB chunk
1039 means that the pixel data is in the
1040 sRGB color space. This chunk also
1041 implies specific values of gAMA and
1042 cHRM.
1043
1044 png_get_iCCP(png_ptr, info_ptr, &name,
1045 &compression_type, &profile, &proflen);
1046 name - The profile name.
1047 compression - The compression type; always
1048 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1049 You may give NULL to this argument to
1050 ignore it.
1051 profile - International Color Consortium color
1052 profile data. May contain NULs.
1053 proflen - length of profile data in bytes.
1054
1055 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1056 sig_bit - the number of significant bits for
1057 (PNG_INFO_sBIT) each of the gray,
1058 red, green, and blue channels,
1059 whichever are appropriate for the
1060 given color type (png_color_16)
1061
1062 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
1063 &trans_values);
1064 trans - array of transparent
1065 entries for palette (PNG_INFO_tRNS)
1066 trans_values - graylevel or color sample values of
1067 the single transparent color for
1068 non-paletted images (PNG_INFO_tRNS)
1069 num_trans - number of transparent entries
1070 (PNG_INFO_tRNS)
1071
1072 png_get_hIST(png_ptr, info_ptr, &hist);
1073 (PNG_INFO_hIST)
1074 hist - histogram of palette (array of
1075 png_uint_16)
1076
1077 png_get_tIME(png_ptr, info_ptr, &mod_time);
1078 mod_time - time image was last modified
1079 (PNG_VALID_tIME)
1080
1081 png_get_bKGD(png_ptr, info_ptr, &background);
1082 background - background color (PNG_VALID_bKGD)
1083 valid 16-bit red, green and blue
1084 values, regardless of color_type
1085
1086 num_comments = png_get_text(png_ptr, info_ptr,
1087 &text_ptr, &num_text);
1088 num_comments - number of comments
1089 text_ptr - array of png_text holding image
1090 comments
1091 text_ptr[i].compression - type of compression used
1092 on "text" PNG_TEXT_COMPRESSION_NONE
1093 PNG_TEXT_COMPRESSION_zTXt
1094 PNG_ITXT_COMPRESSION_NONE
1095 PNG_ITXT_COMPRESSION_zTXt
1096 text_ptr[i].key - keyword for comment. Must contain
1097 1-79 characters.
1098 text_ptr[i].text - text comments for current
1099 keyword. Can be empty.
1100 text_ptr[i].text_length - length of text string,
1101 after decompression, 0 for iTXt
1102 text_ptr[i].itxt_length - length of itxt string,
1103 after decompression, 0 for tEXt/zTXt
1104 text_ptr[i].lang - language of comment (empty
1105 string for unknown).
1106 text_ptr[i].lang_key - keyword in UTF-8
1107 (empty string for unknown).
1108 Note that the itxt_length, lang, and lang_key
1109 members of the text_ptr structure only exist
1110 when the library is built with iTXt chunk support.
1111
1112 num_text - number of comments (same as
1113 num_comments; you can put NULL here
1114 to avoid the duplication)
1115 Note while png_set_text() will accept text, language,
1116 and translated keywords that can be NULL pointers, the
1117 structure returned by png_get_text will always contain
1118 regular zero-terminated C strings. They might be
1119 empty strings but they will never be NULL pointers.
1120
1121 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1122 &palette_ptr);
1123 palette_ptr - array of palette structures holding
1124 contents of one or more sPLT chunks
1125 read.
1126 num_spalettes - number of sPLT chunks read.
1127
1128 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
1129 &unit_type);
1130 offset_x - positive offset from the left edge
1131 of the screen
1132 offset_y - positive offset from the top edge
1133 of the screen
1134 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1135
1136 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
1137 &unit_type);
1138 res_x - pixels/unit physical resolution in
1139 x direction
1140 res_y - pixels/unit physical resolution in
1141 x direction
1142 unit_type - PNG_RESOLUTION_UNKNOWN,
1143 PNG_RESOLUTION_METER
1144
1145 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1146 &height)
1147 unit - physical scale units (an integer)
1148 width - width of a pixel in physical scale units
1149 height - height of a pixel in physical scale units
1150 (width and height are doubles)
1151
1152 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1153 &height)
1154 unit - physical scale units (an integer)
1155 width - width of a pixel in physical scale units
1156 height - height of a pixel in physical scale units
1157 (width and height are strings like "2.54")
1158
1159 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1160 info_ptr, &unknowns)
1161 unknowns - array of png_unknown_chunk
1162 structures holding unknown chunks
1163 unknowns[i].name - name of unknown chunk
1164 unknowns[i].data - data of unknown chunk
1165 unknowns[i].size - size of unknown chunk's data
1166 unknowns[i].location - position of chunk in file
1167
1168 The value of "i" corresponds to the order in which the
1169 chunks were read from the PNG file or inserted with the
1170 png_set_unknown_chunks() function.
1171
1172The data from the pHYs chunk can be retrieved in several convenient
1173forms:
1174
1175 res_x = png_get_x_pixels_per_meter(png_ptr,
1176 info_ptr)
1177 res_y = png_get_y_pixels_per_meter(png_ptr,
1178 info_ptr)
1179 res_x_and_y = png_get_pixels_per_meter(png_ptr,
1180 info_ptr)
1181 res_x = png_get_x_pixels_per_inch(png_ptr,
1182 info_ptr)
1183 res_y = png_get_y_pixels_per_inch(png_ptr,
1184 info_ptr)
1185 res_x_and_y = png_get_pixels_per_inch(png_ptr,
1186 info_ptr)
1187 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
1188 info_ptr)
1189
1190 (Each of these returns 0 [signifying "unknown"] if
1191 the data is not present or if res_x is 0;
1192 res_x_and_y is 0 if res_x != res_y)
1193
1194The data from the oFFs chunk can be retrieved in several convenient
1195forms:
1196
1197 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1198 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1199 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1200 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1201
1202 (Each of these returns 0 [signifying "unknown" if both
1203 x and y are 0] if the data is not present or if the
1204 chunk is present but the unit is the pixel)
1205
1206For more information, see the png_info definition in png.h and the
1207PNG specification for chunk contents. Be careful with trusting
1208rowbytes, as some of the transformations could increase the space
1209needed to hold a row (expand, filler, gray_to_rgb, etc.).
1210See png_read_update_info(), below.
1211
1212A quick word about text_ptr and num_text. PNG stores comments in
1213keyword/text pairs, one pair per chunk, with no limit on the number
1214of text chunks, and a 2^31 byte limit on their size. While there are
1215suggested keywords, there is no requirement to restrict the use to these
1216strings. It is strongly suggested that keywords and text be sensible
1217to humans (that's the point), so don't use abbreviations. Non-printing
1218symbols are not allowed. See the PNG specification for more details.
1219There is also no requirement to have text after the keyword.
1220
1221Keywords should be limited to 79 Latin-1 characters without leading or
1222trailing spaces, but non-consecutive spaces are allowed within the
1223keyword. It is possible to have the same keyword any number of times.
1224The text_ptr is an array of png_text structures, each holding a
1225pointer to a language string, a pointer to a keyword and a pointer to
1226a text string. The text string, language code, and translated
1227keyword may be empty or NULL pointers. The keyword/text
1228pairs are put into the array in the order that they are received.
1229However, some or all of the text chunks may be after the image, so, to
1230make sure you have read all the text chunks, don't mess with these
1231until after you read the stuff after the image. This will be
1232mentioned again below in the discussion that goes with png_read_end().
1233
1234.SS Input transformations
1235
1236After you've read the header information, you can set up the library
1237to handle any special transformations of the image data. The various
1238ways to transform the data will be described in the order that they
1239should occur. This is important, as some of these change the color
1240type and/or bit depth of the data, and some others only work on
1241certain color types and bit depths. Even though each transformation
1242checks to see if it has data that it can do something with, you should
1243make sure to only enable a transformation if it will be valid for the
1244data. For example, don't swap red and blue on grayscale data.
1245
1246The colors used for the background and transparency values should be
1247supplied in the same format/depth as the current image data. They
1248are stored in the same format/depth as the image data in a bKGD or tRNS
1249chunk, so this is what libpng expects for this data. The colors are
1250transformed to keep in sync with the image data when an application
1251calls the png_read_update_info() routine (see below).
1252
1253Data will be decoded into the supplied row buffers packed into bytes
1254unless the library has been told to transform it into another format.
1255For example, 4 bit/pixel paletted or grayscale data will be returned
12562 pixels/byte with the leftmost pixel in the high-order bits of the
1257byte, unless png_set_packing() is called. 8-bit RGB data will be stored
1258in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
1259is called to insert filler bytes, either before or after each RGB triplet.
126016-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
1261byte of the color value first, unless png_set_strip_16() is called to
1262transform it to regular RGB RGB triplets, or png_set_filler() or
1263png_set_add alpha() is called to insert filler bytes, either before or
1264after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
1265be modified with
1266png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
1267
1268The following code transforms grayscale images of less than 8 to 8 bits,
1269changes paletted images to RGB, and adds a full alpha channel if there is
1270transparency information in a tRNS chunk. This is most useful on
1271grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1272viewing application that wishes to treat all images in the same way.
1273
1274 if (color_type == PNG_COLOR_TYPE_PALETTE)
1275 png_set_palette_to_rgb(png_ptr);
1276
1277 if (color_type == PNG_COLOR_TYPE_GRAY &&
1278 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
1279
1280 if (png_get_valid(png_ptr, info_ptr,
1281 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1282
1283These three functions are actually aliases for png_set_expand(), added
1284in libpng version 1.0.4, with the function names expanded to improve code
1285readability. In some future version they may actually do different
1286things.
1287
1288As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
1289added. It expands the sample depth without changing tRNS to alpha.
1290
1291As of libpng version 1.2.53, not all possible expansions are supported.
1292
1293In the following table, the 01 means grayscale with depth<8, 31 means
1294indexed with depth<8, other numerals represent the color type, "T" means
1295the tRNS chunk is present, A means an alpha channel is present, and O
1296means tRNS or alpha is present but all pixels in the image are opaque.
1297
1298 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
1299 TO
1300 01 -
1301 31 -
1302 0 1 -
1303 0T -
1304 0O -
1305 2 GX -
1306 2T -
1307 2O -
1308 3 1 -
1309 3T -
1310 3O -
1311 4A T -
1312 4O -
1313 6A GX TX TX -
1314 6O GX TX -
1315
1316Within the matrix,
1317 "-" means the transformation is not supported.
1318 "X" means the transformation is obtained by png_set_expand().
1319 "1" means the transformation is obtained by
1320 png_set_expand_gray_1_2_4_to_8
1321 "G" means the transformation is obtained by
1322 png_set_gray_to_rgb().
1323 "P" means the transformation is obtained by
1324 png_set_expand_palette_to_rgb().
1325 "T" means the transformation is obtained by
1326 png_set_tRNS_to_alpha().
1327
1328PNG can have files with 16 bits per channel. If you only can handle
13298 bits per channel, this will strip the pixels down to 8 bit.
1330
1331 if (bit_depth == 16)
1332 png_set_strip_16(png_ptr);
1333
1334If, for some reason, you don't need the alpha channel on an image,
1335and you want to remove it rather than combining it with the background
1336(but the image author certainly had in mind that you *would* combine
1337it with the background, so that's what you should probably do):
1338
1339 if (color_type & PNG_COLOR_MASK_ALPHA)
1340 png_set_strip_alpha(png_ptr);
1341
1342In PNG files, the alpha channel in an image
1343is the level of opacity. If you need the alpha channel in an image to
1344be the level of transparency instead of opacity, you can invert the
1345alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1346fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1347images) is fully transparent, with
1348
1349 png_set_invert_alpha(png_ptr);
1350
1351The PNG format only supports pixels with postmultiplied alpha.
1352If you want to replace the pixels, after reading them, with pixels
1353that have premultiplied color samples, you can do this with
1354
1355 png_set_premultiply_alpha(png_ptr);
1356
1357If you do this, any input with a tRNS chunk will be expanded to
1358have an alpha channel.
1359
1360PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1361they can, resulting in, for example, 8 pixels per byte for 1 bit
1362files. This code expands to 1 pixel per byte without changing the
1363values of the pixels:
1364
1365 if (bit_depth < 8)
1366 png_set_packing(png_ptr);
1367
1368PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1369stored in a PNG image have been "scaled" or "shifted" up to the next
1370higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
1371to 8 bits/sample in the range [0, 255]). However, it is also possible
1372to convert the PNG pixel data back to the original bit depth of the
1373image. This call reduces the pixels back down to the original bit depth:
1374
1375 png_color_8p sig_bit;
1376
1377 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1378 png_set_shift(png_ptr, sig_bit);
1379
1380PNG files store 3-color pixels in red, green, blue order. This code
1381changes the storage of the pixels to blue, green, red:
1382
1383 if (color_type == PNG_COLOR_TYPE_RGB ||
1384 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1385 png_set_bgr(png_ptr);
1386
1387PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
1388into 4 or 8 bytes for windowing systems that need them in this format:
1389
1390 if (color_type == PNG_COLOR_TYPE_RGB)
1391 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
1392
1393where "filler" is the 8 or 16-bit number to fill with, and the location is
1394either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1395you want the filler before the RGB or after. This transformation
1396does not affect images that already have full alpha channels. To add an
1397opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
1398will generate RGBA pixels.
1399
1400Note that png_set_filler() does not change the color type. If you want
1401to do that, you can add a true alpha channel with
1402
1403 if (color_type == PNG_COLOR_TYPE_RGB ||
1404 color_type == PNG_COLOR_TYPE_GRAY)
1405 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
1406
1407where "filler" contains the alpha value to assign to each pixel.
1408This function was added in libpng-1.2.7.
1409
1410If you are reading an image with an alpha channel, and you need the
1411data as ARGB instead of the normal PNG format RGBA:
1412
1413 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1414 png_set_swap_alpha(png_ptr);
1415
1416For some uses, you may want a grayscale image to be represented as
1417RGB. This code will do that conversion:
1418
1419 if (color_type == PNG_COLOR_TYPE_GRAY ||
1420 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1421 png_set_gray_to_rgb(png_ptr);
1422
1423Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
1424with alpha.
1425
1426 if (color_type == PNG_COLOR_TYPE_RGB ||
1427 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1428 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1429 int red_weight, int green_weight);
1430
1431 error_action = 1: silently do the conversion
1432 error_action = 2: issue a warning if the original
1433 image has any pixel where
1434 red != green or red != blue
1435 error_action = 3: issue an error and abort the
1436 conversion if the original
1437 image has any pixel where
1438 red != green or red != blue
1439
1440 red_weight: weight of red component times 100000
1441 green_weight: weight of green component times 100000
1442 If either weight is negative, default
1443 weights (21268, 71514) are used.
1444
1445If you have set error_action = 1 or 2, you can
1446later check whether the image really was gray, after processing
1447the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1448It will return a png_byte that is zero if the image was gray or
14491 if there were any non-gray pixels. bKGD and sBIT data
1450will be silently converted to grayscale, using the green channel
1451data, regardless of the error_action setting.
1452
1453With red_weight+green_weight<=100000,
1454the normalized graylevel is computed:
1455
1456 int rw = red_weight * 65536;
1457 int gw = green_weight * 65536;
1458 int bw = 65536 - (rw + gw);
1459 gray = (rw*red + gw*green + bw*blue)/65536;
1460
1461The default values approximate those recommended in the Charles
1462Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
1463Copyright (c) 1998-01-04 Charles Poynton <poynton at inforamp.net>
1464
1465 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1466
1467Libpng approximates this with
1468
1469 Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
1470
1471which can be expressed with integers as
1472
1473 Y = (6969 * R + 23434 * G + 2365 * B)/32768
1474
1475The calculation is done in a linear colorspace, if the image gamma
1476is known.
1477
1478If you have a grayscale and you are using png_set_expand_depth(),
1479png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
1480a higher bit-depth, you must either supply the background color as a gray
1481value at the original file bit-depth (need_expand = 1) or else supply the
1482background color as an RGB triplet at the final, expanded bit depth
1483(need_expand = 0). Similarly, if you are reading a paletted image, you
1484must either supply the background color as a palette index (need_expand = 1)
1485or as an RGB triplet that may or may not be in the palette (need_expand = 0).
1486
1487 png_color_16 my_background;
1488 png_color_16p image_background;
1489
1490 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1491 png_set_background(png_ptr, image_background,
1492 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
1493 else
1494 png_set_background(png_ptr, &my_background,
1495 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1496
1497The png_set_background() function tells libpng to composite images
1498with alpha or simple transparency against the supplied background
1499color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1500you may use this color, or supply another color more suitable for
1501the current display (e.g., the background color from a web page). You
1502need to tell libpng whether the color is in the gamma space of the
1503display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
1504(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
1505that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
1506know why anyone would use this, but it's here).
1507
1508To properly display PNG images on any kind of system, the application needs
1509to know what the display gamma is. Ideally, the user will know this, and
1510the application will allow them to set it. One method of allowing the user
1511to set the display gamma separately for each system is to check for a
1512SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
1513correctly set.
1514
1515Note that display_gamma is the overall gamma correction required to produce
1516pleasing results, which depends on the lighting conditions in the surrounding
1517environment. In a dim or brightly lit room, no compensation other than
1518the physical gamma exponent of the monitor is needed, while in a dark room
1519a slightly smaller exponent is better.
1520
1521 double gamma, screen_gamma;
1522
1523 if (/* We have a user-defined screen
1524 gamma value */)
1525 {
1526 screen_gamma = user_defined_screen_gamma;
1527 }
1528 /* One way that applications can share the same
1529 screen gamma value */
1530 else if ((gamma_str = getenv("SCREEN_GAMMA"))
1531 != NULL)
1532 {
1533 screen_gamma = (double)atof(gamma_str);
1534 }
1535 /* If we don't have another value */
1536 else
1537 {
1538 screen_gamma = 2.2; /* A good guess for a
1539 PC monitor in a bright office or a dim room */
1540 screen_gamma = 2.0; /* A good guess for a
1541 PC monitor in a dark room */
1542 screen_gamma = 1.7 or 1.0; /* A good
1543 guess for Mac systems */
1544 }
1545
1546The png_set_gamma() function handles gamma transformations of the data.
1547Pass both the file gamma and the current screen_gamma. If the file does
1548not have a gamma value, you can pass one anyway if you have an idea what
1549it is (usually 0.45455 is a good guess for GIF images on PCs). Note
1550that file gammas are inverted from screen gammas. See the discussions
1551on gamma in the PNG specification for an excellent description of what
1552gamma is, and why all applications should support it. It is strongly
1553recommended that PNG viewers support gamma correction.
1554
1555 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
1556 png_set_gamma(png_ptr, screen_gamma, gamma);
1557 else
1558 png_set_gamma(png_ptr, screen_gamma, 0.45455);
1559
1560If you need to reduce an RGB file to a paletted file, or if a paletted
1561file has more entries then will fit on your screen, png_set_dither()
1562will do that. Note that this is a simple match dither that merely
1563finds the closest color available. This should work fairly well with
1564optimized palettes, and fairly badly with linear color cubes. If you
1565pass a palette that is larger then maximum_colors, the file will
1566reduce the number of colors in the palette so it will fit into
1567maximum_colors. If there is a histogram, it will use it to make
1568more intelligent choices when reducing the palette. If there is no
1569histogram, it may not do as good a job.
1570
1571 if (color_type & PNG_COLOR_MASK_COLOR)
1572 {
1573 if (png_get_valid(png_ptr, info_ptr,
1574 PNG_INFO_PLTE))
1575 {
1576 png_uint_16p histogram = NULL;
1577
1578 png_get_hIST(png_ptr, info_ptr,
1579 &histogram);
1580 png_set_dither(png_ptr, palette, num_palette,
1581 max_screen_colors, histogram, 1);
1582 }
1583 else
1584 {
1585 png_color std_color_cube[MAX_SCREEN_COLORS] =
1586 { ... colors ... };
1587
1588 png_set_dither(png_ptr, std_color_cube,
1589 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
1590 NULL,0);
1591 }
1592 }
1593
1594PNG files describe monochrome as black being zero and white being one.
1595The following code will reverse this (make black be one and white be
1596zero):
1597
1598 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
1599 png_set_invert_mono(png_ptr);
1600
1601This function can also be used to invert grayscale and gray-alpha images:
1602
1603 if (color_type == PNG_COLOR_TYPE_GRAY ||
1604 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1605 png_set_invert_mono(png_ptr);
1606
1607PNG files store 16 bit pixels in network byte order (big-endian,
1608ie. most significant bits first). This code changes the storage to the
1609other way (little-endian, i.e. least significant bits first, the
1610way PCs store them):
1611
1612 if (bit_depth == 16)
1613 png_set_swap(png_ptr);
1614
1615If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
1616need to change the order the pixels are packed into bytes, you can use:
1617
1618 if (bit_depth < 8)
1619 png_set_packswap(png_ptr);
1620
1621Finally, you can write your own transformation function if none of
1622the existing ones meets your needs. This is done by setting a callback
1623with
1624
1625 png_set_read_user_transform_fn(png_ptr,
1626 read_transform_fn);
1627
1628You must supply the function
1629
1630 void read_transform_fn(png_ptr ptr, row_info_ptr
1631 row_info, png_bytep data)
1632
1633See pngtest.c for a working example. Your function will be called
1634after all of the other transformations have been processed.
1635
1636You can also set up a pointer to a user structure for use by your
1637callback function, and you can inform libpng that your transform
1638function will change the number of channels or bit depth with the
1639function
1640
1641 png_set_user_transform_info(png_ptr, user_ptr,
1642 user_depth, user_channels);
1643
1644The user's application, not libpng, is responsible for allocating and
1645freeing any memory required for the user structure.
1646
1647You can retrieve the pointer via the function
1648png_get_user_transform_ptr(). For example:
1649
1650 voidp read_user_transform_ptr =
1651 png_get_user_transform_ptr(png_ptr);
1652
1653The last thing to handle is interlacing; this is covered in detail below,
1654but you must call the function here if you want libpng to handle expansion
1655of the interlaced image.
1656
1657 number_of_passes = png_set_interlace_handling(png_ptr);
1658
1659After setting the transformations, libpng can update your png_info
1660structure to reflect any transformations you've requested with this
1661call. This is most useful to update the info structure's rowbytes
1662field so you can use it to allocate your image memory. This function
1663will also update your palette with the correct screen_gamma and
1664background if these have been given with the calls above.
1665
1666 png_read_update_info(png_ptr, info_ptr);
1667
1668After you call png_read_update_info(), you can allocate any
1669memory you need to hold the image. The row data is simply
1670raw byte data for all forms of images. As the actual allocation
1671varies among applications, no example will be given. If you
1672are allocating one large chunk, you will need to build an
1673array of pointers to each row, as it will be needed for some
1674of the functions below.
1675
1676.SS Reading image data
1677
1678After you've allocated memory, you can read the image data.
1679The simplest way to do this is in one function call. If you are
1680allocating enough memory to hold the whole image, you can just
1681call png_read_image() and libpng will read in all the image data
1682and put it in the memory area supplied. You will need to pass in
1683an array of pointers to each row.
1684
1685This function automatically handles interlacing, so you don't need
1686to call png_set_interlace_handling() or call this function multiple
1687times, or any of that other stuff necessary with png_read_rows().
1688
1689 png_read_image(png_ptr, row_pointers);
1690
1691where row_pointers is:
1692
1693 png_bytep row_pointers[height];
1694
1695You can point to void or char or whatever you use for pixels.
1696
1697If you don't want to read in the whole image at once, you can
1698use png_read_rows() instead. If there is no interlacing (check
1699interlace_type == PNG_INTERLACE_NONE), this is simple:
1700
1701 png_read_rows(png_ptr, row_pointers, NULL,
1702 number_of_rows);
1703
1704where row_pointers is the same as in the png_read_image() call.
1705
1706If you are doing this just one row at a time, you can do this with
1707a single row_pointer instead of an array of row_pointers:
1708
1709 png_bytep row_pointer = row;
1710 png_read_row(png_ptr, row_pointer, NULL);
1711
1712If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
1713get somewhat harder. The only current (PNG Specification version 1.2)
1714interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
1715is a somewhat complicated 2D interlace scheme, known as Adam7, that
1716breaks down an image into seven smaller images of varying size, based
1717on an 8x8 grid.
1718
1719libpng can fill out those images or it can give them to you "as is".
1720If you want them filled out, there are two ways to do that. The one
1721mentioned in the PNG specification is to expand each pixel to cover
1722those pixels that have not been read yet (the "rectangle" method).
1723This results in a blocky image for the first pass, which gradually
1724smooths out as more pixels are read. The other method is the "sparkle"
1725method, where pixels are drawn only in their final locations, with the
1726rest of the image remaining whatever colors they were initialized to
1727before the start of the read. The first method usually looks better,
1728but tends to be slower, as there are more pixels to put in the rows.
1729
1730If you don't want libpng to handle the interlacing details, just call
1731png_read_rows() seven times to read in all seven images. Each of the
1732images is a valid image by itself, or they can all be combined on an
17338x8 grid to form a single image (although if you intend to combine them
1734you would be far better off using the libpng interlace handling).
1735
1736The first pass will return an image 1/8 as wide as the entire image
1737(every 8th column starting in column 0) and 1/8 as high as the original
1738(every 8th row starting in row 0), the second will be 1/8 as wide
1739(starting in column 4) and 1/8 as high (also starting in row 0). The
1740third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
17411/8 as high (every 8th row starting in row 4), and the fourth pass will
1742be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
1743and every 4th row starting in row 0). The fifth pass will return an
1744image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
1745while the sixth pass will be 1/2 as wide and 1/2 as high as the original
1746(starting in column 1 and row 0). The seventh and final pass will be as
1747wide as the original, and 1/2 as high, containing all of the odd
1748numbered scanlines. Phew!
1749
1750If you want libpng to expand the images, call this before calling
1751png_start_read_image() or png_read_update_info():
1752
1753 if (interlace_type == PNG_INTERLACE_ADAM7)
1754 number_of_passes
1755 = png_set_interlace_handling(png_ptr);
1756
1757This will return the number of passes needed. Currently, this
1758is seven, but may change if another interlace type is added.
1759This function can be called even if the file is not interlaced,
1760where it will return one pass.
1761
1762If you are not going to display the image after each pass, but are
1763going to wait until the entire image is read in, use the sparkle
1764effect. This effect is faster and the end result of either method
1765is exactly the same. If you are planning on displaying the image
1766after each pass, the "rectangle" effect is generally considered the
1767better looking one.
1768
1769If you only want the "sparkle" effect, just call png_read_rows() as
1770normal, with the third parameter NULL. Make sure you make pass over
1771the image number_of_passes times, and you don't change the data in the
1772rows between calls. You can change the locations of the data, just
1773not the data. Each pass only writes the pixels appropriate for that
1774pass, and assumes the data from previous passes is still valid.
1775
1776 png_read_rows(png_ptr, row_pointers, NULL,
1777 number_of_rows);
1778
1779If you only want the first effect (the rectangles), do the same as
1780before except pass the row buffer in the third parameter, and leave
1781the second parameter NULL.
1782
1783 png_read_rows(png_ptr, NULL, row_pointers,
1784 number_of_rows);
1785
1786.SS Finishing a sequential read
1787
1788After you are finished reading the image through the
1789low-level interface, you can finish reading the file. If you are
1790interested in comments or time, which may be stored either before or
1791after the image data, you should pass the separate png_info struct if
1792you want to keep the comments from before and after the image
1793separate. If you are not interested, you can pass NULL.
1794
1795 png_read_end(png_ptr, end_info);
1796
1797When you are done, you can free all memory allocated by libpng like this:
1798
1799 png_destroy_read_struct(&png_ptr, &info_ptr,
1800 &end_info);
1801
1802It is also possible to individually free the info_ptr members that
1803point to libpng-allocated storage with the following function:
1804
1805 png_free_data(png_ptr, info_ptr, mask, seq)
1806 mask - identifies data to be freed, a mask
1807 containing the bitwise OR of one or
1808 more of
1809 PNG_FREE_PLTE, PNG_FREE_TRNS,
1810 PNG_FREE_HIST, PNG_FREE_ICCP,
1811 PNG_FREE_PCAL, PNG_FREE_ROWS,
1812 PNG_FREE_SCAL, PNG_FREE_SPLT,
1813 PNG_FREE_TEXT, PNG_FREE_UNKN,
1814 or simply PNG_FREE_ALL
1815 seq - sequence number of item to be freed
1816 (\-1 for all items)
1817
1818This function may be safely called when the relevant storage has
1819already been freed, or has not yet been allocated, or was allocated
1820by the user and not by libpng, and will in those cases do nothing.
1821The "seq" parameter is ignored if only one item of the selected data
1822type, such as PLTE, is allowed. If "seq" is not \-1, and multiple items
1823are allowed for the data type identified in the mask, such as text or
1824sPLT, only the n'th item in the structure is freed, where n is "seq".
1825
1826The default behavior is only to free data that was allocated internally
1827by libpng. This can be changed, so that libpng will not free the data,
1828or so that it will free data that was allocated by the user with png_malloc()
1829or png_zalloc() and passed in via a png_set_*() function, with
1830
1831 png_data_freer(png_ptr, info_ptr, freer, mask)
1832 mask - which data elements are affected
1833 same choices as in png_free_data()
1834 freer - one of
1835 PNG_DESTROY_WILL_FREE_DATA
1836 PNG_SET_WILL_FREE_DATA
1837 PNG_USER_WILL_FREE_DATA
1838
1839This function only affects data that has already been allocated.
1840You can call this function after reading the PNG data but before calling
1841any png_set_*() functions, to control whether the user or the png_set_*()
1842function is responsible for freeing any existing data that might be present,
1843and again after the png_set_*() functions to control whether the user
1844or png_destroy_*() is supposed to free the data. When the user assumes
1845responsibility for libpng-allocated data, the application must use
1846png_free() to free it, and when the user transfers responsibility to libpng
1847for data that the user has allocated, the user must have used png_malloc()
1848or png_zalloc() to allocate it.
1849
1850If you allocated your row_pointers in a single block, as suggested above in
1851the description of the high level read interface, you must not transfer
1852responsibility for freeing it to the png_set_rows or png_read_destroy function,
1853because they would also try to free the individual row_pointers[i].
1854
1855If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
1856separately, do not transfer responsibility for freeing text_ptr to libpng,
1857because when libpng fills a png_text structure it combines these members with
1858the key member, and png_free_data() will free only text_ptr.key. Similarly,
1859if you transfer responsibility for free'ing text_ptr from libpng to your
1860application, your application must not separately free those members.
1861
1862The png_free_data() function will turn off the "valid" flag for anything
1863it frees. If you need to turn the flag off for a chunk that was freed by
1864your application instead of by libpng, you can use
1865
1866 png_set_invalid(png_ptr, info_ptr, mask);
1867 mask - identifies the chunks to be made invalid,
1868 containing the bitwise OR of one or
1869 more of
1870 PNG_INFO_gAMA, PNG_INFO_sBIT,
1871 PNG_INFO_cHRM, PNG_INFO_PLTE,
1872 PNG_INFO_tRNS, PNG_INFO_bKGD,
1873 PNG_INFO_hIST, PNG_INFO_pHYs,
1874 PNG_INFO_oFFs, PNG_INFO_tIME,
1875 PNG_INFO_pCAL, PNG_INFO_sRGB,
1876 PNG_INFO_iCCP, PNG_INFO_sPLT,
1877 PNG_INFO_sCAL, PNG_INFO_IDAT
1878
1879For a more compact example of reading a PNG image, see the file example.c.
1880
1881.SS Reading PNG files progressively
1882
1883The progressive reader is slightly different then the non-progressive
1884reader. Instead of calling png_read_info(), png_read_rows(), and
1885png_read_end(), you make one call to png_process_data(), which calls
1886callbacks when it has the info, a row, or the end of the image. You
1887set up these callbacks with png_set_progressive_read_fn(). You don't
1888have to worry about the input/output functions of libpng, as you are
1889giving the library the data directly in png_process_data(). I will
1890assume that you have read the section on reading PNG files above,
1891so I will only highlight the differences (although I will show
1892all of the code).
1893
1894png_structp png_ptr;
1895png_infop info_ptr;
1896
1897 /* An example code fragment of how you would
1898 initialize the progressive reader in your
1899 application. */
1900 int
1901 initialize_png_reader()
1902 {
1903 png_ptr = png_create_read_struct
1904 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1905 user_error_fn, user_warning_fn);
1906 if (!png_ptr)
1907 return (ERROR);
1908 info_ptr = png_create_info_struct(png_ptr);
1909 if (!info_ptr)
1910 {
1911 png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
1912 (png_infopp)NULL);
1913 return (ERROR);
1914 }
1915
1916 if (setjmp(png_jmpbuf(png_ptr)))
1917 {
1918 png_destroy_read_struct(&png_ptr, &info_ptr,
1919 (png_infopp)NULL);
1920 return (ERROR);
1921 }
1922
1923 /* This one's new. You can provide functions
1924 to be called when the header info is valid,
1925 when each row is completed, and when the image
1926 is finished. If you aren't using all functions,
1927 you can specify NULL parameters. Even when all
1928 three functions are NULL, you need to call
1929 png_set_progressive_read_fn(). You can use
1930 any struct as the user_ptr (cast to a void pointer
1931 for the function call), and retrieve the pointer
1932 from inside the callbacks using the function
1933
1934 png_get_progressive_ptr(png_ptr);
1935
1936 which will return a void pointer, which you have
1937 to cast appropriately.
1938 */
1939 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
1940 info_callback, row_callback, end_callback);
1941
1942 return 0;
1943 }
1944
1945 /* A code fragment that you call as you receive blocks
1946 of data */
1947 int
1948 process_data(png_bytep buffer, png_uint_32 length)
1949 {
1950 if (setjmp(png_jmpbuf(png_ptr)))
1951 {
1952 png_destroy_read_struct(&png_ptr, &info_ptr,
1953 (png_infopp)NULL);
1954 return (ERROR);
1955 }
1956
1957 /* This one's new also. Simply give it a chunk
1958 of data from the file stream (in order, of
1959 course). On machines with segmented memory
1960 models machines, don't give it any more than
1961 64K. The library seems to run fine with sizes
1962 of 4K. Although you can give it much less if
1963 necessary (I assume you can give it chunks of
1964 1 byte, I haven't tried less then 256 bytes
1965 yet). When this function returns, you may
1966 want to display any rows that were generated
1967 in the row callback if you don't already do
1968 so there.
1969 */
1970 png_process_data(png_ptr, info_ptr, buffer, length);
1971 return 0;
1972 }
1973
1974 /* This function is called (as set by
1975 png_set_progressive_read_fn() above) when enough data
1976 has been supplied so all of the header has been
1977 read.
1978 */
1979 void
1980 info_callback(png_structp png_ptr, png_infop info)
1981 {
1982 /* Do any setup here, including setting any of
1983 the transformations mentioned in the Reading
1984 PNG files section. For now, you _must_ call
1985 either png_start_read_image() or
1986 png_read_update_info() after all the
1987 transformations are set (even if you don't set
1988 any). You may start getting rows before
1989 png_process_data() returns, so this is your
1990 last chance to prepare for that.
1991 */
1992 }
1993
1994 /* This function is called when each row of image
1995 data is complete */
1996 void
1997 row_callback(png_structp png_ptr, png_bytep new_row,
1998 png_uint_32 row_num, int pass)
1999 {
2000 /* If the image is interlaced, and you turned
2001 on the interlace handler, this function will
2002 be called for every row in every pass. Some
2003 of these rows will not be changed from the
2004 previous pass. When the row is not changed,
2005 the new_row variable will be NULL. The rows
2006 and passes are called in order, so you don't
2007 really need the row_num and pass, but I'm
2008 supplying them because it may make your life
2009 easier.
2010
2011 For the non-NULL rows of interlaced images,
2012 you must call png_progressive_combine_row()
2013 passing in the row and the old row. You can
2014 call this function for NULL rows (it will just
2015 return) and for non-interlaced images (it just
2016 does the memcpy for you) if it will make the
2017 code easier. Thus, you can just do this for
2018 all cases:
2019 */
2020
2021 png_progressive_combine_row(png_ptr, old_row,
2022 new_row);
2023
2024 /* where old_row is what was displayed for
2025 previously for the row. Note that the first
2026 pass (pass == 0, really) will completely cover
2027 the old row, so the rows do not have to be
2028 initialized. After the first pass (and only
2029 for interlaced images), you will have to pass
2030 the current row, and the function will combine
2031 the old row and the new row.
2032 */
2033 }
2034
2035 void
2036 end_callback(png_structp png_ptr, png_infop info)
2037 {
2038 /* This function is called after the whole image
2039 has been read, including any chunks after the
2040 image (up to and including the IEND). You
2041 will usually have the same info chunk as you
2042 had in the header, although some data may have
2043 been added to the comments and time fields.
2044
2045 Most people won't do much here, perhaps setting
2046 a flag that marks the image as finished.
2047 */
2048 }
2049
2050
2051
2052.SH IV. Writing
2053
2054Much of this is very similar to reading. However, everything of
2055importance is repeated here, so you won't have to constantly look
2056back up in the reading section to understand writing.
2057
2058.SS Setup
2059
2060You will want to do the I/O initialization before you get into libpng,
2061so if it doesn't work, you don't have anything to undo. If you are not
2062using the standard I/O functions, you will need to replace them with
2063custom writing functions. See the discussion under Customizing libpng.
2064
2065 FILE *fp = fopen(file_name, "wb");
2066 if (!fp)
2067 {
2068 return (ERROR);
2069 }
2070
2071Next, png_struct and png_info need to be allocated and initialized.
2072As these can be both relatively large, you may not want to store these
2073on the stack, unless you have stack space to spare. Of course, you
2074will want to check if they return NULL. If you are also reading,
2075you won't want to name your read structure and your write structure
2076both "png_ptr"; you can call them anything you like, such as
2077"read_ptr" and "write_ptr". Look at pngtest.c, for example.
2078
2079 png_structp png_ptr = png_create_write_struct
2080 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2081 user_error_fn, user_warning_fn);
2082 if (!png_ptr)
2083 return (ERROR);
2084
2085 png_infop info_ptr = png_create_info_struct(png_ptr);
2086 if (!info_ptr)
2087 {
2088 png_destroy_write_struct(&png_ptr,
2089 (png_infopp)NULL);
2090 return (ERROR);
2091 }
2092
2093If you want to use your own memory allocation routines,
2094define PNG_USER_MEM_SUPPORTED and use
2095png_create_write_struct_2() instead of png_create_write_struct():
2096
2097 png_structp png_ptr = png_create_write_struct_2
2098 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2099 user_error_fn, user_warning_fn, (png_voidp)
2100 user_mem_ptr, user_malloc_fn, user_free_fn);
2101
2102After you have these structures, you will need to set up the
2103error handling. When libpng encounters an error, it expects to
2104longjmp() back to your routine. Therefore, you will need to call
2105setjmp() and pass the png_jmpbuf(png_ptr). If you
2106write the file from different routines, you will need to update
2107the png_jmpbuf(png_ptr) every time you enter a new routine that will
2108call a png_*() function. See your documentation of setjmp/longjmp
2109for your compiler for more information on setjmp/longjmp. See
2110the discussion on libpng error handling in the Customizing Libpng
2111section below for more information on the libpng error handling.
2112
2113 if (setjmp(png_jmpbuf(png_ptr)))
2114 {
2115 png_destroy_write_struct(&png_ptr, &info_ptr);
2116 fclose(fp);
2117 return (ERROR);
2118 }
2119 ...
2120 return;
2121
2122If you would rather avoid the complexity of setjmp/longjmp issues,
2123you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
2124errors will result in a call to PNG_ABORT() which defaults to abort().
2125
2126Now you need to set up the output code. The default for libpng is to
2127use the C function fwrite(). If you use this, you will need to pass a
2128valid FILE * in the function png_init_io(). Be sure that the file is
2129opened in binary mode. Again, if you wish to handle writing data in
2130another way, see the discussion on libpng I/O handling in the Customizing
2131Libpng section below.
2132
2133 png_init_io(png_ptr, fp);
2134
2135If you are embedding your PNG into a datastream such as MNG, and don't
2136want libpng to write the 8-byte signature, or if you have already
2137written the signature in your application, use
2138
2139 png_set_sig_bytes(png_ptr, 8);
2140
2141to inform libpng that it should not write a signature.
2142
2143.SS Write callbacks
2144
2145At this point, you can set up a callback function that will be
2146called after each row has been written, which you can use to control
2147a progress meter or the like. It's demonstrated in pngtest.c.
2148You must supply a function
2149
2150 void write_row_callback(png_ptr, png_uint_32 row,
2151 int pass);
2152 {
2153 /* put your code here */
2154 }
2155
2156(You can give it another name that you like instead of "write_row_callback")
2157
2158To inform libpng about your function, use
2159
2160 png_set_write_status_fn(png_ptr, write_row_callback);
2161
2162You now have the option of modifying how the compression library will
2163run. The following functions are mainly for testing, but may be useful
2164in some cases, like if you need to write PNG files extremely fast and
2165are willing to give up some compression, or if you want to get the
2166maximum possible compression at the expense of slower writing. If you
2167have no special needs in this area, let the library do what it wants by
2168not calling this function at all, as it has been tuned to deliver a good
2169speed/compression ratio. The second parameter to png_set_filter() is
2170the filter method, for which the only valid values are 0 (as of the
2171July 1999 PNG specification, version 1.2) or 64 (if you are writing
2172a PNG datastream that is to be embedded in a MNG datastream). The third
2173parameter is a flag that indicates which filter type(s) are to be tested
2174for each scanline. See the PNG specification for details on the specific
2175filter types.
2176
2177
2178 /* turn on or off filtering, and/or choose
2179 specific filters. You can use either a single
2180 PNG_FILTER_VALUE_NAME or the bitwise OR of one
2181 or more PNG_FILTER_NAME masks. */
2182 png_set_filter(png_ptr, 0,
2183 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
2184 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
2185 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
2186 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
2187 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
2188 PNG_ALL_FILTERS);
2189
2190If an application
2191wants to start and stop using particular filters during compression,
2192it should start out with all of the filters (to ensure that the previous
2193row of pixels will be stored in case it's needed later), and then add
2194and remove them after the start of compression.
2195
2196If you are writing a PNG datastream that is to be embedded in a MNG
2197datastream, the second parameter can be either 0 or 64.
2198
2199The png_set_compression_*() functions interface to the zlib compression
2200library, and should mostly be ignored unless you really know what you are
2201doing. The only generally useful call is png_set_compression_level()
2202which changes how much time zlib spends on trying to compress the image
2203data. See the Compression Library (zlib.h and algorithm.txt, distributed
2204with zlib) for details on the compression levels.
2205
2206 /* set the zlib compression level */
2207 png_set_compression_level(png_ptr,
2208 Z_BEST_COMPRESSION);
2209
2210 /* set other zlib parameters */
2211 png_set_compression_mem_level(png_ptr, 8);
2212 png_set_compression_strategy(png_ptr,
2213 Z_DEFAULT_STRATEGY);
2214 png_set_compression_window_bits(png_ptr, 15);
2215 png_set_compression_method(png_ptr, 8);
2216 png_set_compression_buffer_size(png_ptr, 8192)
2217
2218extern PNG_EXPORT(void,png_set_zbuf_size)
2219
2220.SS Setting the contents of info for output
2221
2222You now need to fill in the png_info structure with all the data you
2223wish to write before the actual image. Note that the only thing you
2224are allowed to write after the image is the text chunks and the time
2225chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
2226the latest PNG specification for more information on that. If you
2227wish to write them before the image, fill them in now, and flag that
2228data as being valid. If you want to wait until after the data, don't
2229fill them until png_write_end(). For all the fields in png_info and
2230their data types, see png.h. For explanations of what the fields
2231contain, see the PNG specification.
2232
2233Some of the more important parts of the png_info are:
2234
2235 png_set_IHDR(png_ptr, info_ptr, width, height,
2236 bit_depth, color_type, interlace_type,
2237 compression_type, filter_method)
2238 width - holds the width of the image
2239 in pixels (up to 2^31).
2240 height - holds the height of the image
2241 in pixels (up to 2^31).
2242 bit_depth - holds the bit depth of one of the
2243 image channels.
2244 (valid values are 1, 2, 4, 8, 16
2245 and depend also on the
2246 color_type. See also significant
2247 bits (sBIT) below).
2248 color_type - describes which color/alpha
2249 channels are present.
2250 PNG_COLOR_TYPE_GRAY
2251 (bit depths 1, 2, 4, 8, 16)
2252 PNG_COLOR_TYPE_GRAY_ALPHA
2253 (bit depths 8, 16)
2254 PNG_COLOR_TYPE_PALETTE
2255 (bit depths 1, 2, 4, 8)
2256 PNG_COLOR_TYPE_RGB
2257 (bit_depths 8, 16)
2258 PNG_COLOR_TYPE_RGB_ALPHA
2259 (bit_depths 8, 16)
2260
2261 PNG_COLOR_MASK_PALETTE
2262 PNG_COLOR_MASK_COLOR
2263 PNG_COLOR_MASK_ALPHA
2264
2265 interlace_type - PNG_INTERLACE_NONE or
2266 PNG_INTERLACE_ADAM7
2267 compression_type - (must be
2268 PNG_COMPRESSION_TYPE_DEFAULT)
2269 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
2270 or, if you are writing a PNG to
2271 be embedded in a MNG datastream,
2272 can also be
2273 PNG_INTRAPIXEL_DIFFERENCING)
2274
2275If you call png_set_IHDR(), the call must appear before any of the
2276other png_set_*() functions, because they might require access to some of
2277the IHDR settings. The remaining png_set_*() functions can be called
2278in any order.
2279
2280If you wish, you can reset the compression_type, interlace_type, or
2281filter_method later by calling png_set_IHDR() again; if you do this, the
2282width, height, bit_depth, and color_type must be the same in each call.
2283
2284 png_set_PLTE(png_ptr, info_ptr, palette,
2285 num_palette);
2286 palette - the palette for the file
2287 (array of png_color)
2288 num_palette - number of entries in the palette
2289
2290 png_set_gAMA(png_ptr, info_ptr, gamma);
2291 gamma - the gamma the image was created
2292 at (PNG_INFO_gAMA)
2293
2294 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2295 srgb_intent - the rendering intent
2296 (PNG_INFO_sRGB) The presence of
2297 the sRGB chunk means that the pixel
2298 data is in the sRGB color space.
2299 This chunk also implies specific
2300 values of gAMA and cHRM. Rendering
2301 intent is the CSS-1 property that
2302 has been defined by the International
2303 Color Consortium
2304 (http://www.color.org).
2305 It can be one of
2306 PNG_sRGB_INTENT_SATURATION,
2307 PNG_sRGB_INTENT_PERCEPTUAL,
2308 PNG_sRGB_INTENT_ABSOLUTE, or
2309 PNG_sRGB_INTENT_RELATIVE.
2310
2311
2312 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2313 srgb_intent);
2314 srgb_intent - the rendering intent
2315 (PNG_INFO_sRGB) The presence of the
2316 sRGB chunk means that the pixel
2317 data is in the sRGB color space.
2318 This function also causes gAMA and
2319 cHRM chunks with the specific values
2320 that are consistent with sRGB to be
2321 written.
2322
2323 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2324 profile, proflen);
2325 name - The profile name.
2326 compression - The compression type; always
2327 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2328 You may give NULL to this argument to
2329 ignore it.
2330 profile - International Color Consortium color
2331 profile data. May contain NULs.
2332 proflen - length of profile data in bytes.
2333
2334 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2335 sig_bit - the number of significant bits for
2336 (PNG_INFO_sBIT) each of the gray, red,
2337 green, and blue channels, whichever are
2338 appropriate for the given color type
2339 (png_color_16)
2340
2341 png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
2342 trans_values);
2343 trans - array of transparent
2344 entries for palette (PNG_INFO_tRNS)
2345 trans_values - graylevel or color sample values
2346 (in order red, green, blue) of the
2347 single transparent color for
2348 non-paletted images (PNG_INFO_tRNS)
2349 num_trans - number of transparent entries
2350 (PNG_INFO_tRNS)
2351
2352 png_set_hIST(png_ptr, info_ptr, hist);
2353 (PNG_INFO_hIST)
2354 hist - histogram of palette (array of
2355 png_uint_16)
2356
2357 png_set_tIME(png_ptr, info_ptr, mod_time);
2358 mod_time - time image was last modified
2359 (PNG_VALID_tIME)
2360
2361 png_set_bKGD(png_ptr, info_ptr, background);
2362 background - background color (PNG_VALID_bKGD)
2363
2364 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2365 text_ptr - array of png_text holding image
2366 comments
2367 text_ptr[i].compression - type of compression used
2368 on "text" PNG_TEXT_COMPRESSION_NONE
2369 PNG_TEXT_COMPRESSION_zTXt
2370 PNG_ITXT_COMPRESSION_NONE
2371 PNG_ITXT_COMPRESSION_zTXt
2372 text_ptr[i].key - keyword for comment. Must contain
2373 1-79 characters.
2374 text_ptr[i].text - text comments for current
2375 keyword. Can be NULL or empty.
2376 text_ptr[i].text_length - length of text string,
2377 after decompression, 0 for iTXt
2378 text_ptr[i].itxt_length - length of itxt string,
2379 after decompression, 0 for tEXt/zTXt
2380 text_ptr[i].lang - language of comment (NULL or
2381 empty for unknown).
2382 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
2383 or empty for unknown).
2384 Note that the itxt_length, lang, and lang_key
2385 members of the text_ptr structure only exist
2386 when the library is built with iTXt chunk support.
2387
2388 num_text - number of comments
2389
2390 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
2391 num_spalettes);
2392 palette_ptr - array of png_sPLT_struct structures
2393 to be added to the list of palettes
2394 in the info structure.
2395 num_spalettes - number of palette structures to be
2396 added.
2397
2398 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2399 unit_type);
2400 offset_x - positive offset from the left
2401 edge of the screen
2402 offset_y - positive offset from the top
2403 edge of the screen
2404 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2405
2406 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2407 unit_type);
2408 res_x - pixels/unit physical resolution
2409 in x direction
2410 res_y - pixels/unit physical resolution
2411 in y direction
2412 unit_type - PNG_RESOLUTION_UNKNOWN,
2413 PNG_RESOLUTION_METER
2414
2415 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
2416 unit - physical scale units (an integer)
2417 width - width of a pixel in physical scale units
2418 height - height of a pixel in physical scale units
2419 (width and height are doubles)
2420
2421 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
2422 unit - physical scale units (an integer)
2423 width - width of a pixel in physical scale units
2424 height - height of a pixel in physical scale units
2425 (width and height are strings like "2.54")
2426
2427 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
2428 num_unknowns)
2429 unknowns - array of png_unknown_chunk
2430 structures holding unknown chunks
2431 unknowns[i].name - name of unknown chunk
2432 unknowns[i].data - data of unknown chunk
2433 unknowns[i].size - size of unknown chunk's data
2434 unknowns[i].location - position to write chunk in file
2435 0: do not write chunk
2436 PNG_HAVE_IHDR: before PLTE
2437 PNG_HAVE_PLTE: before IDAT
2438 PNG_AFTER_IDAT: after IDAT
2439
2440The "location" member is set automatically according to
2441what part of the output file has already been written.
2442You can change its value after calling png_set_unknown_chunks()
2443as demonstrated in pngtest.c. Within each of the "locations",
2444the chunks are sequenced according to their position in the
2445structure (that is, the value of "i", which is the order in which
2446the chunk was either read from the input file or defined with
2447png_set_unknown_chunks).
2448
2449A quick word about text and num_text. text is an array of png_text
2450structures. num_text is the number of valid structures in the array.
2451Each png_text structure holds a language code, a keyword, a text value,
2452and a compression type.
2453
2454The compression types have the same valid numbers as the compression
2455types of the image data. Currently, the only valid number is zero.
2456However, you can store text either compressed or uncompressed, unlike
2457images, which always have to be compressed. So if you don't want the
2458text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
2459Because tEXt and zTXt chunks don't have a language field, if you
2460specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
2461any language code or translated keyword will not be written out.
2462
2463Until text gets around 1000 bytes, it is not worth compressing it.
2464After the text has been written out to the file, the compression type
2465is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2466so that it isn't written out again at the end (in case you are calling
2467png_write_end() with the same struct.
2468
2469The keywords that are given in the PNG Specification are:
2470
2471 Title Short (one line) title or
2472 caption for image
2473 Author Name of image's creator
2474 Description Description of image (possibly long)
2475 Copyright Copyright notice
2476 Creation Time Time of original image creation
2477 (usually RFC 1123 format, see below)
2478 Software Software used to create the image
2479 Disclaimer Legal disclaimer
2480 Warning Warning of nature of content
2481 Source Device used to create the image
2482 Comment Miscellaneous comment; conversion
2483 from other image format
2484
2485The keyword-text pairs work like this. Keywords should be short
2486simple descriptions of what the comment is about. Some typical
2487keywords are found in the PNG specification, as is some recommendations
2488on keywords. You can repeat keywords in a file. You can even write
2489some text before the image and some after. For example, you may want
2490to put a description of the image before the image, but leave the
2491disclaimer until after, so viewers working over modem connections
2492don't have to wait for the disclaimer to go over the modem before
2493they start seeing the image. Finally, keywords should be full
2494words, not abbreviations. Keywords and text are in the ISO 8859-1
2495(Latin-1) character set (a superset of regular ASCII) and can not
2496contain NUL characters, and should not contain control or other
2497unprintable characters. To make the comments widely readable, stick
2498with basic ASCII, and avoid machine specific character set extensions
2499like the IBM-PC character set. The keyword must be present, but
2500you can leave off the text string on non-compressed pairs.
2501Compressed pairs must have a text string, as only the text string
2502is compressed anyway, so the compression would be meaningless.
2503
2504PNG supports modification time via the png_time structure. Two
2505conversion routines are provided, png_convert_from_time_t() for
2506time_t and png_convert_from_struct_tm() for struct tm. The
2507time_t routine uses gmtime(). You don't have to use either of
2508these, but if you wish to fill in the png_time structure directly,
2509you should provide the time in universal time (GMT) if possible
2510instead of your local time. Note that the year number is the full
2511year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
2512that months start with 1.
2513
2514If you want to store the time of the original image creation, you should
2515use a plain tEXt chunk with the "Creation Time" keyword. This is
2516necessary because the "creation time" of a PNG image is somewhat vague,
2517depending on whether you mean the PNG file, the time the image was
2518created in a non-PNG format, a still photo from which the image was
2519scanned, or possibly the subject matter itself. In order to facilitate
2520machine-readable dates, it is recommended that the "Creation Time"
2521tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
2522although this isn't a requirement. Unlike the tIME chunk, the
2523"Creation Time" tEXt chunk is not expected to be automatically changed
2524by the software. To facilitate the use of RFC 1123 dates, a function
2525png_convert_to_rfc1123(png_timep) is provided to convert from PNG
2526time to an RFC 1123 format string.
2527
2528.SS Writing unknown chunks
2529
2530You can use the png_set_unknown_chunks function to queue up chunks
2531for writing. You give it a chunk name, raw data, and a size; that's
2532all there is to it. The chunks will be written by the next following
2533png_write_info_before_PLTE, png_write_info, or png_write_end function.
2534Any chunks previously read into the info structure's unknown-chunk
2535list will also be written out in a sequence that satisfies the PNG
2536specification's ordering rules.
2537
2538.SS The high-level write interface
2539
2540At this point there are two ways to proceed; through the high-level
2541write interface, or through a sequence of low-level write operations.
2542You can use the high-level interface if your image data is present
2543in the info structure. All defined output
2544transformations are permitted, enabled by the following masks.
2545
2546 PNG_TRANSFORM_IDENTITY No transformation
2547 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
2548 PNG_TRANSFORM_PACKSWAP Change order of packed
2549 pixels to LSB first
2550 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
2551 PNG_TRANSFORM_SHIFT Normalize pixels to the
2552 sBIT depth
2553 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
2554 to BGRA
2555 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
2556 to AG
2557 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
2558 to transparency
2559 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
2560 PNG_TRANSFORM_STRIP_FILLER Strip out filler
2561 bytes (deprecated).
2562 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
2563 filler bytes
2564 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
2565 filler bytes
2566
2567If you have valid image data in the info structure (you can use
2568png_set_rows() to put image data in the info structure), simply do this:
2569
2570 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
2571
2572where png_transforms is an integer containing the bitwise OR of some set of
2573transformation flags. This call is equivalent to png_write_info(),
2574followed the set of transformations indicated by the transform mask,
2575then png_write_image(), and finally png_write_end().
2576
2577(The final parameter of this call is not yet used. Someday it might point
2578to transformation parameters required by some future output transform.)
2579
2580You must use png_transforms and not call any png_set_transform() functions
2581when you use png_write_png().
2582
2583.SS The low-level write interface
2584
2585If you are going the low-level route instead, you are now ready to
2586write all the file information up to the actual image data. You do
2587this with a call to png_write_info().
2588
2589 png_write_info(png_ptr, info_ptr);
2590
2591Note that there is one transformation you may need to do before
2592png_write_info(). In PNG files, the alpha channel in an image is the
2593level of opacity. If your data is supplied as a level of transparency,
2594you can invert the alpha channel before you write it, so that 0 is
2595fully transparent and 255 (in 8-bit or paletted images) or 65535
2596(in 16-bit images) is fully opaque, with
2597
2598 png_set_invert_alpha(png_ptr);
2599
2600This must appear before png_write_info() instead of later with the
2601other transformations because in the case of paletted images the tRNS
2602chunk data has to be inverted before the tRNS chunk is written. If
2603your image is not a paletted image, the tRNS data (which in such cases
2604represents a single color to be rendered as transparent) won't need to
2605be changed, and you can safely do this transformation after your
2606png_write_info() call.
2607
2608If you need to write a private chunk that you want to appear before
2609the PLTE chunk when PLTE is present, you can write the PNG info in
2610two steps, and insert code to write your own chunk between them:
2611
2612 png_write_info_before_PLTE(png_ptr, info_ptr);
2613 png_set_unknown_chunks(png_ptr, info_ptr, ...);
2614 png_write_info(png_ptr, info_ptr);
2615
2616After you've written the file information, you can set up the library
2617to handle any special transformations of the image data. The various
2618ways to transform the data will be described in the order that they
2619should occur. This is important, as some of these change the color
2620type and/or bit depth of the data, and some others only work on
2621certain color types and bit depths. Even though each transformation
2622checks to see if it has data that it can do something with, you should
2623make sure to only enable a transformation if it will be valid for the
2624data. For example, don't swap red and blue on grayscale data.
2625
2626PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
2627the library to strip input data that has 4 or 8 bytes per pixel down
2628to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
2629bytes per pixel).
2630
2631 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
2632
2633where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
2634PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
2635is stored XRGB or RGBX.
2636
2637PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2638they can, resulting in, for example, 8 pixels per byte for 1 bit files.
2639If the data is supplied at 1 pixel per byte, use this code, which will
2640correctly pack the pixels into a single byte:
2641
2642 png_set_packing(png_ptr);
2643
2644PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
2645data is of another bit depth, you can write an sBIT chunk into the
2646file so that decoders can recover the original data if desired.
2647
2648 /* Set the true bit depth of the image data */
2649 if (color_type & PNG_COLOR_MASK_COLOR)
2650 {
2651 sig_bit.red = true_bit_depth;
2652 sig_bit.green = true_bit_depth;
2653 sig_bit.blue = true_bit_depth;
2654 }
2655 else
2656 {
2657 sig_bit.gray = true_bit_depth;
2658 }
2659 if (color_type & PNG_COLOR_MASK_ALPHA)
2660 {
2661 sig_bit.alpha = true_bit_depth;
2662 }
2663
2664 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
2665
2666If the data is stored in the row buffer in a bit depth other than
2667one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
2668this will scale the values to appear to be the correct bit depth as
2669is required by PNG.
2670
2671 png_set_shift(png_ptr, &sig_bit);
2672
2673PNG files store 16 bit pixels in network byte order (big-endian,
2674ie. most significant bits first). This code would be used if they are
2675supplied the other way (little-endian, i.e. least significant bits
2676first, the way PCs store them):
2677
2678 if (bit_depth > 8)
2679 png_set_swap(png_ptr);
2680
2681If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2682need to change the order the pixels are packed into bytes, you can use:
2683
2684 if (bit_depth < 8)
2685 png_set_packswap(png_ptr);
2686
2687PNG files store 3 color pixels in red, green, blue order. This code
2688would be used if they are supplied as blue, green, red:
2689
2690 png_set_bgr(png_ptr);
2691
2692PNG files describe monochrome as black being zero and white being
2693one. This code would be used if the pixels are supplied with this reversed
2694(black being one and white being zero):
2695
2696 png_set_invert_mono(png_ptr);
2697
2698Finally, you can write your own transformation function if none of
2699the existing ones meets your needs. This is done by setting a callback
2700with
2701
2702 png_set_write_user_transform_fn(png_ptr,
2703 write_transform_fn);
2704
2705You must supply the function
2706
2707 void write_transform_fn(png_ptr ptr, row_info_ptr
2708 row_info, png_bytep data)
2709
2710See pngtest.c for a working example. Your function will be called
2711before any of the other transformations are processed.
2712
2713You can also set up a pointer to a user structure for use by your
2714callback function.
2715
2716 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
2717
2718The user_channels and user_depth parameters of this function are ignored
2719when writing; you can set them to zero as shown.
2720
2721You can retrieve the pointer via the function png_get_user_transform_ptr().
2722For example:
2723
2724 voidp write_user_transform_ptr =
2725 png_get_user_transform_ptr(png_ptr);
2726
2727It is possible to have libpng flush any pending output, either manually,
2728or automatically after a certain number of lines have been written. To
2729flush the output stream a single time call:
2730
2731 png_write_flush(png_ptr);
2732
2733and to have libpng flush the output stream periodically after a certain
2734number of scanlines have been written, call:
2735
2736 png_set_flush(png_ptr, nrows);
2737
2738Note that the distance between rows is from the last time png_write_flush()
2739was called, or the first row of the image if it has never been called.
2740So if you write 50 lines, and then png_set_flush 25, it will flush the
2741output on the next scanline, and every 25 lines thereafter, unless
2742png_write_flush() is called before 25 more lines have been written.
2743If nrows is too small (less than about 10 lines for a 640 pixel wide
2744RGB image) the image compression may decrease noticeably (although this
2745may be acceptable for real-time applications). Infrequent flushing will
2746only degrade the compression performance by a few percent over images
2747that do not use flushing.
2748
2749.SS Writing the image data
2750
2751That's it for the transformations. Now you can write the image data.
2752The simplest way to do this is in one function call. If you have the
2753whole image in memory, you can just call png_write_image() and libpng
2754will write the image. You will need to pass in an array of pointers to
2755each row. This function automatically handles interlacing, so you don't
2756need to call png_set_interlace_handling() or call this function multiple
2757times, or any of that other stuff necessary with png_write_rows().
2758
2759 png_write_image(png_ptr, row_pointers);
2760
2761where row_pointers is:
2762
2763 png_byte *row_pointers[height];
2764
2765You can point to void or char or whatever you use for pixels.
2766
2767If you don't want to write the whole image at once, you can
2768use png_write_rows() instead. If the file is not interlaced,
2769this is simple:
2770
2771 png_write_rows(png_ptr, row_pointers,
2772 number_of_rows);
2773
2774row_pointers is the same as in the png_write_image() call.
2775
2776If you are just writing one row at a time, you can do this with
2777a single row_pointer instead of an array of row_pointers:
2778
2779 png_bytep row_pointer = row;
2780
2781 png_write_row(png_ptr, row_pointer);
2782
2783When the file is interlaced, things can get a good deal more complicated.
2784The only currently (as of the PNG Specification version 1.2, dated July
27851999) defined interlacing scheme for PNG files is the "Adam7" interlace
2786scheme, that breaks down an image into seven smaller images of varying
2787size. libpng will build these images for you, or you can do them
2788yourself. If you want to build them yourself, see the PNG specification
2789for details of which pixels to write when.
2790
2791If you don't want libpng to handle the interlacing details, just
2792use png_set_interlace_handling() and call png_write_rows() the
2793correct number of times to write all seven sub-images.
2794
2795If you want libpng to build the sub-images, call this before you start
2796writing any rows:
2797
2798 number_of_passes =
2799 png_set_interlace_handling(png_ptr);
2800
2801This will return the number of passes needed. Currently, this is seven,
2802but may change if another interlace type is added.
2803
2804Then write the complete image number_of_passes times.
2805
2806 png_write_rows(png_ptr, row_pointers,
2807 number_of_rows);
2808
2809As some of these rows are not used, and thus return immediately, you may
2810want to read about interlacing in the PNG specification, and only update
2811the rows that are actually used.
2812
2813.SS Finishing a sequential write
2814
2815After you are finished writing the image, you should finish writing
2816the file. If you are interested in writing comments or time, you should
2817pass an appropriately filled png_info pointer. If you are not interested,
2818you can pass NULL.
2819
2820 png_write_end(png_ptr, info_ptr);
2821
2822When you are done, you can free all memory used by libpng like this:
2823
2824 png_destroy_write_struct(&png_ptr, &info_ptr);
2825
2826It is also possible to individually free the info_ptr members that
2827point to libpng-allocated storage with the following function:
2828
2829 png_free_data(png_ptr, info_ptr, mask, seq)
2830 mask - identifies data to be freed, a mask
2831 containing the bitwise OR of one or
2832 more of
2833 PNG_FREE_PLTE, PNG_FREE_TRNS,
2834 PNG_FREE_HIST, PNG_FREE_ICCP,
2835 PNG_FREE_PCAL, PNG_FREE_ROWS,
2836 PNG_FREE_SCAL, PNG_FREE_SPLT,
2837 PNG_FREE_TEXT, PNG_FREE_UNKN,
2838 or simply PNG_FREE_ALL
2839 seq - sequence number of item to be freed
2840 (\-1 for all items)
2841
2842This function may be safely called when the relevant storage has
2843already been freed, or has not yet been allocated, or was allocated
2844by the user and not by libpng, and will in those cases do nothing.
2845The "seq" parameter is ignored if only one item of the selected data
2846type, such as PLTE, is allowed. If "seq" is not \-1, and multiple items
2847are allowed for the data type identified in the mask, such as text or
2848sPLT, only the n'th item in the structure is freed, where n is "seq".
2849
2850If you allocated data such as a palette that you passed in to libpng
2851with png_set_*, you must not free it until just before the call to
2852png_destroy_write_struct().
2853
2854The default behavior is only to free data that was allocated internally
2855by libpng. This can be changed, so that libpng will not free the data,
2856or so that it will free data that was allocated by the user with png_malloc()
2857or png_zalloc() and passed in via a png_set_*() function, with
2858
2859 png_data_freer(png_ptr, info_ptr, freer, mask)
2860 mask - which data elements are affected
2861 same choices as in png_free_data()
2862 freer - one of
2863 PNG_DESTROY_WILL_FREE_DATA
2864 PNG_SET_WILL_FREE_DATA
2865 PNG_USER_WILL_FREE_DATA
2866
2867For example, to transfer responsibility for some data from a read structure
2868to a write structure, you could use
2869
2870 png_data_freer(read_ptr, read_info_ptr,
2871 PNG_USER_WILL_FREE_DATA,
2872 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
2873 png_data_freer(write_ptr, write_info_ptr,
2874 PNG_DESTROY_WILL_FREE_DATA,
2875 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
2876
2877thereby briefly reassigning responsibility for freeing to the user but
2878immediately afterwards reassigning it once more to the write_destroy
2879function. Having done this, it would then be safe to destroy the read
2880structure and continue to use the PLTE, tRNS, and hIST data in the write
2881structure.
2882
2883This function only affects data that has already been allocated.
2884You can call this function before calling after the png_set_*() functions
2885to control whether the user or png_destroy_*() is supposed to free the data.
2886When the user assumes responsibility for libpng-allocated data, the
2887application must use
2888png_free() to free it, and when the user transfers responsibility to libpng
2889for data that the user has allocated, the user must have used png_malloc()
2890or png_zalloc() to allocate it.
2891
2892If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2893separately, do not transfer responsibility for freeing text_ptr to libpng,
2894because when libpng fills a png_text structure it combines these members with
2895the key member, and png_free_data() will free only text_ptr.key. Similarly,
2896if you transfer responsibility for free'ing text_ptr from libpng to your
2897application, your application must not separately free those members.
2898For a more compact example of writing a PNG image, see the file example.c.
2899
2900.SH V. Modifying/Customizing libpng:
2901
2902There are two issues here. The first is changing how libpng does
2903standard things like memory allocation, input/output, and error handling.
2904The second deals with more complicated things like adding new chunks,
2905adding new transformations, and generally changing how libpng works.
2906Both of those are compile-time issues; that is, they are generally
2907determined at the time the code is written, and there is rarely a need
2908to provide the user with a means of changing them.
2909
2910Memory allocation, input/output, and error handling
2911
2912All of the memory allocation, input/output, and error handling in libpng
2913goes through callbacks that are user-settable. The default routines are
2914in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
2915these functions, call the appropriate png_set_*_fn() function.
2916
2917Memory allocation is done through the functions png_malloc(), png_calloc(),
2918and png_free(). These currently just call the standard C functions.
2919png_calloc() calls png_malloc() and then png_memset() to clear the newly
2920allocated memory to zero. If your pointers can't access more then 64K
2921at a time, you will want to set MAXSEG_64K in zlib.h. Since it is
2922unlikely that the method of handling memory allocation on a platform
2923will change between applications, these functions must be modified in
2924the library at compile time. If you prefer to use a different method
2925of allocating and freeing data, you can use png_create_read_struct_2() or
2926png_create_write_struct_2() to register your own functions as described
2927above. These functions also provide a void pointer that can be retrieved
2928via
2929
2930 mem_ptr=png_get_mem_ptr(png_ptr);
2931
2932Your replacement memory functions must have prototypes as follows:
2933
2934 png_voidp malloc_fn(png_structp png_ptr,
2935 png_size_t size);
2936 void free_fn(png_structp png_ptr, png_voidp ptr);
2937
2938Your malloc_fn() must return NULL in case of failure. The png_malloc()
2939function will normally call png_error() if it receives a NULL from the
2940system memory allocator or from your replacement malloc_fn().
2941
2942Your free_fn() will never be called with a NULL ptr, since libpng's
2943png_free() checks for NULL before calling free_fn().
2944
2945Input/Output in libpng is done through png_read() and png_write(),
2946which currently just call fread() and fwrite(). The FILE * is stored in
2947png_struct and is initialized via png_init_io(). If you wish to change
2948the method of I/O, the library supplies callbacks that you can set
2949through the function png_set_read_fn() and png_set_write_fn() at run
2950time, instead of calling the png_init_io() function. These functions
2951also provide a void pointer that can be retrieved via the function
2952png_get_io_ptr(). For example:
2953
2954 png_set_read_fn(png_structp read_ptr,
2955 voidp read_io_ptr, png_rw_ptr read_data_fn)
2956
2957 png_set_write_fn(png_structp write_ptr,
2958 voidp write_io_ptr, png_rw_ptr write_data_fn,
2959 png_flush_ptr output_flush_fn);
2960
2961 voidp read_io_ptr = png_get_io_ptr(read_ptr);
2962 voidp write_io_ptr = png_get_io_ptr(write_ptr);
2963
2964The replacement I/O functions must have prototypes as follows:
2965
2966 void user_read_data(png_structp png_ptr,
2967 png_bytep data, png_size_t length);
2968 void user_write_data(png_structp png_ptr,
2969 png_bytep data, png_size_t length);
2970 void user_flush_data(png_structp png_ptr);
2971
2972The user_read_data() function is responsible for detecting and
2973handling end-of-data errors.
2974
2975Supplying NULL for the read, write, or flush functions sets them back
2976to using the default C stream functions, which expect the io_ptr to
2977point to a standard *FILE structure. It is probably a mistake
2978to use NULL for one of write_data_fn and output_flush_fn but not both
2979of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
2980It is an error to read from a write stream, and vice versa.
2981
2982Error handling in libpng is done through png_error() and png_warning().
2983Errors handled through png_error() are fatal, meaning that png_error()
2984should never return to its caller. Currently, this is handled via
2985setjmp() and longjmp() (unless you have compiled libpng with
2986PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
2987but you could change this to do things like exit() if you should wish.
2988
2989On non-fatal errors, png_warning() is called
2990to print a warning message, and then control returns to the calling code.
2991By default png_error() and png_warning() print a message on stderr via
2992fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
2993(because you don't want the messages) or PNG_NO_STDIO defined (because
2994fprintf() isn't available). If you wish to change the behavior of the error
2995functions, you will need to set up your own message callbacks. These
2996functions are normally supplied at the time that the png_struct is created.
2997It is also possible to redirect errors and warnings to your own replacement
2998functions after png_create_*_struct() has been called by calling:
2999
3000 png_set_error_fn(png_structp png_ptr,
3001 png_voidp error_ptr, png_error_ptr error_fn,
3002 png_error_ptr warning_fn);
3003
3004 png_voidp error_ptr = png_get_error_ptr(png_ptr);
3005
3006If NULL is supplied for either error_fn or warning_fn, then the libpng
3007default function will be used, calling fprintf() and/or longjmp() if a
3008problem is encountered. The replacement error functions should have
3009parameters as follows:
3010
3011 void user_error_fn(png_structp png_ptr,
3012 png_const_charp error_msg);
3013 void user_warning_fn(png_structp png_ptr,
3014 png_const_charp warning_msg);
3015
3016The motivation behind using setjmp() and longjmp() is the C++ throw and
3017catch exception handling methods. This makes the code much easier to write,
3018as there is no need to check every return code of every function call.
3019However, there are some uncertainties about the status of local variables
3020after a longjmp, so the user may want to be careful about doing anything
3021after setjmp returns non-zero besides returning itself. Consult your
3022compiler documentation for more details. For an alternative approach, you
3023may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net).
3024
3025.SS Custom chunks
3026
3027If you need to read or write custom chunks, you may need to get deeper
3028into the libpng code. The library now has mechanisms for storing
3029and writing chunks of unknown type; you can even declare callbacks
3030for custom chunks. However, this may not be good enough if the
3031library code itself needs to know about interactions between your
3032chunk and existing `intrinsic' chunks.
3033
3034If you need to write a new intrinsic chunk, first read the PNG
3035specification. Acquire a first level of understanding of how it works.
3036Pay particular attention to the sections that describe chunk names,
3037and look at how other chunks were designed, so you can do things
3038similarly. Second, check out the sections of libpng that read and
3039write chunks. Try to find a chunk that is similar to yours and use
3040it as a template. More details can be found in the comments inside
3041the code. It is best to handle unknown chunks in a generic method,
3042via callback functions, instead of by modifying libpng functions.
3043
3044If you wish to write your own transformation for the data, look through
3045the part of the code that does the transformations, and check out some of
3046the simpler ones to get an idea of how they work. Try to find a similar
3047transformation to the one you want to add and copy off of it. More details
3048can be found in the comments inside the code itself.
3049
3050.SS Configuring for 16 bit platforms
3051
3052You will want to look into zconf.h to tell zlib (and thus libpng) that
3053it cannot allocate more then 64K at a time. Even if you can, the memory
3054won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
3055
3056.SS Configuring for DOS
3057
3058For DOS users who only have access to the lower 640K, you will
3059have to limit zlib's memory usage via a png_set_compression_mem_level()
3060call. See zlib.h or zconf.h in the zlib library for more information.
3061
3062.SS Configuring for Medium Model
3063
3064Libpng's support for medium model has been tested on most of the popular
3065compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
3066defined, and FAR gets defined to far in pngconf.h, and you should be
3067all set. Everything in the library (except for zlib's structure) is
3068expecting far data. You must use the typedefs with the p or pp on
3069the end for pointers (or at least look at them and be careful). Make
3070note that the rows of data are defined as png_bytepp, which is an
3071unsigned char far * far *.
3072
3073.SS Configuring for gui/windowing platforms:
3074
3075You will need to write new error and warning functions that use the GUI
3076interface, as described previously, and set them to be the error and
3077warning functions at the time that png_create_*_struct() is called,
3078in order to have them available during the structure initialization.
3079They can be changed later via png_set_error_fn(). On some compilers,
3080you may also have to change the memory allocators (png_malloc, etc.).
3081
3082.SS Configuring for compiler xxx:
3083
3084All includes for libpng are in pngconf.h. If you need to add, change
3085or delete an include, this is the place to do it.
3086The includes that are not needed outside libpng are protected by the
3087PNG_INTERNAL definition, which is only defined for those routines inside
3088libpng itself. The files in libpng proper only include png.h, which
3089includes pngconf.h.
3090
3091.SS Configuring zlib:
3092
3093There are special functions to configure the compression. Perhaps the
3094most useful one changes the compression level, which currently uses
3095input compression values in the range 0 - 9. The library normally
3096uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
3097have shown that for a large majority of images, compression values in
3098the range 3-6 compress nearly as well as higher levels, and do so much
3099faster. For online applications it may be desirable to have maximum speed
3100(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
3101specify no compression (Z_NO_COMPRESSION = 0), but this would create
3102files larger than just storing the raw bitmap. You can specify the
3103compression level by calling:
3104
3105 png_set_compression_level(png_ptr, level);
3106
3107Another useful one is to reduce the memory level used by the library.
3108The memory level defaults to 8, but it can be lowered if you are
3109short on memory (running DOS, for example, where you only have 640K).
3110Note that the memory level does have an effect on compression; among
3111other things, lower levels will result in sections of incompressible
3112data being emitted in smaller stored blocks, with a correspondingly
3113larger relative overhead of up to 15% in the worst case.
3114
3115 png_set_compression_mem_level(png_ptr, level);
3116
3117The other functions are for configuring zlib. They are not recommended
3118for normal use and may result in writing an invalid PNG file. See
3119zlib.h for more information on what these mean.
3120
3121 png_set_compression_strategy(png_ptr,
3122 strategy);
3123 png_set_compression_window_bits(png_ptr,
3124 window_bits);
3125 png_set_compression_method(png_ptr, method);
3126 png_set_compression_buffer_size(png_ptr, size);
3127
3128.SS Controlling row filtering
3129
3130If you want to control whether libpng uses filtering or not, which
3131filters are used, and how it goes about picking row filters, you
3132can call one of these functions. The selection and configuration
3133of row filters can have a significant impact on the size and
3134encoding speed and a somewhat lesser impact on the decoding speed
3135of an image. Filtering is enabled by default for RGB and grayscale
3136images (with and without alpha), but not for paletted images nor
3137for any images with bit depths less than 8 bits/pixel.
3138
3139The 'method' parameter sets the main filtering method, which is
3140currently only '0' in the PNG 1.2 specification. The 'filters'
3141parameter sets which filter(s), if any, should be used for each
3142scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
3143to turn filtering on and off, respectively.
3144
3145Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3146PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
3147ORed together with '|' to specify one or more filters to use.
3148These filters are described in more detail in the PNG specification.
3149If you intend to change the filter type during the course of writing
3150the image, you should start with flags set for all of the filters
3151you intend to use so that libpng can initialize its internal
3152structures appropriately for all of the filter types. (Note that this
3153means the first row must always be adaptively filtered, because libpng
3154currently does not allocate the filter buffers until png_write_row()
3155is called for the first time.)
3156
3157 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
3158 PNG_FILTER_UP | PNG_FILTER_AVG |
3159 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
3160
3161 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3162 filters);
3163 The second parameter can also be
3164 PNG_INTRAPIXEL_DIFFERENCING if you are
3165 writing a PNG to be embedded in a MNG
3166 datastream. This parameter must be the
3167 same as the value of filter_method used
3168 in png_set_IHDR().
3169
3170It is also possible to influence how libpng chooses from among the
3171available filters. This is done in one or both of two ways - by
3172telling it how important it is to keep the same filter for successive
3173rows, and by telling it the relative computational costs of the filters.
3174
3175 double weights[3] = {1.5, 1.3, 1.1},
3176 costs[PNG_FILTER_VALUE_LAST] =
3177 {1.0, 1.3, 1.3, 1.5, 1.7};
3178
3179 png_set_filter_heuristics(png_ptr,
3180 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
3181 weights, costs);
3182
3183The weights are multiplying factors that indicate to libpng that the
3184row filter should be the same for successive rows unless another row filter
3185is that many times better than the previous filter. In the above example,
3186if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
3187"sum of absolute differences" 1.5 x 1.3 times higher than other filters
3188and still be chosen, while the NONE filter could have a sum 1.1 times
3189higher than other filters and still be chosen. Unspecified weights are
3190taken to be 1.0, and the specified weights should probably be declining
3191like those above in order to emphasize recent filters over older filters.
3192
3193The filter costs specify for each filter type a relative decoding cost
3194to be considered when selecting row filters. This means that filters
3195with higher costs are less likely to be chosen over filters with lower
3196costs, unless their "sum of absolute differences" is that much smaller.
3197The costs do not necessarily reflect the exact computational speeds of
3198the various filters, since this would unduly influence the final image
3199size.
3200
3201Note that the numbers above were invented purely for this example and
3202are given only to help explain the function usage. Little testing has
3203been done to find optimum values for either the costs or the weights.
3204
3205.SS Removing unwanted object code
3206
3207There are a bunch of #define's in pngconf.h that control what parts of
3208libpng are compiled. All the defines end in _SUPPORTED. If you are
3209never going to use a capability, you can change the #define to #undef
3210before recompiling libpng and save yourself code and data space, or
3211you can turn off individual capabilities with defines that begin with
3212PNG_NO_.
3213
3214You can also turn all of the transforms and ancillary chunk capabilities
3215off en masse with compiler directives that define
3216PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3217or all four,
3218along with directives to turn on any of the capabilities that you do
3219want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
3220transformations but still leave the library fully capable of reading
3221and writing PNG files with all known public chunks. Use of the
3222PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
3223that is incapable of reading or writing ancillary chunks. If you are
3224not using the progressive reading capability, you can turn that off
3225with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
3226capability, which you'll still have).
3227
3228All the reading and writing specific code are in separate files, so the
3229linker should only grab the files it needs. However, if you want to
3230make sure, or if you are building a stand alone library, all the
3231reading files start with pngr and all the writing files start with
3232pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
3233are used for both reading and writing, and always need to be included.
3234The progressive reader is in pngpread.c
3235
3236If you are creating or distributing a dynamically linked library (a .so
3237or DLL file), you should not remove or disable any parts of the library,
3238as this will cause applications linked with different versions of the
3239library to fail if they call functions not available in your library.
3240The size of the library itself should not be an issue, because only
3241those sections that are actually used will be loaded into memory.
3242
3243.SS Requesting debug printout
3244
3245The macro definition PNG_DEBUG can be used to request debugging
3246printout. Set it to an integer value in the range 0 to 3. Higher
3247numbers result in increasing amounts of debugging information. The
3248information is printed to the "stderr" file, unless another file
3249name is specified in the PNG_DEBUG_FILE macro definition.
3250
3251When PNG_DEBUG > 0, the following functions (macros) become available:
3252
3253 png_debug(level, message)
3254 png_debug1(level, message, p1)
3255 png_debug2(level, message, p1, p2)
3256
3257in which "level" is compared to PNG_DEBUG to decide whether to print
3258the message, "message" is the formatted string to be printed,
3259and p1 and p2 are parameters that are to be embedded in the string
3260according to printf-style formatting directives. For example,
3261
3262 png_debug1(2, "foo=%d", foo);
3263
3264is expanded to
3265
3266 if(PNG_DEBUG > 2)
3267 fprintf(PNG_DEBUG_FILE, "foo=%d\en", foo);
3268
3269When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3270can still use PNG_DEBUG to control your own debugging:
3271
3272 #ifdef PNG_DEBUG
3273 fprintf(stderr, ...
3274 #endif
3275
3276When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3277having level = 0 will be printed. There aren't any such statements in
3278this version of libpng, but if you insert some they will be printed.
3279
3280.SH VI. MNG support
3281
3282The MNG specification (available at http://www.libpng.org/pub/mng) allows
3283certain extensions to PNG for PNG images that are embedded in MNG datastreams.
3284Libpng can support some of these extensions. To enable them, use the
3285png_permit_mng_features() function:
3286
3287 feature_set = png_permit_mng_features(png_ptr, mask)
3288 mask is a png_uint_32 containing the bitwise OR of the
3289 features you want to enable. These include
3290 PNG_FLAG_MNG_EMPTY_PLTE
3291 PNG_FLAG_MNG_FILTER_64
3292 PNG_ALL_MNG_FEATURES
3293 feature_set is a png_uint_32 that is the bitwise AND of
3294 your mask with the set of MNG features that is
3295 supported by the version of libpng that you are using.
3296
3297It is an error to use this function when reading or writing a standalone
3298PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
3299in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
3300and the MHDR and MEND chunks. Libpng does not provide support for these
3301or any other MNG chunks; your application must provide its own support for
3302them. You may wish to consider using libmng (available at
3303http://www.libmng.com) instead.
3304
3305.SH VII. Changes to Libpng from version 0.88
3306
3307It should be noted that versions of libpng later than 0.96 are not
3308distributed by the original libpng author, Guy Schalnat, nor by
3309Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3310distributed versions 0.89 through 0.96, but rather by another member
3311of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3312still alive and well, but they have moved on to other things.
3313
3314The old libpng functions png_read_init(), png_write_init(),
3315png_info_init(), png_read_destroy(), and png_write_destroy() have been
3316moved to PNG_INTERNAL in version 0.95 to discourage their use. These
3317functions will be removed from libpng version 2.0.0.
3318
3319The preferred method of creating and initializing the libpng structures is
3320via the png_create_read_struct(), png_create_write_struct(), and
3321png_create_info_struct() because they isolate the size of the structures
3322from the application, allow version error checking, and also allow the
3323use of custom error handling routines during the initialization, which
3324the old functions do not. The functions png_read_destroy() and
3325png_write_destroy() do not actually free the memory that libpng
3326allocated for these structs, but just reset the data structures, so they
3327can be used instead of png_destroy_read_struct() and
3328png_destroy_write_struct() if you feel there is too much system overhead
3329allocating and freeing the png_struct for each image read.
3330
3331Setting the error callbacks via png_set_message_fn() before
3332png_read_init() as was suggested in libpng-0.88 is no longer supported
3333because this caused applications that do not use custom error functions
3334to fail if the png_ptr was not initialized to zero. It is still possible
3335to set the error callbacks AFTER png_read_init(), or to change them with
3336png_set_error_fn(), which is essentially the same function, but with a new
3337name to force compilation errors with applications that try to use the old
3338method.
3339
3340Support for the sCAL, iCCP, iTXt, and sPLT chunks was added at libpng-1.0.6;
3341however, iTXt support was not enabled by default.
3342
3343Starting with version 1.0.7, you can find out which version of the library
3344you are using at run-time:
3345
3346 png_uint_32 libpng_vn = png_access_version_number();
3347
3348The number libpng_vn is constructed from the major version, minor
3349version with leading zero, and release number with leading zero,
3350(e.g., libpng_vn for version 1.0.7 is 10007).
3351
3352You can also check which version of png.h you used when compiling your
3353application:
3354
3355 png_uint_32 application_vn = PNG_LIBPNG_VER;
3356
3357.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x
3358
3359Support for user memory management was enabled by default. To
3360accomplish this, the functions png_create_read_struct_2(),
3361png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
3362png_malloc_default(), and png_free_default() were added.
3363
3364Support for the iTXt chunk has been enabled by default as of
3365version 1.2.41.
3366
3367Support for certain MNG features was enabled.
3368
3369Support for numbered error messages was added. However, we never got
3370around to actually numbering the error messages. The function
3371png_set_strip_error_numbers() was added (Note: the prototype for this
3372function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
3373builds of libpng-1.2.15. It was restored in libpng-1.2.36).
3374
3375The png_malloc_warn() function was added at libpng-1.2.3. This issues
3376a png_warning and returns NULL instead of aborting when it fails to
3377acquire the requested memory allocation.
3378
3379Support for setting user limits on image width and height was enabled
3380by default. The functions png_set_user_limits(), png_get_user_width_max(),
3381and png_get_user_height_max() were added at libpng-1.2.6.
3382
3383The png_set_add_alpha() function was added at libpng-1.2.7.
3384
3385The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
3386Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
3387tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
3388deprecated.
3389
3390A number of macro definitions in support of runtime selection of
3391assembler code features (especially Intel MMX code support) were
3392added at libpng-1.2.0:
3393
3394 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
3395 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
3396 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
3397 PNG_ASM_FLAG_MMX_READ_INTERLACE
3398 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
3399 PNG_ASM_FLAG_MMX_READ_FILTER_UP
3400 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
3401 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
3402 PNG_ASM_FLAGS_INITIALIZED
3403 PNG_MMX_READ_FLAGS
3404 PNG_MMX_FLAGS
3405 PNG_MMX_WRITE_FLAGS
3406 PNG_MMX_FLAGS
3407
3408We added the following functions in support of runtime
3409selection of assembler code features:
3410
3411 png_get_mmx_flagmask()
3412 png_set_mmx_thresholds()
3413 png_get_asm_flags()
3414 png_get_mmx_bitdepth_threshold()
3415 png_get_mmx_rowbytes_threshold()
3416 png_set_asm_flags()
3417
3418We replaced all of these functions with simple stubs in libpng-1.2.20,
3419when the Intel assembler code was removed due to a licensing issue.
3420
3421These macros are deprecated:
3422
3423 PNG_READ_TRANSFORMS_NOT_SUPPORTED
3424 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
3425 PNG_NO_SEQUENTIAL_READ_SUPPORTED
3426 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
3427 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
3428 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
3429
3430They have been replaced, respectively, by:
3431
3432 PNG_NO_READ_TRANSFORMS
3433 PNG_NO_PROGRESSIVE_READ
3434 PNG_NO_SEQUENTIAL_READ
3435 PNG_NO_WRITE_TRANSFORMS
3436 PNG_NO_READ_ANCILLARY_CHUNKS
3437 PNG_NO_WRITE_ANCILLARY_CHUNKS
3438
3439PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
3440deprecated since libpng-1.0.16 and libpng-1.2.6.
3441
3442The function
3443 png_check_sig(sig, num)
3444was replaced with
3445 !png_sig_cmp(sig, 0, num)
3446It has been deprecated since libpng-0.90.
3447
3448The function
3449 png_set_gray_1_2_4_to_8()
3450which also expands tRNS to alpha was replaced with
3451 png_set_expand_gray_1_2_4_to_8()
3452which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
3453
3454.SH IX. (Omitted)
3455
3456
3457.SH X. Detecting libpng
3458
3459The png_get_io_ptr() function has been present since libpng-0.88, has never
3460changed, and is unaffected by conditional compilation macros. It is the
3461best choice for use in configure scripts for detecting the presence of any
3462libpng version since 0.88. In an autoconf "configure.in" you could use
3463
3464 AC_CHECK_LIB(png, png_get_io_ptr, ...
3465
3466.SH XI. Source code repository
3467
3468Since about February 2009, version 1.2.34, libpng has been under "git" source
3469control. The git repository was built from old libpng-x.y.z.tar.gz files
3470going back to version 0.70. You can access the git repository (read only)
3471at
3472
3473 git://git.code.sf.net/p/libpng/code
3474
3475or you can browse it with a web browser by selecting the "code" button at
3476
3477 https://sourceforge.net/projects/libpng/
3478
3479Patches can be sent to glennrp at users.sourceforge.net or to
3480png-mng-implement at lists.sourceforge.net or you can upload them to
3481the libpng bug tracker at
3482
3483 http://libpng.sourceforge.net
3484
3485.SH XII. Coding style
3486
3487Our coding style is similar to the "Allman" style
3488(See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly
3489braces on separate lines:
3490
3491 if (condition)
3492 {
3493 action;
3494 }
3495
3496 else if (another condition)
3497 {
3498 another action;
3499 }
3500
3501The braces can be omitted from simple one-line actions:
3502
3503 if (condition)
3504 return (0);
3505
3506We use 3-space indentation, except for continued statements which
3507are usually indented the same as the first line of the statement
3508plus four more spaces.
3509
3510For macro definitions we use 2-space indentation, always leaving the "#"
3511in the first column.
3512
3513 #ifndef PNG_NO_FEATURE
3514 # ifndef PNG_FEATURE_SUPPORTED
3515 # define PNG_FEATURE_SUPPORTED
3516 # endif
3517 #endif
3518
3519Comments appear with the leading "/*" at the same indentation as
3520the statement that follows the comment:
3521
3522 /* Single-line comment */
3523 statement;
3524
3525 /* Multiple-line
3526 * comment
3527 */
3528 statement;
3529
3530Very short comments can be placed at the end of the statement
3531to which they pertain:
3532
3533 statement; /* comment */
3534
3535We don't use C++ style ("//") comments. We have, however,
3536used them in the past in some now-abandoned MMX assembler
3537code.
3538
3539Functions and their curly braces are not indented, and
3540exported functions are marked with PNGAPI:
3541
3542 /* This is a public function that is visible to
3543 * application programers. It does thus-and-so.
3544 */
3545 void PNGAPI
3546 png_exported_function(png_ptr, png_info, foo)
3547 {
3548 body;
3549 }
3550
3551The prototypes for all exported functions appear in png.h,
3552above the comment that says
3553
3554 /* Maintainer: Put new public prototypes here ... */
3555
3556We mark all non-exported functions with "/* PRIVATE */"":
3557
3558 void /* PRIVATE */
3559 png_non_exported_function(png_ptr, png_info, foo)
3560 {
3561 body;
3562 }
3563
3564The prototypes for non-exported functions (except for those in
3565pngtest) appear in
3566the PNG_INTERNAL section of png.h
3567above the comment that says
3568
3569 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
3570
3571The names of all exported functions and variables begin
3572with "png_", and all publicly visible C preprocessor
3573macros begin with "PNG".
3574
3575We put a space after each comma and after each semicolon
3576in "for" statments, and we put spaces before and after each
3577C binary operator and after "for" or "while". We don't
3578put a space between a typecast and the expression being
3579cast, nor do we put one between a function name and the
3580left parenthesis that follows it:
3581
3582 for (i = 2; i > 0; --i)
3583 y[i] = a(x) + (int)b;
3584
3585We prefer #ifdef and #ifndef to #if defined() and if !defined()
3586when there is only one macro being tested.
3587
3588We do not use the TAB character for indentation in the C sources.
3589
3590Lines do not exceed 80 characters.
3591
3592Other rules can be inferred by inspecting the libpng source.
3593
3594.SH XIII. Y2K Compliance in libpng
3595
3596February 26, 2015
3597
3598Since the PNG Development group is an ad-hoc body, we can't make
3599an official declaration.
3600
3601This is your unofficial assurance that libpng from version 0.71 and
3602upward through 1.2.53 are Y2K compliant. It is my belief that earlier
3603versions were also Y2K compliant.
3604
3605Libpng only has three year fields. One is a 2-byte unsigned integer that
3606will hold years up to 65535. The other two hold the date in text
3607format, and will hold years up to 9999.
3608
3609The integer is
3610 "png_uint_16 year" in png_time_struct.
3611
3612The strings are
3613 "png_charp time_buffer" in png_struct and
3614 "near_time_buffer", which is a local character string in png.c.
3615
3616There are seven time-related functions:
3617
3618 png_convert_to_rfc_1123() in png.c
3619 (formerly png_convert_to_rfc_1152() in error)
3620 png_convert_from_struct_tm() in pngwrite.c, called
3621 in pngwrite.c
3622 png_convert_from_time_t() in pngwrite.c
3623 png_get_tIME() in pngget.c
3624 png_handle_tIME() in pngrutil.c, called in pngread.c
3625 png_set_tIME() in pngset.c
3626 png_write_tIME() in pngwutil.c, called in pngwrite.c
3627
3628All appear to handle dates properly in a Y2K environment. The
3629png_convert_from_time_t() function calls gmtime() to convert from system
3630clock time, which returns (year - 1900), which we properly convert to
3631the full 4-digit year. There is a possibility that applications using
3632libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
3633function, or that they are incorrectly passing only a 2-digit year
3634instead of "year - 1900" into the png_convert_from_struct_tm() function,
3635but this is not under our control. The libpng documentation has always
3636stated that it works with 4-digit years, and the APIs have been
3637documented as such.
3638
3639The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
3640integer to hold the year, and can hold years as large as 65535.
3641
3642zlib, upon which libpng depends, is also Y2K compliant. It contains
3643no date-related code.
3644
3645
3646 Glenn Randers-Pehrson
3647 libpng maintainer
3648 PNG Development Group
3649
3650.SH NOTE
3651
3652Note about libpng version numbers:
3653
3654Due to various miscommunications, unforeseen code incompatibilities
3655and occasional factors outside the authors' control, version numbering
3656on the library has not always been consistent and straightforward.
3657The following table summarizes matters since version 0.89c, which was
3658the first widely used release:
3659
3660 source png.h png.h shared-lib
3661 version string int version
3662 ------- ------ ----- ----------
3663 0.89c ("beta 3") 0.89 89 1.0.89
3664 0.90 ("beta 4") 0.90 90 0.90
3665 0.95 ("beta 5") 0.95 95 0.95
3666 0.96 ("beta 6") 0.96 96 0.96
3667 0.97b ("beta 7") 1.00.97 97 1.0.1
3668 0.97c 0.97 97 2.0.97
3669 0.98 0.98 98 2.0.98
3670 0.99 0.99 98 2.0.99
3671 0.99a-m 0.99 99 2.0.99
3672 1.00 1.00 100 2.1.0
3673 1.0.0 1.0.0 100 2.1.0
3674 1.0.0 (from here on, the 100 2.1.0
3675 1.0.1 png.h string is 10001 2.1.0
3676 1.0.1a-e identical to the 10002 from here on, the
3677 1.0.2 source version) 10002 shared library is 2.V
3678 1.0.2a-b 10003 where V is the source
3679 1.0.1 10001 code version except as
3680 1.0.1a-e 10002 2.1.0.1a-e noted.
3681 1.0.2 10002 2.1.0.2
3682 1.0.2a-b 10003 2.1.0.2a-b
3683 1.0.3 10003 2.1.0.3
3684 1.0.3a-d 10004 2.1.0.3a-d
3685 1.0.4 10004 2.1.0.4
3686 1.0.4a-f 10005 2.1.0.4a-f
3687 1.0.5 (+ 2 patches) 10005 2.1.0.5
3688 1.0.5a-d 10006 2.1.0.5a-d
3689 1.0.5e-r 10100 2.1.0.5e-r
3690 1.0.5s-v 10006 2.1.0.5s-v
3691 1.0.6 (+ 3 patches) 10006 2.1.0.6
3692 1.0.6d-g 10007 2.1.0.6d-g
3693 1.0.6h 10007 10.6h
3694 1.0.6i 10007 10.6i
3695 1.0.6j 10007 2.1.0.6j
3696 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
3697 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
3698 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
3699 1.0.7 1 10007 2.1.0.7
3700 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
3701 1.0.8rc1 1 10008 2.1.0.8rc1
3702 1.0.8 1 10008 2.1.0.8
3703 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
3704 1.0.9rc1 1 10009 2.1.0.9rc1
3705 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
3706 1.0.9rc2 1 10009 2.1.0.9rc2
3707 1.0.9 1 10009 2.1.0.9
3708 1.0.10beta1 1 10010 2.1.0.10beta1
3709 1.0.10rc1 1 10010 2.1.0.10rc1
3710 1.0.10 1 10010 2.1.0.10
3711 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
3712 1.0.11rc1 1 10011 2.1.0.11rc1
3713 1.0.11 1 10011 2.1.0.11
3714 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
3715 1.0.12rc1 2 10012 2.1.0.12rc1
3716 1.0.12 2 10012 2.1.0.12
3717 1.1.0a-f - 10100 2.1.1.0a-f abandoned
3718 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
3719 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
3720 1.2.0rc1 3 10200 3.1.2.0rc1
3721 1.2.0 3 10200 3.1.2.0
3722 1.2.1beta-4 3 10201 3.1.2.1beta1-4
3723 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
3724 1.2.1 3 10201 3.1.2.1
3725 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
3726 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
3727 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
3728 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
3729 1.0.13 10 10013 10.so.0.1.0.13
3730 1.2.2 12 10202 12.so.0.1.2.2
3731 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
3732 1.2.3 12 10203 12.so.0.1.2.3
3733 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
3734 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
3735 1.0.14 10 10014 10.so.0.1.0.14
3736 1.2.4 13 10204 12.so.0.1.2.4
3737 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
3738 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
3739 1.0.15 10 10015 10.so.0.1.0.15
3740 1.2.5 13 10205 12.so.0.1.2.5
3741 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
3742 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
3743 1.0.16 10 10016 10.so.0.1.0.16
3744 1.2.6 13 10206 12.so.0.1.2.6
3745 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
3746 1.0.17rc1 10 10017 10.so.0.1.0.17rc1
3747 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
3748 1.0.17 10 10017 10.so.0.1.0.17
3749 1.2.7 13 10207 12.so.0.1.2.7
3750 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
3751 1.0.18rc1-5 10 10018 10.so.0.1.0.18rc1-5
3752 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
3753 1.0.18 10 10018 10.so.0.1.0.18
3754 1.2.8 13 10208 12.so.0.1.2.8
3755 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
3756 1.2.9beta4-11 13 10209 12.so.0.9[.0]
3757 1.2.9rc1 13 10209 12.so.0.9[.0]
3758 1.2.9 13 10209 12.so.0.9[.0]
3759 1.2.10beta1-8 13 10210 12.so.0.10[.0]
3760 1.2.10rc1-3 13 10210 12.so.0.10[.0]
3761 1.2.10 13 10210 12.so.0.10[.0]
3762 1.2.11beta1-4 13 10211 12.so.0.11[.0]
3763 1.0.19rc1-5 10 10019 10.so.0.19[.0]
3764 1.2.11rc1-5 13 10211 12.so.0.11[.0]
3765 1.0.19 10 10019 10.so.0.19[.0]
3766 1.2.11 13 10211 12.so.0.11[.0]
3767 1.0.20 10 10020 10.so.0.20[.0]
3768 1.2.12 13 10212 12.so.0.12[.0]
3769 1.2.13beta1 13 10213 12.so.0.13[.0]
3770 1.0.21 10 10021 10.so.0.21[.0]
3771 1.2.13 13 10213 12.so.0.13[.0]
3772 1.2.14beta1-2 13 10214 12.so.0.14[.0]
3773 1.0.22rc1 10 10022 10.so.0.22[.0]
3774 1.2.14rc1 13 10214 12.so.0.14[.0]
3775 1.2.15beta1-6 13 10215 12.so.0.15[.0]
3776 1.0.23rc1-5 10 10023 10.so.0.23[.0]
3777 1.2.15rc1-5 13 10215 12.so.0.15[.0]
3778 1.0.23 10 10023 10.so.0.23[.0]
3779 1.2.15 13 10215 12.so.0.15[.0]
3780 1.2.16beta1-2 13 10216 12.so.0.16[.0]
3781 1.2.16rc1 13 10216 12.so.0.16[.0]
3782 1.0.24 10 10024 10.so.0.24[.0]
3783 1.2.16 13 10216 12.so.0.16[.0]
3784 1.2.17beta1-2 13 10217 12.so.0.17[.0]
3785 1.0.25rc1 10 10025 10.so.0.25[.0]
3786 1.2.17rc1-3 13 10217 12.so.0.17[.0]
3787 1.0.25 10 10025 10.so.0.25[.0]
3788 1.2.17 13 10217 12.so.0.17[.0]
3789 1.0.26 10 10026 10.so.0.26[.0]
3790 1.2.18 13 10218 12.so.0.18[.0]
3791 1.2.19beta1-31 13 10219 12.so.0.19[.0]
3792 1.0.27rc1-6 10 10027 10.so.0.27[.0]
3793 1.2.19rc1-6 13 10219 12.so.0.19[.0]
3794 1.0.27 10 10027 10.so.0.27[.0]
3795 1.2.19 13 10219 12.so.0.19[.0]
3796 1.2.20beta01-04 13 10220 12.so.0.20[.0]
3797 1.0.28rc1-6 10 10028 10.so.0.28[.0]
3798 1.2.20rc1-6 13 10220 12.so.0.20[.0]
3799 1.0.28 10 10028 10.so.0.28[.0]
3800 1.2.20 13 10220 12.so.0.20[.0]
3801 1.2.21beta1-2 13 10221 12.so.0.21[.0]
3802 1.2.21rc1-3 13 10221 12.so.0.21[.0]
3803 1.0.29 10 10029 10.so.0.29[.0]
3804 1.2.21 13 10221 12.so.0.21[.0]
3805 1.2.22beta1-4 13 10222 12.so.0.22[.0]
3806 1.0.30rc1 13 10030 10.so.0.30[.0]
3807 1.2.22rc1 13 10222 12.so.0.22[.0]
3808 1.0.30 10 10030 10.so.0.30[.0]
3809 1.2.22 13 10222 12.so.0.22[.0]
3810 1.2.23beta01-05 13 10223 12.so.0.23[.0]
3811 1.2.23rc01 13 10223 12.so.0.23[.0]
3812 1.2.23 13 10223 12.so.0.23[.0]
3813 1.2.24beta01-02 13 10224 12.so.0.24[.0]
3814 1.2.24rc01 13 10224 12.so.0.24[.0]
3815 1.2.24 13 10224 12.so.0.24[.0]
3816 1.2.25beta01-06 13 10225 12.so.0.25[.0]
3817 1.2.25rc01-02 13 10225 12.so.0.25[.0]
3818 1.0.31 10 10031 10.so.0.31[.0]
3819 1.2.25 13 10225 12.so.0.25[.0]
3820 1.2.26beta01-06 13 10226 12.so.0.26[.0]
3821 1.2.26rc01 13 10226 12.so.0.26[.0]
3822 1.2.26 13 10226 12.so.0.26[.0]
3823 1.0.32 10 10032 10.so.0.32[.0]
3824 1.2.27beta01-06 13 10227 12.so.0.27[.0]
3825 1.2.27rc01 13 10227 12.so.0.27[.0]
3826 1.0.33 10 10033 10.so.0.33[.0]
3827 1.2.27 13 10227 12.so.0.27[.0]
3828 1.0.34 10 10034 10.so.0.34[.0]
3829 1.2.28 13 10228 12.so.0.28[.0]
3830 1.2.29beta01-03 13 10229 12.so.0.29[.0]
3831 1.2.29rc01 13 10229 12.so.0.29[.0]
3832 1.0.35 10 10035 10.so.0.35[.0]
3833 1.2.29 13 10229 12.so.0.29[.0]
3834 1.0.37 10 10037 10.so.0.37[.0]
3835 1.2.30beta01-04 13 10230 12.so.0.30[.0]
3836 1.0.38rc01-08 10 10038 10.so.0.38[.0]
3837 1.2.30rc01-08 13 10230 12.so.0.30[.0]
3838 1.0.38 10 10038 10.so.0.38[.0]
3839 1.2.30 13 10230 12.so.0.30[.0]
3840 1.0.39rc01-03 10 10039 10.so.0.39[.0]
3841 1.2.31rc01-03 13 10231 12.so.0.31[.0]
3842 1.0.39 10 10039 10.so.0.39[.0]
3843 1.2.31 13 10231 12.so.0.31[.0]
3844 1.2.32beta01-02 13 10232 12.so.0.32[.0]
3845 1.0.40rc01 10 10040 10.so.0.40[.0]
3846 1.2.32rc01 13 10232 12.so.0.32[.0]
3847 1.0.40 10 10040 10.so.0.40[.0]
3848 1.2.32 13 10232 12.so.0.32[.0]
3849 1.2.33beta01-02 13 10233 12.so.0.33[.0]
3850 1.2.33rc01-02 13 10233 12.so.0.33[.0]
3851 1.0.41rc01 10 10041 10.so.0.41[.0]
3852 1.2.33 13 10233 12.so.0.33[.0]
3853 1.0.41 10 10041 10.so.0.41[.0]
3854 1.2.34beta01-07 13 10234 12.so.0.34[.0]
3855 1.0.42rc01 10 10042 10.so.0.42[.0]
3856 1.2.34rc01 13 10234 12.so.0.34[.0]
3857 1.0.42 10 10042 10.so.0.42[.0]
3858 1.2.34 13 10234 12.so.0.34[.0]
3859 1.2.35beta01-03 13 10235 12.so.0.35[.0]
3860 1.0.43rc01-02 10 10043 10.so.0.43[.0]
3861 1.2.35rc01-02 13 10235 12.so.0.35[.0]
3862 1.0.43 10 10043 10.so.0.43[.0]
3863 1.2.35 13 10235 12.so.0.35[.0]
3864 1.2.36beta01-05 13 10236 12.so.0.36[.0]
3865 1.2.36rc01 13 10236 12.so.0.36[.0]
3866 1.0.44 10 10044 10.so.0.44[.0]
3867 1.2.36 13 10236 12.so.0.36[.0]
3868 1.2.37beta01-03 13 10237 12.so.0.37[.0]
3869 1.2.37rc01 13 10237 12.so.0.37[.0]
3870 1.2.37 13 10237 12.so.0.37[.0]
3871 1.0.45 10 10045 12.so.0.45[.0]
3872 1.0.46 10 10046 10.so.0.46[.0]
3873 1.2.38beta01 13 10238 12.so.0.38[.0]
3874 1.2.38rc01-03 13 10238 12.so.0.38[.0]
3875 1.0.47 10 10047 10.so.0.47[.0]
3876 1.2.38 13 10238 12.so.0.38[.0]
3877 1.2.39beta01-05 13 10239 12.so.0.39[.0]
3878 1.2.39rc01 13 10239 12.so.0.39[.0]
3879 1.0.48 10 10048 10.so.0.48[.0]
3880 1.2.39 13 10239 12.so.0.39[.0]
3881 1.2.40beta01 13 10240 12.so.0.40[.0]
3882 1.2.40rc01 13 10240 12.so.0.40[.0]
3883 1.0.49 10 10049 10.so.0.49[.0]
3884 1.2.40 13 10240 12.so.0.40[.0]
3885 1.0.50 10 10050 10.so.0.50[.0]
3886 1.2.41beta01-18 13 10241 12.so.0.41[.0]
3887 1.0.51rc01 10 10051 10.so.0.51[.0]
3888 1.2.41rc01-03 13 10241 12.so.0.41[.0]
3889 1.0.51 10 10051 10.so.0.51[.0]
3890 1.2.41 13 10241 12.so.0.41[.0]
3891 1.2.42beta01-02 13 10242 12.so.0.42[.0]
3892 1.2.42rc01-05 13 10242 12.so.0.42[.0]
3893 1.0.52 10 10052 10.so.0.52[.0]
3894 1.2.42 13 10242 12.so.0.42[.0]
3895 1.2.43beta01-05 13 10243 12.so.0.43[.0]
3896 1.0.53rc01-02 10 10053 10.so.0.53[.0]
3897 1.2.43rc01-02 13 10243 12.so.0.43[.0]
3898 1.0.53 10 10053 10.so.0.53[.0]
3899 1.2.43 13 10243 12.so.0.43[.0]
3900 1.2.44beta01-03 13 10244 12.so.0.44[.0]
3901 1.2.44rc01-03 13 10244 12.so.0.44[.0]
3902 1.2.44 13 10244 12.so.0.44[.0]
3903 1.2.45beta01-03 13 10245 12.so.0.45[.0]
3904 1.0.55rc01 10 10055 10.so.0.55[.0]
3905 1.2.45rc01 13 10245 12.so.0.45[.0]
3906 1.0.55 10 10055 10.so.0.55[.0]
3907 1.2.45 13 10245 12.so.0.45[.0]
3908 1.2.46rc01-02 13 10246 12.so.0.46[.0]
3909 1.0.56 10 10056 10.so.0.56[.0]
3910 1.2.46 13 10246 12.so.0.46[.0]
3911 1.2.47beta01 13 10247 12.so.0.47[.0]
3912 1.2.47rc01 13 10247 12.so.0.47[.0]
3913 1.0.57rc01 10 10057 10.so.0.57[.0]
3914 1.2.47 13 10247 12.so.0.47[.0]
3915 1.0.57 10 10057 10.so.0.57[.0]
3916 1.2.48beta01 13 10248 12.so.0.48[.0]
3917 1.2.48rc01-02 13 10248 12.so.0.48[.0]
3918 1.0.58 10 10058 10.so.0.58[.0]
3919 1.2.48 13 10248 12.so.0.48[.0]
3920 1.2.49rc01 13 10249 12.so.0.49[.0]
3921 1.0.59 10 10059 10.so.0.59[.0]
3922 1.2.49 13 10249 12.so.0.49[.0]
3923 1.2.50 13 10250 12.so.0.50[.0]
3924 1.0.60 10 10060 10.so.0.60[.0]
3925 1.2.51beta01-05 13 10251 12.so.0.51[.0]
3926 1.2.51rc01-04 13 10251 12.so.0.51[.0]
3927 1.0.61 10 10061 10.so.0.61[.0]
3928 1.2.51 13 10251 12.so.0.51[.0]
3929 1.2.52beta01 13 10252 12.so.0.52[.0]
3930 1.2.52rc01-02 13 10252 12.so.0.52[.0]
3931 1.0.62 10 10062 10.so.0.62[.0]
3932 1.2.52 13 10252 12.so.0.52[.0]
3933 1.2.53beta01-02 13 10253 12.so.0.53[.0]
3934 1.2.53rc01-03 13 10253 12.so.0.53[.0]
3935 1.0.63 10 10063 10.so.0.63[.0]
3936 1.2.53 13 10253 12.so.0.53[.0]
3937
3938Henceforth the source version will match the shared-library minor
3939and patch numbers; the shared-library major version number will be
3940used for changes in backward compatibility, as it is intended. The
3941PNG_PNGLIB_VER macro, which is not used within libpng but is available
3942for applications, is an unsigned integer of the form xyyzz corresponding
3943to the source version x.y.z (leading zeros in y and z). Beta versions
3944were given the previous public release number plus a letter, until
3945version 1.0.6j; from then on they were given the upcoming public
3946release number plus "betaNN" or "rcNN".
3947
3948.SH "SEE ALSO"
3949.IR libpngpf(3) ", " png(5)
3950.LP
3951.IR libpng :
3952.IP
3953http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
3954http://www.libpng.org/pub/png
3955
3956.LP
3957.IR zlib :
3958.IP
3959(generally) at the same location as
3960.I libpng
3961or at
3962.br
3963ftp://ftp.info-zip.org/pub/infozip/zlib
3964
3965.LP
3966.IR PNG specification: RFC 2083
3967.IP
3968(generally) at the same location as
3969.I libpng
3970or at
3971.br
3972ftp://ftp.rfc-editor.org:/in-notes/rfc2083.txt
3973.br
3974or (as a W3C Recommendation) at
3975.br
3976http://www.w3.org/TR/REC-png.html
3977
3978.LP
3979In the case of any inconsistency between the PNG specification
3980and this library, the specification takes precedence.
3981
3982.SH AUTHORS
3983This man page: Glenn Randers-Pehrson
3984<glennrp at users.sourceforge.net>
3985
3986The contributing authors would like to thank all those who helped
3987with testing, bug fixes, and patience. This wouldn't have been
3988possible without all of you.
3989
3990Thanks to Frank J. T. Wojcik for helping with the documentation.
3991
3992Libpng version 1.2.53 - February 26, 2015:
3993Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
3994Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
3995
3996Supported by the PNG development group
3997.br
3998png-mng-implement at lists.sf.net
3999(subscription required; visit
4000png-mng-implement at lists.sourceforge.net (subscription required; visit
4001https://lists.sourceforge.net/lists/listinfo/png-mng-implement
4002to subscribe).
4003
4004.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
4005
4006(This copy of the libpng notices is provided for your convenience. In case of
4007any discrepancy between this copy and the notices in the file png.h that is
4008included in the libpng distribution, the latter shall prevail.)
4009
4010If you modify libpng you may insert additional notices immediately following
4011this sentence.
4012
4013This code is released under the libpng license.
4014
4015libpng versions 1.2.6, August 15, 2004, through 1.2.53, February 26, 2015, are
4016Copyright (c) 2004,2006-2008 Glenn Randers-Pehrson, and are
4017distributed according to the same disclaimer and license as libpng-1.2.5
4018with the following individual added to the list of Contributing Authors
4019
4020 Cosmin Truta
4021
4022libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
4023Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
4024distributed according to the same disclaimer and license as libpng-1.0.6
4025with the following individuals added to the list of Contributing Authors
4026
4027 Simon-Pierre Cadieux
4028 Eric S. Raymond
4029 Gilles Vollant
4030
4031and with the following additions to the disclaimer:
4032
4033 There is no warranty against interference with your
4034 enjoyment of the library or against infringement.
4035 There is no warranty that our efforts or the library
4036 will fulfill any of your particular purposes or needs.
4037 This library is provided with all faults, and the entire
4038 risk of satisfactory quality, performance, accuracy, and
4039 effort is with the user.
4040
4041libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
4042Copyright (c) 1998, 1999 Glenn Randers-Pehrson
4043Distributed according to the same disclaimer and license as libpng-0.96,
4044with the following individuals added to the list of Contributing Authors:
4045
4046 Tom Lane
4047 Glenn Randers-Pehrson
4048 Willem van Schaik
4049
4050libpng versions 0.89, June 1996, through 0.96, May 1997, are
4051Copyright (c) 1996, 1997 Andreas Dilger
4052Distributed according to the same disclaimer and license as libpng-0.88,
4053with the following individuals added to the list of Contributing Authors:
4054
4055 John Bowler
4056 Kevin Bracey
4057 Sam Bushell
4058 Magnus Holmgren
4059 Greg Roelofs
4060 Tom Tanner
4061
4062libpng versions 0.5, May 1995, through 0.88, January 1996, are
4063Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
4064
4065For the purposes of this copyright and license, "Contributing Authors"
4066is defined as the following set of individuals:
4067
4068 Andreas Dilger
4069 Dave Martindale
4070 Guy Eric Schalnat
4071 Paul Schmidt
4072 Tim Wegner
4073
4074The PNG Reference Library is supplied "AS IS". The Contributing Authors
4075and Group 42, Inc. disclaim all warranties, expressed or implied,
4076including, without limitation, the warranties of merchantability and of
4077fitness for any purpose. The Contributing Authors and Group 42, Inc.
4078assume no liability for direct, indirect, incidental, special, exemplary,
4079or consequential damages, which may result from the use of the PNG
4080Reference Library, even if advised of the possibility of such damage.
4081
4082Permission is hereby granted to use, copy, modify, and distribute this
4083source code, or portions hereof, for any purpose, without fee, subject
4084to the following restrictions:
4085
40861. The origin of this source code must not be misrepresented.
4087
40882. Altered versions must be plainly marked as such and
4089 must not be misrepresented as being the original source.
4090
40913. This Copyright notice may not be removed or altered from
4092 any source or altered source distribution.
4093
4094The Contributing Authors and Group 42, Inc. specifically permit, without
4095fee, and encourage the use of this source code as a component to
4096supporting the PNG file format in commercial products. If you use this
4097source code in a product, acknowledgment is not required but would be
4098appreciated.
4099
4100
4101A "png_get_copyright" function is available, for convenient use in "about"
4102boxes and the like:
4103
4104 printf("%s",png_get_copyright(NULL));
4105
4106Also, the PNG logo (in PNG format, of course) is supplied in the
4107files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
4108
4109Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
4110certification mark of the Open Source Initiative.
4111
4112Glenn Randers-Pehrson
4113glennrp at users.sourceforge.net
4114February 26, 2015
4115
4116.\" end of man page
4117
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette