]> git.saurik.com Git - wxWidgets.git/blob - src/png/libpng.3
Compilation fix for wxMSW with wxUSE_MSGBOX_HOOK==0.
[wxWidgets.git] / src / png / libpng.3
1 .TH LIBPNG 3 "April 25, 2013"
2 .SH NAME
3 libpng \- Portable Network Graphics (PNG) Reference Library 1.6.2
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 \fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
11
12 \fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
13
14 \fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
15
16 \fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
17
18 \fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
19
20 \fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
21
22 \fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
23
24 \fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
25
26 \fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
27
28 \fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
29
30 \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
31
32 \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
33
34 \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
35
36 \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
37
38 \fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP
39
40 \fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
41
42 \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
43
44 \fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
45
46 \fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
47
48 \fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
49
50 \fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
51
52 \fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
53
54 \fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
55
56 \fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
57
58 \fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
59
60 \fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
61
62 \fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
63
64 \fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
65
66 \fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
67
68 \fBpng_uint_32 png_get_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*red_X\fP\fB, double \fP\fI*red_Y\fP\fB, double \fP\fI*red_Z\fP\fB, double \fP\fI*green_X\fP\fB, double \fP\fI*green_Y\fP\fB, double \fP\fI*green_Z\fP\fB, double \fP\fI*blue_X\fP\fB, double \fP\fI*blue_Y\fP\fB, double \fI*blue_Z\fP\fB);\fP
69
70 \fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fI*int_red_X\fP\fB, png_fixed_point \fP\fI*int_red_Y\fP\fB, png_fixed_point \fP\fI*int_red_Z\fP\fB, png_fixed_point \fP\fI*int_green_X\fP\fB, png_fixed_point \fP\fI*int_green_Y\fP\fB, png_fixed_point \fP\fI*int_green_Z\fP\fB, png_fixed_point \fP\fI*int_blue_X\fP\fB, png_fixed_point \fP\fI*int_blue_Y\fP\fB, png_fixed_point \fI*int_blue_Z\fP\fB);\fP
71
72 \fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
73
74 \fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP
75
76 \fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
77
78 \fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP
79
80 \fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
81
82 \fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP
83
84 \fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP
85
86 \fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
87
88 \fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
89
90 \fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
91
92 \fBpng_uint_32 png_get_gAMA (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
93
94 \fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
95
96 \fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
97
98 \fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP
99
100 \fBpng_uint_32 png_get_hIST (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
101
102 \fBpng_uint_32 png_get_iCCP (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_bytepp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
103
104 \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
105
106 \fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
107
108 \fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
109
110 \fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
111
112 \fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
113
114 \fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
115
116 \fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
117
118 \fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
119
120 \fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
121
122 \fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
123
124 \fBpng_uint_32 png_get_oFFs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
125
126 \fBpng_uint_32 png_get_pCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
127
128 \fBpng_uint_32 png_get_pHYs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
129
130 \fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
131
132 \fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
133
134 \fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
135
136 \fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
137
138 \fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
139
140 \fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
141
142 \fBpng_uint_32 png_get_PLTE (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
143
144 \fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr\fP\fB);\fP
145
146 \fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
147
148 \fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
149
150 \fBpng_uint_32 png_get_sBIT (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
151
152 \fBvoid png_get_sCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, double* \fP\fIwidth\fP\fB, double* \fIheight\fP\fB);\fP
153
154 \fBvoid png_get_sCAL_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_fixed_pointp \fP\fIwidth\fP\fB, png_fixed_pointp \fIheight\fP\fB);\fP
155
156 \fBvoid png_get_sCAL_s (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_charpp \fP\fIwidth\fP\fB, png_charpp \fIheight\fP\fB);\fP
157
158 \fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
159
160 \fBpng_uint_32 png_get_sPLT (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
161
162 \fBpng_uint_32 png_get_sRGB (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int \fI*file_srgb_intent\fP\fB);\fP
163
164 \fBpng_uint_32 png_get_text (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
165
166 \fBpng_uint_32 png_get_tIME (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
167
168 \fBpng_uint_32 png_get_tRNS (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans_alpha\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_color\fP\fB);\fP
169
170 \fB/* This function is really an inline macro. \fI*/
171
172 \fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
173
174 \fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP
175
176 \fB/* This function is really an inline macro. \fI*/
177
178 \fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
179
180 \fBpng_uint_32 png_get_unknown_chunks (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
181
182 \fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
183
184 \fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
185
186 \fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
187
188 \fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
189
190 \fBpng_uint_32 png_get_valid (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
191
192 \fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
193
194 \fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
195
196 \fBpng_int_32 png_get_x_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
197
198 \fBpng_int_32 png_get_x_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
199
200 \fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
201
202 \fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
203
204 \fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
205
206 \fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
207
208 \fBpng_int_32 png_get_y_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
209
210 \fBpng_int_32 png_get_y_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
211
212 \fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
213
214 \fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
215
216 \fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
217
218 \fBint png_image_begin_read_from_file (png_imagep \fP\fIimage\fP\fB, const char \fI*file_name\fP\fB);\fP
219
220 \fBint png_image_begin_read_from_stdio (png_imagep \fP\fIimage\fP\fB, FILE* \fIfile\fP\fB);\fP
221
222 \fBint, png_image_begin_read_from_memory (png_imagep \fP\fIimage\fP\fB, png_const_voidp \fP\fImemory\fP\fB, png_size_t \fIsize\fP\fB);\fP
223
224 \fBint png_image_finish_read (png_imagep \fP\fIimage\fP\fB, png_colorp \fP\fIbackground\fP\fB, void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap\fP\fB);\fP
225
226 \fBvoid png_image_free (png_imagep \fIimage\fP\fB);\fP
227
228 \fBint png_image_write_to_file (png_imagep \fP\fIimage\fP\fB, const char \fP\fI*file\fP\fB, int \fP\fIconvert_to_8bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap\fP\fB);\fP
229
230 \fBint png_image_write_to_stdio (png_imagep \fP\fIimage\fP\fB, FILE \fP\fI*file\fP\fB, int \fP\fIconvert_to_8_bit\fP\fB, const void \fP\fI*buffer\fP\fB, png_int_32 \fP\fIrow_stride\fP\fB, void \fI*colormap)\fP\fB);\fP
231
232 \fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
233
234 \fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
235
236 \fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
237
238 \fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
239
240 \fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
241
242 \fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
243
244 \fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP
245
246 \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
247
248 \fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
249
250 \fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
251
252 \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
253
254 \fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
255
256 \fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
257
258 \fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
259
260 \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
261
262 \fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
263
264 \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
265
266 \fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
267
268 \fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
269
270 \fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
271
272 \fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
273
274 \fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
275
276 \fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
277
278 \fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP
279
280 \fBvoid png_set_alpha_mode_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, png_fixed_point \fIoutput_gamma\fP\fB);\fP
281
282 \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
283
284 \fBvoid png_set_background_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, png_uint_32 \fIbackground_gamma\fP\fB);\fP
285
286 \fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
287
288 \fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
289
290 \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
291
292 \fBvoid png_set_check_for_invalid_index(png_structrp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
293
294 \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
295
296 \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
297
298 \fBvoid png_set_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIred_X\fP\fB, double \fP\fIred_Y\fP\fB, double \fP\fIred_Z\fP\fB, double \fP\fIgreen_X\fP\fB, double \fP\fIgreen_Y\fP\fB, double \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP
299
300 \fBvoid png_set_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fIint_red_X\fP\fB, png_fixed_point \fP\fIint_red_Y\fP\fB, png_fixed_point \fP\fIint_red_Z\fP\fB, png_fixed_point \fP\fIint_green_X\fP\fB, png_fixed_point \fP\fIint_green_Y\fP\fB, png_fixed_point \fP\fIint_green_Z\fP\fB, png_fixed_point \fP\fIint_blue_X\fP\fB, png_fixed_point \fP\fIint_blue_Y\fP\fB, png_fixed_point \fIint_blue_Z\fP\fB);\fP
301
302 \fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
303
304 \fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
305
306 \fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
307
308 \fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
309
310 \fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
311
312 \fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
313
314 \fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
315
316 \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
317
318 \fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
319
320 \fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
321
322 \fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
323
324 \fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
325
326 \fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
327
328 \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
329
330 \fBvoid png_set_filter_heuristics_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_fixed_point_p \fP\fIfilter_weights\fP\fB, png_fixed_point_p \fIfilter_costs\fP\fB);\fP
331
332 \fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
333
334 \fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
335
336 \fBvoid png_set_gamma_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIscreen_gamma\fP\fB, png_uint_32 \fIdefault_file_gamma\fP\fB);\fP
337
338 \fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
339
340 \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
341
342 \fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
343
344 \fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
345
346 \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
347
348 \fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_const_bytep \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
349
350 \fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
351
352 \fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
353
354 \fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
355
356 \fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
357
358 \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
359
360 \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
361
362 \fBjmp_buf* png_set_longjmp_fn (png_structp \fP\fIpng_ptr\fP\fB, png_longjmp_ptr \fP\fIlongjmp_fn\fP\fB, size_t \fIjmp_buf_size\fP\fB);\fP
363
364 \fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
365
366 \fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
367
368 \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
369
370 \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
371
372 \fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
373
374 \fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
375
376 \fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
377
378 \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
379
380 \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
381
382 \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
383
384 \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
385
386 \fBvoid png_set_quantize (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_quantize\fP\fB);\fP
387
388 \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
389
390 \fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
391
392 \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
393
394 \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
395
396 \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
397
398 \fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_uint_32 \fP\fIred\fP\fB, png_uint_32 \fIgreen\fP\fB);\fP
399
400 \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
401
402 \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
403
404 \fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
405
406 \fBvoid png_set_sCAL_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_fixed_point \fP\fIwidth\fP\fB, png_fixed_point \fIheight\fP\fB);\fP
407
408 \fBvoid png_set_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
409
410 \fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
411
412 \fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
413
414 \fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
415
416 \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
417
418 \fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
419
420 \fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
421
422 \fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
423
424 \fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
425
426 \fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
427
428 \fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
429
430 \fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
431
432 \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
433
434 \fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
435
436 \fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
437
438 \fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
439
440 \fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
441
442 \fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
443
444 \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
445
446 \fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans_alpha\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP
447
448 \fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
449
450 \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
451
452 \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
453
454 \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
455
456 \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
457
458 \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
459
460 \fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
461
462 \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
463
464 \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
465
466 \fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
467
468 \fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
469
470 \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
471
472 \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
473
474 \fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
475
476 \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
477
478 \fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
479
480 \fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
481
482 \fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
483
484 \fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
485
486 \fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
487
488 \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
489
490 \fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
491
492 \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
493
494 \fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
495
496 .SH DESCRIPTION
497 The
498 .I libpng
499 library supports encoding, decoding, and various manipulations of
500 the Portable Network Graphics (PNG) format image files. It uses the
501 .IR zlib(3)
502 compression library.
503 Following is a copy of the libpng-manual.txt file that accompanies libpng.
504 .SH LIBPNG.TXT
505 libpng-manual.txt - A description on how to use and modify libpng
506
507 libpng version 1.6.2 - April 25, 2013
508 Updated and distributed by Glenn Randers-Pehrson
509 <glennrp at users.sourceforge.net>
510 Copyright (c) 1998-2013 Glenn Randers-Pehrson
511
512 This document is released under the libpng license.
513 For conditions of distribution and use, see the disclaimer
514 and license in png.h
515
516 Based on:
517
518 libpng versions 0.97, January 1998, through 1.6.2 - April 25, 2013
519 Updated and distributed by Glenn Randers-Pehrson
520 Copyright (c) 1998-2013 Glenn Randers-Pehrson
521
522 libpng 1.0 beta 6 version 0.96 May 28, 1997
523 Updated and distributed by Andreas Dilger
524 Copyright (c) 1996, 1997 Andreas Dilger
525
526 libpng 1.0 beta 2 - version 0.88 January 26, 1996
527 For conditions of distribution and use, see copyright
528 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
529 Schalnat, Group 42, Inc.
530
531 Updated/rewritten per request in the libpng FAQ
532 Copyright (c) 1995, 1996 Frank J. T. Wojcik
533 December 18, 1995 & January 20, 1996
534
535 TABLE OF CONTENTS
536
537 I. Introduction
538 II. Structures
539 III. Reading
540 IV. Writing
541 V. Simplified API
542 VI. Modifying/Customizing libpng
543 VII. MNG support
544 VIII. Changes to Libpng from version 0.88
545 IX. Changes to Libpng from version 1.0.x to 1.2.x
546 X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
547 XI. Changes to Libpng from version 1.4.x to 1.5.x
548 XII. Changes to Libpng from version 1.5.x to 1.6.x
549 XIII. Detecting libpng
550 XIV. Source code repository
551 XV. Coding style
552 XVI. Y2K Compliance in libpng
553
554 .SH I. Introduction
555
556 This file describes how to use and modify the PNG reference library
557 (known as libpng) for your own use. There are five sections to this
558 file: introduction, structures, reading, writing, and modification and
559 configuration notes for various special platforms. In addition to this
560 file, example.c is a good starting point for using the library, as
561 it is heavily commented and should include everything most people
562 will need. We assume that libpng is already installed; see the
563 INSTALL file for instructions on how to install libpng.
564
565 For examples of libpng usage, see the files "example.c", "pngtest.c",
566 and the files in the "contrib" directory, all of which are included in
567 the libpng distribution.
568
569 Libpng was written as a companion to the PNG specification, as a way
570 of reducing the amount of time and effort it takes to support the PNG
571 file format in application programs.
572
573 The PNG specification (second edition), November 2003, is available as
574 a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at
575 <http://www.w3.org/TR/2003/REC-PNG-20031110/
576 The W3C and ISO documents have identical technical content.
577
578 The PNG-1.2 specification is available at
579 <http://www.libpng.org/pub/png/documents/>. It is technically equivalent
580 to the PNG specification (second edition) but has some additional material.
581
582 The PNG-1.0 specification is available
583 as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
584 W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
585
586 Some additional chunks are described in the special-purpose public chunks
587 documents at <http://www.libpng.org/pub/png/documents/>.
588
589 Other information
590 about PNG, and the latest version of libpng, can be found at the PNG home
591 page, <http://www.libpng.org/pub/png/>.
592
593 Most users will not have to modify the library significantly; advanced
594 users may want to modify it more. All attempts were made to make it as
595 complete as possible, while keeping the code easy to understand.
596 Currently, this library only supports C. Support for other languages
597 is being considered.
598
599 Libpng has been designed to handle multiple sessions at one time,
600 to be easily modifiable, to be portable to the vast majority of
601 machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
602 to use. The ultimate goal of libpng is to promote the acceptance of
603 the PNG file format in whatever way possible. While there is still
604 work to be done (see the TODO file), libpng should cover the
605 majority of the needs of its users.
606
607 Libpng uses zlib for its compression and decompression of PNG files.
608 Further information about zlib, and the latest version of zlib, can
609 be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
610 The zlib compression utility is a general purpose utility that is
611 useful for more than PNG files, and can be used without libpng.
612 See the documentation delivered with zlib for more details.
613 You can usually find the source files for the zlib utility wherever you
614 find the libpng source files.
615
616 Libpng is thread safe, provided the threads are using different
617 instances of the structures. Each thread should have its own
618 png_struct and png_info instances, and thus its own image.
619 Libpng does not protect itself against two threads using the
620 same instance of a structure.
621
622 .SH II. Structures
623
624 There are two main structures that are important to libpng, png_struct
625 and png_info. Both are internal structures that are no longer exposed
626 in the libpng interface (as of libpng 1.5.0).
627
628 The png_info structure is designed to provide information about the
629 PNG file. At one time, the fields of png_info were intended to be
630 directly accessible to the user. However, this tended to cause problems
631 with applications using dynamically loaded libraries, and as a result
632 a set of interface functions for png_info (the png_get_*() and png_set_*()
633 functions) was developed, and direct access to the png_info fields was
634 deprecated..
635
636 The png_struct structure is the object used by the library to decode a
637 single image. As of 1.5.0 this structure is also not exposed.
638
639 Almost all libpng APIs require a pointer to a png_struct as the first argument.
640 Many (in particular the png_set and png_get APIs) also require a pointer
641 to png_info as the second argument. Some application visible macros
642 defined in png.h designed for basic data access (reading and writing
643 integers in the PNG format) don't take a png_info pointer, but it's almost
644 always safe to assume that a (png_struct*) has to be passed to call an API
645 function.
646
647 You can have more than one png_info structure associated with an image,
648 as illustrated in pngtest.c, one for information valid prior to the
649 IDAT chunks and another (called "end_info" below) for things after them.
650
651 The png.h header file is an invaluable reference for programming with libpng.
652 And while I'm on the topic, make sure you include the libpng header file:
653
654 #include <png.h>
655
656 and also (as of libpng-1.5.0) the zlib header file, if you need it:
657
658 #include <zlib.h>
659
660 .SS Types
661
662 The png.h header file defines a number of integral types used by the
663 APIs. Most of these are fairly obvious; for example types corresponding
664 to integers of particular sizes and types for passing color values.
665
666 One exception is how non-integral numbers are handled. For application
667 convenience most APIs that take such numbers have C (double) arguments;
668 however, internally PNG, and libpng, use 32 bit signed integers and encode
669 the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
670 macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
671 which is simply (png_int_32).
672
673 All APIs that take (double) arguments also have a matching API that
674 takes the corresponding fixed point integer arguments. The fixed point
675 API has the same name as the floating point one with "_fixed" appended.
676 The actual range of values permitted in the APIs is frequently less than
677 the full range of (png_fixed_point) (-21474 to +21474). When APIs require
678 a non-negative argument the type is recorded as png_uint_32 above. Consult
679 the header file and the text below for more information.
680
681 Special care must be take with sCAL chunk handling because the chunk itself
682 uses non-integral values encoded as strings containing decimal floating point
683 numbers. See the comments in the header file.
684
685 .SS Configuration
686
687 The main header file function declarations are frequently protected by C
688 preprocessing directives of the form:
689
690 #ifdef PNG_feature_SUPPORTED
691 declare-function
692 #endif
693 ...
694 #ifdef PNG_feature_SUPPORTED
695 use-function
696 #endif
697
698 The library can be built without support for these APIs, although a
699 standard build will have all implemented APIs. Application programs
700 should check the feature macros before using an API for maximum
701 portability. From libpng 1.5.0 the feature macros set during the build
702 of libpng are recorded in the header file "pnglibconf.h" and this file
703 is always included by png.h.
704
705 If you don't need to change the library configuration from the default, skip to
706 the next section ("Reading").
707
708 Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
709 of the build project files in the 'projects' directory simply copy
710 scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
711 systems do not permit easy auto-configuration of the library - they only
712 support the default configuration.
713
714 The easiest way to make minor changes to the libpng configuration when
715 auto-configuration is supported is to add definitions to the command line
716 using (typically) CPPFLAGS. For example:
717
718 CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
719
720 will change the internal libpng math implementation for gamma correction and
721 other arithmetic calculations to fixed point, avoiding the need for fast
722 floating point support. The result can be seen in the generated pnglibconf.h -
723 make sure it contains the changed feature macro setting.
724
725 If you need to make more extensive configuration changes - more than one or two
726 feature macro settings - you can either add -DPNG_USER_CONFIG to the build
727 command line and put a list of feature macro settings in pngusr.h or you can set
728 DFA_XTRA (a makefile variable) to a file containing the same information in the
729 form of 'option' settings.
730
731 A. Changing pnglibconf.h
732
733 A variety of methods exist to build libpng. Not all of these support
734 reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
735 rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
736
737 Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
738 pnglibconf.h and changing the lines defining the supported features, paying
739 very close attention to the 'option' information in scripts/pnglibconf.dfa
740 that describes those features and their requirements. This is easy to get
741 wrong.
742
743 B. Configuration using DFA_XTRA
744
745 Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
746 variant such as 'nawk' or 'gawk', is available. The configure build will
747 automatically find an appropriate awk and build pnglibconf.h.
748 The scripts/pnglibconf.mak file contains a set of make rules for doing the
749 same thing if configure is not used, and many of the makefiles in the scripts
750 directory use this approach.
751
752 When rebuilding simply write a new file containing changed options and set
753 DFA_XTRA to the name of this file. This causes the build to append the new file
754 to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
755 of the following forms:
756
757 everything = off
758
759 This turns all optional features off. Include it at the start of pngusr.dfa to
760 make it easier to build a minimal configuration. You will need to turn at least
761 some features on afterward to enable either reading or writing code, or both.
762
763 option feature on
764 option feature off
765
766 Enable or disable a single feature. This will automatically enable other
767 features required by a feature that is turned on or disable other features that
768 require a feature which is turned off. Conflicting settings will cause an error
769 message to be emitted by awk.
770
771 setting feature default value
772
773 Changes the default value of setting 'feature' to 'value'. There are a small
774 number of settings listed at the top of pnglibconf.h, they are documented in the
775 source code. Most of these values have performance implications for the library
776 but most of them have no visible effect on the API. Some can also be overridden
777 from the API.
778
779 This method of building a customized pnglibconf.h is illustrated in
780 contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
781 pngusr.dfa in these directories.
782
783 C. Configuration using PNG_USR_CONFIG
784
785 If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
786 pngusr.h will automatically be included before the options in
787 scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
788 macro definitions turning features on or off or setting settings.
789
790 Apart from the global setting "everything = off" all the options listed above
791 can be set using macros in pngusr.h:
792
793 #define PNG_feature_SUPPORTED
794
795 is equivalent to:
796
797 option feature on
798
799 #define PNG_NO_feature
800
801 is equivalent to:
802
803 option feature off
804
805 #define PNG_feature value
806
807 is equivalent to:
808
809 setting feature default value
810
811 Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
812 pngusr file you supply override the contents of scripts/pnglibconf.dfa
813
814 If confusing or incomprehensible behavior results it is possible to
815 examine the intermediate file pnglibconf.dfn to find the full set of
816 dependency information for each setting and option. Simply locate the
817 feature in the file and read the C comments that precede it.
818
819 This method is also illustrated in the contrib/pngminim/* makefiles and
820 pngusr.h.
821
822 .SH III. Reading
823
824 We'll now walk you through the possible functions to call when reading
825 in a PNG file sequentially, briefly explaining the syntax and purpose
826 of each one. See example.c and png.h for more detail. While
827 progressive reading is covered in the next section, you will still
828 need some of the functions discussed in this section to read a PNG
829 file.
830
831 .SS Setup
832
833 You will want to do the I/O initialization(*) before you get into libpng,
834 so if it doesn't work, you don't have much to undo. Of course, you
835 will also want to insure that you are, in fact, dealing with a PNG
836 file. Libpng provides a simple check to see if a file is a PNG file.
837 To use it, pass in the first 1 to 8 bytes of the file to the function
838 png_sig_cmp(), and it will return 0 (false) if the bytes match the
839 corresponding bytes of the PNG signature, or nonzero (true) otherwise.
840 Of course, the more bytes you pass in, the greater the accuracy of the
841 prediction.
842
843 If you are intending to keep the file pointer open for use in libpng,
844 you must ensure you don't read more than 8 bytes from the beginning
845 of the file, and you also have to make a call to png_set_sig_bytes_read()
846 with the number of bytes you read from the beginning. Libpng will
847 then only check the bytes (if any) that your program didn't read.
848
849 (*): If you are not using the standard I/O functions, you will need
850 to replace them with custom functions. See the discussion under
851 Customizing libpng.
852
853
854 FILE *fp = fopen(file_name, "rb");
855 if (!fp)
856 {
857 return (ERROR);
858 }
859
860 fread(header, 1, number, fp);
861 is_png = !png_sig_cmp(header, 0, number);
862
863 if (!is_png)
864 {
865 return (NOT_PNG);
866 }
867
868
869 Next, png_struct and png_info need to be allocated and initialized. In
870 order to ensure that the size of these structures is correct even with a
871 dynamically linked libpng, there are functions to initialize and
872 allocate the structures. We also pass the library version, optional
873 pointers to error handling functions, and a pointer to a data struct for
874 use by the error functions, if necessary (the pointer and functions can
875 be NULL if the default error handlers are to be used). See the section
876 on Changes to Libpng below regarding the old initialization functions.
877 The structure allocation functions quietly return NULL if they fail to
878 create the structure, so your application should check for that.
879
880 png_structp png_ptr = png_create_read_struct
881 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
882 user_error_fn, user_warning_fn);
883
884 if (!png_ptr)
885 return (ERROR);
886
887 png_infop info_ptr = png_create_info_struct(png_ptr);
888
889 if (!info_ptr)
890 {
891 png_destroy_read_struct(&png_ptr,
892 (png_infopp)NULL, (png_infopp)NULL);
893 return (ERROR);
894 }
895
896 If you want to use your own memory allocation routines,
897 use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
898 png_create_read_struct_2() instead of png_create_read_struct():
899
900 png_structp png_ptr = png_create_read_struct_2
901 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
902 user_error_fn, user_warning_fn, (png_voidp)
903 user_mem_ptr, user_malloc_fn, user_free_fn);
904
905 The error handling routines passed to png_create_read_struct()
906 and the memory alloc/free routines passed to png_create_struct_2()
907 are only necessary if you are not using the libpng supplied error
908 handling and memory alloc/free functions.
909
910 When libpng encounters an error, it expects to longjmp back
911 to your routine. Therefore, you will need to call setjmp and pass
912 your png_jmpbuf(png_ptr). If you read the file from different
913 routines, you will need to update the longjmp buffer every time you enter
914 a new routine that will call a png_*() function.
915
916 See your documentation of setjmp/longjmp for your compiler for more
917 information on setjmp/longjmp. See the discussion on libpng error
918 handling in the Customizing Libpng section below for more information
919 on the libpng error handling. If an error occurs, and libpng longjmp's
920 back to your setjmp, you will want to call png_destroy_read_struct() to
921 free any memory.
922
923 if (setjmp(png_jmpbuf(png_ptr)))
924 {
925 png_destroy_read_struct(&png_ptr, &info_ptr,
926 &end_info);
927 fclose(fp);
928 return (ERROR);
929 }
930
931 Pass (png_infopp)NULL instead of &end_info if you didn't create
932 an end_info structure.
933
934 If you would rather avoid the complexity of setjmp/longjmp issues,
935 you can compile libpng with PNG_NO_SETJMP, in which case
936 errors will result in a call to PNG_ABORT() which defaults to abort().
937
938 You can #define PNG_ABORT() to a function that does something
939 more useful than abort(), as long as your function does not
940 return.
941
942 Now you need to set up the input code. The default for libpng is to
943 use the C function fread(). If you use this, you will need to pass a
944 valid FILE * in the function png_init_io(). Be sure that the file is
945 opened in binary mode. If you wish to handle reading data in another
946 way, you need not call the png_init_io() function, but you must then
947 implement the libpng I/O methods discussed in the Customizing Libpng
948 section below.
949
950 png_init_io(png_ptr, fp);
951
952 If you had previously opened the file and read any of the signature from
953 the beginning in order to see if this was a PNG file, you need to let
954 libpng know that there are some bytes missing from the start of the file.
955
956 png_set_sig_bytes(png_ptr, number);
957
958 You can change the zlib compression buffer size to be used while
959 reading compressed data with
960
961 png_set_compression_buffer_size(png_ptr, buffer_size);
962
963 where the default size is 8192 bytes. Note that the buffer size
964 is changed immediately and the buffer is reallocated immediately,
965 instead of setting a flag to be acted upon later.
966
967 If you want CRC errors to be handled in a different manner than
968 the default, use
969
970 png_set_crc_action(png_ptr, crit_action, ancil_action);
971
972 The values for png_set_crc_action() say how libpng is to handle CRC errors in
973 ancillary and critical chunks, and whether to use the data contained
974 therein. Note that it is impossible to "discard" data in a critical
975 chunk.
976
977 Choices for (int) crit_action are
978 PNG_CRC_DEFAULT 0 error/quit
979 PNG_CRC_ERROR_QUIT 1 error/quit
980 PNG_CRC_WARN_USE 3 warn/use data
981 PNG_CRC_QUIET_USE 4 quiet/use data
982 PNG_CRC_NO_CHANGE 5 use the current value
983
984 Choices for (int) ancil_action are
985 PNG_CRC_DEFAULT 0 error/quit
986 PNG_CRC_ERROR_QUIT 1 error/quit
987 PNG_CRC_WARN_DISCARD 2 warn/discard data
988 PNG_CRC_WARN_USE 3 warn/use data
989 PNG_CRC_QUIET_USE 4 quiet/use data
990 PNG_CRC_NO_CHANGE 5 use the current value
991
992 .SS Setting up callback code
993
994 You can set up a callback function to handle any unknown chunks in the
995 input stream. You must supply the function
996
997 read_chunk_callback(png_structp png_ptr,
998 png_unknown_chunkp chunk);
999 {
1000 /* The unknown chunk structure contains your
1001 chunk data, along with similar data for any other
1002 unknown chunks: */
1003
1004 png_byte name[5];
1005 png_byte *data;
1006 png_size_t size;
1007
1008 /* Note that libpng has already taken care of
1009 the CRC handling */
1010
1011 /* put your code here. Search for your chunk in the
1012 unknown chunk structure, process it, and return one
1013 of the following: */
1014
1015 return (-n); /* chunk had an error */
1016 return (0); /* did not recognize */
1017 return (n); /* success */
1018 }
1019
1020 (You can give your function another name that you like instead of
1021 "read_chunk_callback")
1022
1023 To inform libpng about your function, use
1024
1025 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1026 read_chunk_callback);
1027
1028 This names not only the callback function, but also a user pointer that
1029 you can retrieve with
1030
1031 png_get_user_chunk_ptr(png_ptr);
1032
1033 If you call the png_set_read_user_chunk_fn() function, then all unknown
1034 chunks which the callback does not handle will be saved when read. You can
1035 cause them to be discarded by returning '1' ("handled") instead of '0'. This
1036 behavior will change in libpng 1.7 and the default handling set by the
1037 png_set_keep_unknown_chunks() function, described below, will be used when the
1038 callback returns 0. If you want the existing behavior you should set the global
1039 default to PNG_HANDLE_CHUNK_IF_SAFE now; this is compatible with all current
1040 versions of libpng and with 1.7. Libpng 1.6 issues a warning if you keep the
1041 default, or PNG_HANDLE_CHUNK_NEVER, and the callback returns 0.
1042
1043 At this point, you can set up a callback function that will be
1044 called after each row has been read, which you can use to control
1045 a progress meter or the like. It's demonstrated in pngtest.c.
1046 You must supply a function
1047
1048 void read_row_callback(png_structp png_ptr,
1049 png_uint_32 row, int pass);
1050 {
1051 /* put your code here */
1052 }
1053
1054 (You can give it another name that you like instead of "read_row_callback")
1055
1056 To inform libpng about your function, use
1057
1058 png_set_read_status_fn(png_ptr, read_row_callback);
1059
1060 When this function is called the row has already been completely processed and
1061 the 'row' and 'pass' refer to the next row to be handled. For the
1062 non-interlaced case the row that was just handled is simply one less than the
1063 passed in row number, and pass will always be 0. For the interlaced case the
1064 same applies unless the row value is 0, in which case the row just handled was
1065 the last one from one of the preceding passes. Because interlacing may skip a
1066 pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1067 need to know what the last pass is record (row,pass) from the callback and use
1068 the last recorded value each time.
1069
1070 As with the user transform you can find the output row using the
1071 PNG_ROW_FROM_PASS_ROW macro.
1072
1073 .SS Unknown-chunk handling
1074
1075 Now you get to set the way the library processes unknown chunks in the
1076 input PNG stream. Both known and unknown chunks will be read. Normal
1077 behavior is that known chunks will be parsed into information in
1078 various info_ptr members while unknown chunks will be discarded. This
1079 behavior can be wasteful if your application will never use some known
1080 chunk types. To change this, you can call:
1081
1082 png_set_keep_unknown_chunks(png_ptr, keep,
1083 chunk_list, num_chunks);
1084
1085 keep - 0: default unknown chunk handling
1086 1: ignore; do not keep
1087 2: keep only if safe-to-copy
1088 3: keep even if unsafe-to-copy
1089
1090 You can use these definitions:
1091 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1092 PNG_HANDLE_CHUNK_NEVER 1
1093 PNG_HANDLE_CHUNK_IF_SAFE 2
1094 PNG_HANDLE_CHUNK_ALWAYS 3
1095
1096 chunk_list - list of chunks affected (a byte string,
1097 five bytes per chunk, NULL or '\0' if
1098 num_chunks is positive; ignored if
1099 numchunks <= 0).
1100
1101 num_chunks - number of chunks affected; if 0, all
1102 unknown chunks are affected. If positive,
1103 only the chunks in the list are affected,
1104 and if negative all unknown chunks and
1105 all known chunks except for the IHDR,
1106 PLTE, tRNS, IDAT, and IEND chunks are
1107 affected.
1108
1109 Unknown chunks declared in this way will be saved as raw data onto a
1110 list of png_unknown_chunk structures. If a chunk that is normally
1111 known to libpng is named in the list, it will be handled as unknown,
1112 according to the "keep" directive. If a chunk is named in successive
1113 instances of png_set_keep_unknown_chunks(), the final instance will
1114 take precedence. The IHDR and IEND chunks should not be named in
1115 chunk_list; if they are, libpng will process them normally anyway.
1116 If you know that your application will never make use of some particular
1117 chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
1118
1119 Here is an example of the usage of png_set_keep_unknown_chunks(),
1120 where the private "vpAg" chunk will later be processed by a user chunk
1121 callback function:
1122
1123 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1124
1125 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1126 png_byte unused_chunks[]=
1127 {
1128 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1129 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1130 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1131 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1132 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1133 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1134 };
1135 #endif
1136
1137 ...
1138
1139 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1140 /* ignore all unknown chunks
1141 * (use global setting "2" for libpng16 and earlier):
1142 */
1143 png_set_keep_unknown_chunks(read_ptr, 2, NULL, 0);
1144
1145 /* except for vpAg: */
1146 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
1147
1148 /* also ignore unused known chunks: */
1149 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1150 (int)(sizeof unused_chunks)/5);
1151 #endif
1152
1153 .SS User limits
1154
1155 The PNG specification allows the width and height of an image to be as
1156 large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1157 Since very few applications really need to process such large images,
1158 we have imposed an arbitrary 1-million limit on rows and columns.
1159 Larger images will be rejected immediately with a png_error() call. If
1160 you wish to change this limit, you can use
1161
1162 png_set_user_limits(png_ptr, width_max, height_max);
1163
1164 to set your own limits, or use width_max = height_max = 0x7fffffffL
1165 to allow all valid dimensions (libpng may reject some very large images
1166 anyway because of potential buffer overflow conditions).
1167
1168 You should put this statement after you create the PNG structure and
1169 before calling png_read_info(), png_read_png(), or png_process_data().
1170
1171 When writing a PNG datastream, put this statement before calling
1172 png_write_info() or png_write_png().
1173
1174 If you need to retrieve the limits that are being applied, use
1175
1176 width_max = png_get_user_width_max(png_ptr);
1177 height_max = png_get_user_height_max(png_ptr);
1178
1179 The PNG specification sets no limit on the number of ancillary chunks
1180 allowed in a PNG datastream. You can impose a limit on the total number
1181 of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1182
1183 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1184
1185 where 0x7fffffffL means unlimited. You can retrieve this limit with
1186
1187 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1188
1189 You can also set a limit on the amount of memory that a compressed chunk
1190 other than IDAT can occupy, with
1191
1192 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1193
1194 and you can retrieve the limit with
1195
1196 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1197
1198 Any chunks that would cause either of these limits to be exceeded will
1199 be ignored.
1200
1201 .SS Information about your system
1202
1203 If you intend to display the PNG or to incorporate it in other image data you
1204 need to tell libpng information about your display or drawing surface so that
1205 libpng can convert the values in the image to match the display.
1206
1207 From libpng-1.5.4 this information can be set before reading the PNG file
1208 header. In earlier versions png_set_gamma() existed but behaved incorrectly if
1209 called before the PNG file header had been read and png_set_alpha_mode() did not
1210 exist.
1211
1212 If you need to support versions prior to libpng-1.5.4 test the version number
1213 as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1214 described in the appropriate manual page.
1215
1216 You give libpng the encoding expected by your system expressed as a 'gamma'
1217 value. You can also specify a default encoding for the PNG file in
1218 case the required information is missing from the file. By default libpng
1219 assumes that the PNG data matches your system, to keep this default call:
1220
1221 png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
1222
1223 or you can use the fixed point equivalent:
1224
1225 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma,
1226 PNG_FP_1/screen_gamma);
1227
1228 If you don't know the gamma for your system it is probably 2.2 - a good
1229 approximation to the IEC standard for display systems (sRGB). If images are
1230 too contrasty or washed out you got the value wrong - check your system
1231 documentation!
1232
1233 Many systems permit the system gamma to be changed via a lookup table in the
1234 display driver, a few systems, including older Macs, change the response by
1235 default. As of 1.5.4 three special values are available to handle common
1236 situations:
1237
1238 PNG_DEFAULT_sRGB: Indicates that the system conforms to the
1239 IEC 61966-2-1 standard. This matches almost
1240 all systems.
1241 PNG_GAMMA_MAC_18: Indicates that the system is an older
1242 (pre Mac OS 10.6) Apple Macintosh system with
1243 the default settings.
1244 PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates
1245 that the system expects data with no gamma
1246 encoding.
1247
1248 You would use the linear (unencoded) value if you need to process the pixel
1249 values further because this avoids the need to decode and reencode each
1250 component value whenever arithmetic is performed. A lot of graphics software
1251 uses linear values for this reason, often with higher precision component values
1252 to preserve overall accuracy.
1253
1254 The second thing you may need to tell libpng about is how your system handles
1255 alpha channel information. Some, but not all, PNG files contain an alpha
1256 channel. To display these files correctly you need to compose the data onto a
1257 suitable background, as described in the PNG specification.
1258
1259 Libpng only supports composing onto a single color (using png_set_background;
1260 see below). Otherwise you must do the composition yourself and, in this case,
1261 you may need to call png_set_alpha_mode:
1262
1263 #if PNG_LIBPNG_VER >= 10504
1264 png_set_alpha_mode(png_ptr, mode, screen_gamma);
1265 #else
1266 png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);
1267 #endif
1268
1269 The screen_gamma value is the same as the argument to png_set_gamma; however,
1270 how it affects the output depends on the mode. png_set_alpha_mode() sets the
1271 file gamma default to 1/screen_gamma, so normally you don't need to call
1272 png_set_gamma. If you need different defaults call png_set_gamma() before
1273 png_set_alpha_mode() - if you call it after it will override the settings made
1274 by png_set_alpha_mode().
1275
1276 The mode is as follows:
1277
1278 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
1279 green and blue, or gray, components are gamma encoded color
1280 values and are not premultiplied by the alpha value. The
1281 alpha value is a linear measure of the contribution of the
1282 pixel to the corresponding final output pixel.
1283
1284 You should normally use this format if you intend to perform
1285 color correction on the color values; most, maybe all, color
1286 correction software has no handling for the alpha channel and,
1287 anyway, the math to handle pre-multiplied component values is
1288 unnecessarily complex.
1289
1290 Before you do any arithmetic on the component values you need
1291 to remove the gamma encoding and multiply out the alpha
1292 channel. See the PNG specification for more detail. It is
1293 important to note that when an image with an alpha channel is
1294 scaled, linear encoded, pre-multiplied component values must
1295 be used!
1296
1297 The remaining modes assume you don't need to do any further color correction or
1298 that if you do, your color correction software knows all about alpha (it
1299 probably doesn't!)
1300
1301 PNG_ALPHA_STANDARD: The data libpng produces
1302 is encoded in the standard way
1303 assumed by most correctly written graphics software.
1304 The gamma encoding will be removed by libpng and the
1305 linear component values will be pre-multiplied by the
1306 alpha channel.
1307
1308 With this format the final image must be re-encoded to
1309 match the display gamma before the image is displayed.
1310 If your system doesn't do that, yet still seems to
1311 perform arithmetic on the pixels without decoding them,
1312 it is broken - check out the modes below.
1313
1314 With PNG_ALPHA_STANDARD libpng always produces linear
1315 component values, whatever screen_gamma you supply. The
1316 screen_gamma value is, however, used as a default for
1317 the file gamma if the PNG file has no gamma information.
1318
1319 If you call png_set_gamma() after png_set_alpha_mode() you
1320 will override the linear encoding. Instead the
1321 pre-multiplied pixel values will be gamma encoded but
1322 the alpha channel will still be linear. This may
1323 actually match the requirements of some broken software,
1324 but it is unlikely.
1325
1326 While linear 8-bit data is often used it has
1327 insufficient precision for any image with a reasonable
1328 dynamic range. To avoid problems, and if your software
1329 supports it, use png_set_expand_16() to force all
1330 components to 16 bits.
1331
1332 PNG_ALPHA_OPTIMIZED: This mode is the same
1333 as PNG_ALPHA_STANDARD except that
1334 completely opaque pixels are gamma encoded according to
1335 the screen_gamma value. Pixels with alpha less than 1.0
1336 will still have linear components.
1337
1338 Use this format if you have control over your
1339 compositing software and so don't do other arithmetic
1340 (such as scaling) on the data you get from libpng. Your
1341 compositing software can simply copy opaque pixels to
1342 the output but still has linear values for the
1343 non-opaque pixels.
1344
1345 In normal compositing, where the alpha channel encodes
1346 partial pixel coverage (as opposed to broad area
1347 translucency), the inaccuracies of the 8-bit
1348 representation of non-opaque pixels are irrelevant.
1349
1350 You can also try this format if your software is broken;
1351 it might look better.
1352
1353 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD;
1354 however, all component values,
1355 including the alpha channel are gamma encoded. This is
1356 an appropriate format to try if your software, or more
1357 likely hardware, is totally broken, i.e., if it performs
1358 linear arithmetic directly on gamma encoded values.
1359
1360 In most cases of broken software or hardware the bug in the final display
1361 manifests as a subtle halo around composited parts of the image. You may not
1362 even perceive this as a halo; the composited part of the image may simply appear
1363 separate from the background, as though it had been cut out of paper and pasted
1364 on afterward.
1365
1366 If you don't have to deal with bugs in software or hardware, or if you can fix
1367 them, there are three recommended ways of using png_set_alpha_mode():
1368
1369 png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
1370 screen_gamma);
1371
1372 You can do color correction on the result (libpng does not currently
1373 support color correction internally). When you handle the alpha channel
1374 you need to undo the gamma encoding and multiply out the alpha.
1375
1376 png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
1377 screen_gamma);
1378 png_set_expand_16(png_ptr);
1379
1380 If you are using the high level interface, don't call png_set_expand_16();
1381 instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
1382
1383 With this mode you can't do color correction, but you can do arithmetic,
1384 including composition and scaling, on the data without further processing.
1385
1386 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1387 screen_gamma);
1388
1389 You can avoid the expansion to 16-bit components with this mode, but you
1390 lose the ability to scale the image or perform other linear arithmetic.
1391 All you can do is compose the result onto a matching output. Since this
1392 mode is libpng-specific you also need to write your own composition
1393 software.
1394
1395 If you don't need, or can't handle, the alpha channel you can call
1396 png_set_background() to remove it by compositing against a fixed color. Don't
1397 call png_set_strip_alpha() to do this - it will leave spurious pixel values in
1398 transparent parts of this image.
1399
1400 png_set_background(png_ptr, &background_color,
1401 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
1402
1403 The background_color is an RGB or grayscale value according to the data format
1404 libpng will produce for you. Because you don't yet know the format of the PNG
1405 file, if you call png_set_background at this point you must arrange for the
1406 format produced by libpng to always have 8-bit or 16-bit components and then
1407 store the color as an 8-bit or 16-bit color as appropriate. The color contains
1408 separate gray and RGB component values, so you can let libpng produce gray or
1409 RGB output according to the input format, but low bit depth grayscale images
1410 must always be converted to at least 8-bit format. (Even though low bit depth
1411 grayscale images can't have an alpha channel they can have a transparent
1412 color!)
1413
1414 You set the transforms you need later, either as flags to the high level
1415 interface or libpng API calls for the low level interface. For reference the
1416 settings and API calls required are:
1417
1418 8-bit values:
1419 PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
1420 png_set_expand(png_ptr); png_set_scale_16(png_ptr);
1421
1422 If you must get exactly the same inaccurate results
1423 produced by default in versions prior to libpng-1.5.4,
1424 use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
1425 instead.
1426
1427 16-bit values:
1428 PNG_TRANSFORM_EXPAND_16
1429 png_set_expand_16(png_ptr);
1430
1431 In either case palette image data will be expanded to RGB. If you just want
1432 color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1433 to the list.
1434
1435 Calling png_set_background before the PNG file header is read will not work
1436 prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
1437 errors it is therefore much safer to call png_set_background after the head has
1438 been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
1439 used with the high level interface.
1440
1441 .SS The high-level read interface
1442
1443 At this point there are two ways to proceed; through the high-level
1444 read interface, or through a sequence of low-level read operations.
1445 You can use the high-level interface if (a) you are willing to read
1446 the entire image into memory, and (b) the input transformations
1447 you want to do are limited to the following set:
1448
1449 PNG_TRANSFORM_IDENTITY No transformation
1450 PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
1451 8-bit accurately
1452 PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
1453 8-bit less accurately
1454 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
1455 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1456 samples to bytes
1457 PNG_TRANSFORM_PACKSWAP Change order of packed
1458 pixels to LSB first
1459 PNG_TRANSFORM_EXPAND Perform set_expand()
1460 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
1461 PNG_TRANSFORM_SHIFT Normalize pixels to the
1462 sBIT depth
1463 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1464 to BGRA
1465 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1466 to AG
1467 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1468 to transparency
1469 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
1470 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1471 to RGB (or GA to RGBA)
1472 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
1473
1474 (This excludes setting a background color, doing gamma transformation,
1475 quantizing, and setting filler.) If this is the case, simply do this:
1476
1477 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1478
1479 where png_transforms is an integer containing the bitwise OR of some
1480 set of transformation flags. This call is equivalent to png_read_info(),
1481 followed the set of transformations indicated by the transform mask,
1482 then png_read_image(), and finally png_read_end().
1483
1484 (The final parameter of this call is not yet used. Someday it might point
1485 to transformation parameters required by some future input transform.)
1486
1487 You must use png_transforms and not call any png_set_transform() functions
1488 when you use png_read_png().
1489
1490 After you have called png_read_png(), you can retrieve the image data
1491 with
1492
1493 row_pointers = png_get_rows(png_ptr, info_ptr);
1494
1495 where row_pointers is an array of pointers to the pixel data for each row:
1496
1497 png_bytep row_pointers[height];
1498
1499 If you know your image size and pixel size ahead of time, you can allocate
1500 row_pointers prior to calling png_read_png() with
1501
1502 if (height > PNG_UINT_32_MAX/(sizeof (png_byte)))
1503 png_error (png_ptr,
1504 "Image is too tall to process in memory");
1505
1506 if (width > PNG_UINT_32_MAX/pixel_size)
1507 png_error (png_ptr,
1508 "Image is too wide to process in memory");
1509
1510 row_pointers = png_malloc(png_ptr,
1511 height*(sizeof (png_bytep)));
1512
1513 for (int i=0; i<height, i++)
1514 row_pointers[i]=NULL; /* security precaution */
1515
1516 for (int i=0; i<height, i++)
1517 row_pointers[i]=png_malloc(png_ptr,
1518 width*pixel_size);
1519
1520 png_set_rows(png_ptr, info_ptr, &row_pointers);
1521
1522 Alternatively you could allocate your image in one big block and define
1523 row_pointers[i] to point into the proper places in your block.
1524
1525 If you use png_set_rows(), the application is responsible for freeing
1526 row_pointers (and row_pointers[i], if they were separately allocated).
1527
1528 If you don't allocate row_pointers ahead of time, png_read_png() will
1529 do it, and it'll be free'ed by libpng when you call png_destroy_*().
1530
1531 .SS The low-level read interface
1532
1533 If you are going the low-level route, you are now ready to read all
1534 the file information up to the actual image data. You do this with a
1535 call to png_read_info().
1536
1537 png_read_info(png_ptr, info_ptr);
1538
1539 This will process all chunks up to but not including the image data.
1540
1541 This also copies some of the data from the PNG file into the decode structure
1542 for use in later transformations. Important information copied in is:
1543
1544 1) The PNG file gamma from the gAMA chunk. This overwrites the default value
1545 provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1546
1547 2) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
1548 damages the information provided by an earlier call to png_set_background
1549 resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
1550
1551 3) The number of significant bits in each component value. Libpng uses this to
1552 optimize gamma handling by reducing the internal lookup table sizes.
1553
1554 4) The transparent color information from a tRNS chunk. This can be modified by
1555 a later call to png_set_tRNS.
1556
1557 .SS Querying the info structure
1558
1559 Functions are used to get the information from the info_ptr once it
1560 has been read. Note that these fields may not be completely filled
1561 in until png_read_end() has read the chunk data following the image.
1562
1563 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1564 &bit_depth, &color_type, &interlace_type,
1565 &compression_type, &filter_method);
1566
1567 width - holds the width of the image
1568 in pixels (up to 2^31).
1569
1570 height - holds the height of the image
1571 in pixels (up to 2^31).
1572
1573 bit_depth - holds the bit depth of one of the
1574 image channels. (valid values are
1575 1, 2, 4, 8, 16 and depend also on
1576 the color_type. See also
1577 significant bits (sBIT) below).
1578
1579 color_type - describes which color/alpha channels
1580 are present.
1581 PNG_COLOR_TYPE_GRAY
1582 (bit depths 1, 2, 4, 8, 16)
1583 PNG_COLOR_TYPE_GRAY_ALPHA
1584 (bit depths 8, 16)
1585 PNG_COLOR_TYPE_PALETTE
1586 (bit depths 1, 2, 4, 8)
1587 PNG_COLOR_TYPE_RGB
1588 (bit_depths 8, 16)
1589 PNG_COLOR_TYPE_RGB_ALPHA
1590 (bit_depths 8, 16)
1591
1592 PNG_COLOR_MASK_PALETTE
1593 PNG_COLOR_MASK_COLOR
1594 PNG_COLOR_MASK_ALPHA
1595
1596 interlace_type - (PNG_INTERLACE_NONE or
1597 PNG_INTERLACE_ADAM7)
1598
1599 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1600 for PNG 1.0)
1601
1602 filter_method - (must be PNG_FILTER_TYPE_BASE
1603 for PNG 1.0, and can also be
1604 PNG_INTRAPIXEL_DIFFERENCING if
1605 the PNG datastream is embedded in
1606 a MNG-1.0 datastream)
1607
1608 Any or all of interlace_type, compression_type, or
1609 filter_method can be NULL if you are
1610 not interested in their values.
1611
1612 Note that png_get_IHDR() returns 32-bit data into
1613 the application's width and height variables.
1614 This is an unsafe situation if these are 16-bit
1615 variables. In such situations, the
1616 png_get_image_width() and png_get_image_height()
1617 functions described below are safer.
1618
1619 width = png_get_image_width(png_ptr,
1620 info_ptr);
1621
1622 height = png_get_image_height(png_ptr,
1623 info_ptr);
1624
1625 bit_depth = png_get_bit_depth(png_ptr,
1626 info_ptr);
1627
1628 color_type = png_get_color_type(png_ptr,
1629 info_ptr);
1630
1631 interlace_type = png_get_interlace_type(png_ptr,
1632 info_ptr);
1633
1634 compression_type = png_get_compression_type(png_ptr,
1635 info_ptr);
1636
1637 filter_method = png_get_filter_type(png_ptr,
1638 info_ptr);
1639
1640 channels = png_get_channels(png_ptr, info_ptr);
1641
1642 channels - number of channels of info for the
1643 color type (valid values are 1 (GRAY,
1644 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1645 4 (RGB_ALPHA or RGB + filler byte))
1646
1647 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1648
1649 rowbytes - number of bytes needed to hold a row
1650
1651 signature = png_get_signature(png_ptr, info_ptr);
1652
1653 signature - holds the signature read from the
1654 file (if any). The data is kept in
1655 the same offset it would be if the
1656 whole signature were read (i.e. if an
1657 application had already read in 4
1658 bytes of signature before starting
1659 libpng, the remaining 4 bytes would
1660 be in signature[4] through signature[7]
1661 (see png_set_sig_bytes())).
1662
1663 These are also important, but their validity depends on whether the chunk
1664 has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1665 png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1666 data has been read, or zero if it is missing. The parameters to the
1667 png_get_<chunk> are set directly if they are simple data types, or a
1668 pointer into the info_ptr is returned for any complex types.
1669
1670 The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks
1671 is simply returned to give the application information about how the
1672 image was encoded. Libpng itself only does transformations using the file
1673 gamma when combining semitransparent pixels with the background color, and,
1674 since libpng-1.6.0, when converting between 8-bit sRGB and 16-bit linear pixels
1675 within the simplified API. Libpng also uses the file gamma when converting
1676 RGB to gray, beginning with libpng-1.0.5, if the application calls
1677 png_set_rgb_to_gray()).
1678
1679 png_get_PLTE(png_ptr, info_ptr, &palette,
1680 &num_palette);
1681
1682 palette - the palette for the file
1683 (array of png_color)
1684
1685 num_palette - number of entries in the palette
1686
1687 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
1688 png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
1689
1690 file_gamma - the gamma at which the file is
1691 written (PNG_INFO_gAMA)
1692
1693 int_file_gamma - 100,000 times the gamma at which the
1694 file is written
1695
1696 png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x,
1697 &red_y, &green_x, &green_y, &blue_x, &blue_y)
1698 png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z,
1699 &green_X, &green_Y, &green_Z, &blue_X, &blue_Y,
1700 &blue_Z)
1701 png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x,
1702 &int_white_y, &int_red_x, &int_red_y,
1703 &int_green_x, &int_green_y, &int_blue_x,
1704 &int_blue_y)
1705 png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
1706 &int_red_Z, &int_green_X, &int_green_Y,
1707 &int_green_Z, &int_blue_X, &int_blue_Y,
1708 &int_blue_Z)
1709
1710 {white,red,green,blue}_{x,y}
1711 A color space encoding specified using the
1712 chromaticities of the end points and the
1713 white point. (PNG_INFO_cHRM)
1714
1715 {red,green,blue}_{X,Y,Z}
1716 A color space encoding specified using the
1717 encoding end points - the CIE tristimulus
1718 specification of the intended color of the red,
1719 green and blue channels in the PNG RGB data.
1720 The white point is simply the sum of the three
1721 end points. (PNG_INFO_cHRM)
1722
1723 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1724
1725 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
1726 The presence of the sRGB chunk
1727 means that the pixel data is in the
1728 sRGB color space. This chunk also
1729 implies specific values of gAMA and
1730 cHRM.
1731
1732 png_get_iCCP(png_ptr, info_ptr, &name,
1733 &compression_type, &profile, &proflen);
1734
1735 name - The profile name.
1736
1737 compression_type - The compression type; always
1738 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1739 You may give NULL to this argument to
1740 ignore it.
1741
1742 profile - International Color Consortium color
1743 profile data. May contain NULs.
1744
1745 proflen - length of profile data in bytes.
1746
1747 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1748
1749 sig_bit - the number of significant bits for
1750 (PNG_INFO_sBIT) each of the gray,
1751 red, green, and blue channels,
1752 whichever are appropriate for the
1753 given color type (png_color_16)
1754
1755 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
1756 &num_trans, &trans_color);
1757
1758 trans_alpha - array of alpha (transparency)
1759 entries for palette (PNG_INFO_tRNS)
1760
1761 num_trans - number of transparent entries
1762 (PNG_INFO_tRNS)
1763
1764 trans_color - graylevel or color sample values of
1765 the single transparent color for
1766 non-paletted images (PNG_INFO_tRNS)
1767
1768 png_get_hIST(png_ptr, info_ptr, &hist);
1769 (PNG_INFO_hIST)
1770
1771 hist - histogram of palette (array of
1772 png_uint_16)
1773
1774 png_get_tIME(png_ptr, info_ptr, &mod_time);
1775
1776 mod_time - time image was last modified
1777 (PNG_VALID_tIME)
1778
1779 png_get_bKGD(png_ptr, info_ptr, &background);
1780
1781 background - background color (of type
1782 png_color_16p) (PNG_VALID_bKGD)
1783 valid 16-bit red, green and blue
1784 values, regardless of color_type
1785
1786 num_comments = png_get_text(png_ptr, info_ptr,
1787 &text_ptr, &num_text);
1788
1789 num_comments - number of comments
1790
1791 text_ptr - array of png_text holding image
1792 comments
1793
1794 text_ptr[i].compression - type of compression used
1795 on "text" PNG_TEXT_COMPRESSION_NONE
1796 PNG_TEXT_COMPRESSION_zTXt
1797 PNG_ITXT_COMPRESSION_NONE
1798 PNG_ITXT_COMPRESSION_zTXt
1799
1800 text_ptr[i].key - keyword for comment. Must contain
1801 1-79 characters.
1802
1803 text_ptr[i].text - text comments for current
1804 keyword. Can be empty.
1805
1806 text_ptr[i].text_length - length of text string,
1807 after decompression, 0 for iTXt
1808
1809 text_ptr[i].itxt_length - length of itxt string,
1810 after decompression, 0 for tEXt/zTXt
1811
1812 text_ptr[i].lang - language of comment (empty
1813 string for unknown).
1814
1815 text_ptr[i].lang_key - keyword in UTF-8
1816 (empty string for unknown).
1817
1818 Note that the itxt_length, lang, and lang_key
1819 members of the text_ptr structure only exist when the
1820 library is built with iTXt chunk support. Prior to
1821 libpng-1.4.0 the library was built by default without
1822 iTXt support. Also note that when iTXt is supported,
1823 they contain NULL pointers when the "compression"
1824 field contains PNG_TEXT_COMPRESSION_NONE or
1825 PNG_TEXT_COMPRESSION_zTXt.
1826
1827 num_text - number of comments (same as
1828 num_comments; you can put NULL here
1829 to avoid the duplication)
1830
1831 Note while png_set_text() will accept text, language,
1832 and translated keywords that can be NULL pointers, the
1833 structure returned by png_get_text will always contain
1834 regular zero-terminated C strings. They might be
1835 empty strings but they will never be NULL pointers.
1836
1837 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1838 &palette_ptr);
1839
1840 num_spalettes - number of sPLT chunks read.
1841
1842 palette_ptr - array of palette structures holding
1843 contents of one or more sPLT chunks
1844 read.
1845
1846 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
1847 &unit_type);
1848
1849 offset_x - positive offset from the left edge
1850 of the screen (can be negative)
1851
1852 offset_y - positive offset from the top edge
1853 of the screen (can be negative)
1854
1855 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1856
1857 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
1858 &unit_type);
1859
1860 res_x - pixels/unit physical resolution in
1861 x direction
1862
1863 res_y - pixels/unit physical resolution in
1864 x direction
1865
1866 unit_type - PNG_RESOLUTION_UNKNOWN,
1867 PNG_RESOLUTION_METER
1868
1869 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1870 &height)
1871
1872 unit - physical scale units (an integer)
1873
1874 width - width of a pixel in physical scale units
1875
1876 height - height of a pixel in physical scale units
1877 (width and height are doubles)
1878
1879 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1880 &height)
1881
1882 unit - physical scale units (an integer)
1883
1884 width - width of a pixel in physical scale units
1885 (expressed as a string)
1886
1887 height - height of a pixel in physical scale units
1888 (width and height are strings like "2.54")
1889
1890 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1891 info_ptr, &unknowns)
1892
1893 unknowns - array of png_unknown_chunk
1894 structures holding unknown chunks
1895
1896 unknowns[i].name - name of unknown chunk
1897
1898 unknowns[i].data - data of unknown chunk
1899
1900 unknowns[i].size - size of unknown chunk's data
1901
1902 unknowns[i].location - position of chunk in file
1903
1904 The value of "i" corresponds to the order in which the
1905 chunks were read from the PNG file or inserted with the
1906 png_set_unknown_chunks() function.
1907
1908 The value of "location" is a bitwise "or" of
1909
1910 PNG_HAVE_IHDR (0x01)
1911 PNG_HAVE_PLTE (0x02)
1912 PNG_AFTER_IDAT (0x08)
1913
1914 The data from the pHYs chunk can be retrieved in several convenient
1915 forms:
1916
1917 res_x = png_get_x_pixels_per_meter(png_ptr,
1918 info_ptr)
1919
1920 res_y = png_get_y_pixels_per_meter(png_ptr,
1921 info_ptr)
1922
1923 res_x_and_y = png_get_pixels_per_meter(png_ptr,
1924 info_ptr)
1925
1926 res_x = png_get_x_pixels_per_inch(png_ptr,
1927 info_ptr)
1928
1929 res_y = png_get_y_pixels_per_inch(png_ptr,
1930 info_ptr)
1931
1932 res_x_and_y = png_get_pixels_per_inch(png_ptr,
1933 info_ptr)
1934
1935 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
1936 info_ptr)
1937
1938 Each of these returns 0 [signifying "unknown"] if
1939 the data is not present or if res_x is 0;
1940 res_x_and_y is 0 if res_x != res_y
1941
1942 Note that because of the way the resolutions are
1943 stored internally, the inch conversions won't
1944 come out to exactly even number. For example,
1945 72 dpi is stored as 0.28346 pixels/meter, and
1946 when this is retrieved it is 71.9988 dpi, so
1947 be sure to round the returned value appropriately
1948 if you want to display a reasonable-looking result.
1949
1950 The data from the oFFs chunk can be retrieved in several convenient
1951 forms:
1952
1953 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1954
1955 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1956
1957 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1958
1959 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1960
1961 Each of these returns 0 [signifying "unknown" if both
1962 x and y are 0] if the data is not present or if the
1963 chunk is present but the unit is the pixel. The
1964 remark about inexact inch conversions applies here
1965 as well, because a value in inches can't always be
1966 converted to microns and back without some loss
1967 of precision.
1968
1969 For more information, see the
1970 PNG specification for chunk contents. Be careful with trusting
1971 rowbytes, as some of the transformations could increase the space
1972 needed to hold a row (expand, filler, gray_to_rgb, etc.).
1973 See png_read_update_info(), below.
1974
1975 A quick word about text_ptr and num_text. PNG stores comments in
1976 keyword/text pairs, one pair per chunk, with no limit on the number
1977 of text chunks, and a 2^31 byte limit on their size. While there are
1978 suggested keywords, there is no requirement to restrict the use to these
1979 strings. It is strongly suggested that keywords and text be sensible
1980 to humans (that's the point), so don't use abbreviations. Non-printing
1981 symbols are not allowed. See the PNG specification for more details.
1982 There is also no requirement to have text after the keyword.
1983
1984 Keywords should be limited to 79 Latin-1 characters without leading or
1985 trailing spaces, but non-consecutive spaces are allowed within the
1986 keyword. It is possible to have the same keyword any number of times.
1987 The text_ptr is an array of png_text structures, each holding a
1988 pointer to a language string, a pointer to a keyword and a pointer to
1989 a text string. The text string, language code, and translated
1990 keyword may be empty or NULL pointers. The keyword/text
1991 pairs are put into the array in the order that they are received.
1992 However, some or all of the text chunks may be after the image, so, to
1993 make sure you have read all the text chunks, don't mess with these
1994 until after you read the stuff after the image. This will be
1995 mentioned again below in the discussion that goes with png_read_end().
1996
1997 .SS Input transformations
1998
1999 After you've read the header information, you can set up the library
2000 to handle any special transformations of the image data. The various
2001 ways to transform the data will be described in the order that they
2002 should occur. This is important, as some of these change the color
2003 type and/or bit depth of the data, and some others only work on
2004 certain color types and bit depths.
2005
2006 Transformations you request are ignored if they don't have any meaning for a
2007 particular input data format. However some transformations can have an effect
2008 as a result of a previous transformation. If you specify a contradictory set of
2009 transformations, for example both adding and removing the alpha channel, you
2010 cannot predict the final result.
2011
2012 The color used for the transparency values should be supplied in the same
2013 format/depth as the current image data. It is stored in the same format/depth
2014 as the image data in a tRNS chunk, so this is what libpng expects for this data.
2015
2016 The color used for the background value depends on the need_expand argument as
2017 described below.
2018
2019 Data will be decoded into the supplied row buffers packed into bytes
2020 unless the library has been told to transform it into another format.
2021 For example, 4 bit/pixel paletted or grayscale data will be returned
2022 2 pixels/byte with the leftmost pixel in the high-order bits of the
2023 byte, unless png_set_packing() is called. 8-bit RGB data will be stored
2024 in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2025 is called to insert filler bytes, either before or after each RGB triplet.
2026 16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
2027 byte of the color value first, unless png_set_scale_16() is called to
2028 transform it to regular RGB RGB triplets, or png_set_filler() or
2029 png_set_add alpha() is called to insert filler bytes, either before or
2030 after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
2031 be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2032 or png_set_scale_16().
2033
2034 The following code transforms grayscale images of less than 8 to 8 bits,
2035 changes paletted images to RGB, and adds a full alpha channel if there is
2036 transparency information in a tRNS chunk. This is most useful on
2037 grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2038 viewing application that wishes to treat all images in the same way.
2039
2040 if (color_type == PNG_COLOR_TYPE_PALETTE)
2041 png_set_palette_to_rgb(png_ptr);
2042
2043 if (png_get_valid(png_ptr, info_ptr,
2044 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2045
2046 if (color_type == PNG_COLOR_TYPE_GRAY &&
2047 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2048
2049 The first two functions are actually aliases for png_set_expand(), added
2050 in libpng version 1.0.4, with the function names expanded to improve code
2051 readability. In some future version they may actually do different
2052 things.
2053
2054 As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2055 added. It expands the sample depth without changing tRNS to alpha.
2056
2057 As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
2058 png_set_expand(); however, the resultant channels have 16 bits rather than 8.
2059 Use this when the output color or gray channels are made linear to avoid fairly
2060 severe accuracy loss.
2061
2062 if (bit_depth < 16)
2063 png_set_expand_16(png_ptr);
2064
2065 PNG can have files with 16 bits per channel. If you only can handle
2066 8 bits per channel, this will strip the pixels down to 8-bit.
2067
2068 if (bit_depth == 16)
2069 #if PNG_LIBPNG_VER >= 10504
2070 png_set_scale_16(png_ptr);
2071 #else
2072 png_set_strip_16(png_ptr);
2073 #endif
2074
2075 (The more accurate "png_set_scale_16()" API became available in libpng version
2076 1.5.4).
2077
2078 If you need to process the alpha channel on the image separately from the image
2079 data (for example if you convert it to a bitmap mask) it is possible to have
2080 libpng strip the channel leaving just RGB or gray data:
2081
2082 if (color_type & PNG_COLOR_MASK_ALPHA)
2083 png_set_strip_alpha(png_ptr);
2084
2085 If you strip the alpha channel you need to find some other way of dealing with
2086 the information. If, instead, you want to convert the image to an opaque
2087 version with no alpha channel use png_set_background; see below.
2088
2089 As of libpng version 1.5.2, almost all useful expansions are supported, the
2090 major ommissions are conversion of grayscale to indexed images (which can be
2091 done trivially in the application) and conversion of indexed to grayscale (which
2092 can be done by a trivial manipulation of the palette.)
2093
2094 In the following table, the 01 means grayscale with depth<8, 31 means
2095 indexed with depth<8, other numerals represent the color type, "T" means
2096 the tRNS chunk is present, A means an alpha channel is present, and O
2097 means tRNS or alpha is present but all pixels in the image are opaque.
2098
2099 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
2100 TO
2101 01 - [G] - - - - - - - - - - - - -
2102 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
2103 0 1 G + . . G G G G G G B B GB GB
2104 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
2105 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
2106 2 C P C C C + . . C - - CB CB B B
2107 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
2108 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
2109 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
2110 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
2111 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
2112 4A lA G A T T GA GT GT GA GT GT + BA G GBA
2113 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
2114 6A CA PA CA C C A T tT PA P P C CBA + BA
2115 6O CA PBA CA C C A tT T PA P P CBA C BA +
2116
2117 Within the matrix,
2118 "+" identifies entries where 'from' and 'to' are the same.
2119 "-" means the transformation is not supported.
2120 "." means nothing is necessary (a tRNS chunk can just be ignored).
2121 "t" means the transformation is obtained by png_set_tRNS.
2122 "A" means the transformation is obtained by png_set_add_alpha().
2123 "X" means the transformation is obtained by png_set_expand().
2124 "1" means the transformation is obtained by
2125 png_set_expand_gray_1_2_4_to_8() (and by png_set_expand()
2126 if there is no transparency in the original or the final
2127 format).
2128 "C" means the transformation is obtained by png_set_gray_to_rgb().
2129 "G" means the transformation is obtained by png_set_rgb_to_gray().
2130 "P" means the transformation is obtained by
2131 png_set_expand_palette_to_rgb().
2132 "p" means the transformation is obtained by png_set_packing().
2133 "Q" means the transformation is obtained by png_set_quantize().
2134 "T" means the transformation is obtained by
2135 png_set_tRNS_to_alpha().
2136 "B" means the transformation is obtained by
2137 png_set_background(), or png_strip_alpha().
2138
2139 When an entry has multiple transforms listed all are required to cause the
2140 right overall transformation. When two transforms are separated by a comma
2141 either will do the job. When transforms are enclosed in [] the transform should
2142 do the job but this is currently unimplemented - a different format will result
2143 if the suggested transformations are used.
2144
2145 In PNG files, the alpha channel in an image
2146 is the level of opacity. If you need the alpha channel in an image to
2147 be the level of transparency instead of opacity, you can invert the
2148 alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2149 fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2150 images) is fully transparent, with
2151
2152 png_set_invert_alpha(png_ptr);
2153
2154 PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2155 they can, resulting in, for example, 8 pixels per byte for 1 bit
2156 files. This code expands to 1 pixel per byte without changing the
2157 values of the pixels:
2158
2159 if (bit_depth < 8)
2160 png_set_packing(png_ptr);
2161
2162 PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
2163 stored in a PNG image have been "scaled" or "shifted" up to the next
2164 higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2165 to 8 bits/sample in the range [0, 255]). However, it is also possible
2166 to convert the PNG pixel data back to the original bit depth of the
2167 image. This call reduces the pixels back down to the original bit depth:
2168
2169 png_color_8p sig_bit;
2170
2171 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
2172 png_set_shift(png_ptr, sig_bit);
2173
2174 PNG files store 3-color pixels in red, green, blue order. This code
2175 changes the storage of the pixels to blue, green, red:
2176
2177 if (color_type == PNG_COLOR_TYPE_RGB ||
2178 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2179 png_set_bgr(png_ptr);
2180
2181 PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2182 into 4 or 8 bytes for windowing systems that need them in this format:
2183
2184 if (color_type == PNG_COLOR_TYPE_RGB)
2185 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
2186
2187 where "filler" is the 8 or 16-bit number to fill with, and the location is
2188 either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2189 you want the filler before the RGB or after. This transformation
2190 does not affect images that already have full alpha channels. To add an
2191 opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2192 will generate RGBA pixels.
2193
2194 Note that png_set_filler() does not change the color type. If you want
2195 to do that, you can add a true alpha channel with
2196
2197 if (color_type == PNG_COLOR_TYPE_RGB ||
2198 color_type == PNG_COLOR_TYPE_GRAY)
2199 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
2200
2201 where "filler" contains the alpha value to assign to each pixel.
2202 This function was added in libpng-1.2.7.
2203
2204 If you are reading an image with an alpha channel, and you need the
2205 data as ARGB instead of the normal PNG format RGBA:
2206
2207 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2208 png_set_swap_alpha(png_ptr);
2209
2210 For some uses, you may want a grayscale image to be represented as
2211 RGB. This code will do that conversion:
2212
2213 if (color_type == PNG_COLOR_TYPE_GRAY ||
2214 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2215 png_set_gray_to_rgb(png_ptr);
2216
2217 Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
2218 with alpha.
2219
2220 if (color_type == PNG_COLOR_TYPE_RGB ||
2221 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2222 png_set_rgb_to_gray(png_ptr, error_action,
2223 double red_weight, double green_weight);
2224
2225 error_action = 1: silently do the conversion
2226
2227 error_action = 2: issue a warning if the original
2228 image has any pixel where
2229 red != green or red != blue
2230
2231 error_action = 3: issue an error and abort the
2232 conversion if the original
2233 image has any pixel where
2234 red != green or red != blue
2235
2236 red_weight: weight of red component
2237
2238 green_weight: weight of green component
2239 If either weight is negative, default
2240 weights are used.
2241
2242 In the corresponding fixed point API the red_weight and green_weight values are
2243 simply scaled by 100,000:
2244
2245 png_set_rgb_to_gray(png_ptr, error_action,
2246 png_fixed_point red_weight,
2247 png_fixed_point green_weight);
2248
2249 If you have set error_action = 1 or 2, you can
2250 later check whether the image really was gray, after processing
2251 the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2252 It will return a png_byte that is zero if the image was gray or
2253 1 if there were any non-gray pixels. Background and sBIT data
2254 will be silently converted to grayscale, using the green channel
2255 data for sBIT, regardless of the error_action setting.
2256
2257 The default values come from the PNG file cHRM chunk if present; otherwise, the
2258 defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2259 space, as recommended in the Charles Poynton's Colour FAQ,
2260 <http://www.poynton.com/>, in section 9:
2261
2262 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
2263
2264 Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
2265
2266 Previous versions of this document, 1998 through 2002, recommended a slightly
2267 different formula:
2268
2269 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2270
2271 Libpng uses an integer approximation:
2272
2273 Y = (6968 * R + 23434 * G + 2366 * B)/32768
2274
2275 The calculation is done in a linear colorspace, if the image gamma
2276 can be determined.
2277
2278 The png_set_background() function has been described already; it tells libpng to
2279 composite images with alpha or simple transparency against the supplied
2280 background color. For compatibility with versions of libpng earlier than
2281 libpng-1.5.4 it is recommended that you call the function after reading the file
2282 header, even if you don't want to use the color in a bKGD chunk, if one exists.
2283
2284 If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2285 you may use this color, or supply another color more suitable for
2286 the current display (e.g., the background color from a web page). You
2287 need to tell libpng how the color is represented, both the format of the
2288 component values in the color (the number of bits) and the gamma encoding of the
2289 color. The function takes two arguments, background_gamma_mode and need_expand
2290 to convey this information; however, only two combinations are likely to be
2291 useful:
2292
2293 png_color_16 my_background;
2294 png_color_16p image_background;
2295
2296 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
2297 png_set_background(png_ptr, image_background,
2298 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
2299 else
2300 png_set_background(png_ptr, &my_background,
2301 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
2302
2303 The second call was described above - my_background is in the format of the
2304 final, display, output produced by libpng. Because you now know the format of
2305 the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2306 output and to retain palette images (the palette colors will be modified
2307 appropriately and the tRNS chunk removed.) However, if you are doing this,
2308 take great care not to ask for transformations without checking first that
2309 they apply!
2310
2311 In the first call the background color has the original bit depth and color type
2312 of the PNG file. So, for palette images the color is supplied as a palette
2313 index and for low bit greyscale images the color is a reduced bit value in
2314 image_background->gray.
2315
2316 If you didn't call png_set_gamma() before reading the file header, for example
2317 if you need your code to remain compatible with older versions of libpng prior
2318 to libpng-1.5.4, this is the place to call it.
2319
2320 Do not call it if you called png_set_alpha_mode(); doing so will damage the
2321 settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
2322 supported then you can certainly do png_set_gamma() before reading the PNG
2323 header.)
2324
2325 This API unconditionally sets the screen and file gamma values, so it will
2326 override the value in the PNG file unless it is called before the PNG file
2327 reading starts. For this reason you must always call it with the PNG file
2328 value when you call it in this position:
2329
2330 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
2331 png_set_gamma(png_ptr, screen_gamma, file_gamma);
2332
2333 else
2334 png_set_gamma(png_ptr, screen_gamma, 0.45455);
2335
2336 If you need to reduce an RGB file to a paletted file, or if a paletted
2337 file has more entries then will fit on your screen, png_set_quantize()
2338 will do that. Note that this is a simple match quantization that merely
2339 finds the closest color available. This should work fairly well with
2340 optimized palettes, but fairly badly with linear color cubes. If you
2341 pass a palette that is larger than maximum_colors, the file will
2342 reduce the number of colors in the palette so it will fit into
2343 maximum_colors. If there is a histogram, libpng will use it to make
2344 more intelligent choices when reducing the palette. If there is no
2345 histogram, it may not do as good a job.
2346
2347 if (color_type & PNG_COLOR_MASK_COLOR)
2348 {
2349 if (png_get_valid(png_ptr, info_ptr,
2350 PNG_INFO_PLTE))
2351 {
2352 png_uint_16p histogram = NULL;
2353
2354 png_get_hIST(png_ptr, info_ptr,
2355 &histogram);
2356 png_set_quantize(png_ptr, palette, num_palette,
2357 max_screen_colors, histogram, 1);
2358 }
2359
2360 else
2361 {
2362 png_color std_color_cube[MAX_SCREEN_COLORS] =
2363 { ... colors ... };
2364
2365 png_set_quantize(png_ptr, std_color_cube,
2366 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2367 NULL,0);
2368 }
2369 }
2370
2371 PNG files describe monochrome as black being zero and white being one.
2372 The following code will reverse this (make black be one and white be
2373 zero):
2374
2375 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2376 png_set_invert_mono(png_ptr);
2377
2378 This function can also be used to invert grayscale and gray-alpha images:
2379
2380 if (color_type == PNG_COLOR_TYPE_GRAY ||
2381 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2382 png_set_invert_mono(png_ptr);
2383
2384 PNG files store 16-bit pixels in network byte order (big-endian,
2385 ie. most significant bits first). This code changes the storage to the
2386 other way (little-endian, i.e. least significant bits first, the
2387 way PCs store them):
2388
2389 if (bit_depth == 16)
2390 png_set_swap(png_ptr);
2391
2392 If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2393 need to change the order the pixels are packed into bytes, you can use:
2394
2395 if (bit_depth < 8)
2396 png_set_packswap(png_ptr);
2397
2398 Finally, you can write your own transformation function if none of
2399 the existing ones meets your needs. This is done by setting a callback
2400 with
2401
2402 png_set_read_user_transform_fn(png_ptr,
2403 read_transform_fn);
2404
2405 You must supply the function
2406
2407 void read_transform_fn(png_structp png_ptr, png_row_infop
2408 row_info, png_bytep data)
2409
2410 See pngtest.c for a working example. Your function will be called
2411 after all of the other transformations have been processed. Take care with
2412 interlaced images if you do the interlace yourself - the width of the row is the
2413 width in 'row_info', not the overall image width.
2414
2415 If supported, libpng provides two information routines that you can use to find
2416 where you are in processing the image:
2417
2418 png_get_current_pass_number(png_structp png_ptr);
2419 png_get_current_row_number(png_structp png_ptr);
2420
2421 Don't try using these outside a transform callback - firstly they are only
2422 supported if user transforms are supported, secondly they may well return
2423 unexpected results unless the row is actually being processed at the moment they
2424 are called.
2425
2426 With interlaced
2427 images the value returned is the row in the input sub-image image. Use
2428 PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2429 find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2430
2431 The discussion of interlace handling above contains more information on how to
2432 use these values.
2433
2434 You can also set up a pointer to a user structure for use by your
2435 callback function, and you can inform libpng that your transform
2436 function will change the number of channels or bit depth with the
2437 function
2438
2439 png_set_user_transform_info(png_ptr, user_ptr,
2440 user_depth, user_channels);
2441
2442 The user's application, not libpng, is responsible for allocating and
2443 freeing any memory required for the user structure.
2444
2445 You can retrieve the pointer via the function
2446 png_get_user_transform_ptr(). For example:
2447
2448 voidp read_user_transform_ptr =
2449 png_get_user_transform_ptr(png_ptr);
2450
2451 The last thing to handle is interlacing; this is covered in detail below,
2452 but you must call the function here if you want libpng to handle expansion
2453 of the interlaced image.
2454
2455 number_of_passes = png_set_interlace_handling(png_ptr);
2456
2457 After setting the transformations, libpng can update your png_info
2458 structure to reflect any transformations you've requested with this
2459 call.
2460
2461 png_read_update_info(png_ptr, info_ptr);
2462
2463 This is most useful to update the info structure's rowbytes
2464 field so you can use it to allocate your image memory. This function
2465 will also update your palette with the correct screen_gamma and
2466 background if these have been given with the calls above. You may
2467 only call png_read_update_info() once with a particular info_ptr.
2468
2469 After you call png_read_update_info(), you can allocate any
2470 memory you need to hold the image. The row data is simply
2471 raw byte data for all forms of images. As the actual allocation
2472 varies among applications, no example will be given. If you
2473 are allocating one large chunk, you will need to build an
2474 array of pointers to each row, as it will be needed for some
2475 of the functions below.
2476
2477 Remember: Before you call png_read_update_info(), the png_get_*()
2478 functions return the values corresponding to the original PNG image.
2479 After you call png_read_update_info the values refer to the image
2480 that libpng will output. Consequently you must call all the png_set_
2481 functions before you call png_read_update_info(). This is particularly
2482 important for png_set_interlace_handling() - if you are going to call
2483 png_read_update_info() you must call png_set_interlace_handling() before
2484 it unless you want to receive interlaced output.
2485
2486 .SS Reading image data
2487
2488 After you've allocated memory, you can read the image data.
2489 The simplest way to do this is in one function call. If you are
2490 allocating enough memory to hold the whole image, you can just
2491 call png_read_image() and libpng will read in all the image data
2492 and put it in the memory area supplied. You will need to pass in
2493 an array of pointers to each row.
2494
2495 This function automatically handles interlacing, so you don't
2496 need to call png_set_interlace_handling() (unless you call
2497 png_read_update_info()) or call this function multiple times, or any
2498 of that other stuff necessary with png_read_rows().
2499
2500 png_read_image(png_ptr, row_pointers);
2501
2502 where row_pointers is:
2503
2504 png_bytep row_pointers[height];
2505
2506 You can point to void or char or whatever you use for pixels.
2507
2508 If you don't want to read in the whole image at once, you can
2509 use png_read_rows() instead. If there is no interlacing (check
2510 interlace_type == PNG_INTERLACE_NONE), this is simple:
2511
2512 png_read_rows(png_ptr, row_pointers, NULL,
2513 number_of_rows);
2514
2515 where row_pointers is the same as in the png_read_image() call.
2516
2517 If you are doing this just one row at a time, you can do this with
2518 a single row_pointer instead of an array of row_pointers:
2519
2520 png_bytep row_pointer = row;
2521 png_read_row(png_ptr, row_pointer, NULL);
2522
2523 If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2524 get somewhat harder. The only current (PNG Specification version 1.2)
2525 interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
2526 a somewhat complicated 2D interlace scheme, known as Adam7, that
2527 breaks down an image into seven smaller images of varying size, based
2528 on an 8x8 grid. This number is defined (from libpng 1.5) as
2529 PNG_INTERLACE_ADAM7_PASSES in png.h
2530
2531 libpng can fill out those images or it can give them to you "as is".
2532 It is almost always better to have libpng handle the interlacing for you.
2533 If you want the images filled out, there are two ways to do that. The one
2534 mentioned in the PNG specification is to expand each pixel to cover
2535 those pixels that have not been read yet (the "rectangle" method).
2536 This results in a blocky image for the first pass, which gradually
2537 smooths out as more pixels are read. The other method is the "sparkle"
2538 method, where pixels are drawn only in their final locations, with the
2539 rest of the image remaining whatever colors they were initialized to
2540 before the start of the read. The first method usually looks better,
2541 but tends to be slower, as there are more pixels to put in the rows.
2542
2543 If, as is likely, you want libpng to expand the images, call this before
2544 calling png_start_read_image() or png_read_update_info():
2545
2546 if (interlace_type == PNG_INTERLACE_ADAM7)
2547 number_of_passes
2548 = png_set_interlace_handling(png_ptr);
2549
2550 This will return the number of passes needed. Currently, this is seven,
2551 but may change if another interlace type is added. This function can be
2552 called even if the file is not interlaced, where it will return one pass.
2553 You then need to read the whole image 'number_of_passes' times. Each time
2554 will distribute the pixels from the current pass to the correct place in
2555 the output image, so you need to supply the same rows to png_read_rows in
2556 each pass.
2557
2558 If you are not going to display the image after each pass, but are
2559 going to wait until the entire image is read in, use the sparkle
2560 effect. This effect is faster and the end result of either method
2561 is exactly the same. If you are planning on displaying the image
2562 after each pass, the "rectangle" effect is generally considered the
2563 better looking one.
2564
2565 If you only want the "sparkle" effect, just call png_read_rows() as
2566 normal, with the third parameter NULL. Make sure you make pass over
2567 the image number_of_passes times, and you don't change the data in the
2568 rows between calls. You can change the locations of the data, just
2569 not the data. Each pass only writes the pixels appropriate for that
2570 pass, and assumes the data from previous passes is still valid.
2571
2572 png_read_rows(png_ptr, row_pointers, NULL,
2573 number_of_rows);
2574
2575 If you only want the first effect (the rectangles), do the same as
2576 before except pass the row buffer in the third parameter, and leave
2577 the second parameter NULL.
2578
2579 png_read_rows(png_ptr, NULL, row_pointers,
2580 number_of_rows);
2581
2582 If you don't want libpng to handle the interlacing details, just call
2583 png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
2584 Each of the images is a valid image by itself; however, you will almost
2585 certainly need to distribute the pixels from each sub-image to the
2586 correct place. This is where everything gets very tricky.
2587
2588 If you want to retrieve the separate images you must pass the correct
2589 number of rows to each successive call of png_read_rows(). The calculation
2590 gets pretty complicated for small images, where some sub-images may
2591 not even exist because either their width or height ends up zero.
2592 libpng provides two macros to help you in 1.5 and later versions:
2593
2594 png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
2595 png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
2596
2597 Respectively these tell you the width and height of the sub-image
2598 corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
2599 this can be confusing because the specification refers to the same passes
2600 as 1 to 7! Be careful, you must check both the width and height before
2601 calling png_read_rows() and not call it for that pass if either is zero.
2602
2603 You can, of course, read each sub-image row by row. If you want to
2604 produce optimal code to make a pixel-by-pixel transformation of an
2605 interlaced image this is the best approach; read each row of each pass,
2606 transform it, and write it out to a new interlaced image.
2607
2608 If you want to de-interlace the image yourself libpng provides further
2609 macros to help that tell you where to place the pixels in the output image.
2610 Because the interlacing scheme is rectangular - sub-image pixels are always
2611 arranged on a rectangular grid - all you need to know for each pass is the
2612 starting column and row in the output image of the first pixel plus the
2613 spacing between each pixel. As of libpng 1.5 there are four macros to
2614 retrieve this information:
2615
2616 png_uint_32 x = PNG_PASS_START_COL(pass);
2617 png_uint_32 y = PNG_PASS_START_ROW(pass);
2618 png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
2619 png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
2620
2621 These allow you to write the obvious loop:
2622
2623 png_uint_32 input_y = 0;
2624 png_uint_32 output_y = PNG_PASS_START_ROW(pass);
2625
2626 while (output_y < output_image_height)
2627 {
2628 png_uint_32 input_x = 0;
2629 png_uint_32 output_x = PNG_PASS_START_COL(pass);
2630
2631 while (output_x < output_image_width)
2632 {
2633 image[output_y][output_x] =
2634 subimage[pass][input_y][input_x++];
2635
2636 output_x += xStep;
2637 }
2638
2639 ++input_y;
2640 output_y += yStep;
2641 }
2642
2643 Notice that the steps between successive output rows and columns are
2644 returned as shifts. This is possible because the pixels in the subimages
2645 are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
2646 image. In practice you may need to directly calculate the output coordinate
2647 given an input coordinate. libpng provides two further macros for this
2648 purpose:
2649
2650 png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
2651 png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
2652
2653 Finally a pair of macros are provided to tell you if a particular image
2654 row or column appears in a given pass:
2655
2656 int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
2657 int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
2658
2659 Bear in mind that you will probably also need to check the width and height
2660 of the pass in addition to the above to be sure the pass even exists!
2661
2662 With any luck you are convinced by now that you don't want to do your own
2663 interlace handling. In reality normally the only good reason for doing this
2664 is if you are processing PNG files on a pixel-by-pixel basis and don't want
2665 to load the whole file into memory when it is interlaced.
2666
2667 libpng includes a test program, pngvalid, that illustrates reading and
2668 writing of interlaced images. If you can't get interlacing to work in your
2669 code and don't want to leave it to libpng (the recommended approach), see
2670 how pngvalid.c does it.
2671
2672 .SS Finishing a sequential read
2673
2674 After you are finished reading the image through the
2675 low-level interface, you can finish reading the file. If you are
2676 interested in comments or time, which may be stored either before or
2677 after the image data, you should pass the separate png_info struct if
2678 you want to keep the comments from before and after the image
2679 separate.
2680
2681 png_infop end_info = png_create_info_struct(png_ptr);
2682
2683 if (!end_info)
2684 {
2685 png_destroy_read_struct(&png_ptr, &info_ptr,
2686 (png_infopp)NULL);
2687 return (ERROR);
2688 }
2689
2690 png_read_end(png_ptr, end_info);
2691
2692 If you are not interested, you should still call png_read_end()
2693 but you can pass NULL, avoiding the need to create an end_info structure.
2694
2695 png_read_end(png_ptr, (png_infop)NULL);
2696
2697 If you don't call png_read_end(), then your file pointer will be
2698 left pointing to the first chunk after the last IDAT, which is probably
2699 not what you want if you expect to read something beyond the end of
2700 the PNG datastream.
2701
2702 When you are done, you can free all memory allocated by libpng like this:
2703
2704 png_destroy_read_struct(&png_ptr, &info_ptr,
2705 &end_info);
2706
2707 or, if you didn't create an end_info structure,
2708
2709 png_destroy_read_struct(&png_ptr, &info_ptr,
2710 (png_infopp)NULL);
2711
2712 It is also possible to individually free the info_ptr members that
2713 point to libpng-allocated storage with the following function:
2714
2715 png_free_data(png_ptr, info_ptr, mask, seq)
2716
2717 mask - identifies data to be freed, a mask
2718 containing the bitwise OR of one or
2719 more of
2720 PNG_FREE_PLTE, PNG_FREE_TRNS,
2721 PNG_FREE_HIST, PNG_FREE_ICCP,
2722 PNG_FREE_PCAL, PNG_FREE_ROWS,
2723 PNG_FREE_SCAL, PNG_FREE_SPLT,
2724 PNG_FREE_TEXT, PNG_FREE_UNKN,
2725 or simply PNG_FREE_ALL
2726
2727 seq - sequence number of item to be freed
2728 (-1 for all items)
2729
2730 This function may be safely called when the relevant storage has
2731 already been freed, or has not yet been allocated, or was allocated
2732 by the user and not by libpng, and will in those cases do nothing.
2733 The "seq" parameter is ignored if only one item of the selected data
2734 type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
2735 are allowed for the data type identified in the mask, such as text or
2736 sPLT, only the n'th item in the structure is freed, where n is "seq".
2737
2738 The default behavior is only to free data that was allocated internally
2739 by libpng. This can be changed, so that libpng will not free the data,
2740 or so that it will free data that was allocated by the user with png_malloc()
2741 or png_calloc() and passed in via a png_set_*() function, with
2742
2743 png_data_freer(png_ptr, info_ptr, freer, mask)
2744
2745 freer - one of
2746 PNG_DESTROY_WILL_FREE_DATA
2747 PNG_SET_WILL_FREE_DATA
2748 PNG_USER_WILL_FREE_DATA
2749
2750 mask - which data elements are affected
2751 same choices as in png_free_data()
2752
2753 This function only affects data that has already been allocated.
2754 You can call this function after reading the PNG data but before calling
2755 any png_set_*() functions, to control whether the user or the png_set_*()
2756 function is responsible for freeing any existing data that might be present,
2757 and again after the png_set_*() functions to control whether the user
2758 or png_destroy_*() is supposed to free the data. When the user assumes
2759 responsibility for libpng-allocated data, the application must use
2760 png_free() to free it, and when the user transfers responsibility to libpng
2761 for data that the user has allocated, the user must have used png_malloc()
2762 or png_calloc() to allocate it.
2763
2764 If you allocated your row_pointers in a single block, as suggested above in
2765 the description of the high level read interface, you must not transfer
2766 responsibility for freeing it to the png_set_rows or png_read_destroy function,
2767 because they would also try to free the individual row_pointers[i].
2768
2769 If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2770 separately, do not transfer responsibility for freeing text_ptr to libpng,
2771 because when libpng fills a png_text structure it combines these members with
2772 the key member, and png_free_data() will free only text_ptr.key. Similarly,
2773 if you transfer responsibility for free'ing text_ptr from libpng to your
2774 application, your application must not separately free those members.
2775
2776 The png_free_data() function will turn off the "valid" flag for anything
2777 it frees. If you need to turn the flag off for a chunk that was freed by
2778 your application instead of by libpng, you can use
2779
2780 png_set_invalid(png_ptr, info_ptr, mask);
2781
2782 mask - identifies the chunks to be made invalid,
2783 containing the bitwise OR of one or
2784 more of
2785 PNG_INFO_gAMA, PNG_INFO_sBIT,
2786 PNG_INFO_cHRM, PNG_INFO_PLTE,
2787 PNG_INFO_tRNS, PNG_INFO_bKGD,
2788 PNG_INFO_hIST, PNG_INFO_pHYs,
2789 PNG_INFO_oFFs, PNG_INFO_tIME,
2790 PNG_INFO_pCAL, PNG_INFO_sRGB,
2791 PNG_INFO_iCCP, PNG_INFO_sPLT,
2792 PNG_INFO_sCAL, PNG_INFO_IDAT
2793
2794 For a more compact example of reading a PNG image, see the file example.c.
2795
2796 .SS Reading PNG files progressively
2797
2798 The progressive reader is slightly different then the non-progressive
2799 reader. Instead of calling png_read_info(), png_read_rows(), and
2800 png_read_end(), you make one call to png_process_data(), which calls
2801 callbacks when it has the info, a row, or the end of the image. You
2802 set up these callbacks with png_set_progressive_read_fn(). You don't
2803 have to worry about the input/output functions of libpng, as you are
2804 giving the library the data directly in png_process_data(). I will
2805 assume that you have read the section on reading PNG files above,
2806 so I will only highlight the differences (although I will show
2807 all of the code).
2808
2809 png_structp png_ptr;
2810 png_infop info_ptr;
2811
2812 /* An example code fragment of how you would
2813 initialize the progressive reader in your
2814 application. */
2815 int
2816 initialize_png_reader()
2817 {
2818 png_ptr = png_create_read_struct
2819 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2820 user_error_fn, user_warning_fn);
2821
2822 if (!png_ptr)
2823 return (ERROR);
2824
2825 info_ptr = png_create_info_struct(png_ptr);
2826
2827 if (!info_ptr)
2828 {
2829 png_destroy_read_struct(&png_ptr,
2830 (png_infopp)NULL, (png_infopp)NULL);
2831 return (ERROR);
2832 }
2833
2834 if (setjmp(png_jmpbuf(png_ptr)))
2835 {
2836 png_destroy_read_struct(&png_ptr, &info_ptr,
2837 (png_infopp)NULL);
2838 return (ERROR);
2839 }
2840
2841 /* This one's new. You can provide functions
2842 to be called when the header info is valid,
2843 when each row is completed, and when the image
2844 is finished. If you aren't using all functions,
2845 you can specify NULL parameters. Even when all
2846 three functions are NULL, you need to call
2847 png_set_progressive_read_fn(). You can use
2848 any struct as the user_ptr (cast to a void pointer
2849 for the function call), and retrieve the pointer
2850 from inside the callbacks using the function
2851
2852 png_get_progressive_ptr(png_ptr);
2853
2854 which will return a void pointer, which you have
2855 to cast appropriately.
2856 */
2857 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
2858 info_callback, row_callback, end_callback);
2859
2860 return 0;
2861 }
2862
2863 /* A code fragment that you call as you receive blocks
2864 of data */
2865 int
2866 process_data(png_bytep buffer, png_uint_32 length)
2867 {
2868 if (setjmp(png_jmpbuf(png_ptr)))
2869 {
2870 png_destroy_read_struct(&png_ptr, &info_ptr,
2871 (png_infopp)NULL);
2872 return (ERROR);
2873 }
2874
2875 /* This one's new also. Simply give it a chunk
2876 of data from the file stream (in order, of
2877 course). On machines with segmented memory
2878 models machines, don't give it any more than
2879 64K. The library seems to run fine with sizes
2880 of 4K. Although you can give it much less if
2881 necessary (I assume you can give it chunks of
2882 1 byte, I haven't tried less then 256 bytes
2883 yet). When this function returns, you may
2884 want to display any rows that were generated
2885 in the row callback if you don't already do
2886 so there.
2887 */
2888 png_process_data(png_ptr, info_ptr, buffer, length);
2889
2890 /* At this point you can call png_process_data_skip if
2891 you want to handle data the library will skip yourself;
2892 it simply returns the number of bytes to skip (and stops
2893 libpng skipping that number of bytes on the next
2894 png_process_data call).
2895 return 0;
2896 }
2897
2898 /* This function is called (as set by
2899 png_set_progressive_read_fn() above) when enough data
2900 has been supplied so all of the header has been
2901 read.
2902 */
2903 void
2904 info_callback(png_structp png_ptr, png_infop info)
2905 {
2906 /* Do any setup here, including setting any of
2907 the transformations mentioned in the Reading
2908 PNG files section. For now, you _must_ call
2909 either png_start_read_image() or
2910 png_read_update_info() after all the
2911 transformations are set (even if you don't set
2912 any). You may start getting rows before
2913 png_process_data() returns, so this is your
2914 last chance to prepare for that.
2915
2916 This is where you turn on interlace handling,
2917 assuming you don't want to do it yourself.
2918
2919 If you need to you can stop the processing of
2920 your original input data at this point by calling
2921 png_process_data_pause. This returns the number
2922 of unprocessed bytes from the last png_process_data
2923 call - it is up to you to ensure that the next call
2924 sees these bytes again. If you don't want to bother
2925 with this you can get libpng to cache the unread
2926 bytes by setting the 'save' parameter (see png.h) but
2927 then libpng will have to copy the data internally.
2928 */
2929 }
2930
2931 /* This function is called when each row of image
2932 data is complete */
2933 void
2934 row_callback(png_structp png_ptr, png_bytep new_row,
2935 png_uint_32 row_num, int pass)
2936 {
2937 /* If the image is interlaced, and you turned
2938 on the interlace handler, this function will
2939 be called for every row in every pass. Some
2940 of these rows will not be changed from the
2941 previous pass. When the row is not changed,
2942 the new_row variable will be NULL. The rows
2943 and passes are called in order, so you don't
2944 really need the row_num and pass, but I'm
2945 supplying them because it may make your life
2946 easier.
2947
2948 If you did not turn on interlace handling then
2949 the callback is called for each row of each
2950 sub-image when the image is interlaced. In this
2951 case 'row_num' is the row in the sub-image, not
2952 the row in the output image as it is in all other
2953 cases.
2954
2955 For the non-NULL rows of interlaced images when
2956 you have switched on libpng interlace handling,
2957 you must call png_progressive_combine_row()
2958 passing in the row and the old row. You can
2959 call this function for NULL rows (it will just
2960 return) and for non-interlaced images (it just
2961 does the memcpy for you) if it will make the
2962 code easier. Thus, you can just do this for
2963 all cases if you switch on interlace handling;
2964 */
2965
2966 png_progressive_combine_row(png_ptr, old_row,
2967 new_row);
2968
2969 /* where old_row is what was displayed for
2970 previously for the row. Note that the first
2971 pass (pass == 0, really) will completely cover
2972 the old row, so the rows do not have to be
2973 initialized. After the first pass (and only
2974 for interlaced images), you will have to pass
2975 the current row, and the function will combine
2976 the old row and the new row.
2977
2978 You can also call png_process_data_pause in this
2979 callback - see above.
2980 */
2981 }
2982
2983 void
2984 end_callback(png_structp png_ptr, png_infop info)
2985 {
2986 /* This function is called after the whole image
2987 has been read, including any chunks after the
2988 image (up to and including the IEND). You
2989 will usually have the same info chunk as you
2990 had in the header, although some data may have
2991 been added to the comments and time fields.
2992
2993 Most people won't do much here, perhaps setting
2994 a flag that marks the image as finished.
2995 */
2996 }
2997
2998
2999
3000 .SH IV. Writing
3001
3002 Much of this is very similar to reading. However, everything of
3003 importance is repeated here, so you won't have to constantly look
3004 back up in the reading section to understand writing.
3005
3006 .SS Setup
3007
3008 You will want to do the I/O initialization before you get into libpng,
3009 so if it doesn't work, you don't have anything to undo. If you are not
3010 using the standard I/O functions, you will need to replace them with
3011 custom writing functions. See the discussion under Customizing libpng.
3012
3013 FILE *fp = fopen(file_name, "wb");
3014
3015 if (!fp)
3016 return (ERROR);
3017
3018 Next, png_struct and png_info need to be allocated and initialized.
3019 As these can be both relatively large, you may not want to store these
3020 on the stack, unless you have stack space to spare. Of course, you
3021 will want to check if they return NULL. If you are also reading,
3022 you won't want to name your read structure and your write structure
3023 both "png_ptr"; you can call them anything you like, such as
3024 "read_ptr" and "write_ptr". Look at pngtest.c, for example.
3025
3026 png_structp png_ptr = png_create_write_struct
3027 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3028 user_error_fn, user_warning_fn);
3029
3030 if (!png_ptr)
3031 return (ERROR);
3032
3033 png_infop info_ptr = png_create_info_struct(png_ptr);
3034 if (!info_ptr)
3035 {
3036 png_destroy_write_struct(&png_ptr,
3037 (png_infopp)NULL);
3038 return (ERROR);
3039 }
3040
3041 If you want to use your own memory allocation routines,
3042 define PNG_USER_MEM_SUPPORTED and use
3043 png_create_write_struct_2() instead of png_create_write_struct():
3044
3045 png_structp png_ptr = png_create_write_struct_2
3046 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3047 user_error_fn, user_warning_fn, (png_voidp)
3048 user_mem_ptr, user_malloc_fn, user_free_fn);
3049
3050 After you have these structures, you will need to set up the
3051 error handling. When libpng encounters an error, it expects to
3052 longjmp() back to your routine. Therefore, you will need to call
3053 setjmp() and pass the png_jmpbuf(png_ptr). If you
3054 write the file from different routines, you will need to update
3055 the png_jmpbuf(png_ptr) every time you enter a new routine that will
3056 call a png_*() function. See your documentation of setjmp/longjmp
3057 for your compiler for more information on setjmp/longjmp. See
3058 the discussion on libpng error handling in the Customizing Libpng
3059 section below for more information on the libpng error handling.
3060
3061 if (setjmp(png_jmpbuf(png_ptr)))
3062 {
3063 png_destroy_write_struct(&png_ptr, &info_ptr);
3064 fclose(fp);
3065 return (ERROR);
3066 }
3067 ...
3068 return;
3069
3070 If you would rather avoid the complexity of setjmp/longjmp issues,
3071 you can compile libpng with PNG_NO_SETJMP, in which case
3072 errors will result in a call to PNG_ABORT() which defaults to abort().
3073
3074 You can #define PNG_ABORT() to a function that does something
3075 more useful than abort(), as long as your function does not
3076 return.
3077
3078 Checking for invalid palette index on write was added at libpng
3079 1.5.10. If a pixel contains an invalid (out-of-range) index libpng issues
3080 a benign error. This is enabled by default because this condition is an
3081 error according to the PNG specification, Clause 11.3.2, but the error can
3082 be ignored in each png_ptr with
3083
3084 png_set_check_for_invalid_index(png_ptr, 0);
3085
3086 If the error is ignored, or if png_benign_error() treats it as a warning,
3087 any invalid pixels are written as-is by the encoder, resulting in an
3088 invalid PNG datastream as output. In this case the application is
3089 responsible for ensuring that the pixel indexes are in range when it writes
3090 a PLTE chunk with fewer entries than the bit depth would allow.
3091
3092 Now you need to set up the output code. The default for libpng is to
3093 use the C function fwrite(). If you use this, you will need to pass a
3094 valid FILE * in the function png_init_io(). Be sure that the file is
3095 opened in binary mode. Again, if you wish to handle writing data in
3096 another way, see the discussion on libpng I/O handling in the Customizing
3097 Libpng section below.
3098
3099 png_init_io(png_ptr, fp);
3100
3101 If you are embedding your PNG into a datastream such as MNG, and don't
3102 want libpng to write the 8-byte signature, or if you have already
3103 written the signature in your application, use
3104
3105 png_set_sig_bytes(png_ptr, 8);
3106
3107 to inform libpng that it should not write a signature.
3108
3109 .SS Write callbacks
3110
3111 At this point, you can set up a callback function that will be
3112 called after each row has been written, which you can use to control
3113 a progress meter or the like. It's demonstrated in pngtest.c.
3114 You must supply a function
3115
3116 void write_row_callback(png_structp png_ptr, png_uint_32 row,
3117 int pass);
3118 {
3119 /* put your code here */
3120 }
3121
3122 (You can give it another name that you like instead of "write_row_callback")
3123
3124 To inform libpng about your function, use
3125
3126 png_set_write_status_fn(png_ptr, write_row_callback);
3127
3128 When this function is called the row has already been completely processed and
3129 it has also been written out. The 'row' and 'pass' refer to the next row to be
3130 handled. For the
3131 non-interlaced case the row that was just handled is simply one less than the
3132 passed in row number, and pass will always be 0. For the interlaced case the
3133 same applies unless the row value is 0, in which case the row just handled was
3134 the last one from one of the preceding passes. Because interlacing may skip a
3135 pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3136 need to know what the last pass is record (row,pass) from the callback and use
3137 the last recorded value each time.
3138
3139 As with the user transform you can find the output row using the
3140 PNG_ROW_FROM_PASS_ROW macro.
3141
3142 You now have the option of modifying how the compression library will
3143 run. The following functions are mainly for testing, but may be useful
3144 in some cases, like if you need to write PNG files extremely fast and
3145 are willing to give up some compression, or if you want to get the
3146 maximum possible compression at the expense of slower writing. If you
3147 have no special needs in this area, let the library do what it wants by
3148 not calling this function at all, as it has been tuned to deliver a good
3149 speed/compression ratio. The second parameter to png_set_filter() is
3150 the filter method, for which the only valid values are 0 (as of the
3151 July 1999 PNG specification, version 1.2) or 64 (if you are writing
3152 a PNG datastream that is to be embedded in a MNG datastream). The third
3153 parameter is a flag that indicates which filter type(s) are to be tested
3154 for each scanline. See the PNG specification for details on the specific
3155 filter types.
3156
3157
3158 /* turn on or off filtering, and/or choose
3159 specific filters. You can use either a single
3160 PNG_FILTER_VALUE_NAME or the bitwise OR of one
3161 or more PNG_FILTER_NAME masks.
3162 */
3163 png_set_filter(png_ptr, 0,
3164 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
3165 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
3166 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
3167 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
3168 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3169 PNG_ALL_FILTERS);
3170
3171 If an application wants to start and stop using particular filters during
3172 compression, it should start out with all of the filters (to ensure that
3173 the previous row of pixels will be stored in case it's needed later),
3174 and then add and remove them after the start of compression.
3175
3176 If you are writing a PNG datastream that is to be embedded in a MNG
3177 datastream, the second parameter can be either 0 or 64.
3178
3179 The png_set_compression_*() functions interface to the zlib compression
3180 library, and should mostly be ignored unless you really know what you are
3181 doing. The only generally useful call is png_set_compression_level()
3182 which changes how much time zlib spends on trying to compress the image
3183 data. See the Compression Library (zlib.h and algorithm.txt, distributed
3184 with zlib) for details on the compression levels.
3185
3186 #include zlib.h
3187
3188 /* Set the zlib compression level */
3189 png_set_compression_level(png_ptr,
3190 Z_BEST_COMPRESSION);
3191
3192 /* Set other zlib parameters for compressing IDAT */
3193 png_set_compression_mem_level(png_ptr, 8);
3194 png_set_compression_strategy(png_ptr,
3195 Z_DEFAULT_STRATEGY);
3196 png_set_compression_window_bits(png_ptr, 15);
3197 png_set_compression_method(png_ptr, 8);
3198 png_set_compression_buffer_size(png_ptr, 8192)
3199
3200 /* Set zlib parameters for text compression
3201 * If you don't call these, the parameters
3202 * fall back on those defined for IDAT chunks
3203 */
3204 png_set_text_compression_mem_level(png_ptr, 8);
3205 png_set_text_compression_strategy(png_ptr,
3206 Z_DEFAULT_STRATEGY);
3207 png_set_text_compression_window_bits(png_ptr, 15);
3208 png_set_text_compression_method(png_ptr, 8);
3209
3210 .SS Setting the contents of info for output
3211
3212 You now need to fill in the png_info structure with all the data you
3213 wish to write before the actual image. Note that the only thing you
3214 are allowed to write after the image is the text chunks and the time
3215 chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
3216 the latest PNG specification for more information on that. If you
3217 wish to write them before the image, fill them in now, and flag that
3218 data as being valid. If you want to wait until after the data, don't
3219 fill them until png_write_end(). For all the fields in png_info and
3220 their data types, see png.h. For explanations of what the fields
3221 contain, see the PNG specification.
3222
3223 Some of the more important parts of the png_info are:
3224
3225 png_set_IHDR(png_ptr, info_ptr, width, height,
3226 bit_depth, color_type, interlace_type,
3227 compression_type, filter_method)
3228
3229 width - holds the width of the image
3230 in pixels (up to 2^31).
3231
3232 height - holds the height of the image
3233 in pixels (up to 2^31).
3234
3235 bit_depth - holds the bit depth of one of the
3236 image channels.
3237 (valid values are 1, 2, 4, 8, 16
3238 and depend also on the
3239 color_type. See also significant
3240 bits (sBIT) below).
3241
3242 color_type - describes which color/alpha
3243 channels are present.
3244 PNG_COLOR_TYPE_GRAY
3245 (bit depths 1, 2, 4, 8, 16)
3246 PNG_COLOR_TYPE_GRAY_ALPHA
3247 (bit depths 8, 16)
3248 PNG_COLOR_TYPE_PALETTE
3249 (bit depths 1, 2, 4, 8)
3250 PNG_COLOR_TYPE_RGB
3251 (bit_depths 8, 16)
3252 PNG_COLOR_TYPE_RGB_ALPHA
3253 (bit_depths 8, 16)
3254
3255 PNG_COLOR_MASK_PALETTE
3256 PNG_COLOR_MASK_COLOR
3257 PNG_COLOR_MASK_ALPHA
3258
3259 interlace_type - PNG_INTERLACE_NONE or
3260 PNG_INTERLACE_ADAM7
3261
3262 compression_type - (must be
3263 PNG_COMPRESSION_TYPE_DEFAULT)
3264
3265 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
3266 or, if you are writing a PNG to
3267 be embedded in a MNG datastream,
3268 can also be
3269 PNG_INTRAPIXEL_DIFFERENCING)
3270
3271 If you call png_set_IHDR(), the call must appear before any of the
3272 other png_set_*() functions, because they might require access to some of
3273 the IHDR settings. The remaining png_set_*() functions can be called
3274 in any order.
3275
3276 If you wish, you can reset the compression_type, interlace_type, or
3277 filter_method later by calling png_set_IHDR() again; if you do this, the
3278 width, height, bit_depth, and color_type must be the same in each call.
3279
3280 png_set_PLTE(png_ptr, info_ptr, palette,
3281 num_palette);
3282
3283 palette - the palette for the file
3284 (array of png_color)
3285 num_palette - number of entries in the palette
3286
3287 png_set_gAMA(png_ptr, info_ptr, file_gamma);
3288 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
3289
3290 file_gamma - the gamma at which the image was
3291 created (PNG_INFO_gAMA)
3292
3293 int_file_gamma - 100,000 times the gamma at which
3294 the image was created
3295
3296 png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y,
3297 green_x, green_y, blue_x, blue_y)
3298 png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,
3299 green_Y, green_Z, blue_X, blue_Y, blue_Z)
3300 png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,
3301 int_red_x, int_red_y, int_green_x, int_green_y,
3302 int_blue_x, int_blue_y)
3303 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,
3304 int_red_Z, int_green_X, int_green_Y, int_green_Z,
3305 int_blue_X, int_blue_Y, int_blue_Z)
3306
3307 {white,red,green,blue}_{x,y}
3308 A color space encoding specified using the chromaticities
3309 of the end points and the white point.
3310
3311 {red,green,blue}_{X,Y,Z}
3312 A color space encoding specified using the encoding end
3313 points - the CIE tristimulus specification of the intended
3314 color of the red, green and blue channels in the PNG RGB
3315 data. The white point is simply the sum of the three end
3316 points.
3317
3318 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
3319
3320 srgb_intent - the rendering intent
3321 (PNG_INFO_sRGB) The presence of
3322 the sRGB chunk means that the pixel
3323 data is in the sRGB color space.
3324 This chunk also implies specific
3325 values of gAMA and cHRM. Rendering
3326 intent is the CSS-1 property that
3327 has been defined by the International
3328 Color Consortium
3329 (http://www.color.org).
3330 It can be one of
3331 PNG_sRGB_INTENT_SATURATION,
3332 PNG_sRGB_INTENT_PERCEPTUAL,
3333 PNG_sRGB_INTENT_ABSOLUTE, or
3334 PNG_sRGB_INTENT_RELATIVE.
3335
3336
3337 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
3338 srgb_intent);
3339
3340 srgb_intent - the rendering intent
3341 (PNG_INFO_sRGB) The presence of the
3342 sRGB chunk means that the pixel
3343 data is in the sRGB color space.
3344 This function also causes gAMA and
3345 cHRM chunks with the specific values
3346 that are consistent with sRGB to be
3347 written.
3348
3349 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
3350 profile, proflen);
3351
3352 name - The profile name.
3353
3354 compression_type - The compression type; always
3355 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
3356 You may give NULL to this argument to
3357 ignore it.
3358
3359 profile - International Color Consortium color
3360 profile data. May contain NULs.
3361
3362 proflen - length of profile data in bytes.
3363
3364 png_set_sBIT(png_ptr, info_ptr, sig_bit);
3365
3366 sig_bit - the number of significant bits for
3367 (PNG_INFO_sBIT) each of the gray, red,
3368 green, and blue channels, whichever are
3369 appropriate for the given color type
3370 (png_color_16)
3371
3372 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3373 num_trans, trans_color);
3374
3375 trans_alpha - array of alpha (transparency)
3376 entries for palette (PNG_INFO_tRNS)
3377
3378 num_trans - number of transparent entries
3379 (PNG_INFO_tRNS)
3380
3381 trans_color - graylevel or color sample values
3382 (in order red, green, blue) of the
3383 single transparent color for
3384 non-paletted images (PNG_INFO_tRNS)
3385
3386 png_set_hIST(png_ptr, info_ptr, hist);
3387
3388 hist - histogram of palette (array of
3389 png_uint_16) (PNG_INFO_hIST)
3390
3391 png_set_tIME(png_ptr, info_ptr, mod_time);
3392
3393 mod_time - time image was last modified
3394 (PNG_VALID_tIME)
3395
3396 png_set_bKGD(png_ptr, info_ptr, background);
3397
3398 background - background color (of type
3399 png_color_16p) (PNG_VALID_bKGD)
3400
3401 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
3402
3403 text_ptr - array of png_text holding image
3404 comments
3405
3406 text_ptr[i].compression - type of compression used
3407 on "text" PNG_TEXT_COMPRESSION_NONE
3408 PNG_TEXT_COMPRESSION_zTXt
3409 PNG_ITXT_COMPRESSION_NONE
3410 PNG_ITXT_COMPRESSION_zTXt
3411 text_ptr[i].key - keyword for comment. Must contain
3412 1-79 characters.
3413 text_ptr[i].text - text comments for current
3414 keyword. Can be NULL or empty.
3415 text_ptr[i].text_length - length of text string,
3416 after decompression, 0 for iTXt
3417 text_ptr[i].itxt_length - length of itxt string,
3418 after decompression, 0 for tEXt/zTXt
3419 text_ptr[i].lang - language of comment (NULL or
3420 empty for unknown).
3421 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
3422 or empty for unknown).
3423
3424 Note that the itxt_length, lang, and lang_key
3425 members of the text_ptr structure only exist when the
3426 library is built with iTXt chunk support. Prior to
3427 libpng-1.4.0 the library was built by default without
3428 iTXt support. Also note that when iTXt is supported,
3429 they contain NULL pointers when the "compression"
3430 field contains PNG_TEXT_COMPRESSION_NONE or
3431 PNG_TEXT_COMPRESSION_zTXt.
3432
3433 num_text - number of comments
3434
3435 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3436 num_spalettes);
3437
3438 palette_ptr - array of png_sPLT_struct structures
3439 to be added to the list of palettes
3440 in the info structure.
3441 num_spalettes - number of palette structures to be
3442 added.
3443
3444 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
3445 unit_type);
3446
3447 offset_x - positive offset from the left
3448 edge of the screen
3449
3450 offset_y - positive offset from the top
3451 edge of the screen
3452
3453 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
3454
3455 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
3456 unit_type);
3457
3458 res_x - pixels/unit physical resolution
3459 in x direction
3460
3461 res_y - pixels/unit physical resolution
3462 in y direction
3463
3464 unit_type - PNG_RESOLUTION_UNKNOWN,
3465 PNG_RESOLUTION_METER
3466
3467 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
3468
3469 unit - physical scale units (an integer)
3470
3471 width - width of a pixel in physical scale units
3472
3473 height - height of a pixel in physical scale units
3474 (width and height are doubles)
3475
3476 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
3477
3478 unit - physical scale units (an integer)
3479
3480 width - width of a pixel in physical scale units
3481 expressed as a string
3482
3483 height - height of a pixel in physical scale units
3484 (width and height are strings like "2.54")
3485
3486 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
3487 num_unknowns)
3488
3489 unknowns - array of png_unknown_chunk
3490 structures holding unknown chunks
3491 unknowns[i].name - name of unknown chunk
3492 unknowns[i].data - data of unknown chunk
3493 unknowns[i].size - size of unknown chunk's data
3494 unknowns[i].location - position to write chunk in file
3495 0: do not write chunk
3496 PNG_HAVE_IHDR: before PLTE
3497 PNG_HAVE_PLTE: before IDAT
3498 PNG_AFTER_IDAT: after IDAT
3499
3500 The "location" member is set automatically according to
3501 what part of the output file has already been written.
3502 You can change its value after calling png_set_unknown_chunks()
3503 as demonstrated in pngtest.c. Within each of the "locations",
3504 the chunks are sequenced according to their position in the
3505 structure (that is, the value of "i", which is the order in which
3506 the chunk was either read from the input file or defined with
3507 png_set_unknown_chunks).
3508
3509 A quick word about text and num_text. text is an array of png_text
3510 structures. num_text is the number of valid structures in the array.
3511 Each png_text structure holds a language code, a keyword, a text value,
3512 and a compression type.
3513
3514 The compression types have the same valid numbers as the compression
3515 types of the image data. Currently, the only valid number is zero.
3516 However, you can store text either compressed or uncompressed, unlike
3517 images, which always have to be compressed. So if you don't want the
3518 text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
3519 Because tEXt and zTXt chunks don't have a language field, if you
3520 specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3521 any language code or translated keyword will not be written out.
3522
3523 Until text gets around a few hundred bytes, it is not worth compressing it.
3524 After the text has been written out to the file, the compression type
3525 is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3526 so that it isn't written out again at the end (in case you are calling
3527 png_write_end() with the same struct).
3528
3529 The keywords that are given in the PNG Specification are:
3530
3531 Title Short (one line) title or
3532 caption for image
3533
3534 Author Name of image's creator
3535
3536 Description Description of image (possibly long)
3537
3538 Copyright Copyright notice
3539
3540 Creation Time Time of original image creation
3541 (usually RFC 1123 format, see below)
3542
3543 Software Software used to create the image
3544
3545 Disclaimer Legal disclaimer
3546
3547 Warning Warning of nature of content
3548
3549 Source Device used to create the image
3550
3551 Comment Miscellaneous comment; conversion
3552 from other image format
3553
3554 The keyword-text pairs work like this. Keywords should be short
3555 simple descriptions of what the comment is about. Some typical
3556 keywords are found in the PNG specification, as is some recommendations
3557 on keywords. You can repeat keywords in a file. You can even write
3558 some text before the image and some after. For example, you may want
3559 to put a description of the image before the image, but leave the
3560 disclaimer until after, so viewers working over modem connections
3561 don't have to wait for the disclaimer to go over the modem before
3562 they start seeing the image. Finally, keywords should be full
3563 words, not abbreviations. Keywords and text are in the ISO 8859-1
3564 (Latin-1) character set (a superset of regular ASCII) and can not
3565 contain NUL characters, and should not contain control or other
3566 unprintable characters. To make the comments widely readable, stick
3567 with basic ASCII, and avoid machine specific character set extensions
3568 like the IBM-PC character set. The keyword must be present, but
3569 you can leave off the text string on non-compressed pairs.
3570 Compressed pairs must have a text string, as only the text string
3571 is compressed anyway, so the compression would be meaningless.
3572
3573 PNG supports modification time via the png_time structure. Two
3574 conversion routines are provided, png_convert_from_time_t() for
3575 time_t and png_convert_from_struct_tm() for struct tm. The
3576 time_t routine uses gmtime(). You don't have to use either of
3577 these, but if you wish to fill in the png_time structure directly,
3578 you should provide the time in universal time (GMT) if possible
3579 instead of your local time. Note that the year number is the full
3580 year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
3581 that months start with 1.
3582
3583 If you want to store the time of the original image creation, you should
3584 use a plain tEXt chunk with the "Creation Time" keyword. This is
3585 necessary because the "creation time" of a PNG image is somewhat vague,
3586 depending on whether you mean the PNG file, the time the image was
3587 created in a non-PNG format, a still photo from which the image was
3588 scanned, or possibly the subject matter itself. In order to facilitate
3589 machine-readable dates, it is recommended that the "Creation Time"
3590 tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
3591 although this isn't a requirement. Unlike the tIME chunk, the
3592 "Creation Time" tEXt chunk is not expected to be automatically changed
3593 by the software. To facilitate the use of RFC 1123 dates, a function
3594 png_convert_to_rfc1123_buffer(png_ptr, buffer, png_timep) is provided to
3595 convert from PNG time to an RFC 1123 format string. The caller must provide
3596 a writeable buffer of at least 29 bytes.
3597
3598 .SS Writing unknown chunks
3599
3600 You can use the png_set_unknown_chunks function to queue up chunks
3601 for writing. You give it a chunk name, raw data, and a size; that's
3602 all there is to it. The chunks will be written by the next following
3603 png_write_info_before_PLTE, png_write_info, or png_write_end function.
3604 Any chunks previously read into the info structure's unknown-chunk
3605 list will also be written out in a sequence that satisfies the PNG
3606 specification's ordering rules.
3607
3608 .SS The high-level write interface
3609
3610 At this point there are two ways to proceed; through the high-level
3611 write interface, or through a sequence of low-level write operations.
3612 You can use the high-level interface if your image data is present
3613 in the info structure. All defined output
3614 transformations are permitted, enabled by the following masks.
3615
3616 PNG_TRANSFORM_IDENTITY No transformation
3617 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
3618 PNG_TRANSFORM_PACKSWAP Change order of packed
3619 pixels to LSB first
3620 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
3621 PNG_TRANSFORM_SHIFT Normalize pixels to the
3622 sBIT depth
3623 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
3624 to BGRA
3625 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
3626 to AG
3627 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
3628 to transparency
3629 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
3630 PNG_TRANSFORM_STRIP_FILLER Strip out filler
3631 bytes (deprecated).
3632 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
3633 filler bytes
3634 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
3635 filler bytes
3636
3637 If you have valid image data in the info structure (you can use
3638 png_set_rows() to put image data in the info structure), simply do this:
3639
3640 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
3641
3642 where png_transforms is an integer containing the bitwise OR of some set of
3643 transformation flags. This call is equivalent to png_write_info(),
3644 followed the set of transformations indicated by the transform mask,
3645 then png_write_image(), and finally png_write_end().
3646
3647 (The final parameter of this call is not yet used. Someday it might point
3648 to transformation parameters required by some future output transform.)
3649
3650 You must use png_transforms and not call any png_set_transform() functions
3651 when you use png_write_png().
3652
3653 .SS The low-level write interface
3654
3655 If you are going the low-level route instead, you are now ready to
3656 write all the file information up to the actual image data. You do
3657 this with a call to png_write_info().
3658
3659 png_write_info(png_ptr, info_ptr);
3660
3661 Note that there is one transformation you may need to do before
3662 png_write_info(). In PNG files, the alpha channel in an image is the
3663 level of opacity. If your data is supplied as a level of transparency,
3664 you can invert the alpha channel before you write it, so that 0 is
3665 fully transparent and 255 (in 8-bit or paletted images) or 65535
3666 (in 16-bit images) is fully opaque, with
3667
3668 png_set_invert_alpha(png_ptr);
3669
3670 This must appear before png_write_info() instead of later with the
3671 other transformations because in the case of paletted images the tRNS
3672 chunk data has to be inverted before the tRNS chunk is written. If
3673 your image is not a paletted image, the tRNS data (which in such cases
3674 represents a single color to be rendered as transparent) won't need to
3675 be changed, and you can safely do this transformation after your
3676 png_write_info() call.
3677
3678 If you need to write a private chunk that you want to appear before
3679 the PLTE chunk when PLTE is present, you can write the PNG info in
3680 two steps, and insert code to write your own chunk between them:
3681
3682 png_write_info_before_PLTE(png_ptr, info_ptr);
3683 png_set_unknown_chunks(png_ptr, info_ptr, ...);
3684 png_write_info(png_ptr, info_ptr);
3685
3686 After you've written the file information, you can set up the library
3687 to handle any special transformations of the image data. The various
3688 ways to transform the data will be described in the order that they
3689 should occur. This is important, as some of these change the color
3690 type and/or bit depth of the data, and some others only work on
3691 certain color types and bit depths. Even though each transformation
3692 checks to see if it has data that it can do something with, you should
3693 make sure to only enable a transformation if it will be valid for the
3694 data. For example, don't swap red and blue on grayscale data.
3695
3696 PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
3697 the library to strip input data that has 4 or 8 bytes per pixel down
3698 to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
3699 bytes per pixel).
3700
3701 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
3702
3703 where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
3704 PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
3705 is stored XRGB or RGBX.
3706
3707 PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
3708 they can, resulting in, for example, 8 pixels per byte for 1 bit files.
3709 If the data is supplied at 1 pixel per byte, use this code, which will
3710 correctly pack the pixels into a single byte:
3711
3712 png_set_packing(png_ptr);
3713
3714 PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
3715 data is of another bit depth, you can write an sBIT chunk into the
3716 file so that decoders can recover the original data if desired.
3717
3718 /* Set the true bit depth of the image data */
3719 if (color_type & PNG_COLOR_MASK_COLOR)
3720 {
3721 sig_bit.red = true_bit_depth;
3722 sig_bit.green = true_bit_depth;
3723 sig_bit.blue = true_bit_depth;
3724 }
3725
3726 else
3727 {
3728 sig_bit.gray = true_bit_depth;
3729 }
3730
3731 if (color_type & PNG_COLOR_MASK_ALPHA)
3732 {
3733 sig_bit.alpha = true_bit_depth;
3734 }
3735
3736 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
3737
3738 If the data is stored in the row buffer in a bit depth other than
3739 one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
3740 this will scale the values to appear to be the correct bit depth as
3741 is required by PNG.
3742
3743 png_set_shift(png_ptr, &sig_bit);
3744
3745 PNG files store 16-bit pixels in network byte order (big-endian,
3746 ie. most significant bits first). This code would be used if they are
3747 supplied the other way (little-endian, i.e. least significant bits
3748 first, the way PCs store them):
3749
3750 if (bit_depth > 8)
3751 png_set_swap(png_ptr);
3752
3753 If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
3754 need to change the order the pixels are packed into bytes, you can use:
3755
3756 if (bit_depth < 8)
3757 png_set_packswap(png_ptr);
3758
3759 PNG files store 3 color pixels in red, green, blue order. This code
3760 would be used if they are supplied as blue, green, red:
3761
3762 png_set_bgr(png_ptr);
3763
3764 PNG files describe monochrome as black being zero and white being
3765 one. This code would be used if the pixels are supplied with this reversed
3766 (black being one and white being zero):
3767
3768 png_set_invert_mono(png_ptr);
3769
3770 Finally, you can write your own transformation function if none of
3771 the existing ones meets your needs. This is done by setting a callback
3772 with
3773
3774 png_set_write_user_transform_fn(png_ptr,
3775 write_transform_fn);
3776
3777 You must supply the function
3778
3779 void write_transform_fn(png_structp png_ptr, png_row_infop
3780 row_info, png_bytep data)
3781
3782 See pngtest.c for a working example. Your function will be called
3783 before any of the other transformations are processed. If supported
3784 libpng also supplies an information routine that may be called from
3785 your callback:
3786
3787 png_get_current_row_number(png_ptr);
3788 png_get_current_pass_number(png_ptr);
3789
3790 This returns the current row passed to the transform. With interlaced
3791 images the value returned is the row in the input sub-image image. Use
3792 PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
3793 find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
3794
3795 The discussion of interlace handling above contains more information on how to
3796 use these values.
3797
3798 You can also set up a pointer to a user structure for use by your
3799 callback function.
3800
3801 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
3802
3803 The user_channels and user_depth parameters of this function are ignored
3804 when writing; you can set them to zero as shown.
3805
3806 You can retrieve the pointer via the function png_get_user_transform_ptr().
3807 For example:
3808
3809 voidp write_user_transform_ptr =
3810 png_get_user_transform_ptr(png_ptr);
3811
3812 It is possible to have libpng flush any pending output, either manually,
3813 or automatically after a certain number of lines have been written. To
3814 flush the output stream a single time call:
3815
3816 png_write_flush(png_ptr);
3817
3818 and to have libpng flush the output stream periodically after a certain
3819 number of scanlines have been written, call:
3820
3821 png_set_flush(png_ptr, nrows);
3822
3823 Note that the distance between rows is from the last time png_write_flush()
3824 was called, or the first row of the image if it has never been called.
3825 So if you write 50 lines, and then png_set_flush 25, it will flush the
3826 output on the next scanline, and every 25 lines thereafter, unless
3827 png_write_flush() is called before 25 more lines have been written.
3828 If nrows is too small (less than about 10 lines for a 640 pixel wide
3829 RGB image) the image compression may decrease noticeably (although this
3830 may be acceptable for real-time applications). Infrequent flushing will
3831 only degrade the compression performance by a few percent over images
3832 that do not use flushing.
3833
3834 .SS Writing the image data
3835
3836 That's it for the transformations. Now you can write the image data.
3837 The simplest way to do this is in one function call. If you have the
3838 whole image in memory, you can just call png_write_image() and libpng
3839 will write the image. You will need to pass in an array of pointers to
3840 each row. This function automatically handles interlacing, so you don't
3841 need to call png_set_interlace_handling() or call this function multiple
3842 times, or any of that other stuff necessary with png_write_rows().
3843
3844 png_write_image(png_ptr, row_pointers);
3845
3846 where row_pointers is:
3847
3848 png_byte *row_pointers[height];
3849
3850 You can point to void or char or whatever you use for pixels.
3851
3852 If you don't want to write the whole image at once, you can
3853 use png_write_rows() instead. If the file is not interlaced,
3854 this is simple:
3855
3856 png_write_rows(png_ptr, row_pointers,
3857 number_of_rows);
3858
3859 row_pointers is the same as in the png_write_image() call.
3860
3861 If you are just writing one row at a time, you can do this with
3862 a single row_pointer instead of an array of row_pointers:
3863
3864 png_bytep row_pointer = row;
3865
3866 png_write_row(png_ptr, row_pointer);
3867
3868 When the file is interlaced, things can get a good deal more complicated.
3869 The only currently (as of the PNG Specification version 1.2, dated July
3870 1999) defined interlacing scheme for PNG files is the "Adam7" interlace
3871 scheme, that breaks down an image into seven smaller images of varying
3872 size. libpng will build these images for you, or you can do them
3873 yourself. If you want to build them yourself, see the PNG specification
3874 for details of which pixels to write when.
3875
3876 If you don't want libpng to handle the interlacing details, just
3877 use png_set_interlace_handling() and call png_write_rows() the
3878 correct number of times to write all the sub-images
3879 (png_set_interlace_handling() returns the number of sub-images.)
3880
3881 If you want libpng to build the sub-images, call this before you start
3882 writing any rows:
3883
3884 number_of_passes = png_set_interlace_handling(png_ptr);
3885
3886 This will return the number of passes needed. Currently, this is seven,
3887 but may change if another interlace type is added.
3888
3889 Then write the complete image number_of_passes times.
3890
3891 png_write_rows(png_ptr, row_pointers, number_of_rows);
3892
3893 Think carefully before you write an interlaced image. Typically code that
3894 reads such images reads all the image data into memory, uncompressed, before
3895 doing any processing. Only code that can display an image on the fly can
3896 take advantage of the interlacing and even then the image has to be exactly
3897 the correct size for the output device, because scaling an image requires
3898 adjacent pixels and these are not available until all the passes have been
3899 read.
3900
3901 If you do write an interlaced image you will hardly ever need to handle
3902 the interlacing yourself. Call png_set_interlace_handling() and use the
3903 approach described above.
3904
3905 The only time it is conceivable that you will really need to write an
3906 interlaced image pass-by-pass is when you have read one pass by pass and
3907 made some pixel-by-pixel transformation to it, as described in the read
3908 code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
3909 to determine the size of each sub-image in turn and simply write the rows
3910 you obtained from the read code.
3911
3912 .SS Finishing a sequential write
3913
3914 After you are finished writing the image, you should finish writing
3915 the file. If you are interested in writing comments or time, you should
3916 pass an appropriately filled png_info pointer. If you are not interested,
3917 you can pass NULL.
3918
3919 png_write_end(png_ptr, info_ptr);
3920
3921 When you are done, you can free all memory used by libpng like this:
3922
3923 png_destroy_write_struct(&png_ptr, &info_ptr);
3924
3925 It is also possible to individually free the info_ptr members that
3926 point to libpng-allocated storage with the following function:
3927
3928 png_free_data(png_ptr, info_ptr, mask, seq)
3929
3930 mask - identifies data to be freed, a mask
3931 containing the bitwise OR of one or
3932 more of
3933 PNG_FREE_PLTE, PNG_FREE_TRNS,
3934 PNG_FREE_HIST, PNG_FREE_ICCP,
3935 PNG_FREE_PCAL, PNG_FREE_ROWS,
3936 PNG_FREE_SCAL, PNG_FREE_SPLT,
3937 PNG_FREE_TEXT, PNG_FREE_UNKN,
3938 or simply PNG_FREE_ALL
3939
3940 seq - sequence number of item to be freed
3941 (-1 for all items)
3942
3943 This function may be safely called when the relevant storage has
3944 already been freed, or has not yet been allocated, or was allocated
3945 by the user and not by libpng, and will in those cases do nothing.
3946 The "seq" parameter is ignored if only one item of the selected data
3947 type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3948 are allowed for the data type identified in the mask, such as text or
3949 sPLT, only the n'th item in the structure is freed, where n is "seq".
3950
3951 If you allocated data such as a palette that you passed in to libpng
3952 with png_set_*, you must not free it until just before the call to
3953 png_destroy_write_struct().
3954
3955 The default behavior is only to free data that was allocated internally
3956 by libpng. This can be changed, so that libpng will not free the data,
3957 or so that it will free data that was allocated by the user with png_malloc()
3958 or png_calloc() and passed in via a png_set_*() function, with
3959
3960 png_data_freer(png_ptr, info_ptr, freer, mask)
3961
3962 freer - one of
3963 PNG_DESTROY_WILL_FREE_DATA
3964 PNG_SET_WILL_FREE_DATA
3965 PNG_USER_WILL_FREE_DATA
3966
3967 mask - which data elements are affected
3968 same choices as in png_free_data()
3969
3970 For example, to transfer responsibility for some data from a read structure
3971 to a write structure, you could use
3972
3973 png_data_freer(read_ptr, read_info_ptr,
3974 PNG_USER_WILL_FREE_DATA,
3975 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3976
3977 png_data_freer(write_ptr, write_info_ptr,
3978 PNG_DESTROY_WILL_FREE_DATA,
3979 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3980
3981 thereby briefly reassigning responsibility for freeing to the user but
3982 immediately afterwards reassigning it once more to the write_destroy
3983 function. Having done this, it would then be safe to destroy the read
3984 structure and continue to use the PLTE, tRNS, and hIST data in the write
3985 structure.
3986
3987 This function only affects data that has already been allocated.
3988 You can call this function before calling after the png_set_*() functions
3989 to control whether the user or png_destroy_*() is supposed to free the data.
3990 When the user assumes responsibility for libpng-allocated data, the
3991 application must use
3992 png_free() to free it, and when the user transfers responsibility to libpng
3993 for data that the user has allocated, the user must have used png_malloc()
3994 or png_calloc() to allocate it.
3995
3996 If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3997 separately, do not transfer responsibility for freeing text_ptr to libpng,
3998 because when libpng fills a png_text structure it combines these members with
3999 the key member, and png_free_data() will free only text_ptr.key. Similarly,
4000 if you transfer responsibility for free'ing text_ptr from libpng to your
4001 application, your application must not separately free those members.
4002 For a more compact example of writing a PNG image, see the file example.c.
4003
4004 .SH V. Simplified API
4005
4006 The simplified API, which became available in libpng-1.6.0, hides the details
4007 of both libpng and the PNG file format itself.
4008 It allows PNG files to be read into a very limited number of
4009 in-memory bitmap formats or to be written from the same formats. If these
4010 formats do not accomodate your needs then you can, and should, use the more
4011 sophisticated APIs above - these support a wide variety of in-memory formats
4012 and a wide variety of sophisticated transformations to those formats as well
4013 as a wide variety of APIs to manipulate ancilliary information.
4014
4015 To read a PNG file using the simplified API:
4016
4017 1) Declare a 'png_image' structure (see below) on the
4018 stack and memset() it to all zero.
4019
4020 2) Call the appropriate png_image_begin_read... function.
4021
4022 3) Set the png_image 'format' member to the required
4023 format and allocate a buffer for the image.
4024
4025 4) Call png_image_finish_read to read the image into
4026 your buffer.
4027
4028 There are no restrictions on the format of the PNG input itself; all valid
4029 color types, bit depths, and interlace methods are acceptable, and the
4030 input image is transformed as necessary to the requested in-memory format
4031 during the png_image_finish_read() step.
4032
4033 To write a PNG file using the simplified API:
4034
4035 1) Declare a 'png_image' structure on the stack and memset()
4036 it to all zero.
4037
4038 2) Initialize the members of the structure that describe the
4039 image, setting the 'format' member to the format of the
4040 image in memory.
4041
4042 3) Call the appropriate png_image_write... function with a
4043 pointer to the image to write the PNG data.
4044
4045 png_image is a structure that describes the in-memory format of an image
4046 when it is being read or define the in-memory format of an image that you
4047 need to write. The "png_image" structure contains the following members:
4048
4049 png_uint_32 version Set to PNG_IMAGE_VERSION
4050 png_uint_32 width Image width in pixels (columns)
4051 png_uint_32 height Image height in pixels (rows)
4052 png_uint_32 format Image format as defined below
4053 png_uint_32 flags A bit mask containing informational flags
4054 png_controlp opaque Initialize to NULL, free with png_image_free
4055 png_uint_32 colormap_entries; Number of entries in the color-map
4056 png_uint_32 warning_or_error;
4057 char message[64];
4058
4059 In the event of an error or warning the following field warning_or_error
4060 field will be set to a non-zero value and the 'message' field will contain
4061 a '\0' terminated string with the libpng error or warning message. If both
4062 warnings and an error were encountered, only the error is recorded. If there
4063 are multiple warnings, only the first one is recorded.
4064
4065 The upper 30 bits of this value are reserved; the low two bits contain
4066 a two bit code such that a value more than 1 indicates a failure in the API
4067 just called:
4068
4069 0 - no warning or error
4070 1 - warning
4071 2 - error
4072 3 - error preceded by warning
4073
4074 The pixels (samples) of the image have one to four channels whose components
4075 have original values in the range 0 to 1.0:
4076
4077 1: A single gray or luminance channel (G).
4078 2: A gray/luminance channel and an alpha channel (GA).
4079 3: Three red, green, blue color channels (RGB).
4080 4: Three color channels and an alpha channel (RGBA).
4081
4082 The channels are encoded in one of two ways:
4083
4084 a) As a small integer, value 0..255, contained in a single byte. For the
4085 alpha channel the original value is simply value/255. For the color or
4086 luminance channels the value is encoded according to the sRGB specification
4087 and matches the 8-bit format expected by typical display devices.
4088
4089 The color/gray channels are not scaled (pre-multiplied) by the alpha
4090 channel and are suitable for passing to color management software.
4091
4092 b) As a value in the range 0..65535, contained in a 2-byte integer. All
4093 channels can be converted to the original value by dividing by 65535; all
4094 channels are linear. Color channels use the RGB encoding (RGB end-points) of
4095 the sRGB specification. This encoding is identified by the
4096 PNG_FORMAT_FLAG_LINEAR flag below.
4097
4098 When an alpha channel is present it is expected to denote pixel coverage
4099 of the color or luminance channels and is returned as an associated alpha
4100 channel: the color/gray channels are scaled (pre-multiplied) by the alpha
4101 value.
4102
4103 When a color-mapped image is used as a result of calling
4104 png_image_read_colormap or png_image_write_colormap the channels are encoded
4105 in the color-map and the descriptions above apply to the color-map entries.
4106 The image data is encoded as small integers, value 0..255, that index the
4107 entries in the color-map. One integer (one byte) is stored for each pixel.
4108
4109 PNG_FORMAT_*
4110
4111 The #defines to be used in png_image::format. Each #define identifies a
4112 particular layout of channel data and, if present, alpha values. There are
4113 separate defines for each of the two channel encodings.
4114
4115 A format is built up using single bit flag values. Not all combinations are
4116 valid: use the bit flag values below for testing a format returned by the
4117 read APIs, but set formats from the derived values.
4118
4119 When reading or writing color-mapped images the format should be set to the
4120 format of the entries in the color-map then png_image_{read,write}_colormap
4121 called to read or write the color-map and set the format correctly for the
4122 image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!
4123
4124 NOTE: libpng can be built with particular features disabled, if you see
4125 compiler errors because the definition of one of the following flags has been
4126 compiled out it is because libpng does not have the required support. It is
4127 possible, however, for the libpng configuration to enable the format on just
4128 read or just write; in that case you may see an error at run time. You can
4129 guard against this by checking for the definition of:
4130
4131 PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED
4132
4133 PNG_FORMAT_FLAG_ALPHA 0x01 format with an alpha channel
4134 PNG_FORMAT_FLAG_COLOR 0x02 color format: otherwise grayscale
4135 PNG_FORMAT_FLAG_LINEAR 0x04 png_uint_16 channels else png_byte
4136 PNG_FORMAT_FLAG_COLORMAP 0x08 libpng use only
4137 PNG_FORMAT_FLAG_BGR 0x10 BGR colors, else order is RGB
4138 PNG_FORMAT_FLAG_AFIRST 0x20 alpha channel comes first
4139
4140 Supported formats are as follows. Future versions of libpng may support more
4141 formats; for compatibility with older versions simply check if the format
4142 macro is defined using #ifdef. These defines describe the in-memory layout
4143 of the components of the pixels of the image.
4144
4145 First the single byte formats:
4146
4147 PNG_FORMAT_GRAY 0
4148 PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA
4149 PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)
4150 PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR
4151 PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)
4152 PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)
4153 PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)
4154 PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)
4155 PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)
4156
4157 Then the linear 2-byte formats. When naming these "Y" is used to
4158 indicate a luminance (gray) channel. The component order within the pixel
4159 is always the same - there is no provision for swapping the order of the
4160 components in the linear format.
4161
4162 PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR
4163 PNG_FORMAT_LINEAR_Y_ALPHA
4164 (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)
4165 PNG_FORMAT_LINEAR_RGB
4166 (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)
4167 PNG_FORMAT_LINEAR_RGB_ALPHA
4168 (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|
4169 PNG_FORMAT_FLAG_ALPHA)
4170
4171 Color-mapped formats are obtained by calling png_image_{read,write}_colormap,
4172 as appropriate after setting png_image::format to the format of the color-map
4173 to be read or written. Applications may check the value of
4174 PNG_FORMAT_FLAG_COLORMAP to see if they have called the colormap API. The
4175 format of the color-map may be extracted using the following macro.
4176
4177 PNG_FORMAT_OF_COLORMAP(fmt) ((fmt) & ~PNG_FORMAT_FLAG_COLORMAP)
4178
4179 PNG_IMAGE macros
4180
4181 These are convenience macros to derive information from a png_image
4182 structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the
4183 actual image sample values - either the entries in the color-map or the
4184 pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values
4185 for the pixels and will always return 1 after a call to
4186 png_image_{read,write}_colormap. The remaining macros return information
4187 about the rows in the image and the complete image.
4188
4189 NOTE: All the macros that take a png_image::format parameter are compile time
4190 constants if the format parameter is, itself, a constant. Therefore these
4191 macros can be used in array declarations and case labels where required.
4192 Similarly the macros are also pre-processor constants (sizeof is not used) so
4193 they can be used in #if tests.
4194
4195 First the information about the samples.
4196
4197 PNG_IMAGE_SAMPLE_CHANNELS(fmt)
4198 Returns the total number of channels in a given format: 1..4
4199
4200 PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)
4201 Returns the size in bytes of a single component of a pixel or color-map
4202 entry (as appropriate) in the image.
4203
4204 PNG_IMAGE_SAMPLE_SIZE(fmt)
4205 This is the size of the sample data for one sample. If the image is
4206 color-mapped it is the size of one color-map entry (and image pixels are
4207 one byte in size), otherwise it is the size of one image pixel.
4208
4209 PNG_IMAGE_COLORMAP_SIZE(fmt)
4210 The size of the color-map required by the format; this is the size of the
4211 color-map buffer passed to the png_image_{read,write}_colormap APIs, it is
4212 a fixed number determined by the format so can easily be allocated on the
4213 stack if necessary.
4214
4215 #define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\
4216 (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)
4217 /* The maximum size of the color-map required by the format expressed in a
4218 * count of components. This can be used to compile-time allocate a
4219 * color-map:
4220 *
4221 * png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];
4222 *
4223 * png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];
4224 *
4225 * Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the
4226 * information from one of the png_image_begin_read_ APIs and dynamically
4227 * allocate the required memory.
4228 */
4229
4230
4231 Corresponding information about the pixels
4232
4233 PNG_IMAGE_PIXEL_(test,fmt)
4234
4235 PNG_IMAGE_PIXEL_CHANNELS(fmt)
4236 The number of separate channels (components) in a pixel; 1 for a
4237 color-mapped image.
4238
4239 PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\
4240 The size, in bytes, of each component in a pixel; 1 for a color-mapped
4241 image.
4242
4243 PNG_IMAGE_PIXEL_SIZE(fmt)
4244 The size, in bytes, of a complete pixel; 1 for a color-mapped image.
4245
4246 Information about the whole row, or whole image
4247
4248 PNG_IMAGE_ROW_STRIDE(image)
4249 Returns the total number of components in a single row of the image; this
4250 is the minimum 'row stride', the minimum count of components between each
4251 row. For a color-mapped image this is the minimum number of bytes in a
4252 row.
4253
4254 PNG_IMAGE_BUFFER_SIZE(image, row_stride)
4255 Returns the size, in bytes, of an image buffer given a png_image and a row
4256 stride - the number of components to leave space for in each row.
4257
4258 PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB == 0x01
4259 This indicates the the RGB values of the in-memory bitmap do not
4260 correspond to the red, green and blue end-points defined by sRGB.
4261
4262 PNG_IMAGE_FLAG_COLORMAP == 0x02
4263 The PNG is color-mapped. If this flag is set png_image_read_colormap
4264 can be used without further loss of image information. If it is not set
4265 png_image_read_colormap will cause significant loss if the image has any
4266
4267 READ APIs
4268
4269 The png_image passed to the read APIs must have been initialized by setting
4270 the png_controlp field 'opaque' to NULL (or, better, memset the whole thing.)
4271
4272 int png_image_begin_read_from_file( png_imagep image,
4273 const char *file_name)
4274
4275 The named file is opened for read and the image header
4276 is filled in from the PNG header in the file.
4277
4278 int png_image_begin_read_from_stdio (png_imagep image,
4279 FILE* file)
4280
4281 The PNG header is read from the stdio FILE object.
4282
4283 int png_image_begin_read_from_memory(png_imagep image,
4284 png_const_voidp memory, png_size_t size)
4285
4286 The PNG header is read from the given memory buffer.
4287
4288 int png_image_finish_read(png_imagep image,
4289 png_colorp background, void *buffer,
4290 png_int_32 row_stride, void *colormap));
4291
4292 Finish reading the image into the supplied buffer and
4293 clean up the png_image structure.
4294
4295 row_stride is the step, in png_byte or png_uint_16 units
4296 as appropriate, between adjacent rows. A positive stride
4297 indicates that the top-most row is first in the buffer -
4298 the normal top-down arrangement. A negative stride
4299 indicates that the bottom-most row is first in the buffer.
4300
4301 background need only be supplied if an alpha channel must
4302 be removed from a png_byte format and the removal is to be
4303 done by compositing on a solid color; otherwise it may be
4304 NULL and any composition will be done directly onto the
4305 buffer. The value is an sRGB color to use for the
4306 background, for grayscale output the green channel is used.
4307
4308 For linear output removing the alpha channel is always done
4309 by compositing on black.
4310
4311 void png_image_free(png_imagep image)
4312
4313 Free any data allocated by libpng in image->opaque,
4314 setting the pointer to NULL. May be called at any time
4315 after the structure is initialized.
4316
4317 When the simplified API needs to convert between sRGB and linear colorspaces,
4318 the actual sRGB transfer curve defined in the sRGB specification (see the
4319 article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
4320 approximation used elsewhere in libpng.
4321
4322 WRITE APIS
4323
4324 For write you must initialize a png_image structure to describe the image to
4325 be written:
4326
4327 version: must be set to PNG_IMAGE_VERSION
4328 opaque: must be initialized to NULL
4329 width: image width in pixels
4330 height: image height in rows
4331 format: the format of the data you wish to write
4332 flags: set to 0 unless one of the defined flags applies; set
4333 PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images
4334 where the RGB values do not correspond to the colors in sRGB.
4335 colormap_entries: set to the number of entries in the color-map (0 to 256)
4336
4337 int png_image_write_to_file, (png_imagep image,
4338 const char *file, int convert_to_8bit, const void *buffer,
4339 png_int_32 row_stride, const void *colormap));
4340
4341 Write the image to the named file.
4342
4343 int png_image_write_to_stdio(png_imagep image, FILE *file,
4344 int convert_to_8_bit, const void *buffer,
4345 png_int_32 row_stride, const void *colormap)
4346
4347 Write the image to the given (FILE*).
4348
4349 With all write APIs if image is in one of the linear formats with
4350 (png_uint_16) data then setting convert_to_8_bit will cause the output to be
4351 a (png_byte) PNG gamma encoded according to the sRGB specification, otherwise
4352 a 16-bit linear encoded PNG file is written.
4353
4354 With all APIs row_stride is handled as in the read APIs - it is the spacing
4355 from one row to the next in component sized units (float) and if negative
4356 indicates a bottom-up row layout in the buffer.
4357
4358 Note that the write API does not support interlacing, sub-8-bit pixels,
4359 and indexed (paletted) images.
4360
4361 .SH VI. Modifying/Customizing libpng
4362
4363 There are two issues here. The first is changing how libpng does
4364 standard things like memory allocation, input/output, and error handling.
4365 The second deals with more complicated things like adding new chunks,
4366 adding new transformations, and generally changing how libpng works.
4367 Both of those are compile-time issues; that is, they are generally
4368 determined at the time the code is written, and there is rarely a need
4369 to provide the user with a means of changing them.
4370
4371 Memory allocation, input/output, and error handling
4372
4373 All of the memory allocation, input/output, and error handling in libpng
4374 goes through callbacks that are user-settable. The default routines are
4375 in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
4376 these functions, call the appropriate png_set_*_fn() function.
4377
4378 Memory allocation is done through the functions png_malloc(), png_calloc(),
4379 and png_free(). The png_malloc() and png_free() functions currently just
4380 call the standard C functions and png_calloc() calls png_malloc() and then
4381 clears the newly allocated memory to zero; note that png_calloc(png_ptr, size)
4382 is not the same as the calloc(number, size) function provided by stdlib.h.
4383 There is limited support for certain systems with segmented memory
4384 architectures and the types of pointers declared by png.h match this; you
4385 will have to use appropriate pointers in your application. Since it is
4386 unlikely that the method of handling memory allocation on a platform
4387 will change between applications, these functions must be modified in
4388 the library at compile time. If you prefer to use a different method
4389 of allocating and freeing data, you can use png_create_read_struct_2() or
4390 png_create_write_struct_2() to register your own functions as described
4391 above. These functions also provide a void pointer that can be retrieved
4392 via
4393
4394 mem_ptr=png_get_mem_ptr(png_ptr);
4395
4396 Your replacement memory functions must have prototypes as follows:
4397
4398 png_voidp malloc_fn(png_structp png_ptr,
4399 png_alloc_size_t size);
4400
4401 void free_fn(png_structp png_ptr, png_voidp ptr);
4402
4403 Your malloc_fn() must return NULL in case of failure. The png_malloc()
4404 function will normally call png_error() if it receives a NULL from the
4405 system memory allocator or from your replacement malloc_fn().
4406
4407 Your free_fn() will never be called with a NULL ptr, since libpng's
4408 png_free() checks for NULL before calling free_fn().
4409
4410 Input/Output in libpng is done through png_read() and png_write(),
4411 which currently just call fread() and fwrite(). The FILE * is stored in
4412 png_struct and is initialized via png_init_io(). If you wish to change
4413 the method of I/O, the library supplies callbacks that you can set
4414 through the function png_set_read_fn() and png_set_write_fn() at run
4415 time, instead of calling the png_init_io() function. These functions
4416 also provide a void pointer that can be retrieved via the function
4417 png_get_io_ptr(). For example:
4418
4419 png_set_read_fn(png_structp read_ptr,
4420 voidp read_io_ptr, png_rw_ptr read_data_fn)
4421
4422 png_set_write_fn(png_structp write_ptr,
4423 voidp write_io_ptr, png_rw_ptr write_data_fn,
4424 png_flush_ptr output_flush_fn);
4425
4426 voidp read_io_ptr = png_get_io_ptr(read_ptr);
4427 voidp write_io_ptr = png_get_io_ptr(write_ptr);
4428
4429 The replacement I/O functions must have prototypes as follows:
4430
4431 void user_read_data(png_structp png_ptr,
4432 png_bytep data, png_size_t length);
4433
4434 void user_write_data(png_structp png_ptr,
4435 png_bytep data, png_size_t length);
4436
4437 void user_flush_data(png_structp png_ptr);
4438
4439 The user_read_data() function is responsible for detecting and
4440 handling end-of-data errors.
4441
4442 Supplying NULL for the read, write, or flush functions sets them back
4443 to using the default C stream functions, which expect the io_ptr to
4444 point to a standard *FILE structure. It is probably a mistake
4445 to use NULL for one of write_data_fn and output_flush_fn but not both
4446 of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4447 It is an error to read from a write stream, and vice versa.
4448
4449 Error handling in libpng is done through png_error() and png_warning().
4450 Errors handled through png_error() are fatal, meaning that png_error()
4451 should never return to its caller. Currently, this is handled via
4452 setjmp() and longjmp() (unless you have compiled libpng with
4453 PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
4454 but you could change this to do things like exit() if you should wish,
4455 as long as your function does not return.
4456
4457 On non-fatal errors, png_warning() is called
4458 to print a warning message, and then control returns to the calling code.
4459 By default png_error() and png_warning() print a message on stderr via
4460 fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
4461 (because you don't want the messages) or PNG_NO_STDIO defined (because
4462 fprintf() isn't available). If you wish to change the behavior of the error
4463 functions, you will need to set up your own message callbacks. These
4464 functions are normally supplied at the time that the png_struct is created.
4465 It is also possible to redirect errors and warnings to your own replacement
4466 functions after png_create_*_struct() has been called by calling:
4467
4468 png_set_error_fn(png_structp png_ptr,
4469 png_voidp error_ptr, png_error_ptr error_fn,
4470 png_error_ptr warning_fn);
4471
4472 png_voidp error_ptr = png_get_error_ptr(png_ptr);
4473
4474 If NULL is supplied for either error_fn or warning_fn, then the libpng
4475 default function will be used, calling fprintf() and/or longjmp() if a
4476 problem is encountered. The replacement error functions should have
4477 parameters as follows:
4478
4479 void user_error_fn(png_structp png_ptr,
4480 png_const_charp error_msg);
4481
4482 void user_warning_fn(png_structp png_ptr,
4483 png_const_charp warning_msg);
4484
4485 The motivation behind using setjmp() and longjmp() is the C++ throw and
4486 catch exception handling methods. This makes the code much easier to write,
4487 as there is no need to check every return code of every function call.
4488 However, there are some uncertainties about the status of local variables
4489 after a longjmp, so the user may want to be careful about doing anything
4490 after setjmp returns non-zero besides returning itself. Consult your
4491 compiler documentation for more details. For an alternative approach, you
4492 may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4493 which is illustrated in pngvalid.c and in contrib/visupng.
4494
4495 Beginning in libpng-1.4.0, the png_set_benign_errors() API became available.
4496 You can use this to handle certain errors (normally handled as errors)
4497 as warnings.
4498
4499 png_set_benign_errors (png_ptr, int allowed);
4500
4501 allowed: 0: (default) treat png_benign_error() an error.
4502 1: treat png_benign_error() as a warning.
4503
4504 .SS Custom chunks
4505
4506 If you need to read or write custom chunks, you may need to get deeper
4507 into the libpng code. The library now has mechanisms for storing
4508 and writing chunks of unknown type; you can even declare callbacks
4509 for custom chunks. However, this may not be good enough if the
4510 library code itself needs to know about interactions between your
4511 chunk and existing `intrinsic' chunks.
4512
4513 If you need to write a new intrinsic chunk, first read the PNG
4514 specification. Acquire a first level of understanding of how it works.
4515 Pay particular attention to the sections that describe chunk names,
4516 and look at how other chunks were designed, so you can do things
4517 similarly. Second, check out the sections of libpng that read and
4518 write chunks. Try to find a chunk that is similar to yours and use
4519 it as a template. More details can be found in the comments inside
4520 the code. It is best to handle private or unknown chunks in a generic method,
4521 via callback functions, instead of by modifying libpng functions. This
4522 is illustrated in pngtest.c, which uses a callback function to handle a
4523 private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4524 libpng.
4525
4526 If you wish to write your own transformation for the data, look through
4527 the part of the code that does the transformations, and check out some of
4528 the simpler ones to get an idea of how they work. Try to find a similar
4529 transformation to the one you want to add and copy off of it. More details
4530 can be found in the comments inside the code itself.
4531
4532 .SS Configuring for 16-bit platforms
4533
4534 You will want to look into zconf.h to tell zlib (and thus libpng) that
4535 it cannot allocate more then 64K at a time. Even if you can, the memory
4536 won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
4537
4538 .SS Configuring for DOS
4539
4540 For DOS users who only have access to the lower 640K, you will
4541 have to limit zlib's memory usage via a png_set_compression_mem_level()
4542 call. See zlib.h or zconf.h in the zlib library for more information.
4543
4544 .SS Configuring for Medium Model
4545
4546 Libpng's support for medium model has been tested on most of the popular
4547 compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4548 defined, and FAR gets defined to far in pngconf.h, and you should be
4549 all set. Everything in the library (except for zlib's structure) is
4550 expecting far data. You must use the typedefs with the p or pp on
4551 the end for pointers (or at least look at them and be careful). Make
4552 note that the rows of data are defined as png_bytepp, which is
4553 an "unsigned char far * far *".
4554
4555 .SS Configuring for gui/windowing platforms:
4556
4557 You will need to write new error and warning functions that use the GUI
4558 interface, as described previously, and set them to be the error and
4559 warning functions at the time that png_create_*_struct() is called,
4560 in order to have them available during the structure initialization.
4561 They can be changed later via png_set_error_fn(). On some compilers,
4562 you may also have to change the memory allocators (png_malloc, etc.).
4563
4564 .SS Configuring for compiler xxx:
4565
4566 All includes for libpng are in pngconf.h. If you need to add, change
4567 or delete an include, this is the place to do it.
4568 The includes that are not needed outside libpng are placed in pngpriv.h,
4569 which is only used by the routines inside libpng itself.
4570 The files in libpng proper only include pngpriv.h and png.h, which
4571 %14%in turn includes pngconf.h.
4572 in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
4573 As of libpng-1.5.0, pngpriv.h also includes three other private header
4574 files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
4575 that previously appeared in the public headers.
4576
4577 .SS Configuring zlib:
4578
4579 There are special functions to configure the compression. Perhaps the
4580 most useful one changes the compression level, which currently uses
4581 input compression values in the range 0 - 9. The library normally
4582 uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
4583 have shown that for a large majority of images, compression values in
4584 the range 3-6 compress nearly as well as higher levels, and do so much
4585 faster. For online applications it may be desirable to have maximum speed
4586 (Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
4587 specify no compression (Z_NO_COMPRESSION = 0), but this would create
4588 files larger than just storing the raw bitmap. You can specify the
4589 compression level by calling:
4590
4591 #include zlib.h
4592 png_set_compression_level(png_ptr, level);
4593
4594 Another useful one is to reduce the memory level used by the library.
4595 The memory level defaults to 8, but it can be lowered if you are
4596 short on memory (running DOS, for example, where you only have 640K).
4597 Note that the memory level does have an effect on compression; among
4598 other things, lower levels will result in sections of incompressible
4599 data being emitted in smaller stored blocks, with a correspondingly
4600 larger relative overhead of up to 15% in the worst case.
4601
4602 #include zlib.h
4603 png_set_compression_mem_level(png_ptr, level);
4604
4605 The other functions are for configuring zlib. They are not recommended
4606 for normal use and may result in writing an invalid PNG file. See
4607 zlib.h for more information on what these mean.
4608
4609 #include zlib.h
4610 png_set_compression_strategy(png_ptr,
4611 strategy);
4612
4613 png_set_compression_window_bits(png_ptr,
4614 window_bits);
4615
4616 png_set_compression_method(png_ptr, method);
4617
4618 png_set_compression_buffer_size(png_ptr, size);
4619
4620 As of libpng version 1.5.4, additional APIs became
4621 available to set these separately for non-IDAT
4622 compressed chunks such as zTXt, iTXt, and iCCP:
4623
4624 #include zlib.h
4625 #if PNG_LIBPNG_VER >= 10504
4626 png_set_text_compression_level(png_ptr, level);
4627
4628 png_set_text_compression_mem_level(png_ptr, level);
4629
4630 png_set_text_compression_strategy(png_ptr,
4631 strategy);
4632
4633 png_set_text_compression_window_bits(png_ptr,
4634 window_bits);
4635
4636 png_set_text_compression_method(png_ptr, method);
4637 #endif
4638
4639 .SS Controlling row filtering
4640
4641 If you want to control whether libpng uses filtering or not, which
4642 filters are used, and how it goes about picking row filters, you
4643 can call one of these functions. The selection and configuration
4644 of row filters can have a significant impact on the size and
4645 encoding speed and a somewhat lesser impact on the decoding speed
4646 of an image. Filtering is enabled by default for RGB and grayscale
4647 images (with and without alpha), but not for paletted images nor
4648 for any images with bit depths less than 8 bits/pixel.
4649
4650 The 'method' parameter sets the main filtering method, which is
4651 currently only '0' in the PNG 1.2 specification. The 'filters'
4652 parameter sets which filter(s), if any, should be used for each
4653 scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
4654 to turn filtering on and off, respectively.
4655
4656 Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
4657 PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
4658 ORed together with '|' to specify one or more filters to use.
4659 These filters are described in more detail in the PNG specification.
4660 If you intend to change the filter type during the course of writing
4661 the image, you should start with flags set for all of the filters
4662 you intend to use so that libpng can initialize its internal
4663 structures appropriately for all of the filter types. (Note that this
4664 means the first row must always be adaptively filtered, because libpng
4665 currently does not allocate the filter buffers until png_write_row()
4666 is called for the first time.)
4667
4668 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
4669 PNG_FILTER_UP | PNG_FILTER_AVG |
4670 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
4671
4672 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
4673 filters);
4674 The second parameter can also be
4675 PNG_INTRAPIXEL_DIFFERENCING if you are
4676 writing a PNG to be embedded in a MNG
4677 datastream. This parameter must be the
4678 same as the value of filter_method used
4679 in png_set_IHDR().
4680
4681 It is also possible to influence how libpng chooses from among the
4682 available filters. This is done in one or both of two ways - by
4683 telling it how important it is to keep the same filter for successive
4684 rows, and by telling it the relative computational costs of the filters.
4685
4686 double weights[3] = {1.5, 1.3, 1.1},
4687 costs[PNG_FILTER_VALUE_LAST] =
4688 {1.0, 1.3, 1.3, 1.5, 1.7};
4689
4690 png_set_filter_heuristics(png_ptr,
4691 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
4692 weights, costs);
4693
4694 The weights are multiplying factors that indicate to libpng that the
4695 row filter should be the same for successive rows unless another row filter
4696 is that many times better than the previous filter. In the above example,
4697 if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
4698 "sum of absolute differences" 1.5 x 1.3 times higher than other filters
4699 and still be chosen, while the NONE filter could have a sum 1.1 times
4700 higher than other filters and still be chosen. Unspecified weights are
4701 taken to be 1.0, and the specified weights should probably be declining
4702 like those above in order to emphasize recent filters over older filters.
4703
4704 The filter costs specify for each filter type a relative decoding cost
4705 to be considered when selecting row filters. This means that filters
4706 with higher costs are less likely to be chosen over filters with lower
4707 costs, unless their "sum of absolute differences" is that much smaller.
4708 The costs do not necessarily reflect the exact computational speeds of
4709 the various filters, since this would unduly influence the final image
4710 size.
4711
4712 Note that the numbers above were invented purely for this example and
4713 are given only to help explain the function usage. Little testing has
4714 been done to find optimum values for either the costs or the weights.
4715
4716 .SS Removing unwanted object code
4717
4718 There are a bunch of #define's in pngconf.h that control what parts of
4719 libpng are compiled. All the defines end in _SUPPORTED. If you are
4720 never going to use a capability, you can change the #define to #undef
4721 before recompiling libpng and save yourself code and data space, or
4722 you can turn off individual capabilities with defines that begin with
4723 PNG_NO_.
4724
4725 In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
4726
4727 You can also turn all of the transforms and ancillary chunk capabilities
4728 off en masse with compiler directives that define
4729 PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
4730 or all four,
4731 along with directives to turn on any of the capabilities that you do
4732 want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
4733 transformations but still leave the library fully capable of reading
4734 and writing PNG files with all known public chunks. Use of the
4735 PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
4736 that is incapable of reading or writing ancillary chunks. If you are
4737 not using the progressive reading capability, you can turn that off
4738 with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
4739 capability, which you'll still have).
4740
4741 All the reading and writing specific code are in separate files, so the
4742 linker should only grab the files it needs. However, if you want to
4743 make sure, or if you are building a stand alone library, all the
4744 reading files start with "pngr" and all the writing files start with "pngw".
4745 The files that don't match either (like png.c, pngtrans.c, etc.)
4746 are used for both reading and writing, and always need to be included.
4747 The progressive reader is in pngpread.c
4748
4749 If you are creating or distributing a dynamically linked library (a .so
4750 or DLL file), you should not remove or disable any parts of the library,
4751 as this will cause applications linked with different versions of the
4752 library to fail if they call functions not available in your library.
4753 The size of the library itself should not be an issue, because only
4754 those sections that are actually used will be loaded into memory.
4755
4756 .SS Requesting debug printout
4757
4758 The macro definition PNG_DEBUG can be used to request debugging
4759 printout. Set it to an integer value in the range 0 to 3. Higher
4760 numbers result in increasing amounts of debugging information. The
4761 information is printed to the "stderr" file, unless another file
4762 name is specified in the PNG_DEBUG_FILE macro definition.
4763
4764 When PNG_DEBUG > 0, the following functions (macros) become available:
4765
4766 png_debug(level, message)
4767 png_debug1(level, message, p1)
4768 png_debug2(level, message, p1, p2)
4769
4770 in which "level" is compared to PNG_DEBUG to decide whether to print
4771 the message, "message" is the formatted string to be printed,
4772 and p1 and p2 are parameters that are to be embedded in the string
4773 according to printf-style formatting directives. For example,
4774
4775 png_debug1(2, "foo=%d\n", foo);
4776
4777 is expanded to
4778
4779 if (PNG_DEBUG > 2)
4780 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
4781
4782 When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
4783 can still use PNG_DEBUG to control your own debugging:
4784
4785 #ifdef PNG_DEBUG
4786 fprintf(stderr, ...
4787 #endif
4788
4789 When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
4790 having level = 0 will be printed. There aren't any such statements in
4791 this version of libpng, but if you insert some they will be printed.
4792
4793 .SS Prepending a prefix to exported symbols
4794
4795 Starting with libpng-1.6.0, you can configure libpng (when using the
4796 "configure" script) to prefix all exported symbols by means of the
4797 configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
4798 string beginning with a letter and containing only uppercase
4799 and lowercase letters, digits, and the underscore (i.e., a C language
4800 identifier). This creates a set of macros in pnglibconf.h, so this is
4801 transparent to applications; their function calls get transformed by
4802 the macros to use the modified names.
4803
4804 .SH VII. MNG support
4805
4806 The MNG specification (available at http://www.libpng.org/pub/mng) allows
4807 certain extensions to PNG for PNG images that are embedded in MNG datastreams.
4808 Libpng can support some of these extensions. To enable them, use the
4809 png_permit_mng_features() function:
4810
4811 feature_set = png_permit_mng_features(png_ptr, mask)
4812
4813 mask is a png_uint_32 containing the bitwise OR of the
4814 features you want to enable. These include
4815 PNG_FLAG_MNG_EMPTY_PLTE
4816 PNG_FLAG_MNG_FILTER_64
4817 PNG_ALL_MNG_FEATURES
4818
4819 feature_set is a png_uint_32 that is the bitwise AND of
4820 your mask with the set of MNG features that is
4821 supported by the version of libpng that you are using.
4822
4823 It is an error to use this function when reading or writing a standalone
4824 PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
4825 in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
4826 and the MHDR and MEND chunks. Libpng does not provide support for these
4827 or any other MNG chunks; your application must provide its own support for
4828 them. You may wish to consider using libmng (available at
4829 http://www.libmng.com) instead.
4830
4831 .SH VIII. Changes to Libpng from version 0.88
4832
4833 It should be noted that versions of libpng later than 0.96 are not
4834 distributed by the original libpng author, Guy Schalnat, nor by
4835 Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
4836 distributed versions 0.89 through 0.96, but rather by another member
4837 of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
4838 still alive and well, but they have moved on to other things.
4839
4840 The old libpng functions png_read_init(), png_write_init(),
4841 png_info_init(), png_read_destroy(), and png_write_destroy() have been
4842 moved to PNG_INTERNAL in version 0.95 to discourage their use. These
4843 functions will be removed from libpng version 1.4.0.
4844
4845 The preferred method of creating and initializing the libpng structures is
4846 via the png_create_read_struct(), png_create_write_struct(), and
4847 png_create_info_struct() because they isolate the size of the structures
4848 from the application, allow version error checking, and also allow the
4849 use of custom error handling routines during the initialization, which
4850 the old functions do not. The functions png_read_destroy() and
4851 png_write_destroy() do not actually free the memory that libpng
4852 allocated for these structs, but just reset the data structures, so they
4853 can be used instead of png_destroy_read_struct() and
4854 png_destroy_write_struct() if you feel there is too much system overhead
4855 allocating and freeing the png_struct for each image read.
4856
4857 Setting the error callbacks via png_set_message_fn() before
4858 png_read_init() as was suggested in libpng-0.88 is no longer supported
4859 because this caused applications that do not use custom error functions
4860 to fail if the png_ptr was not initialized to zero. It is still possible
4861 to set the error callbacks AFTER png_read_init(), or to change them with
4862 png_set_error_fn(), which is essentially the same function, but with a new
4863 name to force compilation errors with applications that try to use the old
4864 method.
4865
4866 Starting with version 1.0.7, you can find out which version of the library
4867 you are using at run-time:
4868
4869 png_uint_32 libpng_vn = png_access_version_number();
4870
4871 The number libpng_vn is constructed from the major version, minor
4872 version with leading zero, and release number with leading zero,
4873 (e.g., libpng_vn for version 1.0.7 is 10007).
4874
4875 Note that this function does not take a png_ptr, so you can call it
4876 before you've created one.
4877
4878 You can also check which version of png.h you used when compiling your
4879 application:
4880
4881 png_uint_32 application_vn = PNG_LIBPNG_VER;
4882
4883 .SH IX. Changes to Libpng from version 1.0.x to 1.2.x
4884
4885 Support for user memory management was enabled by default. To
4886 accomplish this, the functions png_create_read_struct_2(),
4887 png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
4888 png_malloc_default(), and png_free_default() were added.
4889
4890 Support for the iTXt chunk has been enabled by default as of
4891 version 1.2.41.
4892
4893 Support for certain MNG features was enabled.
4894
4895 Support for numbered error messages was added. However, we never got
4896 around to actually numbering the error messages. The function
4897 png_set_strip_error_numbers() was added (Note: the prototype for this
4898 function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
4899 builds of libpng-1.2.15. It was restored in libpng-1.2.36).
4900
4901 The png_malloc_warn() function was added at libpng-1.2.3. This issues
4902 a png_warning and returns NULL instead of aborting when it fails to
4903 acquire the requested memory allocation.
4904
4905 Support for setting user limits on image width and height was enabled
4906 by default. The functions png_set_user_limits(), png_get_user_width_max(),
4907 and png_get_user_height_max() were added at libpng-1.2.6.
4908
4909 The png_set_add_alpha() function was added at libpng-1.2.7.
4910
4911 The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
4912 Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
4913 tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
4914 deprecated.
4915
4916 A number of macro definitions in support of runtime selection of
4917 assembler code features (especially Intel MMX code support) were
4918 added at libpng-1.2.0:
4919
4920 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
4921 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
4922 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
4923 PNG_ASM_FLAG_MMX_READ_INTERLACE
4924 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
4925 PNG_ASM_FLAG_MMX_READ_FILTER_UP
4926 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
4927 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
4928 PNG_ASM_FLAGS_INITIALIZED
4929 PNG_MMX_READ_FLAGS
4930 PNG_MMX_FLAGS
4931 PNG_MMX_WRITE_FLAGS
4932 PNG_MMX_FLAGS
4933
4934 We added the following functions in support of runtime
4935 selection of assembler code features:
4936
4937 png_get_mmx_flagmask()
4938 png_set_mmx_thresholds()
4939 png_get_asm_flags()
4940 png_get_mmx_bitdepth_threshold()
4941 png_get_mmx_rowbytes_threshold()
4942 png_set_asm_flags()
4943
4944 We replaced all of these functions with simple stubs in libpng-1.2.20,
4945 when the Intel assembler code was removed due to a licensing issue.
4946
4947 These macros are deprecated:
4948
4949 PNG_READ_TRANSFORMS_NOT_SUPPORTED
4950 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
4951 PNG_NO_SEQUENTIAL_READ_SUPPORTED
4952 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
4953 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
4954 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
4955
4956 They have been replaced, respectively, by:
4957
4958 PNG_NO_READ_TRANSFORMS
4959 PNG_NO_PROGRESSIVE_READ
4960 PNG_NO_SEQUENTIAL_READ
4961 PNG_NO_WRITE_TRANSFORMS
4962 PNG_NO_READ_ANCILLARY_CHUNKS
4963 PNG_NO_WRITE_ANCILLARY_CHUNKS
4964
4965 PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
4966 deprecated since libpng-1.0.16 and libpng-1.2.6.
4967
4968 The function
4969 png_check_sig(sig, num)
4970 was replaced with
4971 !png_sig_cmp(sig, 0, num)
4972 It has been deprecated since libpng-0.90.
4973
4974 The function
4975 png_set_gray_1_2_4_to_8()
4976 which also expands tRNS to alpha was replaced with
4977 png_set_expand_gray_1_2_4_to_8()
4978 which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
4979
4980 .SH X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
4981
4982 Private libpng prototypes and macro definitions were moved from
4983 png.h and pngconf.h into a new pngpriv.h header file.
4984
4985 Functions png_set_benign_errors(), png_benign_error(), and
4986 png_chunk_benign_error() were added.
4987
4988 Support for setting the maximum amount of memory that the application
4989 will allocate for reading chunks was added, as a security measure.
4990 The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
4991 were added to the library.
4992
4993 We implemented support for I/O states by adding png_ptr member io_state
4994 and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
4995
4996 We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
4997 input transforms.
4998
4999 Checking for and reporting of errors in the IHDR chunk is more thorough.
5000
5001 Support for global arrays was removed, to improve thread safety.
5002
5003 Some obsolete/deprecated macros and functions have been removed.
5004
5005 Typecasted NULL definitions such as
5006 #define png_voidp_NULL (png_voidp)NULL
5007 were eliminated. If you used these in your application, just use
5008 NULL instead.
5009
5010 The png_struct and info_struct members "trans" and "trans_values" were
5011 changed to "trans_alpha" and "trans_color", respectively.
5012
5013 The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
5014 were removed.
5015
5016 The PNG_1_0_X and PNG_1_2_X macros were eliminated.
5017
5018 The PNG_LEGACY_SUPPORTED macro was eliminated.
5019
5020 Many WIN32_WCE #ifdefs were removed.
5021
5022 The functions png_read_init(info_ptr), png_write_init(info_ptr),
5023 png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
5024 have been removed. They have been deprecated since libpng-0.95.
5025
5026 The png_permit_empty_plte() was removed. It has been deprecated
5027 since libpng-1.0.9. Use png_permit_mng_features() instead.
5028
5029 We removed the obsolete stub functions png_get_mmx_flagmask(),
5030 png_set_mmx_thresholds(), png_get_asm_flags(),
5031 png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
5032 png_set_asm_flags(), and png_mmx_supported()
5033
5034 We removed the obsolete png_check_sig(), png_memcpy_check(), and
5035 png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
5036 and memset(), respectively.
5037
5038 The function png_set_gray_1_2_4_to_8() was removed. It has been
5039 deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
5040 png_set_expand_gray_1_2_4_to_8() because the former function also
5041 expanded any tRNS chunk to an alpha channel.
5042
5043 Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
5044 were added and are used by default instead of the corresponding
5045 functions. Unfortunately,
5046 from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5047 function) incorrectly returned a value of type png_uint_32.
5048
5049 We changed the prototype for png_malloc() from
5050 png_malloc(png_structp png_ptr, png_uint_32 size)
5051 to
5052 png_malloc(png_structp png_ptr, png_alloc_size_t size)
5053
5054 This also applies to the prototype for the user replacement malloc_fn().
5055
5056 The png_calloc() function was added and is used in place of
5057 of "png_malloc(); memset();" except in the case in png_read_png()
5058 where the array consists of pointers; in this case a "for" loop is used
5059 after the png_malloc() to set the pointers to NULL, to give robust.
5060 behavior in case the application runs out of memory part-way through
5061 the process.
5062
5063 We changed the prototypes of png_get_compression_buffer_size() and
5064 png_set_compression_buffer_size() to work with png_size_t instead of
5065 png_uint_32.
5066
5067 Support for numbered error messages was removed by default, since we
5068 never got around to actually numbering the error messages. The function
5069 png_set_strip_error_numbers() was removed from the library by default.
5070
5071 The png_zalloc() and png_zfree() functions are no longer exported.
5072 The png_zalloc() function no longer zeroes out the memory that it
5073 allocates. Applications that called png_zalloc(png_ptr, number, size)
5074 can call png_calloc(png_ptr, number*size) instead, and can call
5075 png_free() instead of png_zfree().
5076
5077 Support for dithering was disabled by default in libpng-1.4.0, because
5078 it has not been well tested and doesn't actually "dither".
5079 The code was not
5080 removed, however, and could be enabled by building libpng with
5081 PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
5082 was reenabled, but the function was renamed png_set_quantize() to
5083 reflect more accurately what it actually does. At the same time,
5084 the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
5085 PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5086 was renamed to PNG_READ_QUANTIZE_SUPPORTED.
5087
5088 We removed the trailing '.' from the warning and error messages.
5089
5090 .SH XI. Changes to Libpng from version 1.4.x to 1.5.x
5091
5092 From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5093 function) incorrectly returned a value of type png_uint_32.
5094
5095 Checking for invalid palette index on read or write was added at libpng
5096 1.5.10. When an invalid index is found, libpng issues a benign error.
5097 This is enabled by default because this condition is an error according
5098 to the PNG specification, Clause 11.3.2, but the error can be ignored in
5099 each png_ptr with
5100
5101 png_set_check_for_invalid_index(png_ptr, allowed);
5102
5103 allowed - one of
5104 0: disable benign error (accept the
5105 invalid data without warning).
5106 1: enable benign error (treat the
5107 invalid data as an error or a
5108 warning).
5109
5110 If the error is ignored, or if png_benign_error() treats it as a warning,
5111 any invalid pixels are decoded as opaque black by the decoder and written
5112 as-is by the encoder.
5113
5114 Retrieving the maximum palette index found was added at libpng-1.5.15.
5115 This statement must appear after png_read_png() or png_read_image() while
5116 reading, and after png_write_png() or png_write_image() while writing.
5117
5118 int max_palette = png_get_palette_max(png_ptr, info_ptr);
5119
5120 This will return the maximum palette index found in the image, or "-1" if
5121 the palette was not checked, or "0" if no palette was found. Note that this
5122 does not account for any palette index used by ancillary chunks such as the
5123 bKGD chunk; you must check those separately to determine the maximum
5124 palette index actually used.
5125
5126 A. Changes that affect users of libpng
5127
5128 There are no substantial API changes between the non-deprecated parts of
5129 the 1.4.5 API and the 1.5.0 API; however, the ability to directly access
5130 members of the main libpng control structures, png_struct and png_info,
5131 deprecated in earlier versions of libpng, has been completely removed from
5132 libpng 1.5.
5133
5134 We no longer include zlib.h in png.h. The include statement has been moved
5135 to pngstruct.h, where it is not accessible by applications. Applications that
5136 need access to information in zlib.h will need to add the '#include "zlib.h"'
5137 directive. It does not matter whether this is placed prior to or after
5138 the '"#include png.h"' directive.
5139
5140 The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used
5141 and were removed.
5142
5143 We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp()
5144 macros into a private header file (pngpriv.h) that is not accessible to
5145 applications.
5146
5147 In png_get_iCCP, the type of "profile" was changed from png_charpp
5148 to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
5149
5150 There are changes of form in png.h, including new and changed macros to
5151 declare parts of the API. Some API functions with arguments that are
5152 pointers to data not modified within the function have been corrected to
5153 declare these arguments with PNG_CONST.
5154
5155 Much of the internal use of C macros to control the library build has also
5156 changed and some of this is visible in the exported header files, in
5157 particular the use of macros to control data and API elements visible
5158 during application compilation may require significant revision to
5159 application code. (It is extremely rare for an application to do this.)
5160
5161 Any program that compiled against libpng 1.4 and did not use deprecated
5162 features or access internal library structures should compile and work
5163 against libpng 1.5, except for the change in the prototype for
5164 png_get_iCCP() and png_set_iCCP() API functions mentioned above.
5165
5166 libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5167 interlaced images. The macros return the number of rows and columns in
5168 each pass and information that can be used to de-interlace and (if
5169 absolutely necessary) interlace an image.
5170
5171 libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
5172 the application-provided png_longjmp_ptr on the internal, but application
5173 initialized, longjmp buffer. It is provided as a convenience to avoid
5174 the need to use the png_jmpbuf macro, which had the unnecessary side
5175 effect of resetting the internal png_longjmp_ptr value.
5176
5177 libpng 1.5.0 includes a complete fixed point API. By default this is
5178 present along with the corresponding floating point API. In general the
5179 fixed point API is faster and smaller than the floating point one because
5180 the PNG file format used fixed point, not floating point. This applies
5181 even if the library uses floating point in internal calculations. A new
5182 macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5183 uses floating point arithmetic (the default) or fixed point arithmetic
5184 internally for performance critical calculations such as gamma correction.
5185 In some cases, the gamma calculations may produce slightly different
5186 results. This has changed the results in png_rgb_to_gray and in alpha
5187 composition (png_set_background for example). This applies even if the
5188 original image was already linear (gamma == 1.0) and, therefore, it is
5189 not necessary to linearize the image. This is because libpng has *not*
5190 been changed to optimize that case correctly, yet.
5191
5192 Fixed point support for the sCAL chunk comes with an important caveat;
5193 the sCAL specification uses a decimal encoding of floating point values
5194 and the accuracy of PNG fixed point values is insufficient for
5195 representation of these values. Consequently a "string" API
5196 (png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5197 arbitrary sCAL chunks in the absence of either the floating point API or
5198 internal floating point calculations.
5199
5200 Applications no longer need to include the optional distribution header
5201 file pngusr.h or define the corresponding macros during application
5202 build in order to see the correct variant of the libpng API. From 1.5.0
5203 application code can check for the corresponding _SUPPORTED macro:
5204
5205 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
5206 /* code that uses the inch conversion APIs. */
5207 #endif
5208
5209 This macro will only be defined if the inch conversion functions have been
5210 compiled into libpng. The full set of macros, and whether or not support
5211 has been compiled in, are available in the header file pnglibconf.h.
5212 This header file is specific to the libpng build. Notice that prior to
5213 1.5.0 the _SUPPORTED macros would always have the default definition unless
5214 reset by pngusr.h or by explicit settings on the compiler command line.
5215 These settings may produce compiler warnings or errors in 1.5.0 because
5216 of macro redefinition.
5217
5218 From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5219 function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
5220 is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5221 did not exist.)
5222
5223 Applications can now choose whether to use these macros or to call the
5224 corresponding function by defining PNG_USE_READ_MACROS or
5225 PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
5226 only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
5227 will lead to a link failure.
5228
5229 Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
5230 when compressing the IDAT data and textual data such as zTXt and iCCP.
5231 In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
5232 We added five png_set_text_*() functions for setting the parameters to
5233 use with textual data.
5234
5235 Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
5236 option was off by default, and slightly inaccurate scaling occurred.
5237 This option can no longer be turned off, and the choice of accurate
5238 or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5239 API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5240 chopping.
5241
5242 Prior to libpng-1.5.4, the png_set_user_limits() function could only be
5243 used to reduce the width and height limits from the value of
5244 PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5245 that it could be used to override them. Now this function will reduce or
5246 increase the limits.
5247
5248 Starting in libpng-1.5.10, the user limits can be set en masse with the
5249 configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled,
5250 a set of "safe" limits is applied in pngpriv.h. These can be overridden by
5251 application calls to png_set_user_limits(), png_set_user_chunk_cache_max(),
5252 and/or png_set_user_malloc_max() that increase or decrease the limits. Also,
5253 in libpng-1.5.10 the default width and height limits were increased
5254 from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the
5255 limits are now
5256 default safe
5257 png_user_width_max 0x7fffffff 1,000,000
5258 png_user_height_max 0x7fffffff 1,000,000
5259 png_user_chunk_cache_max 0 (unlimited) 128
5260 png_user_chunk_malloc_max 0 (unlimited) 8,000,000
5261
5262 B. Changes to the build and configuration of libpng
5263
5264 Details of internal changes to the library code can be found in the CHANGES
5265 file and in the GIT repository logs. These will be of no concern to the vast
5266 majority of library users or builders; however, the few who configure libpng
5267 to a non-default feature set may need to change how this is done.
5268
5269 There should be no need for library builders to alter build scripts if
5270 these use the distributed build support - configure or the makefiles -
5271 however, users of the makefiles may care to update their build scripts
5272 to build pnglibconf.h where the corresponding makefile does not do so.
5273
5274 Building libpng with a non-default configuration has changed completely.
5275 The old method using pngusr.h should still work correctly even though the
5276 way pngusr.h is used in the build has been changed; however, library
5277 builders will probably want to examine the changes to take advantage of
5278 new capabilities and to simplify their build system.
5279
5280 B.1 Specific changes to library configuration capabilities
5281
5282 The library now supports a complete fixed point implementation and can
5283 thus be used on systems that have no floating point support or very
5284 limited or slow support. Previously gamma correction, an essential part
5285 of complete PNG support, required reasonably fast floating point.
5286
5287 As part of this the choice of internal implementation has been made
5288 independent of the choice of fixed versus floating point APIs and all the
5289 missing fixed point APIs have been implemented.
5290
5291 The exact mechanism used to control attributes of API functions has
5292 changed. A single set of operating system independent macro definitions
5293 is used and operating system specific directives are defined in
5294 pnglibconf.h
5295
5296 As part of this the mechanism used to choose procedure call standards on
5297 those systems that allow a choice has been changed. At present this only
5298 affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
5299 running on Intel processors. As before, PNGAPI is defined where required
5300 to control the exported API functions; however, two new macros, PNGCBAPI
5301 and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5302 (PNGCAPI) for functions that must match a C library prototype (currently
5303 only png_longjmp_ptr, which must match the C longjmp function.) The new
5304 approach is documented in pngconf.h
5305
5306 Despite these changes, libpng 1.5.0 only supports the native C function
5307 calling standard on those platforms tested so far (__cdecl on Microsoft
5308 Windows). This is because the support requirements for alternative
5309 calling conventions seem to no longer exist. Developers who find it
5310 necessary to set PNG_API_RULE to 1 should advise the mailing list
5311 (png-mng-implement) of this and library builders who use Openwatcom and
5312 therefore set PNG_API_RULE to 2 should also contact the mailing list.
5313
5314 A new test program, pngvalid, is provided in addition to pngtest.
5315 pngvalid validates the arithmetic accuracy of the gamma correction
5316 calculations and includes a number of validations of the file format.
5317 A subset of the full range of tests is run when "make check" is done
5318 (in the 'configure' build.) pngvalid also allows total allocated memory
5319 usage to be evaluated and performs additional memory overwrite validation.
5320
5321 Many changes to individual feature macros have been made. The following
5322 are the changes most likely to be noticed by library builders who
5323 configure libpng:
5324
5325 1) All feature macros now have consistent naming:
5326
5327 #define PNG_NO_feature turns the feature off
5328 #define PNG_feature_SUPPORTED turns the feature on
5329
5330 pnglibconf.h contains one line for each feature macro which is either:
5331
5332 #define PNG_feature_SUPPORTED
5333
5334 if the feature is supported or:
5335
5336 /*#undef PNG_feature_SUPPORTED*/
5337
5338 if it is not. Library code consistently checks for the 'SUPPORTED' macro.
5339 It does not, and libpng applications should not, check for the 'NO' macro
5340 which will not normally be defined even if the feature is not supported.
5341 The 'NO' macros are only used internally for setting or not setting the
5342 corresponding 'SUPPORTED' macros.
5343
5344 Compatibility with the old names is provided as follows:
5345
5346 PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5347
5348 And the following definitions disable the corresponding feature:
5349
5350 PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5351 PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5352 PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5353 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5354 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5355 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5356
5357 Library builders should remove use of the above, inconsistent, names.
5358
5359 2) Warning and error message formatting was previously conditional on
5360 the STDIO feature. The library has been changed to use the
5361 CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5362 the library no longer uses the printf(3) functions, even though the
5363 default read/write implementations use (FILE) style stdio.h functions.
5364
5365 3) Three feature macros now control the fixed/floating point decisions:
5366
5367 PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5368
5369 PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5370 practice these are normally required internally anyway (because the PNG
5371 file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5372 merely stops the function from being exported.
5373
5374 PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5375 point implementation or the fixed point one. Typically the fixed point
5376 implementation is larger and slower than the floating point implementation
5377 on a system that supports floating point; however, it may be faster on a
5378 system which lacks floating point hardware and therefore uses a software
5379 emulation.
5380
5381 4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
5382 functions to read and write ints to be disabled independently of
5383 PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5384 even though the default is to use the macros - this allows applications
5385 to choose at app buildtime whether or not to use macros (previously
5386 impossible because the functions weren't in the default build.)
5387
5388 B.2 Changes to the configuration mechanism
5389
5390 Prior to libpng-1.5.0 library builders who needed to configure libpng
5391 had either to modify the exported pngconf.h header file to add system
5392 specific configuration or had to write feature selection macros into
5393 pngusr.h and cause this to be included into pngconf.h by defining
5394 PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5395 application built without PNG_USER_CONFIG defined would see the
5396 unmodified, default, libpng API and thus would probably fail to link.
5397
5398 These mechanisms still work in the configure build and in any makefile
5399 build that builds pnglibconf.h, although the feature selection macros
5400 have changed somewhat as described above. In 1.5.0, however, pngusr.h is
5401 processed only once, when the exported header file pnglibconf.h is built.
5402 pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
5403 build of pnglibconf.h and it is never included in an application build.
5404
5405 The rarely used alternative of adding a list of feature macros to the
5406 CFLAGS setting in the build also still works; however, the macros will be
5407 copied to pnglibconf.h and this may produce macro redefinition warnings
5408 when the individual C files are compiled.
5409
5410 All configuration now only works if pnglibconf.h is built from
5411 scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
5412 (the original author of awk) maintains C source code of that awk and this
5413 and all known later implementations (often called by subtly different
5414 names - nawk and gawk for example) are adequate to build pnglibconf.h.
5415 The Sun Microsystems (now Oracle) program 'awk' is an earlier version
5416 and does not work; this may also apply to other systems that have a
5417 functioning awk called 'nawk'.
5418
5419 Configuration options are now documented in scripts/pnglibconf.dfa. This
5420 file also includes dependency information that ensures a configuration is
5421 consistent; that is, if a feature is switched off dependent features are
5422 also removed. As a recommended alternative to using feature macros in
5423 pngusr.h a system builder may also define equivalent options in pngusr.dfa
5424 (or, indeed, any file) and add that to the configuration by setting
5425 DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
5426 how to do this, and a case where pngusr.h is still required.
5427
5428 .SH XII. Changes to Libpng from version 1.5.x to 1.6.x
5429
5430 A "simplified API" has been added (see documentation in png.h and a simple
5431 example in contrib/examples/pngtopng.c). The new publicly visible API
5432 includes the following:
5433
5434 macros:
5435 PNG_FORMAT_*
5436 PNG_IMAGE_*
5437 structures:
5438 png_control
5439 png_image
5440 read functions
5441 png_image_begin_read_from_file()
5442 png_image_begin_read_from_stdio()
5443 png_image_begin_read_from_memory()
5444 png_image_finish_read()
5445 png_image_free()
5446 write functions
5447 png_image_write_to_file()
5448 png_image_write_to_stdio()
5449
5450 Starting with libpng-1.6.0, you can configure libpng to prefix all exported
5451 symbols, using the PNG_PREFIX macro.
5452
5453 We no longer include string.h in png.h. The include statement has been moved
5454 to pngpriv.h, where it is not accessible by applications. Applications that
5455 need access to information in string.h must add an '#include "string.h"'
5456 directive. It does not matter whether this is placed prior to or after
5457 the '"#include png.h"' directive.
5458
5459 The following API are now DEPRECATED:
5460 png_info_init_3()
5461 png_convert_to_rfc1123() which has been replaced
5462 with png_convert_to_rfc1123_buffer()
5463 png_data_freer()
5464 png_malloc_default()
5465 png_free_default()
5466 png_reset_zstream()
5467
5468 The following have been removed:
5469 png_get_io_chunk_name(), which has been replaced
5470 with png_get_io_chunk_type(). The new
5471 function returns a 32-bit integer instead of
5472 a string.
5473 The png_sizeof(), png_strlen(), png_memcpy(), png_memcmp(), and
5474 png_memset() macros are no longer used in the libpng sources and
5475 have been removed. These had already been made invisible to applications
5476 (i.e., defined in the private pngpriv.h header file) since libpng-1.5.0.
5477
5478 The signatures of many exported functions were changed, such that
5479 png_structp became png_structrp or png_const_structrp
5480 png_infop became png_inforp or png_const_inforp
5481 where "rp" indicates a "restricted pointer".
5482
5483 Error detection in some chunks has improved; in particular the iCCP chunk
5484 reader now does pretty complete validation of the basic format. Some bad
5485 profiles that were previously accepted are now rejected, in particular the
5486 very old broken Microsoft/HP sRGB profile. The PNG spec requirement that
5487 only grayscale profiles may appear in images with color type 0 or 4 and that
5488 even if the image only contains gray pixels, only RGB profiles may appear
5489 in images with color type 2, 3, or 6, is now enforced. The sRGB chunk
5490 is allowed to appear in images with any color type.
5491
5492 The library now issues an error if the application attempts to set a
5493 transform after it calls png_read_update_info().
5494
5495 The library now issues a warning if both background processing and RGB to
5496 gray are used when gamma correction happens. As with previous versions of
5497 the library the results are numerically very incorrect in this case.
5498
5499 There are some minor arithmetic changes in some transforms such as
5500 png_set_background(), that might be detected by certain regression tests.
5501
5502 Unknown chunk handling has been improved internally, without any API change.
5503 This adds more correct option control of the unknown handling, corrects
5504 a pre-existing bug where the per-chunk 'keep' setting is ignored, and makes
5505 it possible to skip IDAT chunks in the sequential reader.
5506
5507 The machine-generated configure files are no longer included in branches
5508 libpng16 and later of the GIT repository. They continue to be included
5509 in the tarball releases, however.
5510
5511 .SH XIII. Detecting libpng
5512
5513 The png_get_io_ptr() function has been present since libpng-0.88, has never
5514 changed, and is unaffected by conditional compilation macros. It is the
5515 best choice for use in configure scripts for detecting the presence of any
5516 libpng version since 0.88. In an autoconf "configure.in" you could use
5517
5518 AC_CHECK_LIB(png, png_get_io_ptr, ...
5519
5520 .SH XV. Source code repository
5521
5522 Since about February 2009, version 1.2.34, libpng has been under "git" source
5523 control. The git repository was built from old libpng-x.y.z.tar.gz files
5524 going back to version 0.70. You can access the git repository (read only)
5525 at
5526
5527 git://git.code.sf.net/p/libpng/code
5528
5529 or you can browse it with a web browser by selecting the "code" button at
5530
5531 https://sourceforge.net/projects/libpng
5532
5533 Patches can be sent to glennrp at users.sourceforge.net or to
5534 png-mng-implement at lists.sourceforge.net or you can upload them to
5535 the libpng bug tracker at
5536
5537 http://libpng.sourceforge.net
5538
5539 We also accept patches built from the tar or zip distributions, and
5540 simple verbal discriptions of bug fixes, reported either to the
5541 SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5542 mailing list, or directly to glennrp.
5543
5544 .SH XV. Coding style
5545
5546 Our coding style is similar to the "Allman" style, with curly
5547 braces on separate lines:
5548
5549 if (condition)
5550 {
5551 action;
5552 }
5553
5554 else if (another condition)
5555 {
5556 another action;
5557 }
5558
5559 The braces can be omitted from simple one-line actions:
5560
5561 if (condition)
5562 return (0);
5563
5564 We use 3-space indentation, except for continued statements which
5565 are usually indented the same as the first line of the statement
5566 plus four more spaces.
5567
5568 For macro definitions we use 2-space indentation, always leaving the "#"
5569 in the first column.
5570
5571 #ifndef PNG_NO_FEATURE
5572 # ifndef PNG_FEATURE_SUPPORTED
5573 # define PNG_FEATURE_SUPPORTED
5574 # endif
5575 #endif
5576
5577 Comments appear with the leading "/*" at the same indentation as
5578 the statement that follows the comment:
5579
5580 /* Single-line comment */
5581 statement;
5582
5583 /* This is a multiple-line
5584 * comment.
5585 */
5586 statement;
5587
5588 Very short comments can be placed after the end of the statement
5589 to which they pertain:
5590
5591 statement; /* comment */
5592
5593 We don't use C++ style ("//") comments. We have, however,
5594 used them in the past in some now-abandoned MMX assembler
5595 code.
5596
5597 Functions and their curly braces are not indented, and
5598 exported functions are marked with PNGAPI:
5599
5600 /* This is a public function that is visible to
5601 * application programmers. It does thus-and-so.
5602 */
5603 void PNGAPI
5604 png_exported_function(png_ptr, png_info, foo)
5605 {
5606 body;
5607 }
5608
5609 The prototypes for all exported functions appear in png.h,
5610 above the comment that says
5611
5612 /* Maintainer: Put new public prototypes here ... */
5613
5614 We mark all non-exported functions with "/* PRIVATE */"":
5615
5616 void /* PRIVATE */
5617 png_non_exported_function(png_ptr, png_info, foo)
5618 {
5619 body;
5620 }
5621
5622 The prototypes for non-exported functions (except for those in
5623 pngtest) appear in
5624 pngpriv.h
5625 above the comment that says
5626
5627 /* Maintainer: Put new private prototypes here ^ */
5628
5629 We put a space after the "sizeof" operator and we omit the
5630 optional parentheses around its argument when the argument
5631 is an expression, not a type name, and we always enclose the
5632 sizeof operator, with its argument, in parentheses:
5633
5634 (sizeof (png_uint_32))
5635 (sizeof array)
5636
5637 Prior to libpng-1.6.0 we used a "png_sizeof()" macro, formatted as
5638 though it were a function.
5639
5640 To avoid polluting the global namespace, the names of all exported
5641 functions and variables begin with "png_", and all publicly visible C
5642 preprocessor macros begin with "PNG". We request that applications that
5643 use libpng *not* begin any of their own symbols with either of these strings.
5644
5645 We put a space after each comma and after each semicolon
5646 in "for" statements, and we put spaces before and after each
5647 C binary operator and after "for" or "while", and before
5648 "?". We don't put a space between a typecast and the expression
5649 being cast, nor do we put one between a function name and the
5650 left parenthesis that follows it:
5651
5652 for (i = 2; i > 0; --i)
5653 y[i] = a(x) + (int)b;
5654
5655 We prefer #ifdef and #ifndef to #if defined() and #if !defined()
5656 when there is only one macro being tested. We always use parentheses
5657 with "defined".
5658
5659 We prefer to express integers that are used as bit masks in hex format,
5660 with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
5661
5662 We prefer to use underscores in variable names rather than camelCase, except
5663 for a few type names that we inherit from zlib.h.
5664
5665 We do not use the TAB character for indentation in the C sources.
5666
5667 Lines do not exceed 80 characters.
5668
5669 Other rules can be inferred by inspecting the libpng source.
5670
5671 .SH XVI. Y2K Compliance in libpng
5672
5673 April 25, 2013
5674
5675 Since the PNG Development group is an ad-hoc body, we can't make
5676 an official declaration.
5677
5678 This is your unofficial assurance that libpng from version 0.71 and
5679 upward through 1.6.2 are Y2K compliant. It is my belief that earlier
5680 versions were also Y2K compliant.
5681
5682 Libpng only has two year fields. One is a 2-byte unsigned integer
5683 that will hold years up to 65535. The other, which is deprecated,
5684 holds the date in text format, and will hold years up to 9999.
5685
5686 The integer is
5687 "png_uint_16 year" in png_time_struct.
5688
5689 The string is
5690 "char time_buffer[29]" in png_struct. This is no longer used
5691 in libpng-1.6.x and will be removed from libpng-1.7.0.
5692
5693 There are seven time-related functions:
5694
5695 png_convert_to_rfc_1123() in png.c
5696 (formerly png_convert_to_rfc_1152() in error)
5697 png_convert_from_struct_tm() in pngwrite.c, called
5698 in pngwrite.c
5699 png_convert_from_time_t() in pngwrite.c
5700 png_get_tIME() in pngget.c
5701 png_handle_tIME() in pngrutil.c, called in pngread.c
5702 png_set_tIME() in pngset.c
5703 png_write_tIME() in pngwutil.c, called in pngwrite.c
5704
5705 All appear to handle dates properly in a Y2K environment. The
5706 png_convert_from_time_t() function calls gmtime() to convert from system
5707 clock time, which returns (year - 1900), which we properly convert to
5708 the full 4-digit year. There is a possibility that applications using
5709 libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
5710 function, or that they are incorrectly passing only a 2-digit year
5711 instead of "year - 1900" into the png_convert_from_struct_tm() function,
5712 but this is not under our control. The libpng documentation has always
5713 stated that it works with 4-digit years, and the APIs have been
5714 documented as such.
5715
5716 The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
5717 integer to hold the year, and can hold years as large as 65535.
5718
5719 zlib, upon which libpng depends, is also Y2K compliant. It contains
5720 no date-related code.
5721
5722
5723 Glenn Randers-Pehrson
5724 libpng maintainer
5725 PNG Development Group
5726
5727 .SH NOTE
5728
5729 Note about libpng version numbers:
5730
5731 Due to various miscommunications, unforeseen code incompatibilities
5732 and occasional factors outside the authors' control, version numbering
5733 on the library has not always been consistent and straightforward.
5734 The following table summarizes matters since version 0.89c, which was
5735 the first widely used release:
5736
5737 source png.h png.h shared-lib
5738 version string int version
5739 ------- ------ ----- ----------
5740 0.89c ("beta 3") 0.89 89 1.0.89
5741 0.90 ("beta 4") 0.90 90 0.90
5742 0.95 ("beta 5") 0.95 95 0.95
5743 0.96 ("beta 6") 0.96 96 0.96
5744 0.97b ("beta 7") 1.00.97 97 1.0.1
5745 0.97c 0.97 97 2.0.97
5746 0.98 0.98 98 2.0.98
5747 0.99 0.99 98 2.0.99
5748 0.99a-m 0.99 99 2.0.99
5749 1.00 1.00 100 2.1.0
5750 1.0.0 1.0.0 100 2.1.0
5751 1.0.0 (from here on, the 100 2.1.0
5752 1.0.1 png.h string is 10001 2.1.0
5753 1.0.1a-e identical to the 10002 from here on, the
5754 1.0.2 source version) 10002 shared library is 2.V
5755 1.0.2a-b 10003 where V is the source
5756 1.0.1 10001 code version except as
5757 1.0.1a-e 10002 2.1.0.1a-e noted.
5758 1.0.2 10002 2.1.0.2
5759 1.0.2a-b 10003 2.1.0.2a-b
5760 1.0.3 10003 2.1.0.3
5761 1.0.3a-d 10004 2.1.0.3a-d
5762 1.0.4 10004 2.1.0.4
5763 1.0.4a-f 10005 2.1.0.4a-f
5764 1.0.5 (+ 2 patches) 10005 2.1.0.5
5765 1.0.5a-d 10006 2.1.0.5a-d
5766 1.0.5e-r 10100 2.1.0.5e-r
5767 1.0.5s-v 10006 2.1.0.5s-v
5768 1.0.6 (+ 3 patches) 10006 2.1.0.6
5769 1.0.6d-g 10007 2.1.0.6d-g
5770 1.0.6h 10007 10.6h
5771 1.0.6i 10007 10.6i
5772 1.0.6j 10007 2.1.0.6j
5773 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
5774 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
5775 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
5776 1.0.7 1 10007 2.1.0.7
5777 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
5778 1.0.8rc1 1 10008 2.1.0.8rc1
5779 1.0.8 1 10008 2.1.0.8
5780 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
5781 1.0.9rc1 1 10009 2.1.0.9rc1
5782 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
5783 1.0.9rc2 1 10009 2.1.0.9rc2
5784 1.0.9 1 10009 2.1.0.9
5785 1.0.10beta1 1 10010 2.1.0.10beta1
5786 1.0.10rc1 1 10010 2.1.0.10rc1
5787 1.0.10 1 10010 2.1.0.10
5788 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
5789 1.0.11rc1 1 10011 2.1.0.11rc1
5790 1.0.11 1 10011 2.1.0.11
5791 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
5792 1.0.12rc1 2 10012 2.1.0.12rc1
5793 1.0.12 2 10012 2.1.0.12
5794 1.1.0a-f - 10100 2.1.1.0a-f abandoned
5795 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
5796 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
5797 1.2.0rc1 3 10200 3.1.2.0rc1
5798 1.2.0 3 10200 3.1.2.0
5799 1.2.1beta-4 3 10201 3.1.2.1beta1-4
5800 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
5801 1.2.1 3 10201 3.1.2.1
5802 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
5803 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
5804 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
5805 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
5806 1.0.13 10 10013 10.so.0.1.0.13
5807 1.2.2 12 10202 12.so.0.1.2.2
5808 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
5809 1.2.3 12 10203 12.so.0.1.2.3
5810 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
5811 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
5812 1.0.14 10 10014 10.so.0.1.0.14
5813 1.2.4 13 10204 12.so.0.1.2.4
5814 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
5815 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
5816 1.0.15 10 10015 10.so.0.1.0.15
5817 1.2.5 13 10205 12.so.0.1.2.5
5818 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
5819 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
5820 1.0.16 10 10016 10.so.0.1.0.16
5821 1.2.6 13 10206 12.so.0.1.2.6
5822 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
5823 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
5824 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
5825 1.0.17 10 10017 12.so.0.1.0.17
5826 1.2.7 13 10207 12.so.0.1.2.7
5827 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
5828 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
5829 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
5830 1.0.18 10 10018 12.so.0.1.0.18
5831 1.2.8 13 10208 12.so.0.1.2.8
5832 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
5833 1.2.9beta4-11 13 10209 12.so.0.9[.0]
5834 1.2.9rc1 13 10209 12.so.0.9[.0]
5835 1.2.9 13 10209 12.so.0.9[.0]
5836 1.2.10beta1-7 13 10210 12.so.0.10[.0]
5837 1.2.10rc1-2 13 10210 12.so.0.10[.0]
5838 1.2.10 13 10210 12.so.0.10[.0]
5839 1.4.0beta1-6 14 10400 14.so.0.0[.0]
5840 1.2.11beta1-4 13 10210 12.so.0.11[.0]
5841 1.4.0beta7-8 14 10400 14.so.0.0[.0]
5842 1.2.11 13 10211 12.so.0.11[.0]
5843 1.2.12 13 10212 12.so.0.12[.0]
5844 1.4.0beta9-14 14 10400 14.so.0.0[.0]
5845 1.2.13 13 10213 12.so.0.13[.0]
5846 1.4.0beta15-36 14 10400 14.so.0.0[.0]
5847 1.4.0beta37-87 14 10400 14.so.14.0[.0]
5848 1.4.0rc01 14 10400 14.so.14.0[.0]
5849 1.4.0beta88-109 14 10400 14.so.14.0[.0]
5850 1.4.0rc02-08 14 10400 14.so.14.0[.0]
5851 1.4.0 14 10400 14.so.14.0[.0]
5852 1.4.1beta01-03 14 10401 14.so.14.1[.0]
5853 1.4.1rc01 14 10401 14.so.14.1[.0]
5854 1.4.1beta04-12 14 10401 14.so.14.1[.0]
5855 1.4.1 14 10401 14.so.14.1[.0]
5856 1.4.2 14 10402 14.so.14.2[.0]
5857 1.4.3 14 10403 14.so.14.3[.0]
5858 1.4.4 14 10404 14.so.14.4[.0]
5859 1.5.0beta01-58 15 10500 15.so.15.0[.0]
5860 1.5.0rc01-07 15 10500 15.so.15.0[.0]
5861 1.5.0 15 10500 15.so.15.0[.0]
5862 1.5.1beta01-11 15 10501 15.so.15.1[.0]
5863 1.5.1rc01-02 15 10501 15.so.15.1[.0]
5864 1.5.1 15 10501 15.so.15.1[.0]
5865 1.5.2beta01-03 15 10502 15.so.15.2[.0]
5866 1.5.2rc01-03 15 10502 15.so.15.2[.0]
5867 1.5.2 15 10502 15.so.15.2[.0]
5868 1.5.3beta01-10 15 10503 15.so.15.3[.0]
5869 1.5.3rc01-02 15 10503 15.so.15.3[.0]
5870 1.5.3beta11 15 10503 15.so.15.3[.0]
5871 1.5.3 [omitted]
5872 1.5.4beta01-08 15 10504 15.so.15.4[.0]
5873 1.5.4rc01 15 10504 15.so.15.4[.0]
5874 1.5.4 15 10504 15.so.15.4[.0]
5875 1.5.5beta01-08 15 10505 15.so.15.5[.0]
5876 1.5.5rc01 15 10505 15.so.15.5[.0]
5877 1.5.5 15 10505 15.so.15.5[.0]
5878 1.5.6beta01-07 15 10506 15.so.15.6[.0]
5879 1.5.6rc01-03 15 10506 15.so.15.6[.0]
5880 1.5.6 15 10506 15.so.15.6[.0]
5881 1.5.7beta01-05 15 10507 15.so.15.7[.0]
5882 1.5.7rc01-03 15 10507 15.so.15.7[.0]
5883 1.5.7 15 10507 15.so.15.7[.0]
5884 1.6.0beta01-40 16 10600 16.so.16.0[.0]
5885 1.6.0rc01-08 16 10600 16.so.16.0[.0]
5886 1.6.0 16 10600 16.so.16.0[.0]
5887 1.6.1beta01-09 16 10601 16.so.16.1[.0]
5888 1.6.1rc01 16 10601 16.so.16.1[.0]
5889 1.6.1 16 10601 16.so.16.1[.0]
5890 1.6.2beta01 16 10602 16.so.16.2[.0]
5891 1.6.2rc01-06 16 10602 16.so.16.2[.0]
5892 1.6.2 16 10602 16.so.16.2[.0]
5893
5894 Henceforth the source version will match the shared-library minor
5895 and patch numbers; the shared-library major version number will be
5896 used for changes in backward compatibility, as it is intended. The
5897 PNG_PNGLIB_VER macro, which is not used within libpng but is available
5898 for applications, is an unsigned integer of the form xyyzz corresponding
5899 to the source version x.y.z (leading zeros in y and z). Beta versions
5900 were given the previous public release number plus a letter, until
5901 version 1.0.6j; from then on they were given the upcoming public
5902 release number plus "betaNN" or "rcN".
5903
5904 .SH "SEE ALSO"
5905 .BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
5906
5907 .LP
5908 .IR libpng :
5909 .IP
5910 http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
5911 http://www.libpng.org/pub/png
5912
5913 .LP
5914 .IR zlib :
5915 .IP
5916 (generally) at the same location as
5917 .I libpng
5918 or at
5919 .br
5920 ftp://ftp.info-zip.org/pub/infozip/zlib
5921
5922 .LP
5923 .IR PNG specification: RFC 2083
5924 .IP
5925 (generally) at the same location as
5926 .I libpng
5927 or at
5928 .br
5929 ftp://ds.internic.net/rfc/rfc2083.txt
5930 .br
5931 or (as a W3C Recommendation) at
5932 .br
5933 http://www.w3.org/TR/REC-png.html
5934
5935 .LP
5936 In the case of any inconsistency between the PNG specification
5937 and this library, the specification takes precedence.
5938
5939 .SH AUTHORS
5940 This man page: Glenn Randers-Pehrson
5941 <glennrp at users.sourceforge.net>
5942
5943 The contributing authors would like to thank all those who helped
5944 with testing, bug fixes, and patience. This wouldn't have been
5945 possible without all of you.
5946
5947 Thanks to Frank J. T. Wojcik for helping with the documentation.
5948
5949 Libpng version 1.6.2 - April 25, 2013:
5950 Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
5951 Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
5952
5953 Supported by the PNG development group
5954 .br
5955 png-mng-implement at lists.sf.net
5956 (subscription required; visit
5957 png-mng-implement at lists.sourceforge.net (subscription required; visit
5958 https://lists.sourceforge.net/lists/listinfo/png-mng-implement
5959 to subscribe).
5960
5961 .SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
5962
5963 (This copy of the libpng notices is provided for your convenience. In case of
5964 any discrepancy between this copy and the notices in the file png.h that is
5965 included in the libpng distribution, the latter shall prevail.)
5966
5967 If you modify libpng you may insert additional notices immediately following
5968 this sentence.
5969
5970 This code is released under the libpng license.
5971
5972 libpng versions 1.2.6, August 15, 2004, through 1.6.2, April 25, 2013, are
5973 Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
5974 distributed according to the same disclaimer and license as libpng-1.2.5
5975 with the following individual added to the list of Contributing Authors
5976
5977 Cosmin Truta
5978
5979 libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
5980 Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
5981 distributed according to the same disclaimer and license as libpng-1.0.6
5982 with the following individuals added to the list of Contributing Authors
5983
5984 Simon-Pierre Cadieux
5985 Eric S. Raymond
5986 Gilles Vollant
5987
5988 and with the following additions to the disclaimer:
5989
5990 There is no warranty against interference with your
5991 enjoyment of the library or against infringement.
5992 There is no warranty that our efforts or the library
5993 will fulfill any of your particular purposes or needs.
5994 This library is provided with all faults, and the entire
5995 risk of satisfactory quality, performance, accuracy, and
5996 effort is with the user.
5997
5998 libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
5999 Copyright (c) 1998, 1999 Glenn Randers-Pehrson
6000 Distributed according to the same disclaimer and license as libpng-0.96,
6001 with the following individuals added to the list of Contributing Authors:
6002
6003 Tom Lane
6004 Glenn Randers-Pehrson
6005 Willem van Schaik
6006
6007 libpng versions 0.89, June 1996, through 0.96, May 1997, are
6008 Copyright (c) 1996, 1997 Andreas Dilger
6009 Distributed according to the same disclaimer and license as libpng-0.88,
6010 with the following individuals added to the list of Contributing Authors:
6011
6012 John Bowler
6013 Kevin Bracey
6014 Sam Bushell
6015 Magnus Holmgren
6016 Greg Roelofs
6017 Tom Tanner
6018
6019 libpng versions 0.5, May 1995, through 0.88, January 1996, are
6020 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
6021
6022 For the purposes of this copyright and license, "Contributing Authors"
6023 is defined as the following set of individuals:
6024
6025 Andreas Dilger
6026 Dave Martindale
6027 Guy Eric Schalnat
6028 Paul Schmidt
6029 Tim Wegner
6030
6031 The PNG Reference Library is supplied "AS IS". The Contributing Authors
6032 and Group 42, Inc. disclaim all warranties, expressed or implied,
6033 including, without limitation, the warranties of merchantability and of
6034 fitness for any purpose. The Contributing Authors and Group 42, Inc.
6035 assume no liability for direct, indirect, incidental, special, exemplary,
6036 or consequential damages, which may result from the use of the PNG
6037 Reference Library, even if advised of the possibility of such damage.
6038
6039 Permission is hereby granted to use, copy, modify, and distribute this
6040 source code, or portions hereof, for any purpose, without fee, subject
6041 to the following restrictions:
6042
6043 1. The origin of this source code must not be misrepresented.
6044
6045 2. Altered versions must be plainly marked as such and
6046 must not be misrepresented as being the original source.
6047
6048 3. This Copyright notice may not be removed or altered from
6049 any source or altered source distribution.
6050
6051 The Contributing Authors and Group 42, Inc. specifically permit, without
6052 fee, and encourage the use of this source code as a component to
6053 supporting the PNG file format in commercial products. If you use this
6054 source code in a product, acknowledgment is not required but would be
6055 appreciated.
6056
6057
6058 A "png_get_copyright" function is available, for convenient use in "about"
6059 boxes and the like:
6060
6061 printf("%s",png_get_copyright(NULL));
6062
6063 Also, the PNG logo (in PNG format, of course) is supplied in the
6064 files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
6065
6066 Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
6067 certification mark of the Open Source Initiative.
6068
6069 Glenn Randers-Pehrson
6070 glennrp at users.sourceforge.net
6071 April 25, 2013
6072
6073 .\" end of man page
6074