]> git.saurik.com Git - wxWidgets.git/blame - src/png/libpng.3
Move code removing "-psn_xxx" command line arguments to common code.
[wxWidgets.git] / src / png / libpng.3
CommitLineData
fff5f7d5 1.TH LIBPNG 3 "April 25, 2013"
0272a10d 2.SH NAME
fff5f7d5 3libpng \- Portable Network Graphics (PNG) Reference Library 1.6.2
0272a10d 4.SH SYNOPSIS
fff5f7d5
VZ
5\fB
6#include <png.h>\fP
0272a10d
VZ
7
8\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
9
b61cc19c
PC
10\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
11
9c0d9ce3
DS
12\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
13
9c0d9ce3
DS
14\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
15
b61cc19c 16\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
0272a10d
VZ
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
9c0d9ce3 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
0272a10d
VZ
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
9c0d9ce3
DS
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
9c0d9ce3 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
0272a10d 39
0272a10d
VZ
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
9c0d9ce3
DS
46\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
47
0272a10d
VZ
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
9c0d9ce3 54\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
0272a10d
VZ
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
9c0d9ce3
DS
58\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
59
9c0d9ce3
DS
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
9c0d9ce3 62\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 63
9c0d9ce3 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
0272a10d 65
9c0d9ce3 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
0272a10d 67
fff5f7d5 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
970f6abe 69
9c0d9ce3 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
0272a10d 71
9c0d9ce3 72\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
b61cc19c 73
9c0d9ce3 74\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP
0272a10d 75
9c0d9ce3 76\fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
b61cc19c 77
9c0d9ce3 78\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP
0272a10d 79
9c0d9ce3 80\fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 81
9c0d9ce3 82\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP
0272a10d 83
9c0d9ce3 84\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP
0272a10d 85
9c0d9ce3 86\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
0272a10d 87
9c0d9ce3 88\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
0272a10d 89
9c0d9ce3 90\fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 91
9c0d9ce3 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
0272a10d 93
9c0d9ce3 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
0272a10d 95
9c0d9ce3
DS
96\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
97
9c0d9ce3
DS
98\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP
99
9c0d9ce3
DS
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
9c0d9ce3 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
0272a10d
VZ
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
9c0d9ce3 106\fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 107
9c0d9ce3 108\fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 109
970f6abe
VZ
110\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
111
9c0d9ce3
DS
112\fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
113
9c0d9ce3 114\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
0272a10d
VZ
115
116\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
117
9c0d9ce3 118\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
0272a10d 119
9c0d9ce3 120\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
b61cc19c 121
9c0d9ce3 122\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
0272a10d 123
9c0d9ce3 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
0272a10d 125
9c0d9ce3 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
0272a10d 127
9c0d9ce3 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
0272a10d 129
9c0d9ce3 130\fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 131
9c0d9ce3 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
0272a10d 133
9c0d9ce3 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
0272a10d 135
9c0d9ce3 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
0272a10d 137
9c0d9ce3 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
970f6abe 139
9c0d9ce3 140\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
970f6abe 141
9c0d9ce3 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
0272a10d 143
fff5f7d5 144\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr\fP\fB);\fP
9c0d9ce3
DS
145
146\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 147
9c0d9ce3 148\fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 149
9c0d9ce3 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
0272a10d 151
9c0d9ce3 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
0272a10d 153
9c0d9ce3 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
0272a10d 155
9c0d9ce3 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
0272a10d 157
9c0d9ce3
DS
158\fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
159
9c0d9ce3
DS
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
9c0d9ce3
DS
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
9c0d9ce3
DS
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
9c0d9ce3
DS
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
9c0d9ce3 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
0272a10d 169
b61cc19c 170\fB/* This function is really an inline macro. \fI*/
970f6abe
VZ
171
172\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
173
9c0d9ce3 174\fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP
0272a10d 175
b61cc19c 176\fB/* This function is really an inline macro. \fI*/
970f6abe 177
b61cc19c 178\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
970f6abe 179
9c0d9ce3
DS
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
9c0d9ce3
DS
182\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
183
9c0d9ce3
DS
184\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
185
9c0d9ce3
DS
186\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
187
9c0d9ce3
DS
188\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
189
9c0d9ce3
DS
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
9c0d9ce3 192\fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 193
9c0d9ce3 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
0272a10d 195
9c0d9ce3 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
0272a10d 197
9c0d9ce3 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
0272a10d 199
9c0d9ce3 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
0272a10d 201
9c0d9ce3 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
0272a10d 203
9c0d9ce3 204\fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
0272a10d 205
9c0d9ce3 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
0272a10d 207
9c0d9ce3 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
0272a10d 209
9c0d9ce3 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
0272a10d 211
9c0d9ce3 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
0272a10d 213
9c0d9ce3 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
0272a10d 215
0272a10d
VZ
216\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
217
fff5f7d5 218\fBint png_image_begin_read_from_file (png_imagep \fP\fIimage\fP\fB, const char \fI*file_name\fP\fB);\fP
970f6abe 219
fff5f7d5 220\fBint png_image_begin_read_from_stdio (png_imagep \fP\fIimage\fP\fB, FILE* \fIfile\fP\fB);\fP
9c0d9ce3 221
fff5f7d5 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
9c0d9ce3 223
fff5f7d5 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
0272a10d 225
fff5f7d5 226\fBvoid png_image_free (png_imagep \fIimage\fP\fB);\fP
970f6abe 227
fff5f7d5 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
9c0d9ce3 229
fff5f7d5 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
9c0d9ce3 231
fff5f7d5 232\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
0272a10d 233
fff5f7d5 234\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
970f6abe 235
fff5f7d5 236\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
0272a10d 237
fff5f7d5 238\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
970f6abe 239
fff5f7d5 240\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
0272a10d 241
fff5f7d5 242\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
970f6abe 243
9c0d9ce3 244\fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP
0272a10d 245
0272a10d
VZ
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
9c0d9ce3
DS
248\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
249
9c0d9ce3
DS
250\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
251
0272a10d
VZ
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
0272a10d
VZ
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
0272a10d
VZ
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
9c0d9ce3
DS
268\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
269
9c0d9ce3 270\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
970f6abe 271
0272a10d
VZ
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
970f6abe
VZ
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
9c0d9ce3
DS
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
9c0d9ce3
DS
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
0272a10d
VZ
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
9c0d9ce3
DS
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
9c0d9ce3
DS
286\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
287
0272a10d
VZ
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
fff5f7d5 292\fBvoid png_set_check_for_invalid_index(png_structrp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
970f6abe 293
0272a10d
VZ
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
fff5f7d5 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
9c0d9ce3
DS
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
b61cc19c
PC
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
0272a10d
VZ
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
0272a10d
VZ
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
9c0d9ce3
DS
320\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
321
9c0d9ce3 322\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
0272a10d
VZ
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
9c0d9ce3
DS
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
0272a10d
VZ
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
9c0d9ce3
DS
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
0272a10d
VZ
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
9c0d9ce3 342\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
0272a10d
VZ
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
9c0d9ce3 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
0272a10d
VZ
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
b61cc19c
PC
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
b61cc19c
PC
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
9c0d9ce3
DS
366\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
367
9c0d9ce3 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
0272a10d
VZ
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
9c0d9ce3 376\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
0272a10d
VZ
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
b61cc19c
PC
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
0272a10d
VZ
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
9c0d9ce3
DS
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
0272a10d
VZ
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
9c0d9ce3 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
0272a10d
VZ
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
9c0d9ce3
DS
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
9c0d9ce3
DS
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
9c0d9ce3
DS
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
9c0d9ce3 410\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
0272a10d
VZ
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
9c0d9ce3 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
0272a10d 419
9c0d9ce3 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
0272a10d
VZ
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
9c0d9ce3
DS
426\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
427
0272a10d
VZ
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
9c0d9ce3 434\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
0272a10d 435
9c0d9ce3 436\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
0272a10d 437
9c0d9ce3 438\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
0272a10d 439
9c0d9ce3 440\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
0272a10d 441
9c0d9ce3 442\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
0272a10d 443
9c0d9ce3
DS
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
9c0d9ce3
DS
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
9c0d9ce3
DS
448\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
449
9c0d9ce3
DS
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
9c0d9ce3 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
0272a10d
VZ
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
0272a10d
VZ
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
0272a10d
VZ
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
0272a10d
VZ
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
b61cc19c
PC
494\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
495
0272a10d
VZ
496.SH DESCRIPTION
497The
498.I libpng
499library supports encoding, decoding, and various manipulations of
500the Portable Network Graphics (PNG) format image files. It uses the
501.IR zlib(3)
502compression library.
9c0d9ce3 503Following is a copy of the libpng-manual.txt file that accompanies libpng.
0272a10d 504.SH LIBPNG.TXT
9c0d9ce3 505libpng-manual.txt - A description on how to use and modify libpng
0272a10d 506
fff5f7d5 507 libpng version 1.6.2 - April 25, 2013
0272a10d
VZ
508 Updated and distributed by Glenn Randers-Pehrson
509 <glennrp at users.sourceforge.net>
fff5f7d5 510 Copyright (c) 1998-2013 Glenn Randers-Pehrson
b61cc19c
PC
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
0272a10d 515
970f6abe
VZ
516 Based on:
517
fff5f7d5 518 libpng versions 0.97, January 1998, through 1.6.2 - April 25, 2013
970f6abe 519 Updated and distributed by Glenn Randers-Pehrson
fff5f7d5 520 Copyright (c) 1998-2013 Glenn Randers-Pehrson
0272a10d
VZ
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
fff5f7d5
VZ
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
0272a10d
VZ
554.SH I. Introduction
555
556This 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
558file: introduction, structures, reading, writing, and modification and
559configuration notes for various special platforms. In addition to this
560file, example.c is a good starting point for using the library, as
561it is heavily commented and should include everything most people
562will need. We assume that libpng is already installed; see the
563INSTALL file for instructions on how to install libpng.
564
565For examples of libpng usage, see the files "example.c", "pngtest.c",
b61cc19c
PC
566and the files in the "contrib" directory, all of which are included in
567the libpng distribution.
0272a10d
VZ
568
569Libpng was written as a companion to the PNG specification, as a way
570of reducing the amount of time and effort it takes to support the PNG
571file format in application programs.
572
573The PNG specification (second edition), November 2003, is available as
fff5f7d5 574a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at
0272a10d
VZ
575<http://www.w3.org/TR/2003/REC-PNG-20031110/
576The W3C and ISO documents have identical technical content.
577
578The PNG-1.2 specification is available at
970f6abe
VZ
579<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
580to the PNG specification (second edition) but has some additional material.
0272a10d
VZ
581
582The PNG-1.0 specification is available
583as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
970f6abe
VZ
584W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
585
586Some additional chunks are described in the special-purpose public chunks
0272a10d
VZ
587documents at <http://www.libpng.org/pub/png/documents/>.
588
589Other information
590about PNG, and the latest version of libpng, can be found at the PNG home
591page, <http://www.libpng.org/pub/png/>.
592
593Most users will not have to modify the library significantly; advanced
594users may want to modify it more. All attempts were made to make it as
595complete as possible, while keeping the code easy to understand.
596Currently, this library only supports C. Support for other languages
597is being considered.
598
599Libpng has been designed to handle multiple sessions at one time,
600to be easily modifiable, to be portable to the vast majority of
601machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
602to use. The ultimate goal of libpng is to promote the acceptance of
603the PNG file format in whatever way possible. While there is still
604work to be done (see the TODO file), libpng should cover the
605majority of the needs of its users.
606
607Libpng uses zlib for its compression and decompression of PNG files.
608Further information about zlib, and the latest version of zlib, can
609be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
610The zlib compression utility is a general purpose utility that is
611useful for more than PNG files, and can be used without libpng.
612See the documentation delivered with zlib for more details.
613You can usually find the source files for the zlib utility wherever you
614find the libpng source files.
615
616Libpng is thread safe, provided the threads are using different
617instances of the structures. Each thread should have its own
618png_struct and png_info instances, and thus its own image.
619Libpng does not protect itself against two threads using the
620same instance of a structure.
621
622.SH II. Structures
623
624There are two main structures that are important to libpng, png_struct
9c0d9ce3
DS
625and png_info. Both are internal structures that are no longer exposed
626in the libpng interface (as of libpng 1.5.0).
0272a10d
VZ
627
628The png_info structure is designed to provide information about the
629PNG file. At one time, the fields of png_info were intended to be
630directly accessible to the user. However, this tended to cause problems
631with applications using dynamically loaded libraries, and as a result
632a set of interface functions for png_info (the png_get_*() and png_set_*()
9c0d9ce3
DS
633functions) was developed, and direct access to the png_info fields was
634deprecated..
635
636The png_struct structure is the object used by the library to decode a
637single image. As of 1.5.0 this structure is also not exposed.
638
639Almost all libpng APIs require a pointer to a png_struct as the first argument.
640Many (in particular the png_set and png_get APIs) also require a pointer
641to png_info as the second argument. Some application visible macros
642defined in png.h designed for basic data access (reading and writing
643integers in the PNG format) don't take a png_info pointer, but it's almost
644always safe to assume that a (png_struct*) has to be passed to call an API
645function.
646
647You can have more than one png_info structure associated with an image,
648as illustrated in pngtest.c, one for information valid prior to the
649IDAT chunks and another (called "end_info" below) for things after them.
0272a10d
VZ
650
651The png.h header file is an invaluable reference for programming with libpng.
652And while I'm on the topic, make sure you include the libpng header file:
653
654#include <png.h>
655
9c0d9ce3
DS
656and 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
662The png.h header file defines a number of integral types used by the
663APIs. Most of these are fairly obvious; for example types corresponding
664to integers of particular sizes and types for passing color values.
665
666One exception is how non-integral numbers are handled. For application
fff5f7d5
VZ
667convenience most APIs that take such numbers have C (double) arguments;
668however, internally PNG, and libpng, use 32 bit signed integers and encode
9c0d9ce3
DS
669the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
670macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
671which is simply (png_int_32).
672
673All APIs that take (double) arguments also have a matching API that
674takes the corresponding fixed point integer arguments. The fixed point
675API has the same name as the floating point one with "_fixed" appended.
676The actual range of values permitted in the APIs is frequently less than
677the full range of (png_fixed_point) (-21474 to +21474). When APIs require
678a non-negative argument the type is recorded as png_uint_32 above. Consult
679the header file and the text below for more information.
680
681Special care must be take with sCAL chunk handling because the chunk itself
682uses non-integral values encoded as strings containing decimal floating point
683numbers. See the comments in the header file.
684
685.SS Configuration
686
687The main header file function declarations are frequently protected by C
688preprocessing 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
698The library can be built without support for these APIs, although a
699standard build will have all implemented APIs. Application programs
700should check the feature macros before using an API for maximum
701portability. From libpng 1.5.0 the feature macros set during the build
702of libpng are recorded in the header file "pnglibconf.h" and this file
703is always included by png.h.
704
705If you don't need to change the library configuration from the default, skip to
706the next section ("Reading").
707
708Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
709of the build project files in the 'projects' directory simply copy
710scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
711systems do not permit easy auto-configuration of the library - they only
712support the default configuration.
713
714The easiest way to make minor changes to the libpng configuration when
715auto-configuration is supported is to add definitions to the command line
716using (typically) CPPFLAGS. For example:
717
718CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
719
720will change the internal libpng math implementation for gamma correction and
721other arithmetic calculations to fixed point, avoiding the need for fast
722floating point support. The result can be seen in the generated pnglibconf.h -
723make sure it contains the changed feature macro setting.
724
725If you need to make more extensive configuration changes - more than one or two
726feature macro settings - you can either add -DPNG_USER_CONFIG to the build
727command line and put a list of feature macro settings in pngusr.h or you can set
728DFA_XTRA (a makefile variable) to a file containing the same information in the
729form of 'option' settings.
730
731A. Changing pnglibconf.h
732
733A variety of methods exist to build libpng. Not all of these support
734reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
735rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
736
737Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
738pnglibconf.h and changing the lines defining the supported features, paying
739very close attention to the 'option' information in scripts/pnglibconf.dfa
740that describes those features and their requirements. This is easy to get
741wrong.
742
743B. Configuration using DFA_XTRA
744
745Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
746variant such as 'nawk' or 'gawk', is available. The configure build will
747automatically find an appropriate awk and build pnglibconf.h.
748The scripts/pnglibconf.mak file contains a set of make rules for doing the
749same thing if configure is not used, and many of the makefiles in the scripts
750directory use this approach.
751
752When rebuilding simply write a new file containing changed options and set
753DFA_XTRA to the name of this file. This causes the build to append the new file
754to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
755of the following forms:
756
757everything = off
758
759This turns all optional features off. Include it at the start of pngusr.dfa to
760make it easier to build a minimal configuration. You will need to turn at least
761some features on afterward to enable either reading or writing code, or both.
762
763option feature on
764option feature off
765
766Enable or disable a single feature. This will automatically enable other
767features required by a feature that is turned on or disable other features that
768require a feature which is turned off. Conflicting settings will cause an error
769message to be emitted by awk.
770
771setting feature default value
772
773Changes the default value of setting 'feature' to 'value'. There are a small
774number of settings listed at the top of pnglibconf.h, they are documented in the
775source code. Most of these values have performance implications for the library
776but most of them have no visible effect on the API. Some can also be overridden
777from the API.
778
779This method of building a customized pnglibconf.h is illustrated in
780contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
781pngusr.dfa in these directories.
782
783C. Configuration using PNG_USR_CONFIG
784
785If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
786pngusr.h will automatically be included before the options in
787scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
788macro definitions turning features on or off or setting settings.
789
790Apart from the global setting "everything = off" all the options listed above
791can be set using macros in pngusr.h:
792
793#define PNG_feature_SUPPORTED
794
795is equivalent to:
796
797option feature on
798
799#define PNG_NO_feature
800
801is equivalent to:
802
803option feature off
804
805#define PNG_feature value
806
807is equivalent to:
808
809setting feature default value
810
811Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
812pngusr file you supply override the contents of scripts/pnglibconf.dfa
813
814If confusing or incomprehensible behavior results it is possible to
815examine the intermediate file pnglibconf.dfn to find the full set of
816dependency information for each setting and option. Simply locate the
817feature in the file and read the C comments that precede it.
818
819This method is also illustrated in the contrib/pngminim/* makefiles and
820pngusr.h.
821
0272a10d
VZ
822.SH III. Reading
823
824We'll now walk you through the possible functions to call when reading
825in a PNG file sequentially, briefly explaining the syntax and purpose
826of each one. See example.c and png.h for more detail. While
827progressive reading is covered in the next section, you will still
828need some of the functions discussed in this section to read a PNG
829file.
830
831.SS Setup
832
833You will want to do the I/O initialization(*) before you get into libpng,
834so if it doesn't work, you don't have much to undo. Of course, you
835will also want to insure that you are, in fact, dealing with a PNG
836file. Libpng provides a simple check to see if a file is a PNG file.
837To use it, pass in the first 1 to 8 bytes of the file to the function
b61cc19c
PC
838png_sig_cmp(), and it will return 0 (false) if the bytes match the
839corresponding bytes of the PNG signature, or nonzero (true) otherwise.
840Of course, the more bytes you pass in, the greater the accuracy of the
841prediction.
0272a10d
VZ
842
843If you are intending to keep the file pointer open for use in libpng,
844you must ensure you don't read more than 8 bytes from the beginning
845of the file, and you also have to make a call to png_set_sig_bytes_read()
846with the number of bytes you read from the beginning. Libpng will
847then 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
850to replace them with custom functions. See the discussion under
851Customizing libpng.
852
853
854 FILE *fp = fopen(file_name, "rb");
855 if (!fp)
856 {
9c0d9ce3 857 return (ERROR);
0272a10d 858 }
9c0d9ce3 859
0272a10d
VZ
860 fread(header, 1, number, fp);
861 is_png = !png_sig_cmp(header, 0, number);
9c0d9ce3 862
0272a10d
VZ
863 if (!is_png)
864 {
9c0d9ce3 865 return (NOT_PNG);
0272a10d
VZ
866 }
867
868
869Next, png_struct and png_info need to be allocated and initialized. In
870order to ensure that the size of these structures is correct even with a
871dynamically linked libpng, there are functions to initialize and
872allocate the structures. We also pass the library version, optional
873pointers to error handling functions, and a pointer to a data struct for
874use by the error functions, if necessary (the pointer and functions can
875be NULL if the default error handlers are to be used). See the section
876on Changes to Libpng below regarding the old initialization functions.
877The structure allocation functions quietly return NULL if they fail to
878create the structure, so your application should check for that.
879
880 png_structp png_ptr = png_create_read_struct
9c0d9ce3 881 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
0272a10d 882 user_error_fn, user_warning_fn);
9c0d9ce3 883
0272a10d 884 if (!png_ptr)
9c0d9ce3 885 return (ERROR);
0272a10d
VZ
886
887 png_infop info_ptr = png_create_info_struct(png_ptr);
9c0d9ce3 888
0272a10d
VZ
889 if (!info_ptr)
890 {
9c0d9ce3 891 png_destroy_read_struct(&png_ptr,
0272a10d 892 (png_infopp)NULL, (png_infopp)NULL);
9c0d9ce3 893 return (ERROR);
0272a10d
VZ
894 }
895
896If you want to use your own memory allocation routines,
9c0d9ce3 897use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
0272a10d
VZ
898png_create_read_struct_2() instead of png_create_read_struct():
899
900 png_structp png_ptr = png_create_read_struct_2
9c0d9ce3 901 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
0272a10d
VZ
902 user_error_fn, user_warning_fn, (png_voidp)
903 user_mem_ptr, user_malloc_fn, user_free_fn);
904
905The error handling routines passed to png_create_read_struct()
906and the memory alloc/free routines passed to png_create_struct_2()
907are only necessary if you are not using the libpng supplied error
908handling and memory alloc/free functions.
909
910When libpng encounters an error, it expects to longjmp back
911to your routine. Therefore, you will need to call setjmp and pass
912your png_jmpbuf(png_ptr). If you read the file from different
9c0d9ce3 913routines, you will need to update the longjmp buffer every time you enter
0272a10d
VZ
914a new routine that will call a png_*() function.
915
916See your documentation of setjmp/longjmp for your compiler for more
917information on setjmp/longjmp. See the discussion on libpng error
918handling in the Customizing Libpng section below for more information
919on the libpng error handling. If an error occurs, and libpng longjmp's
920back to your setjmp, you will want to call png_destroy_read_struct() to
921free any memory.
922
923 if (setjmp(png_jmpbuf(png_ptr)))
924 {
9c0d9ce3 925 png_destroy_read_struct(&png_ptr, &info_ptr,
0272a10d 926 &end_info);
9c0d9ce3
DS
927 fclose(fp);
928 return (ERROR);
0272a10d
VZ
929 }
930
9c0d9ce3
DS
931Pass (png_infopp)NULL instead of &end_info if you didn't create
932an end_info structure.
933
0272a10d 934If you would rather avoid the complexity of setjmp/longjmp issues,
b61cc19c 935you can compile libpng with PNG_NO_SETJMP, in which case
0272a10d
VZ
936errors will result in a call to PNG_ABORT() which defaults to abort().
937
b61cc19c
PC
938You can #define PNG_ABORT() to a function that does something
939more useful than abort(), as long as your function does not
940return.
941
0272a10d
VZ
942Now you need to set up the input code. The default for libpng is to
943use the C function fread(). If you use this, you will need to pass a
944valid FILE * in the function png_init_io(). Be sure that the file is
945opened in binary mode. If you wish to handle reading data in another
946way, you need not call the png_init_io() function, but you must then
947implement the libpng I/O methods discussed in the Customizing Libpng
948section below.
949
950 png_init_io(png_ptr, fp);
951
952If you had previously opened the file and read any of the signature from
953the beginning in order to see if this was a PNG file, you need to let
954libpng know that there are some bytes missing from the start of the file.
955
956 png_set_sig_bytes(png_ptr, number);
957
b61cc19c
PC
958You can change the zlib compression buffer size to be used while
959reading compressed data with
960
961 png_set_compression_buffer_size(png_ptr, buffer_size);
962
963where the default size is 8192 bytes. Note that the buffer size
964is changed immediately and the buffer is reallocated immediately,
965instead of setting a flag to be acted upon later.
966
9c0d9ce3
DS
967If you want CRC errors to be handled in a different manner than
968the default, use
969
970 png_set_crc_action(png_ptr, crit_action, ancil_action);
971
972The values for png_set_crc_action() say how libpng is to handle CRC errors in
973ancillary and critical chunks, and whether to use the data contained
974therein. Note that it is impossible to "discard" data in a critical
975chunk.
976
977Choices 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
984Choices 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
0272a10d
VZ
992.SS Setting up callback code
993
994You can set up a callback function to handle any unknown chunks in the
995input stream. You must supply the function
996
9c0d9ce3 997 read_chunk_callback(png_structp png_ptr,
0272a10d
VZ
998 png_unknown_chunkp chunk);
999 {
1000 /* The unknown chunk structure contains your
970f6abe
VZ
1001 chunk data, along with similar data for any other
1002 unknown chunks: */
1003
0272a10d
VZ
1004 png_byte name[5];
1005 png_byte *data;
1006 png_size_t size;
970f6abe 1007
0272a10d
VZ
1008 /* Note that libpng has already taken care of
1009 the CRC handling */
1010
970f6abe
VZ
1011 /* put your code here. Search for your chunk in the
1012 unknown chunk structure, process it, and return one
1013 of the following: */
0272a10d
VZ
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
1023To inform libpng about your function, use
1024
1025 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1026 read_chunk_callback);
1027
1028This names not only the callback function, but also a user pointer that
1029you can retrieve with
1030
1031 png_get_user_chunk_ptr(png_ptr);
1032
970f6abe 1033If you call the png_set_read_user_chunk_fn() function, then all unknown
fff5f7d5
VZ
1034chunks which the callback does not handle will be saved when read. You can
1035cause them to be discarded by returning '1' ("handled") instead of '0'. This
1036behavior will change in libpng 1.7 and the default handling set by the
1037png_set_keep_unknown_chunks() function, described below, will be used when the
1038callback returns 0. If you want the existing behavior you should set the global
1039default to PNG_HANDLE_CHUNK_IF_SAFE now; this is compatible with all current
1040versions of libpng and with 1.7. Libpng 1.6 issues a warning if you keep the
1041default, or PNG_HANDLE_CHUNK_NEVER, and the callback returns 0.
970f6abe 1042
0272a10d
VZ
1043At this point, you can set up a callback function that will be
1044called after each row has been read, which you can use to control
1045a progress meter or the like. It's demonstrated in pngtest.c.
1046You must supply a function
1047
9c0d9ce3
DS
1048 void read_row_callback(png_structp png_ptr,
1049 png_uint_32 row, int pass);
0272a10d
VZ
1050 {
1051 /* put your code here */
1052 }
1053
1054(You can give it another name that you like instead of "read_row_callback")
1055
1056To inform libpng about your function, use
1057
1058 png_set_read_status_fn(png_ptr, read_row_callback);
1059
9c0d9ce3
DS
1060When this function is called the row has already been completely processed and
1061the 'row' and 'pass' refer to the next row to be handled. For the
1062non-interlaced case the row that was just handled is simply one less than the
1063passed in row number, and pass will always be 0. For the interlaced case the
1064same applies unless the row value is 0, in which case the row just handled was
1065the last one from one of the preceding passes. Because interlacing may skip a
1066pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1067need to know what the last pass is record (row,pass) from the callback and use
1068the last recorded value each time.
1069
1070As with the user transform you can find the output row using the
1071PNG_ROW_FROM_PASS_ROW macro.
1072
0272a10d
VZ
1073.SS Unknown-chunk handling
1074
1075Now you get to set the way the library processes unknown chunks in the
1076input PNG stream. Both known and unknown chunks will be read. Normal
1077behavior is that known chunks will be parsed into information in
970f6abe
VZ
1078various info_ptr members while unknown chunks will be discarded. This
1079behavior can be wasteful if your application will never use some known
1080chunk types. To change this, you can call:
0272a10d
VZ
1081
1082 png_set_keep_unknown_chunks(png_ptr, keep,
1083 chunk_list, num_chunks);
fff5f7d5 1084
970f6abe
VZ
1085 keep - 0: default unknown chunk handling
1086 1: ignore; do not keep
0272a10d
VZ
1087 2: keep only if safe-to-copy
1088 3: keep even if unsafe-to-copy
9c0d9ce3 1089
0272a10d
VZ
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
9c0d9ce3 1095
0272a10d
VZ
1096 chunk_list - list of chunks affected (a byte string,
1097 five bytes per chunk, NULL or '\0' if
fff5f7d5
VZ
1098 num_chunks is positive; ignored if
1099 numchunks <= 0).
9c0d9ce3 1100
0272a10d 1101 num_chunks - number of chunks affected; if 0, all
fff5f7d5
VZ
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.
0272a10d
VZ
1108
1109Unknown chunks declared in this way will be saved as raw data onto a
1110list of png_unknown_chunk structures. If a chunk that is normally
1111known to libpng is named in the list, it will be handled as unknown,
1112according to the "keep" directive. If a chunk is named in successive
1113instances of png_set_keep_unknown_chunks(), the final instance will
1114take precedence. The IHDR and IEND chunks should not be named in
1115chunk_list; if they are, libpng will process them normally anyway.
9c0d9ce3
DS
1116If you know that your application will never make use of some particular
1117chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
0272a10d 1118
970f6abe
VZ
1119Here is an example of the usage of png_set_keep_unknown_chunks(),
1120where the private "vpAg" chunk will later be processed by a user chunk
1121callback 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)
fff5f7d5
VZ
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);
9c0d9ce3 1144
970f6abe
VZ
1145 /* except for vpAg: */
1146 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
9c0d9ce3 1147
970f6abe
VZ
1148 /* also ignore unused known chunks: */
1149 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
fff5f7d5 1150 (int)(sizeof unused_chunks)/5);
970f6abe
VZ
1151 #endif
1152
b61cc19c
PC
1153.SS User limits
1154
1155The PNG specification allows the width and height of an image to be as
1156large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1157Since very few applications really need to process such large images,
1158we have imposed an arbitrary 1-million limit on rows and columns.
1159Larger images will be rejected immediately with a png_error() call. If
9c0d9ce3 1160you wish to change this limit, you can use
b61cc19c
PC
1161
1162 png_set_user_limits(png_ptr, width_max, height_max);
1163
1164to set your own limits, or use width_max = height_max = 0x7fffffffL
1165to allow all valid dimensions (libpng may reject some very large images
1166anyway because of potential buffer overflow conditions).
1167
1168You should put this statement after you create the PNG structure and
1169before calling png_read_info(), png_read_png(), or png_process_data().
9c0d9ce3
DS
1170
1171When writing a PNG datastream, put this statement before calling
1172png_write_info() or png_write_png().
1173
b61cc19c
PC
1174If 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
1179The PNG specification sets no limit on the number of ancillary chunks
1180allowed in a PNG datastream. You can impose a limit on the total number
1181of 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
1185where 0x7fffffffL means unlimited. You can retrieve this limit with
1186
1187 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1188
b61cc19c
PC
1189You can also set a limit on the amount of memory that a compressed chunk
1190other than IDAT can occupy, with
1191
1192 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1193
1194and you can retrieve the limit with
1195
1196 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1197
1198Any chunks that would cause either of these limits to be exceeded will
1199be ignored.
970f6abe 1200
9c0d9ce3
DS
1201.SS Information about your system
1202
1203If you intend to display the PNG or to incorporate it in other image data you
1204need to tell libpng information about your display or drawing surface so that
1205libpng can convert the values in the image to match the display.
1206
1207From libpng-1.5.4 this information can be set before reading the PNG file
1208header. In earlier versions png_set_gamma() existed but behaved incorrectly if
1209called before the PNG file header had been read and png_set_alpha_mode() did not
1210exist.
1211
1212If you need to support versions prior to libpng-1.5.4 test the version number
1213as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1214described in the appropriate manual page.
1215
1216You give libpng the encoding expected by your system expressed as a 'gamma'
1217value. You can also specify a default encoding for the PNG file in
1218case the required information is missing from the file. By default libpng
1219assumes 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
1223or you can use the fixed point equivalent:
1224
fff5f7d5
VZ
1225 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma,
1226 PNG_FP_1/screen_gamma);
9c0d9ce3
DS
1227
1228If you don't know the gamma for your system it is probably 2.2 - a good
1229approximation to the IEC standard for display systems (sRGB). If images are
1230too contrasty or washed out you got the value wrong - check your system
1231documentation!
1232
1233Many systems permit the system gamma to be changed via a lookup table in the
1234display driver, a few systems, including older Macs, change the response by
1235default. As of 1.5.4 three special values are available to handle common
1236situations:
1237
fff5f7d5
VZ
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.
9c0d9ce3
DS
1247
1248You would use the linear (unencoded) value if you need to process the pixel
1249values further because this avoids the need to decode and reencode each
1250component value whenever arithmetic is performed. A lot of graphics software
1251uses linear values for this reason, often with higher precision component values
1252to preserve overall accuracy.
1253
1254The second thing you may need to tell libpng about is how your system handles
1255alpha channel information. Some, but not all, PNG files contain an alpha
1256channel. To display these files correctly you need to compose the data onto a
1257suitable background, as described in the PNG specification.
1258
1259Libpng only supports composing onto a single color (using png_set_background;
1260see below). Otherwise you must do the composition yourself and, in this case,
1261you may need to call png_set_alpha_mode:
1262
fff5f7d5
VZ
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
9c0d9ce3
DS
1268
1269The screen_gamma value is the same as the argument to png_set_gamma; however,
1270how it affects the output depends on the mode. png_set_alpha_mode() sets the
1271file gamma default to 1/screen_gamma, so normally you don't need to call
1272png_set_gamma. If you need different defaults call png_set_gamma() before
1273png_set_alpha_mode() - if you call it after it will override the settings made
1274by png_set_alpha_mode().
1275
1276The mode is as follows:
1277
1278 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
1279green and blue, or gray, components are gamma encoded color
1280values and are not premultiplied by the alpha value. The
1281alpha value is a linear measure of the contribution of the
1282pixel to the corresponding final output pixel.
1283
1284You should normally use this format if you intend to perform
1285color correction on the color values; most, maybe all, color
1286correction software has no handling for the alpha channel and,
1287anyway, the math to handle pre-multiplied component values is
1288unnecessarily complex.
1289
1290Before you do any arithmetic on the component values you need
1291to remove the gamma encoding and multiply out the alpha
1292channel. See the PNG specification for more detail. It is
1293important to note that when an image with an alpha channel is
1294scaled, linear encoded, pre-multiplied component values must
1295be used!
1296
1297The remaining modes assume you don't need to do any further color correction or
1298that if you do, your color correction software knows all about alpha (it
1299probably doesn't!)
1300
1301 PNG_ALPHA_STANDARD: The data libpng produces
1302is encoded in the standard way
1303assumed by most correctly written graphics software.
1304The gamma encoding will be removed by libpng and the
1305linear component values will be pre-multiplied by the
1306alpha channel.
1307
1308With this format the final image must be re-encoded to
1309match the display gamma before the image is displayed.
1310If your system doesn't do that, yet still seems to
1311perform arithmetic on the pixels without decoding them,
1312it is broken - check out the modes below.
1313
1314With PNG_ALPHA_STANDARD libpng always produces linear
1315component values, whatever screen_gamma you supply. The
1316screen_gamma value is, however, used as a default for
1317the file gamma if the PNG file has no gamma information.
1318
1319If you call png_set_gamma() after png_set_alpha_mode() you
1320will override the linear encoding. Instead the
1321pre-multiplied pixel values will be gamma encoded but
1322the alpha channel will still be linear. This may
1323actually match the requirements of some broken software,
1324but it is unlikely.
1325
1326While linear 8-bit data is often used it has
1327insufficient precision for any image with a reasonable
1328dynamic range. To avoid problems, and if your software
1329supports it, use png_set_expand_16() to force all
1330components to 16 bits.
1331
1332 PNG_ALPHA_OPTIMIZED: This mode is the same
1333as PNG_ALPHA_STANDARD except that
1334completely opaque pixels are gamma encoded according to
1335the screen_gamma value. Pixels with alpha less than 1.0
1336will still have linear components.
1337
1338Use this format if you have control over your
fff5f7d5 1339compositing software and so don't do other arithmetic
9c0d9ce3
DS
1340(such as scaling) on the data you get from libpng. Your
1341compositing software can simply copy opaque pixels to
1342the output but still has linear values for the
1343non-opaque pixels.
1344
1345In normal compositing, where the alpha channel encodes
1346partial pixel coverage (as opposed to broad area
1347translucency), the inaccuracies of the 8-bit
1348representation of non-opaque pixels are irrelevant.
1349
1350You can also try this format if your software is broken;
1351it might look better.
1352
1353 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD;
1354however, all component values,
1355including the alpha channel are gamma encoded. This is
1356an appropriate format to try if your software, or more
1357likely hardware, is totally broken, i.e., if it performs
1358linear arithmetic directly on gamma encoded values.
1359
1360In most cases of broken software or hardware the bug in the final display
1361manifests as a subtle halo around composited parts of the image. You may not
1362even perceive this as a halo; the composited part of the image may simply appear
1363separate from the background, as though it had been cut out of paper and pasted
1364on afterward.
1365
1366If you don't have to deal with bugs in software or hardware, or if you can fix
1367them, 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
1372You can do color correction on the result (libpng does not currently
1373support color correction internally). When you handle the alpha channel
1374you 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
1380If you are using the high level interface, don't call png_set_expand_16();
1381instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
1382
1383With this mode you can't do color correction, but you can do arithmetic,
1384including composition and scaling, on the data without further processing.
1385
1386 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1387 screen_gamma);
1388
1389You can avoid the expansion to 16-bit components with this mode, but you
1390lose the ability to scale the image or perform other linear arithmetic.
1391All you can do is compose the result onto a matching output. Since this
1392mode is libpng-specific you also need to write your own composition
1393software.
1394
1395If you don't need, or can't handle, the alpha channel you can call
1396png_set_background() to remove it by compositing against a fixed color. Don't
1397call png_set_strip_alpha() to do this - it will leave spurious pixel values in
1398transparent parts of this image.
1399
1400 png_set_background(png_ptr, &background_color,
1401 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
1402
1403The background_color is an RGB or grayscale value according to the data format
1404libpng will produce for you. Because you don't yet know the format of the PNG
1405file, if you call png_set_background at this point you must arrange for the
1406format produced by libpng to always have 8-bit or 16-bit components and then
1407store the color as an 8-bit or 16-bit color as appropriate. The color contains
1408separate gray and RGB component values, so you can let libpng produce gray or
1409RGB output according to the input format, but low bit depth grayscale images
1410must always be converted to at least 8-bit format. (Even though low bit depth
1411grayscale images can't have an alpha channel they can have a transparent
1412color!)
1413
1414You set the transforms you need later, either as flags to the high level
1415interface or libpng API calls for the low level interface. For reference the
1416settings and API calls required are:
1417
14188-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
142716-bit values:
1428 PNG_TRANSFORM_EXPAND_16
1429 png_set_expand_16(png_ptr);
1430
1431In either case palette image data will be expanded to RGB. If you just want
1432color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1433to the list.
1434
1435Calling png_set_background before the PNG file header is read will not work
1436prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
1437errors it is therefore much safer to call png_set_background after the head has
1438been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
1439used with the high level interface.
1440
0272a10d
VZ
1441.SS The high-level read interface
1442
1443At this point there are two ways to proceed; through the high-level
1444read interface, or through a sequence of low-level read operations.
1445You can use the high-level interface if (a) you are willing to read
1446the entire image into memory, and (b) the input transformations
1447you want to do are limited to the following set:
1448
1449 PNG_TRANSFORM_IDENTITY No transformation
9c0d9ce3
DS
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
0272a10d
VZ
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
b61cc19c
PC
1470 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1471 to RGB (or GA to RGBA)
9c0d9ce3 1472 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
0272a10d
VZ
1473
1474(This excludes setting a background color, doing gamma transformation,
b61cc19c 1475quantizing, and setting filler.) If this is the case, simply do this:
0272a10d
VZ
1476
1477 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1478
b61cc19c
PC
1479where png_transforms is an integer containing the bitwise OR of some
1480set of transformation flags. This call is equivalent to png_read_info(),
0272a10d
VZ
1481followed the set of transformations indicated by the transform mask,
1482then png_read_image(), and finally png_read_end().
1483
1484(The final parameter of this call is not yet used. Someday it might point
1485to transformation parameters required by some future input transform.)
1486
1487You must use png_transforms and not call any png_set_transform() functions
1488when you use png_read_png().
1489
1490After you have called png_read_png(), you can retrieve the image data
1491with
1492
1493 row_pointers = png_get_rows(png_ptr, info_ptr);
1494
1495where row_pointers is an array of pointers to the pixel data for each row:
1496
1497 png_bytep row_pointers[height];
1498
1499If you know your image size and pixel size ahead of time, you can allocate
1500row_pointers prior to calling png_read_png() with
1501
fff5f7d5 1502 if (height > PNG_UINT_32_MAX/(sizeof (png_byte)))
0272a10d 1503 png_error (png_ptr,
9c0d9ce3
DS
1504 "Image is too tall to process in memory");
1505
0272a10d
VZ
1506 if (width > PNG_UINT_32_MAX/pixel_size)
1507 png_error (png_ptr,
9c0d9ce3
DS
1508 "Image is too wide to process in memory");
1509
0272a10d 1510 row_pointers = png_malloc(png_ptr,
fff5f7d5 1511 height*(sizeof (png_bytep)));
9c0d9ce3 1512
b61cc19c
PC
1513 for (int i=0; i<height, i++)
1514 row_pointers[i]=NULL; /* security precaution */
9c0d9ce3 1515
0272a10d
VZ
1516 for (int i=0; i<height, i++)
1517 row_pointers[i]=png_malloc(png_ptr,
9c0d9ce3
DS
1518 width*pixel_size);
1519
0272a10d
VZ
1520 png_set_rows(png_ptr, info_ptr, &row_pointers);
1521
1522Alternatively you could allocate your image in one big block and define
1523row_pointers[i] to point into the proper places in your block.
1524
1525If you use png_set_rows(), the application is responsible for freeing
1526row_pointers (and row_pointers[i], if they were separately allocated).
1527
1528If you don't allocate row_pointers ahead of time, png_read_png() will
9c0d9ce3 1529do it, and it'll be free'ed by libpng when you call png_destroy_*().
0272a10d
VZ
1530
1531.SS The low-level read interface
1532
1533If you are going the low-level route, you are now ready to read all
1534the file information up to the actual image data. You do this with a
1535call to png_read_info().
1536
1537 png_read_info(png_ptr, info_ptr);
1538
1539This will process all chunks up to but not including the image data.
1540
9c0d9ce3
DS
1541This also copies some of the data from the PNG file into the decode structure
1542for use in later transformations. Important information copied in is:
1543
15441) The PNG file gamma from the gAMA chunk. This overwrites the default value
1545provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1546
15472) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
1548damages the information provided by an earlier call to png_set_background
1549resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
1550
15513) The number of significant bits in each component value. Libpng uses this to
1552optimize gamma handling by reducing the internal lookup table sizes.
1553
15544) The transparent color information from a tRNS chunk. This can be modified by
1555a later call to png_set_tRNS.
1556
0272a10d
VZ
1557.SS Querying the info structure
1558
1559Functions are used to get the information from the info_ptr once it
1560has been read. Note that these fields may not be completely filled
1561in 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).
9c0d9ce3 1569
0272a10d
VZ
1570 height - holds the height of the image
1571 in pixels (up to 2^31).
9c0d9ce3 1572
0272a10d
VZ
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).
9c0d9ce3 1578
0272a10d
VZ
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
9c0d9ce3
DS
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
0272a10d
VZ
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)
b61cc19c
PC
1607
1608 Any or all of interlace_type, compression_type, or
0272a10d
VZ
1609 filter_method can be NULL if you are
1610 not interested in their values.
1611
b61cc19c
PC
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);
9c0d9ce3 1621
b61cc19c
PC
1622 height = png_get_image_height(png_ptr,
1623 info_ptr);
9c0d9ce3 1624
b61cc19c
PC
1625 bit_depth = png_get_bit_depth(png_ptr,
1626 info_ptr);
9c0d9ce3 1627
b61cc19c
PC
1628 color_type = png_get_color_type(png_ptr,
1629 info_ptr);
9c0d9ce3
DS
1630
1631 interlace_type = png_get_interlace_type(png_ptr,
b61cc19c 1632 info_ptr);
9c0d9ce3 1633
b61cc19c
PC
1634 compression_type = png_get_compression_type(png_ptr,
1635 info_ptr);
9c0d9ce3
DS
1636
1637 filter_method = png_get_filter_type(png_ptr,
b61cc19c
PC
1638 info_ptr);
1639
0272a10d 1640 channels = png_get_channels(png_ptr, info_ptr);
9c0d9ce3 1641
0272a10d
VZ
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))
9c0d9ce3 1646
0272a10d 1647 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
9c0d9ce3 1648
0272a10d
VZ
1649 rowbytes - number of bytes needed to hold a row
1650
1651 signature = png_get_signature(png_ptr, info_ptr);
9c0d9ce3 1652
0272a10d
VZ
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
0272a10d
VZ
1663These are also important, but their validity depends on whether the chunk
1664has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1665png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1666data has been read, or zero if it is missing. The parameters to the
b61cc19c
PC
1667png_get_<chunk> are set directly if they are simple data types, or a
1668pointer into the info_ptr is returned for any complex types.
0272a10d 1669
fff5f7d5
VZ
1670The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks
1671is simply returned to give the application information about how the
1672image was encoded. Libpng itself only does transformations using the file
1673gamma when combining semitransparent pixels with the background color, and,
1674since libpng-1.6.0, when converting between 8-bit sRGB and 16-bit linear pixels
1675within the simplified API. Libpng also uses the file gamma when converting
1676RGB to gray, beginning with libpng-1.0.5, if the application calls
1677png_set_rgb_to_gray()).
1678
0272a10d
VZ
1679 png_get_PLTE(png_ptr, info_ptr, &palette,
1680 &num_palette);
9c0d9ce3 1681
0272a10d
VZ
1682 palette - the palette for the file
1683 (array of png_color)
9c0d9ce3 1684
0272a10d
VZ
1685 num_palette - number of entries in the palette
1686
9c0d9ce3
DS
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
fff5f7d5
VZ
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)
9c0d9ce3 1705 png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
fff5f7d5
VZ
1706 &int_red_Z, &int_green_X, &int_green_Y,
1707 &int_green_Z, &int_blue_X, &int_blue_Y,
1708 &int_blue_Z)
9c0d9ce3
DS
1709
1710 {white,red,green,blue}_{x,y}
fff5f7d5
VZ
1711 A color space encoding specified using the
1712 chromaticities of the end points and the
1713 white point. (PNG_INFO_cHRM)
9c0d9ce3
DS
1714
1715 {red,green,blue}_{X,Y,Z}
fff5f7d5
VZ
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)
0272a10d
VZ
1722
1723 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
9c0d9ce3
DS
1724
1725 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
0272a10d
VZ
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);
9c0d9ce3
DS
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.
0272a10d
VZ
1746
1747 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
9c0d9ce3 1748
0272a10d
VZ
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
b61cc19c
PC
1755 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
1756 &num_trans, &trans_color);
9c0d9ce3 1757
b61cc19c
PC
1758 trans_alpha - array of alpha (transparency)
1759 entries for palette (PNG_INFO_tRNS)
9c0d9ce3
DS
1760
1761 num_trans - number of transparent entries
1762 (PNG_INFO_tRNS)
1763
b61cc19c 1764 trans_color - graylevel or color sample values of
0272a10d
VZ
1765 the single transparent color for
1766 non-paletted images (PNG_INFO_tRNS)
0272a10d
VZ
1767
1768 png_get_hIST(png_ptr, info_ptr, &hist);
1769 (PNG_INFO_hIST)
9c0d9ce3 1770
0272a10d
VZ
1771 hist - histogram of palette (array of
1772 png_uint_16)
1773
1774 png_get_tIME(png_ptr, info_ptr, &mod_time);
9c0d9ce3 1775
0272a10d
VZ
1776 mod_time - time image was last modified
1777 (PNG_VALID_tIME)
1778
1779 png_get_bKGD(png_ptr, info_ptr, &background);
9c0d9ce3
DS
1780
1781 background - background color (of type
1782 png_color_16p) (PNG_VALID_bKGD)
0272a10d
VZ
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);
9c0d9ce3 1788
0272a10d 1789 num_comments - number of comments
9c0d9ce3 1790
0272a10d
VZ
1791 text_ptr - array of png_text holding image
1792 comments
9c0d9ce3 1793
0272a10d
VZ
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
9c0d9ce3 1799
0272a10d
VZ
1800 text_ptr[i].key - keyword for comment. Must contain
1801 1-79 characters.
9c0d9ce3 1802
0272a10d
VZ
1803 text_ptr[i].text - text comments for current
1804 keyword. Can be empty.
9c0d9ce3 1805
0272a10d
VZ
1806 text_ptr[i].text_length - length of text string,
1807 after decompression, 0 for iTXt
9c0d9ce3 1808
0272a10d
VZ
1809 text_ptr[i].itxt_length - length of itxt string,
1810 after decompression, 0 for tEXt/zTXt
9c0d9ce3 1811
0272a10d
VZ
1812 text_ptr[i].lang - language of comment (empty
1813 string for unknown).
9c0d9ce3 1814
0272a10d
VZ
1815 text_ptr[i].lang_key - keyword in UTF-8
1816 (empty string for unknown).
9c0d9ce3 1817
b61cc19c 1818 Note that the itxt_length, lang, and lang_key
72281370
DS
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.
b61cc19c 1826
0272a10d
VZ
1827 num_text - number of comments (same as
1828 num_comments; you can put NULL here
1829 to avoid the duplication)
9c0d9ce3 1830
0272a10d
VZ
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);
9c0d9ce3
DS
1839
1840 num_spalettes - number of sPLT chunks read.
1841
0272a10d
VZ
1842 palette_ptr - array of palette structures holding
1843 contents of one or more sPLT chunks
1844 read.
0272a10d
VZ
1845
1846 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
1847 &unit_type);
9c0d9ce3 1848
0272a10d 1849 offset_x - positive offset from the left edge
9c0d9ce3
DS
1850 of the screen (can be negative)
1851
0272a10d 1852 offset_y - positive offset from the top edge
9c0d9ce3
DS
1853 of the screen (can be negative)
1854
0272a10d
VZ
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);
9c0d9ce3 1859
0272a10d
VZ
1860 res_x - pixels/unit physical resolution in
1861 x direction
9c0d9ce3 1862
0272a10d
VZ
1863 res_y - pixels/unit physical resolution in
1864 x direction
9c0d9ce3 1865
0272a10d
VZ
1866 unit_type - PNG_RESOLUTION_UNKNOWN,
1867 PNG_RESOLUTION_METER
1868
1869 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1870 &height)
9c0d9ce3 1871
0272a10d 1872 unit - physical scale units (an integer)
9c0d9ce3 1873
0272a10d 1874 width - width of a pixel in physical scale units
9c0d9ce3 1875
0272a10d
VZ
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)
9c0d9ce3 1881
0272a10d 1882 unit - physical scale units (an integer)
9c0d9ce3 1883
0272a10d 1884 width - width of a pixel in physical scale units
9c0d9ce3
DS
1885 (expressed as a string)
1886
0272a10d
VZ
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)
9c0d9ce3 1892
0272a10d
VZ
1893 unknowns - array of png_unknown_chunk
1894 structures holding unknown chunks
9c0d9ce3 1895
0272a10d 1896 unknowns[i].name - name of unknown chunk
9c0d9ce3 1897
0272a10d 1898 unknowns[i].data - data of unknown chunk
9c0d9ce3 1899
0272a10d 1900 unknowns[i].size - size of unknown chunk's data
9c0d9ce3 1901
0272a10d
VZ
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
9c0d9ce3
DS
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
0272a10d
VZ
1914The data from the pHYs chunk can be retrieved in several convenient
1915forms:
1916
1917 res_x = png_get_x_pixels_per_meter(png_ptr,
1918 info_ptr)
9c0d9ce3 1919
0272a10d
VZ
1920 res_y = png_get_y_pixels_per_meter(png_ptr,
1921 info_ptr)
9c0d9ce3 1922
0272a10d
VZ
1923 res_x_and_y = png_get_pixels_per_meter(png_ptr,
1924 info_ptr)
9c0d9ce3 1925
0272a10d
VZ
1926 res_x = png_get_x_pixels_per_inch(png_ptr,
1927 info_ptr)
9c0d9ce3 1928
0272a10d
VZ
1929 res_y = png_get_y_pixels_per_inch(png_ptr,
1930 info_ptr)
9c0d9ce3 1931
0272a10d
VZ
1932 res_x_and_y = png_get_pixels_per_inch(png_ptr,
1933 info_ptr)
9c0d9ce3 1934
0272a10d
VZ
1935 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
1936 info_ptr)
1937
9c0d9ce3 1938 Each of these returns 0 [signifying "unknown"] if
0272a10d 1939 the data is not present or if res_x is 0;
9c0d9ce3
DS
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.
0272a10d
VZ
1949
1950The data from the oFFs chunk can be retrieved in several convenient
1951forms:
1952
1953 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
9c0d9ce3 1954
0272a10d 1955 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
9c0d9ce3 1956
0272a10d 1957 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
9c0d9ce3 1958
0272a10d
VZ
1959 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1960
9c0d9ce3 1961 Each of these returns 0 [signifying "unknown" if both
0272a10d 1962 x and y are 0] if the data is not present or if the
9c0d9ce3
DS
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.
0272a10d 1968
9c0d9ce3 1969For more information, see the
0272a10d
VZ
1970PNG specification for chunk contents. Be careful with trusting
1971rowbytes, as some of the transformations could increase the space
1972needed to hold a row (expand, filler, gray_to_rgb, etc.).
1973See png_read_update_info(), below.
1974
1975A quick word about text_ptr and num_text. PNG stores comments in
1976keyword/text pairs, one pair per chunk, with no limit on the number
1977of text chunks, and a 2^31 byte limit on their size. While there are
1978suggested keywords, there is no requirement to restrict the use to these
1979strings. It is strongly suggested that keywords and text be sensible
1980to humans (that's the point), so don't use abbreviations. Non-printing
1981symbols are not allowed. See the PNG specification for more details.
1982There is also no requirement to have text after the keyword.
1983
1984Keywords should be limited to 79 Latin-1 characters without leading or
1985trailing spaces, but non-consecutive spaces are allowed within the
1986keyword. It is possible to have the same keyword any number of times.
1987The text_ptr is an array of png_text structures, each holding a
1988pointer to a language string, a pointer to a keyword and a pointer to
1989a text string. The text string, language code, and translated
1990keyword may be empty or NULL pointers. The keyword/text
1991pairs are put into the array in the order that they are received.
1992However, some or all of the text chunks may be after the image, so, to
1993make sure you have read all the text chunks, don't mess with these
1994until after you read the stuff after the image. This will be
1995mentioned again below in the discussion that goes with png_read_end().
1996
1997.SS Input transformations
1998
1999After you've read the header information, you can set up the library
2000to handle any special transformations of the image data. The various
2001ways to transform the data will be described in the order that they
2002should occur. This is important, as some of these change the color
2003type and/or bit depth of the data, and some others only work on
9c0d9ce3 2004certain color types and bit depths.
0272a10d 2005
9c0d9ce3
DS
2006Transformations you request are ignored if they don't have any meaning for a
2007particular input data format. However some transformations can have an effect
2008as a result of a previous transformation. If you specify a contradictory set of
2009transformations, for example both adding and removing the alpha channel, you
2010cannot predict the final result.
2011
2012The color used for the transparency values should be supplied in the same
2013format/depth as the current image data. It is stored in the same format/depth
2014as the image data in a tRNS chunk, so this is what libpng expects for this data.
2015
2016The color used for the background value depends on the need_expand argument as
2017described below.
0272a10d
VZ
2018
2019Data will be decoded into the supplied row buffers packed into bytes
2020unless the library has been told to transform it into another format.
2021For example, 4 bit/pixel paletted or grayscale data will be returned
20222 pixels/byte with the leftmost pixel in the high-order bits of the
2023byte, unless png_set_packing() is called. 8-bit RGB data will be stored
2024in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2025is called to insert filler bytes, either before or after each RGB triplet.
202616-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
9c0d9ce3 2027byte of the color value first, unless png_set_scale_16() is called to
0272a10d
VZ
2028transform it to regular RGB RGB triplets, or png_set_filler() or
2029png_set_add alpha() is called to insert filler bytes, either before or
2030after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
9c0d9ce3
DS
2031be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2032or png_set_scale_16().
0272a10d
VZ
2033
2034The following code transforms grayscale images of less than 8 to 8 bits,
2035changes paletted images to RGB, and adds a full alpha channel if there is
2036transparency information in a tRNS chunk. This is most useful on
2037grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2038viewing 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
0272a10d
VZ
2043 if (png_get_valid(png_ptr, info_ptr,
2044 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2045
9c0d9ce3
DS
2046 if (color_type == PNG_COLOR_TYPE_GRAY &&
2047 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2048
2049The first two functions are actually aliases for png_set_expand(), added
0272a10d
VZ
2050in libpng version 1.0.4, with the function names expanded to improve code
2051readability. In some future version they may actually do different
2052things.
2053
2054As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2055added. It expands the sample depth without changing tRNS to alpha.
0272a10d 2056
9c0d9ce3
DS
2057As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
2058png_set_expand(); however, the resultant channels have 16 bits rather than 8.
2059Use this when the output color or gray channels are made linear to avoid fairly
2060severe accuracy loss.
2061
2062 if (bit_depth < 16)
2063 png_set_expand_16(png_ptr);
2064
2065PNG can have files with 16 bits per channel. If you only can handle
20668 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
20761.5.4).
2077
2078If you need to process the alpha channel on the image separately from the image
2079data (for example if you convert it to a bitmap mask) it is possible to have
2080libpng 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
2085If you strip the alpha channel you need to find some other way of dealing with
2086the information. If, instead, you want to convert the image to an opaque
2087version with no alpha channel use png_set_background; see below.
2088
2089As of libpng version 1.5.2, almost all useful expansions are supported, the
2090major ommissions are conversion of grayscale to indexed images (which can be
2091done trivially in the application) and conversion of indexed to grayscale (which
2092can be done by a trivial manipulation of the palette.)
b61cc19c
PC
2093
2094In the following table, the 01 means grayscale with depth<8, 31 means
2095indexed with depth<8, other numerals represent the color type, "T" means
2096the tRNS chunk is present, A means an alpha channel is present, and O
2097means tRNS or alpha is present but all pixels in the image are opaque.
2098
9c0d9ce3 2099 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
b61cc19c 2100 TO
9c0d9ce3
DS
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 +
b61cc19c
PC
2116
2117Within the matrix,
9c0d9ce3 2118 "+" identifies entries where 'from' and 'to' are the same.
b61cc19c 2119 "-" means the transformation is not supported.
9c0d9ce3
DS
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().
b61cc19c
PC
2123 "X" means the transformation is obtained by png_set_expand().
2124 "1" means the transformation is obtained by
fff5f7d5
VZ
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).
9c0d9ce3
DS
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().
b61cc19c
PC
2130 "P" means the transformation is obtained by
2131 png_set_expand_palette_to_rgb().
9c0d9ce3
DS
2132 "p" means the transformation is obtained by png_set_packing().
2133 "Q" means the transformation is obtained by png_set_quantize().
fff5f7d5
VZ
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().
9c0d9ce3
DS
2138
2139When an entry has multiple transforms listed all are required to cause the
2140right overall transformation. When two transforms are separated by a comma
2141either will do the job. When transforms are enclosed in [] the transform should
2142do the job but this is currently unimplemented - a different format will result
2143if the suggested transformations are used.
0272a10d
VZ
2144
2145In PNG files, the alpha channel in an image
2146is the level of opacity. If you need the alpha channel in an image to
2147be the level of transparency instead of opacity, you can invert the
2148alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2149fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2150images) is fully transparent, with
2151
2152 png_set_invert_alpha(png_ptr);
2153
2154PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2155they can, resulting in, for example, 8 pixels per byte for 1 bit
2156files. This code expands to 1 pixel per byte without changing the
2157values of the pixels:
2158
2159 if (bit_depth < 8)
9c0d9ce3 2160 png_set_packing(png_ptr);
0272a10d
VZ
2161
2162PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
2163stored in a PNG image have been "scaled" or "shifted" up to the next
b61cc19c
PC
2164higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2165to 8 bits/sample in the range [0, 255]). However, it is also possible
2166to convert the PNG pixel data back to the original bit depth of the
2167image. This call reduces the pixels back down to the original bit depth:
0272a10d
VZ
2168
2169 png_color_8p sig_bit;
2170
2171 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
9c0d9ce3 2172 png_set_shift(png_ptr, sig_bit);
0272a10d
VZ
2173
2174PNG files store 3-color pixels in red, green, blue order. This code
2175changes 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)
9c0d9ce3 2179 png_set_bgr(png_ptr);
0272a10d
VZ
2180
2181PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2182into 4 or 8 bytes for windowing systems that need them in this format:
2183
2184 if (color_type == PNG_COLOR_TYPE_RGB)
9c0d9ce3 2185 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
0272a10d
VZ
2186
2187where "filler" is the 8 or 16-bit number to fill with, and the location is
2188either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2189you want the filler before the RGB or after. This transformation
2190does not affect images that already have full alpha channels. To add an
2191opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2192will generate RGBA pixels.
2193
2194Note that png_set_filler() does not change the color type. If you want
2195to do that, you can add a true alpha channel with
2196
2197 if (color_type == PNG_COLOR_TYPE_RGB ||
9c0d9ce3
DS
2198 color_type == PNG_COLOR_TYPE_GRAY)
2199 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
0272a10d
VZ
2200
2201where "filler" contains the alpha value to assign to each pixel.
2202This function was added in libpng-1.2.7.
2203
2204If you are reading an image with an alpha channel, and you need the
2205data as ARGB instead of the normal PNG format RGBA:
2206
2207 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
9c0d9ce3 2208 png_set_swap_alpha(png_ptr);
0272a10d
VZ
2209
2210For some uses, you may want a grayscale image to be represented as
2211RGB. This code will do that conversion:
2212
2213 if (color_type == PNG_COLOR_TYPE_GRAY ||
2214 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
9c0d9ce3 2215 png_set_gray_to_rgb(png_ptr);
0272a10d
VZ
2216
2217Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
2218with alpha.
2219
2220 if (color_type == PNG_COLOR_TYPE_RGB ||
2221 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
fff5f7d5
VZ
2222 png_set_rgb_to_gray(png_ptr, error_action,
2223 double red_weight, double green_weight);
0272a10d
VZ
2224
2225 error_action = 1: silently do the conversion
9c0d9ce3 2226
0272a10d
VZ
2227 error_action = 2: issue a warning if the original
2228 image has any pixel where
2229 red != green or red != blue
9c0d9ce3 2230
0272a10d
VZ
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
9c0d9ce3
DS
2236 red_weight: weight of red component
2237
2238 green_weight: weight of green component
0272a10d 2239 If either weight is negative, default
9c0d9ce3
DS
2240 weights are used.
2241
2242In the corresponding fixed point API the red_weight and green_weight values are
2243simply scaled by 100,000:
2244
fff5f7d5
VZ
2245 png_set_rgb_to_gray(png_ptr, error_action,
2246 png_fixed_point red_weight,
9c0d9ce3 2247 png_fixed_point green_weight);
0272a10d
VZ
2248
2249If you have set error_action = 1 or 2, you can
2250later check whether the image really was gray, after processing
2251the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2252It will return a png_byte that is zero if the image was gray or
9c0d9ce3 22531 if there were any non-gray pixels. Background and sBIT data
0272a10d 2254will be silently converted to grayscale, using the green channel
9c0d9ce3 2255data for sBIT, regardless of the error_action setting.
0272a10d 2256
9c0d9ce3
DS
2257The default values come from the PNG file cHRM chunk if present; otherwise, the
2258defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2259space, as recommended in the Charles Poynton's Colour FAQ,
2260<http://www.poynton.com/>, in section 9:
0272a10d 2261
9c0d9ce3 2262 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
0272a10d 2263
9c0d9ce3 2264 Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
0272a10d 2265
9c0d9ce3
DS
2266Previous versions of this document, 1998 through 2002, recommended a slightly
2267different formula:
0272a10d 2268
9c0d9ce3 2269 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
0272a10d 2270
9c0d9ce3 2271Libpng uses an integer approximation:
0272a10d 2272
9c0d9ce3 2273 Y = (6968 * R + 23434 * G + 2366 * B)/32768
0272a10d
VZ
2274
2275The calculation is done in a linear colorspace, if the image gamma
9c0d9ce3 2276can be determined.
0272a10d 2277
9c0d9ce3
DS
2278The png_set_background() function has been described already; it tells libpng to
2279composite images with alpha or simple transparency against the supplied
2280background color. For compatibility with versions of libpng earlier than
2281libpng-1.5.4 it is recommended that you call the function after reading the file
2282header, even if you don't want to use the color in a bKGD chunk, if one exists.
2283
2284If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2285you may use this color, or supply another color more suitable for
2286the current display (e.g., the background color from a web page). You
2287need to tell libpng how the color is represented, both the format of the
2288component values in the color (the number of bits) and the gamma encoding of the
2289color. The function takes two arguments, background_gamma_mode and need_expand
fff5f7d5 2290to convey this information; however, only two combinations are likely to be
9c0d9ce3 2291useful:
0272a10d
VZ
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))
9c0d9ce3
DS
2297 png_set_background(png_ptr, image_background,
2298 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
0272a10d 2299 else
9c0d9ce3
DS
2300 png_set_background(png_ptr, &my_background,
2301 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
2302
2303The second call was described above - my_background is in the format of the
2304final, display, output produced by libpng. Because you now know the format of
2305the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2306output and to retain palette images (the palette colors will be modified
2307appropriately and the tRNS chunk removed.) However, if you are doing this,
2308take great care not to ask for transformations without checking first that
2309they apply!
2310
2311In the first call the background color has the original bit depth and color type
2312of the PNG file. So, for palette images the color is supplied as a palette
2313index and for low bit greyscale images the color is a reduced bit value in
2314image_background->gray.
2315
2316If you didn't call png_set_gamma() before reading the file header, for example
2317if you need your code to remain compatible with older versions of libpng prior
2318to libpng-1.5.4, this is the place to call it.
2319
2320Do not call it if you called png_set_alpha_mode(); doing so will damage the
2321settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
2322supported then you can certainly do png_set_gamma() before reading the PNG
2323header.)
2324
2325This API unconditionally sets the screen and file gamma values, so it will
2326override the value in the PNG file unless it is called before the PNG file
2327reading starts. For this reason you must always call it with the PNG file
2328value 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);
0272a10d 2332
0272a10d
VZ
2333 else
2334 png_set_gamma(png_ptr, screen_gamma, 0.45455);
2335
2336If you need to reduce an RGB file to a paletted file, or if a paletted
b61cc19c 2337file has more entries then will fit on your screen, png_set_quantize()
9c0d9ce3 2338will do that. Note that this is a simple match quantization that merely
0272a10d 2339finds the closest color available. This should work fairly well with
9c0d9ce3
DS
2340optimized palettes, but fairly badly with linear color cubes. If you
2341pass a palette that is larger than maximum_colors, the file will
0272a10d 2342reduce the number of colors in the palette so it will fit into
9c0d9ce3 2343maximum_colors. If there is a histogram, libpng will use it to make
0272a10d
VZ
2344more intelligent choices when reducing the palette. If there is no
2345histogram, 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,
9c0d9ce3 2350 PNG_INFO_PLTE))
0272a10d
VZ
2351 {
2352 png_uint_16p histogram = NULL;
2353
2354 png_get_hIST(png_ptr, info_ptr,
9c0d9ce3 2355 &histogram);
b61cc19c 2356 png_set_quantize(png_ptr, palette, num_palette,
0272a10d
VZ
2357 max_screen_colors, histogram, 1);
2358 }
9c0d9ce3 2359
0272a10d
VZ
2360 else
2361 {
2362 png_color std_color_cube[MAX_SCREEN_COLORS] =
2363 { ... colors ... };
2364
b61cc19c 2365 png_set_quantize(png_ptr, std_color_cube,
0272a10d
VZ
2366 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2367 NULL,0);
2368 }
2369 }
2370
2371PNG files describe monochrome as black being zero and white being one.
2372The following code will reverse this (make black be one and white be
2373zero):
2374
2375 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2376 png_set_invert_mono(png_ptr);
2377
2378This function can also be used to invert grayscale and gray-alpha images:
2379
2380 if (color_type == PNG_COLOR_TYPE_GRAY ||
9c0d9ce3 2381 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
0272a10d
VZ
2382 png_set_invert_mono(png_ptr);
2383
9c0d9ce3 2384PNG files store 16-bit pixels in network byte order (big-endian,
0272a10d
VZ
2385ie. most significant bits first). This code changes the storage to the
2386other way (little-endian, i.e. least significant bits first, the
2387way PCs store them):
2388
2389 if (bit_depth == 16)
9c0d9ce3 2390 png_set_swap(png_ptr);
0272a10d
VZ
2391
2392If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2393need 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
2398Finally, you can write your own transformation function if none of
2399the existing ones meets your needs. This is done by setting a callback
2400with
2401
2402 png_set_read_user_transform_fn(png_ptr,
9c0d9ce3 2403 read_transform_fn);
0272a10d
VZ
2404
2405You must supply the function
2406
9c0d9ce3
DS
2407 void read_transform_fn(png_structp png_ptr, png_row_infop
2408 row_info, png_bytep data)
0272a10d
VZ
2409
2410See pngtest.c for a working example. Your function will be called
9c0d9ce3
DS
2411after all of the other transformations have been processed. Take care with
2412interlaced images if you do the interlace yourself - the width of the row is the
2413width in 'row_info', not the overall image width.
2414
2415If supported, libpng provides two information routines that you can use to find
2416where 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
2421Don't try using these outside a transform callback - firstly they are only
2422supported if user transforms are supported, secondly they may well return
2423unexpected results unless the row is actually being processed at the moment they
2424are called.
2425
2426With interlaced
2427images the value returned is the row in the input sub-image image. Use
2428PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2429find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2430
2431The discussion of interlace handling above contains more information on how to
2432use these values.
0272a10d
VZ
2433
2434You can also set up a pointer to a user structure for use by your
2435callback function, and you can inform libpng that your transform
2436function will change the number of channels or bit depth with the
2437function
2438
2439 png_set_user_transform_info(png_ptr, user_ptr,
9c0d9ce3 2440 user_depth, user_channels);
0272a10d
VZ
2441
2442The user's application, not libpng, is responsible for allocating and
2443freeing any memory required for the user structure.
2444
2445You can retrieve the pointer via the function
2446png_get_user_transform_ptr(). For example:
2447
2448 voidp read_user_transform_ptr =
9c0d9ce3 2449 png_get_user_transform_ptr(png_ptr);
0272a10d
VZ
2450
2451The last thing to handle is interlacing; this is covered in detail below,
2452but you must call the function here if you want libpng to handle expansion
2453of the interlaced image.
2454
2455 number_of_passes = png_set_interlace_handling(png_ptr);
2456
2457After setting the transformations, libpng can update your png_info
2458structure to reflect any transformations you've requested with this
9c0d9ce3 2459call.
0272a10d
VZ
2460
2461 png_read_update_info(png_ptr, info_ptr);
2462
9c0d9ce3
DS
2463This is most useful to update the info structure's rowbytes
2464field so you can use it to allocate your image memory. This function
2465will also update your palette with the correct screen_gamma and
2466background if these have been given with the calls above. You may
2467only call png_read_update_info() once with a particular info_ptr.
2468
0272a10d
VZ
2469After you call png_read_update_info(), you can allocate any
2470memory you need to hold the image. The row data is simply
2471raw byte data for all forms of images. As the actual allocation
2472varies among applications, no example will be given. If you
2473are allocating one large chunk, you will need to build an
2474array of pointers to each row, as it will be needed for some
2475of the functions below.
2476
9c0d9ce3
DS
2477Remember: Before you call png_read_update_info(), the png_get_*()
2478functions return the values corresponding to the original PNG image.
2479After you call png_read_update_info the values refer to the image
2480that libpng will output. Consequently you must call all the png_set_
2481functions before you call png_read_update_info(). This is particularly
2482important for png_set_interlace_handling() - if you are going to call
2483png_read_update_info() you must call png_set_interlace_handling() before
2484it unless you want to receive interlaced output.
2485
0272a10d
VZ
2486.SS Reading image data
2487
2488After you've allocated memory, you can read the image data.
2489The simplest way to do this is in one function call. If you are
2490allocating enough memory to hold the whole image, you can just
2491call png_read_image() and libpng will read in all the image data
2492and put it in the memory area supplied. You will need to pass in
2493an array of pointers to each row.
2494
9c0d9ce3
DS
2495This function automatically handles interlacing, so you don't
2496need to call png_set_interlace_handling() (unless you call
2497png_read_update_info()) or call this function multiple times, or any
2498of that other stuff necessary with png_read_rows().
0272a10d
VZ
2499
2500 png_read_image(png_ptr, row_pointers);
2501
2502where row_pointers is:
2503
2504 png_bytep row_pointers[height];
2505
2506You can point to void or char or whatever you use for pixels.
2507
2508If you don't want to read in the whole image at once, you can
2509use png_read_rows() instead. If there is no interlacing (check
2510interlace_type == PNG_INTERLACE_NONE), this is simple:
2511
2512 png_read_rows(png_ptr, row_pointers, NULL,
9c0d9ce3 2513 number_of_rows);
0272a10d
VZ
2514
2515where row_pointers is the same as in the png_read_image() call.
2516
2517If you are doing this just one row at a time, you can do this with
2518a 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
2523If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2524get somewhat harder. The only current (PNG Specification version 1.2)
9c0d9ce3
DS
2525interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
2526a somewhat complicated 2D interlace scheme, known as Adam7, that
0272a10d 2527breaks down an image into seven smaller images of varying size, based
9c0d9ce3
DS
2528on an 8x8 grid. This number is defined (from libpng 1.5) as
2529PNG_INTERLACE_ADAM7_PASSES in png.h
0272a10d
VZ
2530
2531libpng can fill out those images or it can give them to you "as is".
9c0d9ce3
DS
2532It is almost always better to have libpng handle the interlacing for you.
2533If you want the images filled out, there are two ways to do that. The one
0272a10d
VZ
2534mentioned in the PNG specification is to expand each pixel to cover
2535those pixels that have not been read yet (the "rectangle" method).
2536This results in a blocky image for the first pass, which gradually
2537smooths out as more pixels are read. The other method is the "sparkle"
2538method, where pixels are drawn only in their final locations, with the
2539rest of the image remaining whatever colors they were initialized to
2540before the start of the read. The first method usually looks better,
2541but tends to be slower, as there are more pixels to put in the rows.
2542
9c0d9ce3
DS
2543If, as is likely, you want libpng to expand the images, call this before
2544calling png_start_read_image() or png_read_update_info():
0272a10d
VZ
2545
2546 if (interlace_type == PNG_INTERLACE_ADAM7)
9c0d9ce3 2547 number_of_passes
0272a10d
VZ
2548 = png_set_interlace_handling(png_ptr);
2549
9c0d9ce3
DS
2550This will return the number of passes needed. Currently, this is seven,
2551but may change if another interlace type is added. This function can be
2552called even if the file is not interlaced, where it will return one pass.
2553You then need to read the whole image 'number_of_passes' times. Each time
2554will distribute the pixels from the current pass to the correct place in
2555the output image, so you need to supply the same rows to png_read_rows in
2556each pass.
0272a10d
VZ
2557
2558If you are not going to display the image after each pass, but are
2559going to wait until the entire image is read in, use the sparkle
2560effect. This effect is faster and the end result of either method
2561is exactly the same. If you are planning on displaying the image
2562after each pass, the "rectangle" effect is generally considered the
2563better looking one.
2564
2565If you only want the "sparkle" effect, just call png_read_rows() as
2566normal, with the third parameter NULL. Make sure you make pass over
2567the image number_of_passes times, and you don't change the data in the
2568rows between calls. You can change the locations of the data, just
2569not the data. Each pass only writes the pixels appropriate for that
2570pass, and assumes the data from previous passes is still valid.
2571
2572 png_read_rows(png_ptr, row_pointers, NULL,
9c0d9ce3 2573 number_of_rows);
0272a10d
VZ
2574
2575If you only want the first effect (the rectangles), do the same as
2576before except pass the row buffer in the third parameter, and leave
2577the second parameter NULL.
2578
2579 png_read_rows(png_ptr, NULL, row_pointers,
9c0d9ce3
DS
2580 number_of_rows);
2581
2582If you don't want libpng to handle the interlacing details, just call
2583png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
fff5f7d5 2584Each of the images is a valid image by itself; however, you will almost
9c0d9ce3
DS
2585certainly need to distribute the pixels from each sub-image to the
2586correct place. This is where everything gets very tricky.
2587
2588If you want to retrieve the separate images you must pass the correct
2589number of rows to each successive call of png_read_rows(). The calculation
2590gets pretty complicated for small images, where some sub-images may
2591not even exist because either their width or height ends up zero.
2592libpng 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
2597Respectively these tell you the width and height of the sub-image
2598corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
2599this can be confusing because the specification refers to the same passes
2600as 1 to 7! Be careful, you must check both the width and height before
2601calling png_read_rows() and not call it for that pass if either is zero.
2602
2603You can, of course, read each sub-image row by row. If you want to
2604produce optimal code to make a pixel-by-pixel transformation of an
2605interlaced image this is the best approach; read each row of each pass,
2606transform it, and write it out to a new interlaced image.
2607
2608If you want to de-interlace the image yourself libpng provides further
2609macros to help that tell you where to place the pixels in the output image.
2610Because the interlacing scheme is rectangular - sub-image pixels are always
2611arranged on a rectangular grid - all you need to know for each pass is the
2612starting column and row in the output image of the first pixel plus the
2613spacing between each pixel. As of libpng 1.5 there are four macros to
2614retrieve 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
2621These 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
2643Notice that the steps between successive output rows and columns are
2644returned as shifts. This is possible because the pixels in the subimages
2645are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
2646image. In practice you may need to directly calculate the output coordinate
2647given an input coordinate. libpng provides two further macros for this
2648purpose:
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
2653Finally a pair of macros are provided to tell you if a particular image
2654row 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
2659Bear in mind that you will probably also need to check the width and height
2660of the pass in addition to the above to be sure the pass even exists!
2661
2662With any luck you are convinced by now that you don't want to do your own
2663interlace handling. In reality normally the only good reason for doing this
2664is if you are processing PNG files on a pixel-by-pixel basis and don't want
2665to load the whole file into memory when it is interlaced.
2666
2667libpng includes a test program, pngvalid, that illustrates reading and
2668writing of interlaced images. If you can't get interlacing to work in your
2669code and don't want to leave it to libpng (the recommended approach), see
2670how pngvalid.c does it.
0272a10d
VZ
2671
2672.SS Finishing a sequential read
2673
2674After you are finished reading the image through the
2675low-level interface, you can finish reading the file. If you are
2676interested in comments or time, which may be stored either before or
2677after the image data, you should pass the separate png_info struct if
2678you want to keep the comments from before and after the image
9c0d9ce3
DS
2679separate.
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 }
0272a10d
VZ
2689
2690 png_read_end(png_ptr, end_info);
2691
9c0d9ce3
DS
2692If you are not interested, you should still call png_read_end()
2693but you can pass NULL, avoiding the need to create an end_info structure.
2694
2695 png_read_end(png_ptr, (png_infop)NULL);
2696
2697If you don't call png_read_end(), then your file pointer will be
2698left pointing to the first chunk after the last IDAT, which is probably
2699not what you want if you expect to read something beyond the end of
2700the PNG datastream.
2701
0272a10d
VZ
2702When 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
9c0d9ce3
DS
2707or, if you didn't create an end_info structure,
2708
2709 png_destroy_read_struct(&png_ptr, &info_ptr,
2710 (png_infopp)NULL);
2711
0272a10d
VZ
2712It is also possible to individually free the info_ptr members that
2713point to libpng-allocated storage with the following function:
2714
2715 png_free_data(png_ptr, info_ptr, mask, seq)
9c0d9ce3 2716
0272a10d
VZ
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
9c0d9ce3 2726
0272a10d
VZ
2727 seq - sequence number of item to be freed
2728 (-1 for all items)
2729
2730This function may be safely called when the relevant storage has
2731already been freed, or has not yet been allocated, or was allocated
b61cc19c
PC
2732by the user and not by libpng, and will in those cases do nothing.
2733The "seq" parameter is ignored if only one item of the selected data
2734type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
2735are allowed for the data type identified in the mask, such as text or
2736sPLT, only the n'th item in the structure is freed, where n is "seq".
0272a10d
VZ
2737
2738The default behavior is only to free data that was allocated internally
2739by libpng. This can be changed, so that libpng will not free the data,
2740or so that it will free data that was allocated by the user with png_malloc()
fff5f7d5 2741or png_calloc() and passed in via a png_set_*() function, with
0272a10d
VZ
2742
2743 png_data_freer(png_ptr, info_ptr, freer, mask)
9c0d9ce3 2744
0272a10d
VZ
2745 freer - one of
2746 PNG_DESTROY_WILL_FREE_DATA
2747 PNG_SET_WILL_FREE_DATA
2748 PNG_USER_WILL_FREE_DATA
2749
9c0d9ce3
DS
2750 mask - which data elements are affected
2751 same choices as in png_free_data()
2752
0272a10d
VZ
2753This function only affects data that has already been allocated.
2754You can call this function after reading the PNG data but before calling
2755any png_set_*() functions, to control whether the user or the png_set_*()
2756function is responsible for freeing any existing data that might be present,
2757and again after the png_set_*() functions to control whether the user
2758or png_destroy_*() is supposed to free the data. When the user assumes
2759responsibility for libpng-allocated data, the application must use
2760png_free() to free it, and when the user transfers responsibility to libpng
2761for data that the user has allocated, the user must have used png_malloc()
fff5f7d5 2762or png_calloc() to allocate it.
0272a10d
VZ
2763
2764If you allocated your row_pointers in a single block, as suggested above in
2765the description of the high level read interface, you must not transfer
2766responsibility for freeing it to the png_set_rows or png_read_destroy function,
2767because they would also try to free the individual row_pointers[i].
2768
2769If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2770separately, do not transfer responsibility for freeing text_ptr to libpng,
2771because when libpng fills a png_text structure it combines these members with
2772the key member, and png_free_data() will free only text_ptr.key. Similarly,
2773if you transfer responsibility for free'ing text_ptr from libpng to your
2774application, your application must not separately free those members.
2775
2776The png_free_data() function will turn off the "valid" flag for anything
b61cc19c
PC
2777it frees. If you need to turn the flag off for a chunk that was freed by
2778your application instead of by libpng, you can use
0272a10d
VZ
2779
2780 png_set_invalid(png_ptr, info_ptr, mask);
9c0d9ce3 2781
0272a10d
VZ
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
2794For a more compact example of reading a PNG image, see the file example.c.
2795
2796.SS Reading PNG files progressively
2797
2798The progressive reader is slightly different then the non-progressive
2799reader. Instead of calling png_read_info(), png_read_rows(), and
2800png_read_end(), you make one call to png_process_data(), which calls
2801callbacks when it has the info, a row, or the end of the image. You
2802set up these callbacks with png_set_progressive_read_fn(). You don't
2803have to worry about the input/output functions of libpng, as you are
2804giving the library the data directly in png_process_data(). I will
2805assume that you have read the section on reading PNG files above,
2806so I will only highlight the differences (although I will show
2807all of the code).
2808
2809png_structp png_ptr;
2810png_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);
9c0d9ce3 2821
0272a10d
VZ
2822 if (!png_ptr)
2823 return (ERROR);
9c0d9ce3 2824
0272a10d 2825 info_ptr = png_create_info_struct(png_ptr);
9c0d9ce3 2826
0272a10d
VZ
2827 if (!info_ptr)
2828 {
9c0d9ce3
DS
2829 png_destroy_read_struct(&png_ptr,
2830 (png_infopp)NULL, (png_infopp)NULL);
2831 return (ERROR);
0272a10d
VZ
2832 }
2833
2834 if (setjmp(png_jmpbuf(png_ptr)))
2835 {
9c0d9ce3
DS
2836 png_destroy_read_struct(&png_ptr, &info_ptr,
2837 (png_infopp)NULL);
2838 return (ERROR);
0272a10d
VZ
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 {
9c0d9ce3 2870 png_destroy_read_struct(&png_ptr, &info_ptr,
0272a10d 2871 (png_infopp)NULL);
9c0d9ce3 2872 return (ERROR);
0272a10d
VZ
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);
9c0d9ce3
DS
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).
0272a10d
VZ
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.
9c0d9ce3
DS
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.
0272a10d
VZ
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
9c0d9ce3
DS
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,
0272a10d
VZ
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
9c0d9ce3 2963 all cases if you switch on interlace handling;
0272a10d
VZ
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.
9c0d9ce3
DS
2977
2978 You can also call png_process_data_pause in this
2979 callback - see above.
0272a10d
VZ
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
3002Much of this is very similar to reading. However, everything of
3003importance is repeated here, so you won't have to constantly look
3004back up in the reading section to understand writing.
3005
3006.SS Setup
3007
3008You will want to do the I/O initialization before you get into libpng,
3009so if it doesn't work, you don't have anything to undo. If you are not
3010using the standard I/O functions, you will need to replace them with
3011custom writing functions. See the discussion under Customizing libpng.
3012
3013 FILE *fp = fopen(file_name, "wb");
9c0d9ce3 3014
0272a10d 3015 if (!fp)
0272a10d 3016 return (ERROR);
0272a10d
VZ
3017
3018Next, png_struct and png_info need to be allocated and initialized.
3019As these can be both relatively large, you may not want to store these
3020on the stack, unless you have stack space to spare. Of course, you
3021will want to check if they return NULL. If you are also reading,
3022you won't want to name your read structure and your write structure
3023both "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);
9c0d9ce3 3029
0272a10d
VZ
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,
9c0d9ce3 3037 (png_infopp)NULL);
0272a10d
VZ
3038 return (ERROR);
3039 }
3040
3041If you want to use your own memory allocation routines,
3042define PNG_USER_MEM_SUPPORTED and use
3043png_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
3050After you have these structures, you will need to set up the
3051error handling. When libpng encounters an error, it expects to
3052longjmp() back to your routine. Therefore, you will need to call
3053setjmp() and pass the png_jmpbuf(png_ptr). If you
3054write the file from different routines, you will need to update
3055the png_jmpbuf(png_ptr) every time you enter a new routine that will
3056call a png_*() function. See your documentation of setjmp/longjmp
3057for your compiler for more information on setjmp/longjmp. See
3058the discussion on libpng error handling in the Customizing Libpng
3059section below for more information on the libpng error handling.
3060
3061 if (setjmp(png_jmpbuf(png_ptr)))
3062 {
9c0d9ce3 3063 png_destroy_write_struct(&png_ptr, &info_ptr);
0272a10d
VZ
3064 fclose(fp);
3065 return (ERROR);
3066 }
3067 ...
3068 return;
3069
3070If you would rather avoid the complexity of setjmp/longjmp issues,
b61cc19c 3071you can compile libpng with PNG_NO_SETJMP, in which case
0272a10d
VZ
3072errors will result in a call to PNG_ABORT() which defaults to abort().
3073
b61cc19c
PC
3074You can #define PNG_ABORT() to a function that does something
3075more useful than abort(), as long as your function does not
3076return.
3077
fff5f7d5
VZ
3078Checking for invalid palette index on write was added at libpng
30791.5.10. If a pixel contains an invalid (out-of-range) index libpng issues
3080a benign error. This is enabled by default because this condition is an
3081error according to the PNG specification, Clause 11.3.2, but the error can
3082be ignored in each png_ptr with
3083
3084 png_set_check_for_invalid_index(png_ptr, 0);
3085
3086If the error is ignored, or if png_benign_error() treats it as a warning,
3087any invalid pixels are written as-is by the encoder, resulting in an
3088invalid PNG datastream as output. In this case the application is
3089responsible for ensuring that the pixel indexes are in range when it writes
3090a PLTE chunk with fewer entries than the bit depth would allow.
3091
0272a10d
VZ
3092Now you need to set up the output code. The default for libpng is to
3093use the C function fwrite(). If you use this, you will need to pass a
3094valid FILE * in the function png_init_io(). Be sure that the file is
3095opened in binary mode. Again, if you wish to handle writing data in
3096another way, see the discussion on libpng I/O handling in the Customizing
3097Libpng section below.
3098
3099 png_init_io(png_ptr, fp);
3100
3101If you are embedding your PNG into a datastream such as MNG, and don't
3102want libpng to write the 8-byte signature, or if you have already
3103written the signature in your application, use
3104
3105 png_set_sig_bytes(png_ptr, 8);
3106
3107to inform libpng that it should not write a signature.
3108
3109.SS Write callbacks
3110
3111At this point, you can set up a callback function that will be
3112called after each row has been written, which you can use to control
3113a progress meter or the like. It's demonstrated in pngtest.c.
3114You must supply a function
3115
9c0d9ce3 3116 void write_row_callback(png_structp png_ptr, png_uint_32 row,
0272a10d
VZ
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
3124To inform libpng about your function, use
3125
3126 png_set_write_status_fn(png_ptr, write_row_callback);
3127
9c0d9ce3
DS
3128When this function is called the row has already been completely processed and
3129it has also been written out. The 'row' and 'pass' refer to the next row to be
3130handled. For the
3131non-interlaced case the row that was just handled is simply one less than the
3132passed in row number, and pass will always be 0. For the interlaced case the
3133same applies unless the row value is 0, in which case the row just handled was
3134the last one from one of the preceding passes. Because interlacing may skip a
3135pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3136need to know what the last pass is record (row,pass) from the callback and use
3137the last recorded value each time.
3138
3139As with the user transform you can find the output row using the
3140PNG_ROW_FROM_PASS_ROW macro.
3141
0272a10d
VZ
3142You now have the option of modifying how the compression library will
3143run. The following functions are mainly for testing, but may be useful
3144in some cases, like if you need to write PNG files extremely fast and
3145are willing to give up some compression, or if you want to get the
3146maximum possible compression at the expense of slower writing. If you
3147have no special needs in this area, let the library do what it wants by
3148not calling this function at all, as it has been tuned to deliver a good
3149speed/compression ratio. The second parameter to png_set_filter() is
3150the filter method, for which the only valid values are 0 (as of the
3151July 1999 PNG specification, version 1.2) or 64 (if you are writing
3152a PNG datastream that is to be embedded in a MNG datastream). The third
3153parameter is a flag that indicates which filter type(s) are to be tested
b61cc19c
PC
3154for each scanline. See the PNG specification for details on the specific
3155filter types.
0272a10d
VZ
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
9c0d9ce3
DS
3161 or more PNG_FILTER_NAME masks.
3162 */
0272a10d
VZ
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 |
b61cc19c 3167 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
0272a10d
VZ
3168 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3169 PNG_ALL_FILTERS);
3170
9c0d9ce3
DS
3171If an application wants to start and stop using particular filters during
3172compression, it should start out with all of the filters (to ensure that
3173the previous row of pixels will be stored in case it's needed later),
3174and then add and remove them after the start of compression.
0272a10d
VZ
3175
3176If you are writing a PNG datastream that is to be embedded in a MNG
3177datastream, the second parameter can be either 0 or 64.
3178
3179The png_set_compression_*() functions interface to the zlib compression
3180library, and should mostly be ignored unless you really know what you are
3181doing. The only generally useful call is png_set_compression_level()
3182which changes how much time zlib spends on trying to compress the image
3183data. See the Compression Library (zlib.h and algorithm.txt, distributed
3184with zlib) for details on the compression levels.
3185
9c0d9ce3
DS
3186 #include zlib.h
3187
3188 /* Set the zlib compression level */
0272a10d
VZ
3189 png_set_compression_level(png_ptr,
3190 Z_BEST_COMPRESSION);
3191
9c0d9ce3 3192 /* Set other zlib parameters for compressing IDAT */
0272a10d
VZ
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
9c0d9ce3
DS
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);
0272a10d
VZ
3209
3210.SS Setting the contents of info for output
3211
3212You now need to fill in the png_info structure with all the data you
3213wish to write before the actual image. Note that the only thing you
3214are allowed to write after the image is the text chunks and the time
3215chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
3216the latest PNG specification for more information on that. If you
3217wish to write them before the image, fill them in now, and flag that
3218data as being valid. If you want to wait until after the data, don't
3219fill them until png_write_end(). For all the fields in png_info and
3220their data types, see png.h. For explanations of what the fields
3221contain, see the PNG specification.
3222
3223Some 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)
9c0d9ce3 3228
0272a10d
VZ
3229 width - holds the width of the image
3230 in pixels (up to 2^31).
9c0d9ce3 3231
0272a10d
VZ
3232 height - holds the height of the image
3233 in pixels (up to 2^31).
9c0d9ce3 3234
0272a10d
VZ
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).
9c0d9ce3 3241
0272a10d
VZ
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
9c0d9ce3 3261
0272a10d
VZ
3262 compression_type - (must be
3263 PNG_COMPRESSION_TYPE_DEFAULT)
9c0d9ce3 3264
0272a10d
VZ
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
970f6abe 3271If you call png_set_IHDR(), the call must appear before any of the
b61cc19c 3272other png_set_*() functions, because they might require access to some of
970f6abe
VZ
3273the IHDR settings. The remaining png_set_*() functions can be called
3274in any order.
3275
b61cc19c
PC
3276If you wish, you can reset the compression_type, interlace_type, or
3277filter_method later by calling png_set_IHDR() again; if you do this, the
3278width, height, bit_depth, and color_type must be the same in each call.
3279
0272a10d
VZ
3280 png_set_PLTE(png_ptr, info_ptr, palette,
3281 num_palette);
9c0d9ce3 3282
0272a10d
VZ
3283 palette - the palette for the file
3284 (array of png_color)
3285 num_palette - number of entries in the palette
3286
9c0d9ce3
DS
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.
0272a10d
VZ
3317
3318 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
9c0d9ce3 3319
0272a10d
VZ
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);
9c0d9ce3 3339
0272a10d
VZ
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,
9c0d9ce3
DS
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.
0272a10d
VZ
3363
3364 png_set_sBIT(png_ptr, info_ptr, sig_bit);
9c0d9ce3 3365
0272a10d
VZ
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
b61cc19c
PC
3372 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3373 num_trans, trans_color);
9c0d9ce3 3374
b61cc19c
PC
3375 trans_alpha - array of alpha (transparency)
3376 entries for palette (PNG_INFO_tRNS)
9c0d9ce3
DS
3377
3378 num_trans - number of transparent entries
3379 (PNG_INFO_tRNS)
3380
b61cc19c
PC
3381 trans_color - graylevel or color sample values
3382 (in order red, green, blue) of the
3383 single transparent color for
0272a10d 3384 non-paletted images (PNG_INFO_tRNS)
0272a10d
VZ
3385
3386 png_set_hIST(png_ptr, info_ptr, hist);
9c0d9ce3 3387
0272a10d 3388 hist - histogram of palette (array of
9c0d9ce3 3389 png_uint_16) (PNG_INFO_hIST)
0272a10d
VZ
3390
3391 png_set_tIME(png_ptr, info_ptr, mod_time);
9c0d9ce3 3392
0272a10d
VZ
3393 mod_time - time image was last modified
3394 (PNG_VALID_tIME)
3395
3396 png_set_bKGD(png_ptr, info_ptr, background);
9c0d9ce3
DS
3397
3398 background - background color (of type
3399 png_color_16p) (PNG_VALID_bKGD)
0272a10d
VZ
3400
3401 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
9c0d9ce3 3402
0272a10d
VZ
3403 text_ptr - array of png_text holding image
3404 comments
9c0d9ce3 3405
0272a10d
VZ
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).
72281370 3423
b61cc19c 3424 Note that the itxt_length, lang, and lang_key
72281370
DS
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.
b61cc19c 3432
0272a10d
VZ
3433 num_text - number of comments
3434
3435 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3436 num_spalettes);
9c0d9ce3 3437
0272a10d
VZ
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);
9c0d9ce3 3446
0272a10d
VZ
3447 offset_x - positive offset from the left
3448 edge of the screen
9c0d9ce3 3449
0272a10d
VZ
3450 offset_y - positive offset from the top
3451 edge of the screen
9c0d9ce3 3452
0272a10d
VZ
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);
9c0d9ce3 3457
0272a10d
VZ
3458 res_x - pixels/unit physical resolution
3459 in x direction
9c0d9ce3 3460
0272a10d
VZ
3461 res_y - pixels/unit physical resolution
3462 in y direction
9c0d9ce3 3463
0272a10d
VZ
3464 unit_type - PNG_RESOLUTION_UNKNOWN,
3465 PNG_RESOLUTION_METER
3466
3467 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
9c0d9ce3 3468
0272a10d 3469 unit - physical scale units (an integer)
9c0d9ce3 3470
0272a10d 3471 width - width of a pixel in physical scale units
9c0d9ce3 3472
0272a10d
VZ
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)
9c0d9ce3 3477
0272a10d 3478 unit - physical scale units (an integer)
9c0d9ce3 3479
0272a10d 3480 width - width of a pixel in physical scale units
9c0d9ce3
DS
3481 expressed as a string
3482
0272a10d
VZ
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)
9c0d9ce3 3488
0272a10d
VZ
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
3500The "location" member is set automatically according to
3501what part of the output file has already been written.
3502You can change its value after calling png_set_unknown_chunks()
3503as demonstrated in pngtest.c. Within each of the "locations",
3504the chunks are sequenced according to their position in the
3505structure (that is, the value of "i", which is the order in which
3506the chunk was either read from the input file or defined with
3507png_set_unknown_chunks).
3508
3509A quick word about text and num_text. text is an array of png_text
3510structures. num_text is the number of valid structures in the array.
3511Each png_text structure holds a language code, a keyword, a text value,
3512and a compression type.
3513
3514The compression types have the same valid numbers as the compression
3515types of the image data. Currently, the only valid number is zero.
3516However, you can store text either compressed or uncompressed, unlike
3517images, which always have to be compressed. So if you don't want the
3518text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
3519Because tEXt and zTXt chunks don't have a language field, if you
3520specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3521any language code or translated keyword will not be written out.
3522
9c0d9ce3 3523Until text gets around a few hundred bytes, it is not worth compressing it.
0272a10d
VZ
3524After the text has been written out to the file, the compression type
3525is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3526so that it isn't written out again at the end (in case you are calling
9c0d9ce3 3527png_write_end() with the same struct).
0272a10d
VZ
3528
3529The keywords that are given in the PNG Specification are:
3530
3531 Title Short (one line) title or
3532 caption for image
9c0d9ce3 3533
0272a10d 3534 Author Name of image's creator
9c0d9ce3 3535
0272a10d 3536 Description Description of image (possibly long)
9c0d9ce3 3537
0272a10d 3538 Copyright Copyright notice
9c0d9ce3 3539
0272a10d
VZ
3540 Creation Time Time of original image creation
3541 (usually RFC 1123 format, see below)
9c0d9ce3 3542
0272a10d 3543 Software Software used to create the image
9c0d9ce3 3544
0272a10d 3545 Disclaimer Legal disclaimer
9c0d9ce3 3546
0272a10d 3547 Warning Warning of nature of content
9c0d9ce3 3548
0272a10d 3549 Source Device used to create the image
9c0d9ce3 3550
0272a10d
VZ
3551 Comment Miscellaneous comment; conversion
3552 from other image format
3553
3554The keyword-text pairs work like this. Keywords should be short
3555simple descriptions of what the comment is about. Some typical
3556keywords are found in the PNG specification, as is some recommendations
3557on keywords. You can repeat keywords in a file. You can even write
3558some text before the image and some after. For example, you may want
3559to put a description of the image before the image, but leave the
3560disclaimer until after, so viewers working over modem connections
3561don't have to wait for the disclaimer to go over the modem before
3562they start seeing the image. Finally, keywords should be full
3563words, not abbreviations. Keywords and text are in the ISO 8859-1
3564(Latin-1) character set (a superset of regular ASCII) and can not
3565contain NUL characters, and should not contain control or other
3566unprintable characters. To make the comments widely readable, stick
3567with basic ASCII, and avoid machine specific character set extensions
3568like the IBM-PC character set. The keyword must be present, but
3569you can leave off the text string on non-compressed pairs.
3570Compressed pairs must have a text string, as only the text string
3571is compressed anyway, so the compression would be meaningless.
3572
3573PNG supports modification time via the png_time structure. Two
3574conversion routines are provided, png_convert_from_time_t() for
3575time_t and png_convert_from_struct_tm() for struct tm. The
3576time_t routine uses gmtime(). You don't have to use either of
3577these, but if you wish to fill in the png_time structure directly,
3578you should provide the time in universal time (GMT) if possible
3579instead of your local time. Note that the year number is the full
3580year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
3581that months start with 1.
3582
3583If you want to store the time of the original image creation, you should
3584use a plain tEXt chunk with the "Creation Time" keyword. This is
3585necessary because the "creation time" of a PNG image is somewhat vague,
3586depending on whether you mean the PNG file, the time the image was
3587created in a non-PNG format, a still photo from which the image was
3588scanned, or possibly the subject matter itself. In order to facilitate
3589machine-readable dates, it is recommended that the "Creation Time"
3590tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
3591although this isn't a requirement. Unlike the tIME chunk, the
3592"Creation Time" tEXt chunk is not expected to be automatically changed
3593by the software. To facilitate the use of RFC 1123 dates, a function
fff5f7d5
VZ
3594png_convert_to_rfc1123_buffer(png_ptr, buffer, png_timep) is provided to
3595convert from PNG time to an RFC 1123 format string. The caller must provide
3596a writeable buffer of at least 29 bytes.
0272a10d
VZ
3597
3598.SS Writing unknown chunks
3599
3600You can use the png_set_unknown_chunks function to queue up chunks
3601for writing. You give it a chunk name, raw data, and a size; that's
3602all there is to it. The chunks will be written by the next following
3603png_write_info_before_PLTE, png_write_info, or png_write_end function.
3604Any chunks previously read into the info structure's unknown-chunk
3605list will also be written out in a sequence that satisfies the PNG
3606specification's ordering rules.
3607
3608.SS The high-level write interface
3609
3610At this point there are two ways to proceed; through the high-level
3611write interface, or through a sequence of low-level write operations.
3612You can use the high-level interface if your image data is present
3613in the info structure. All defined output
3614transformations 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
b61cc19c
PC
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
0272a10d
VZ
3636
3637If you have valid image data in the info structure (you can use
3638png_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
3642where png_transforms is an integer containing the bitwise OR of some set of
3643transformation flags. This call is equivalent to png_write_info(),
3644followed the set of transformations indicated by the transform mask,
3645then png_write_image(), and finally png_write_end().
3646
3647(The final parameter of this call is not yet used. Someday it might point
3648to transformation parameters required by some future output transform.)
3649
3650You must use png_transforms and not call any png_set_transform() functions
3651when you use png_write_png().
3652
3653.SS The low-level write interface
3654
3655If you are going the low-level route instead, you are now ready to
3656write all the file information up to the actual image data. You do
3657this with a call to png_write_info().
3658
3659 png_write_info(png_ptr, info_ptr);
3660
3661Note that there is one transformation you may need to do before
3662png_write_info(). In PNG files, the alpha channel in an image is the
b61cc19c
PC
3663level of opacity. If your data is supplied as a level of transparency,
3664you can invert the alpha channel before you write it, so that 0 is
3665fully transparent and 255 (in 8-bit or paletted images) or 65535
3666(in 16-bit images) is fully opaque, with
0272a10d
VZ
3667
3668 png_set_invert_alpha(png_ptr);
3669
3670This must appear before png_write_info() instead of later with the
3671other transformations because in the case of paletted images the tRNS
3672chunk data has to be inverted before the tRNS chunk is written. If
3673your image is not a paletted image, the tRNS data (which in such cases
3674represents a single color to be rendered as transparent) won't need to
3675be changed, and you can safely do this transformation after your
3676png_write_info() call.
3677
3678If you need to write a private chunk that you want to appear before
3679the PLTE chunk when PLTE is present, you can write the PNG info in
3680two 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
3686After you've written the file information, you can set up the library
3687to handle any special transformations of the image data. The various
3688ways to transform the data will be described in the order that they
3689should occur. This is important, as some of these change the color
3690type and/or bit depth of the data, and some others only work on
3691certain color types and bit depths. Even though each transformation
3692checks to see if it has data that it can do something with, you should
3693make sure to only enable a transformation if it will be valid for the
3694data. For example, don't swap red and blue on grayscale data.
3695
3696PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
3697the library to strip input data that has 4 or 8 bytes per pixel down
3698to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
3699bytes per pixel).
3700
3701 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
3702
3703where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
3704PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
3705is stored XRGB or RGBX.
3706
3707PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
3708they can, resulting in, for example, 8 pixels per byte for 1 bit files.
3709If the data is supplied at 1 pixel per byte, use this code, which will
3710correctly pack the pixels into a single byte:
3711
3712 png_set_packing(png_ptr);
3713
3714PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
3715data is of another bit depth, you can write an sBIT chunk into the
3716file 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 {
9c0d9ce3
DS
3721 sig_bit.red = true_bit_depth;
3722 sig_bit.green = true_bit_depth;
3723 sig_bit.blue = true_bit_depth;
0272a10d 3724 }
9c0d9ce3 3725
0272a10d
VZ
3726 else
3727 {
9c0d9ce3 3728 sig_bit.gray = true_bit_depth;
0272a10d 3729 }
9c0d9ce3 3730
0272a10d
VZ
3731 if (color_type & PNG_COLOR_MASK_ALPHA)
3732 {
9c0d9ce3 3733 sig_bit.alpha = true_bit_depth;
0272a10d
VZ
3734 }
3735
3736 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
3737
3738If the data is stored in the row buffer in a bit depth other than
3739one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
3740this will scale the values to appear to be the correct bit depth as
3741is required by PNG.
3742
3743 png_set_shift(png_ptr, &sig_bit);
3744
9c0d9ce3 3745PNG files store 16-bit pixels in network byte order (big-endian,
0272a10d
VZ
3746ie. most significant bits first). This code would be used if they are
3747supplied the other way (little-endian, i.e. least significant bits
3748first, the way PCs store them):
3749
3750 if (bit_depth > 8)
3751 png_set_swap(png_ptr);
3752
3753If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
3754need 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
3759PNG files store 3 color pixels in red, green, blue order. This code
3760would be used if they are supplied as blue, green, red:
3761
3762 png_set_bgr(png_ptr);
3763
3764PNG files describe monochrome as black being zero and white being
3765one. 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
3770Finally, you can write your own transformation function if none of
3771the existing ones meets your needs. This is done by setting a callback
3772with
3773
3774 png_set_write_user_transform_fn(png_ptr,
3775 write_transform_fn);
3776
3777You must supply the function
3778
9c0d9ce3 3779 void write_transform_fn(png_structp png_ptr, png_row_infop
0272a10d
VZ
3780 row_info, png_bytep data)
3781
3782See pngtest.c for a working example. Your function will be called
9c0d9ce3
DS
3783before any of the other transformations are processed. If supported
3784libpng also supplies an information routine that may be called from
3785your callback:
3786
3787 png_get_current_row_number(png_ptr);
3788 png_get_current_pass_number(png_ptr);
3789
3790This returns the current row passed to the transform. With interlaced
3791images the value returned is the row in the input sub-image image. Use
3792PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
3793find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
3794
3795The discussion of interlace handling above contains more information on how to
3796use these values.
0272a10d
VZ
3797
3798You can also set up a pointer to a user structure for use by your
3799callback function.
3800
3801 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
3802
3803The user_channels and user_depth parameters of this function are ignored
3804when writing; you can set them to zero as shown.
3805
3806You can retrieve the pointer via the function png_get_user_transform_ptr().
3807For example:
3808
3809 voidp write_user_transform_ptr =
3810 png_get_user_transform_ptr(png_ptr);
3811
3812It is possible to have libpng flush any pending output, either manually,
3813or automatically after a certain number of lines have been written. To
3814flush the output stream a single time call:
3815
3816 png_write_flush(png_ptr);
3817
3818and to have libpng flush the output stream periodically after a certain
3819number of scanlines have been written, call:
3820
3821 png_set_flush(png_ptr, nrows);
3822
3823Note that the distance between rows is from the last time png_write_flush()
3824was called, or the first row of the image if it has never been called.
3825So if you write 50 lines, and then png_set_flush 25, it will flush the
3826output on the next scanline, and every 25 lines thereafter, unless
3827png_write_flush() is called before 25 more lines have been written.
3828If nrows is too small (less than about 10 lines for a 640 pixel wide
3829RGB image) the image compression may decrease noticeably (although this
3830may be acceptable for real-time applications). Infrequent flushing will
3831only degrade the compression performance by a few percent over images
3832that do not use flushing.
3833
3834.SS Writing the image data
3835
3836That's it for the transformations. Now you can write the image data.
3837The simplest way to do this is in one function call. If you have the
3838whole image in memory, you can just call png_write_image() and libpng
3839will write the image. You will need to pass in an array of pointers to
3840each row. This function automatically handles interlacing, so you don't
3841need to call png_set_interlace_handling() or call this function multiple
3842times, or any of that other stuff necessary with png_write_rows().
3843
3844 png_write_image(png_ptr, row_pointers);
3845
3846where row_pointers is:
3847
3848 png_byte *row_pointers[height];
3849
3850You can point to void or char or whatever you use for pixels.
3851
3852If you don't want to write the whole image at once, you can
3853use png_write_rows() instead. If the file is not interlaced,
3854this is simple:
3855
3856 png_write_rows(png_ptr, row_pointers,
3857 number_of_rows);
3858
3859row_pointers is the same as in the png_write_image() call.
3860
3861If you are just writing one row at a time, you can do this with
3862a 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
b61cc19c
PC
3868When the file is interlaced, things can get a good deal more complicated.
3869The only currently (as of the PNG Specification version 1.2, dated July
38701999) defined interlacing scheme for PNG files is the "Adam7" interlace
3871scheme, that breaks down an image into seven smaller images of varying
3872size. libpng will build these images for you, or you can do them
3873yourself. If you want to build them yourself, see the PNG specification
3874for details of which pixels to write when.
0272a10d
VZ
3875
3876If you don't want libpng to handle the interlacing details, just
3877use png_set_interlace_handling() and call png_write_rows() the
9c0d9ce3
DS
3878correct number of times to write all the sub-images
3879(png_set_interlace_handling() returns the number of sub-images.)
0272a10d
VZ
3880
3881If you want libpng to build the sub-images, call this before you start
3882writing any rows:
3883
9c0d9ce3 3884 number_of_passes = png_set_interlace_handling(png_ptr);
0272a10d 3885
b61cc19c
PC
3886This will return the number of passes needed. Currently, this is seven,
3887but may change if another interlace type is added.
0272a10d
VZ
3888
3889Then write the complete image number_of_passes times.
3890
9c0d9ce3
DS
3891 png_write_rows(png_ptr, row_pointers, number_of_rows);
3892
3893Think carefully before you write an interlaced image. Typically code that
3894reads such images reads all the image data into memory, uncompressed, before
3895doing any processing. Only code that can display an image on the fly can
3896take advantage of the interlacing and even then the image has to be exactly
3897the correct size for the output device, because scaling an image requires
3898adjacent pixels and these are not available until all the passes have been
3899read.
0272a10d 3900
9c0d9ce3
DS
3901If you do write an interlaced image you will hardly ever need to handle
3902the interlacing yourself. Call png_set_interlace_handling() and use the
3903approach described above.
3904
3905The only time it is conceivable that you will really need to write an
3906interlaced image pass-by-pass is when you have read one pass by pass and
3907made some pixel-by-pixel transformation to it, as described in the read
3908code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
3909to determine the size of each sub-image in turn and simply write the rows
3910you obtained from the read code.
0272a10d
VZ
3911
3912.SS Finishing a sequential write
3913
3914After you are finished writing the image, you should finish writing
3915the file. If you are interested in writing comments or time, you should
3916pass an appropriately filled png_info pointer. If you are not interested,
3917you can pass NULL.
3918
3919 png_write_end(png_ptr, info_ptr);
3920
3921When you are done, you can free all memory used by libpng like this:
3922
3923 png_destroy_write_struct(&png_ptr, &info_ptr);
3924
3925It is also possible to individually free the info_ptr members that
3926point to libpng-allocated storage with the following function:
3927
3928 png_free_data(png_ptr, info_ptr, mask, seq)
9c0d9ce3 3929
0272a10d
VZ
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
9c0d9ce3 3939
0272a10d
VZ
3940 seq - sequence number of item to be freed
3941 (-1 for all items)
3942
3943This function may be safely called when the relevant storage has
3944already been freed, or has not yet been allocated, or was allocated
b61cc19c
PC
3945by the user and not by libpng, and will in those cases do nothing.
3946The "seq" parameter is ignored if only one item of the selected data
3947type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3948are allowed for the data type identified in the mask, such as text or
3949sPLT, only the n'th item in the structure is freed, where n is "seq".
3950
3951If you allocated data such as a palette that you passed in to libpng
3952with png_set_*, you must not free it until just before the call to
0272a10d
VZ
3953png_destroy_write_struct().
3954
3955The default behavior is only to free data that was allocated internally
3956by libpng. This can be changed, so that libpng will not free the data,
3957or so that it will free data that was allocated by the user with png_malloc()
fff5f7d5 3958or png_calloc() and passed in via a png_set_*() function, with
0272a10d
VZ
3959
3960 png_data_freer(png_ptr, info_ptr, freer, mask)
9c0d9ce3 3961
0272a10d
VZ
3962 freer - one of
3963 PNG_DESTROY_WILL_FREE_DATA
3964 PNG_SET_WILL_FREE_DATA
3965 PNG_USER_WILL_FREE_DATA
3966
9c0d9ce3
DS
3967 mask - which data elements are affected
3968 same choices as in png_free_data()
3969
0272a10d
VZ
3970For example, to transfer responsibility for some data from a read structure
3971to 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)
9c0d9ce3 3976
0272a10d
VZ
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
3981thereby briefly reassigning responsibility for freeing to the user but
3982immediately afterwards reassigning it once more to the write_destroy
3983function. Having done this, it would then be safe to destroy the read
3984structure and continue to use the PLTE, tRNS, and hIST data in the write
3985structure.
3986
3987This function only affects data that has already been allocated.
3988You can call this function before calling after the png_set_*() functions
3989to control whether the user or png_destroy_*() is supposed to free the data.
3990When the user assumes responsibility for libpng-allocated data, the
3991application must use
3992png_free() to free it, and when the user transfers responsibility to libpng
3993for data that the user has allocated, the user must have used png_malloc()
fff5f7d5 3994or png_calloc() to allocate it.
0272a10d
VZ
3995
3996If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3997separately, do not transfer responsibility for freeing text_ptr to libpng,
3998because when libpng fills a png_text structure it combines these members with
3999the key member, and png_free_data() will free only text_ptr.key. Similarly,
4000if you transfer responsibility for free'ing text_ptr from libpng to your
4001application, your application must not separately free those members.
4002For a more compact example of writing a PNG image, see the file example.c.
4003
fff5f7d5
VZ
4004.SH V. Simplified API
4005
4006The simplified API, which became available in libpng-1.6.0, hides the details
4007of both libpng and the PNG file format itself.
4008It allows PNG files to be read into a very limited number of
4009in-memory bitmap formats or to be written from the same formats. If these
4010formats do not accomodate your needs then you can, and should, use the more
4011sophisticated APIs above - these support a wide variety of in-memory formats
4012and a wide variety of sophisticated transformations to those formats as well
4013as a wide variety of APIs to manipulate ancilliary information.
4014
4015To 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
4028There are no restrictions on the format of the PNG input itself; all valid
4029color types, bit depths, and interlace methods are acceptable, and the
4030input image is transformed as necessary to the requested in-memory format
4031during the png_image_finish_read() step.
4032
4033To 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
4045png_image is a structure that describes the in-memory format of an image
4046when it is being read or define the in-memory format of an image that you
4047need 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
4059In the event of an error or warning the following field warning_or_error
4060field will be set to a non-zero value and the 'message' field will contain
4061a '\0' terminated string with the libpng error or warning message. If both
4062warnings and an error were encountered, only the error is recorded. If there
4063are multiple warnings, only the first one is recorded.
4064
4065The upper 30 bits of this value are reserved; the low two bits contain
4066a two bit code such that a value more than 1 indicates a failure in the API
4067just called:
4068
4069 0 - no warning or error
4070 1 - warning
4071 2 - error
4072 3 - error preceded by warning
4073
4074The pixels (samples) of the image have one to four channels whose components
4075have 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
4082The 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
4085alpha channel the original value is simply value/255. For the color or
4086luminance channels the value is encoded according to the sRGB specification
4087and matches the 8-bit format expected by typical display devices.
4088
4089The color/gray channels are not scaled (pre-multiplied) by the alpha
4090channel 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
4093channels can be converted to the original value by dividing by 65535; all
4094channels are linear. Color channels use the RGB encoding (RGB end-points) of
4095the sRGB specification. This encoding is identified by the
4096PNG_FORMAT_FLAG_LINEAR flag below.
4097
4098When an alpha channel is present it is expected to denote pixel coverage
4099of the color or luminance channels and is returned as an associated alpha
4100channel: the color/gray channels are scaled (pre-multiplied) by the alpha
4101value.
4102
4103When a color-mapped image is used as a result of calling
4104png_image_read_colormap or png_image_write_colormap the channels are encoded
4105in the color-map and the descriptions above apply to the color-map entries.
4106The image data is encoded as small integers, value 0..255, that index the
4107entries in the color-map. One integer (one byte) is stored for each pixel.
4108
4109PNG_FORMAT_*
4110
4111The #defines to be used in png_image::format. Each #define identifies a
4112particular layout of channel data and, if present, alpha values. There are
4113separate defines for each of the two channel encodings.
4114
4115A format is built up using single bit flag values. Not all combinations are
4116valid: use the bit flag values below for testing a format returned by the
4117read APIs, but set formats from the derived values.
4118
4119When reading or writing color-mapped images the format should be set to the
4120format of the entries in the color-map then png_image_{read,write}_colormap
4121called to read or write the color-map and set the format correctly for the
4122image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!
4123
4124NOTE: libpng can be built with particular features disabled, if you see
4125compiler errors because the definition of one of the following flags has been
4126compiled out it is because libpng does not have the required support. It is
4127possible, however, for the libpng configuration to enable the format on just
4128read or just write; in that case you may see an error at run time. You can
4129guard 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
4140Supported formats are as follows. Future versions of libpng may support more
4141formats; for compatibility with older versions simply check if the format
4142macro is defined using #ifdef. These defines describe the in-memory layout
4143of the components of the pixels of the image.
4144
4145First 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
4157Then the linear 2-byte formats. When naming these "Y" is used to
4158indicate a luminance (gray) channel. The component order within the pixel
4159is always the same - there is no provision for swapping the order of the
4160components 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
4171Color-mapped formats are obtained by calling png_image_{read,write}_colormap,
4172as appropriate after setting png_image::format to the format of the color-map
4173to be read or written. Applications may check the value of
4174PNG_FORMAT_FLAG_COLORMAP to see if they have called the colormap API. The
4175format of the color-map may be extracted using the following macro.
4176
4177 PNG_FORMAT_OF_COLORMAP(fmt) ((fmt) & ~PNG_FORMAT_FLAG_COLORMAP)
4178
4179PNG_IMAGE macros
4180
4181These are convenience macros to derive information from a png_image
4182structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the
4183actual image sample values - either the entries in the color-map or the
4184pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values
4185for the pixels and will always return 1 after a call to
4186png_image_{read,write}_colormap. The remaining macros return information
4187about the rows in the image and the complete image.
4188
4189NOTE: All the macros that take a png_image::format parameter are compile time
4190constants if the format parameter is, itself, a constant. Therefore these
4191macros can be used in array declarations and case labels where required.
4192Similarly the macros are also pre-processor constants (sizeof is not used) so
4193they can be used in #if tests.
4194
4195First 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
4231Corresponding 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
4246Information 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
4267READ 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
4317When the simplified API needs to convert between sRGB and linear colorspaces,
4318the actual sRGB transfer curve defined in the sRGB specification (see the
4319article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
4320approximation used elsewhere in libpng.
4321
4322WRITE APIS
4323
4324For write you must initialize a png_image structure to describe the image to
4325be 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
4349With 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
4351a (png_byte) PNG gamma encoded according to the sRGB specification, otherwise
4352a 16-bit linear encoded PNG file is written.
4353
4354With all APIs row_stride is handled as in the read APIs - it is the spacing
4355from one row to the next in component sized units (float) and if negative
4356indicates a bottom-up row layout in the buffer.
4357
4358Note that the write API does not support interlacing, sub-8-bit pixels,
4359and indexed (paletted) images.
4360
4361.SH VI. Modifying/Customizing libpng
0272a10d
VZ
4362
4363There are two issues here. The first is changing how libpng does
4364standard things like memory allocation, input/output, and error handling.
4365The second deals with more complicated things like adding new chunks,
4366adding new transformations, and generally changing how libpng works.
4367Both of those are compile-time issues; that is, they are generally
4368determined at the time the code is written, and there is rarely a need
4369to provide the user with a means of changing them.
4370
4371Memory allocation, input/output, and error handling
4372
4373All of the memory allocation, input/output, and error handling in libpng
4374goes through callbacks that are user-settable. The default routines are
4375in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
4376these functions, call the appropriate png_set_*_fn() function.
4377
b61cc19c 4378Memory allocation is done through the functions png_malloc(), png_calloc(),
fff5f7d5
VZ
4379and png_free(). The png_malloc() and png_free() functions currently just
4380call the standard C functions and png_calloc() calls png_malloc() and then
4381clears the newly allocated memory to zero; note that png_calloc(png_ptr, size)
4382is not the same as the calloc(number, size) function provided by stdlib.h.
4383There is limited support for certain systems with segmented memory
4384architectures and the types of pointers declared by png.h match this; you
4385will have to use appropriate pointers in your application. Since it is
b61cc19c
PC
4386unlikely that the method of handling memory allocation on a platform
4387will change between applications, these functions must be modified in
4388the library at compile time. If you prefer to use a different method
4389of allocating and freeing data, you can use png_create_read_struct_2() or
4390png_create_write_struct_2() to register your own functions as described
4391above. These functions also provide a void pointer that can be retrieved
4392via
0272a10d
VZ
4393
4394 mem_ptr=png_get_mem_ptr(png_ptr);
4395
4396Your replacement memory functions must have prototypes as follows:
4397
4398 png_voidp malloc_fn(png_structp png_ptr,
b61cc19c 4399 png_alloc_size_t size);
9c0d9ce3 4400
0272a10d
VZ
4401 void free_fn(png_structp png_ptr, png_voidp ptr);
4402
4403Your malloc_fn() must return NULL in case of failure. The png_malloc()
4404function will normally call png_error() if it receives a NULL from the
4405system memory allocator or from your replacement malloc_fn().
4406
970f6abe
VZ
4407Your free_fn() will never be called with a NULL ptr, since libpng's
4408png_free() checks for NULL before calling free_fn().
4409
0272a10d
VZ
4410Input/Output in libpng is done through png_read() and png_write(),
4411which currently just call fread() and fwrite(). The FILE * is stored in
4412png_struct and is initialized via png_init_io(). If you wish to change
4413the method of I/O, the library supplies callbacks that you can set
4414through the function png_set_read_fn() and png_set_write_fn() at run
4415time, instead of calling the png_init_io() function. These functions
4416also provide a void pointer that can be retrieved via the function
4417png_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
4429The 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);
9c0d9ce3 4433
0272a10d
VZ
4434 void user_write_data(png_structp png_ptr,
4435 png_bytep data, png_size_t length);
9c0d9ce3 4436
0272a10d
VZ
4437 void user_flush_data(png_structp png_ptr);
4438
b61cc19c
PC
4439The user_read_data() function is responsible for detecting and
4440handling end-of-data errors.
4441
0272a10d 4442Supplying NULL for the read, write, or flush functions sets them back
b61cc19c
PC
4443to using the default C stream functions, which expect the io_ptr to
4444point to a standard *FILE structure. It is probably a mistake
4445to use NULL for one of write_data_fn and output_flush_fn but not both
4446of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4447It is an error to read from a write stream, and vice versa.
0272a10d
VZ
4448
4449Error handling in libpng is done through png_error() and png_warning().
4450Errors handled through png_error() are fatal, meaning that png_error()
4451should never return to its caller. Currently, this is handled via
4452setjmp() and longjmp() (unless you have compiled libpng with
b61cc19c
PC
4453PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
4454but you could change this to do things like exit() if you should wish,
4455as long as your function does not return.
0272a10d
VZ
4456
4457On non-fatal errors, png_warning() is called
4458to print a warning message, and then control returns to the calling code.
4459By default png_error() and png_warning() print a message on stderr via
4460fprintf() 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
4462fprintf() isn't available). If you wish to change the behavior of the error
4463functions, you will need to set up your own message callbacks. These
4464functions are normally supplied at the time that the png_struct is created.
4465It is also possible to redirect errors and warnings to your own replacement
4466functions 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
4474If NULL is supplied for either error_fn or warning_fn, then the libpng
4475default function will be used, calling fprintf() and/or longjmp() if a
4476problem is encountered. The replacement error functions should have
4477parameters as follows:
4478
4479 void user_error_fn(png_structp png_ptr,
4480 png_const_charp error_msg);
9c0d9ce3 4481
0272a10d
VZ
4482 void user_warning_fn(png_structp png_ptr,
4483 png_const_charp warning_msg);
4484
4485The motivation behind using setjmp() and longjmp() is the C++ throw and
4486catch exception handling methods. This makes the code much easier to write,
4487as there is no need to check every return code of every function call.
4488However, there are some uncertainties about the status of local variables
b61cc19c
PC
4489after a longjmp, so the user may want to be careful about doing anything
4490after setjmp returns non-zero besides returning itself. Consult your
4491compiler documentation for more details. For an alternative approach, you
9c0d9ce3
DS
4492may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4493which is illustrated in pngvalid.c and in contrib/visupng.
0272a10d 4494
fff5f7d5
VZ
4495Beginning in libpng-1.4.0, the png_set_benign_errors() API became available.
4496You can use this to handle certain errors (normally handled as errors)
4497as 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
0272a10d
VZ
4504.SS Custom chunks
4505
4506If you need to read or write custom chunks, you may need to get deeper
4507into the libpng code. The library now has mechanisms for storing
4508and writing chunks of unknown type; you can even declare callbacks
4509for custom chunks. However, this may not be good enough if the
4510library code itself needs to know about interactions between your
4511chunk and existing `intrinsic' chunks.
4512
4513If you need to write a new intrinsic chunk, first read the PNG
b61cc19c
PC
4514specification. Acquire a first level of understanding of how it works.
4515Pay particular attention to the sections that describe chunk names,
4516and look at how other chunks were designed, so you can do things
4517similarly. Second, check out the sections of libpng that read and
4518write chunks. Try to find a chunk that is similar to yours and use
4519it as a template. More details can be found in the comments inside
9c0d9ce3
DS
4520the code. It is best to handle private or unknown chunks in a generic method,
4521via callback functions, instead of by modifying libpng functions. This
4522is illustrated in pngtest.c, which uses a callback function to handle a
4523private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4524libpng.
0272a10d
VZ
4525
4526If you wish to write your own transformation for the data, look through
4527the part of the code that does the transformations, and check out some of
4528the simpler ones to get an idea of how they work. Try to find a similar
4529transformation to the one you want to add and copy off of it. More details
4530can be found in the comments inside the code itself.
4531
9c0d9ce3 4532.SS Configuring for 16-bit platforms
0272a10d
VZ
4533
4534You will want to look into zconf.h to tell zlib (and thus libpng) that
4535it cannot allocate more then 64K at a time. Even if you can, the memory
4536won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
4537
4538.SS Configuring for DOS
4539
4540For DOS users who only have access to the lower 640K, you will
4541have to limit zlib's memory usage via a png_set_compression_mem_level()
4542call. See zlib.h or zconf.h in the zlib library for more information.
4543
4544.SS Configuring for Medium Model
4545
4546Libpng's support for medium model has been tested on most of the popular
4547compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4548defined, and FAR gets defined to far in pngconf.h, and you should be
4549all set. Everything in the library (except for zlib's structure) is
4550expecting far data. You must use the typedefs with the p or pp on
4551the end for pointers (or at least look at them and be careful). Make
9c0d9ce3
DS
4552note that the rows of data are defined as png_bytepp, which is
4553an "unsigned char far * far *".
0272a10d
VZ
4554
4555.SS Configuring for gui/windowing platforms:
4556
4557You will need to write new error and warning functions that use the GUI
4558interface, as described previously, and set them to be the error and
4559warning functions at the time that png_create_*_struct() is called,
4560in order to have them available during the structure initialization.
4561They can be changed later via png_set_error_fn(). On some compilers,
4562you may also have to change the memory allocators (png_malloc, etc.).
4563
4564.SS Configuring for compiler xxx:
4565
b61cc19c
PC
4566All includes for libpng are in pngconf.h. If you need to add, change
4567or delete an include, this is the place to do it.
4568The includes that are not needed outside libpng are placed in pngpriv.h,
4569which is only used by the routines inside libpng itself.
4570The files in libpng proper only include pngpriv.h and png.h, which
9c0d9ce3
DS
4571%14%in turn includes pngconf.h.
4572in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
4573As of libpng-1.5.0, pngpriv.h also includes three other private header
4574files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
4575that previously appeared in the public headers.
0272a10d
VZ
4576
4577.SS Configuring zlib:
4578
4579There are special functions to configure the compression. Perhaps the
4580most useful one changes the compression level, which currently uses
4581input compression values in the range 0 - 9. The library normally
4582uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
4583have shown that for a large majority of images, compression values in
4584the range 3-6 compress nearly as well as higher levels, and do so much
4585faster. 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
4587specify no compression (Z_NO_COMPRESSION = 0), but this would create
4588files larger than just storing the raw bitmap. You can specify the
4589compression level by calling:
4590
9c0d9ce3 4591 #include zlib.h
0272a10d
VZ
4592 png_set_compression_level(png_ptr, level);
4593
4594Another useful one is to reduce the memory level used by the library.
4595The memory level defaults to 8, but it can be lowered if you are
4596short on memory (running DOS, for example, where you only have 640K).
4597Note that the memory level does have an effect on compression; among
4598other things, lower levels will result in sections of incompressible
4599data being emitted in smaller stored blocks, with a correspondingly
4600larger relative overhead of up to 15% in the worst case.
4601
9c0d9ce3 4602 #include zlib.h
0272a10d
VZ
4603 png_set_compression_mem_level(png_ptr, level);
4604
4605The other functions are for configuring zlib. They are not recommended
4606for normal use and may result in writing an invalid PNG file. See
4607zlib.h for more information on what these mean.
4608
9c0d9ce3 4609 #include zlib.h
0272a10d
VZ
4610 png_set_compression_strategy(png_ptr,
4611 strategy);
9c0d9ce3 4612
0272a10d
VZ
4613 png_set_compression_window_bits(png_ptr,
4614 window_bits);
9c0d9ce3 4615
0272a10d 4616 png_set_compression_method(png_ptr, method);
9c0d9ce3 4617
0272a10d
VZ
4618 png_set_compression_buffer_size(png_ptr, size);
4619
9c0d9ce3
DS
4620As of libpng version 1.5.4, additional APIs became
4621available to set these separately for non-IDAT
4622compressed chunks such as zTXt, iTXt, and iCCP:
4623
4624 #include zlib.h
fff5f7d5 4625 #if PNG_LIBPNG_VER >= 10504
9c0d9ce3
DS
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
0272a10d
VZ
4639.SS Controlling row filtering
4640
4641If you want to control whether libpng uses filtering or not, which
4642filters are used, and how it goes about picking row filters, you
4643can call one of these functions. The selection and configuration
4644of row filters can have a significant impact on the size and
4645encoding speed and a somewhat lesser impact on the decoding speed
4646of an image. Filtering is enabled by default for RGB and grayscale
4647images (with and without alpha), but not for paletted images nor
4648for any images with bit depths less than 8 bits/pixel.
4649
4650The 'method' parameter sets the main filtering method, which is
4651currently only '0' in the PNG 1.2 specification. The 'filters'
4652parameter sets which filter(s), if any, should be used for each
4653scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
4654to turn filtering on and off, respectively.
4655
4656Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
4657PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
4658ORed together with '|' to specify one or more filters to use.
4659These filters are described in more detail in the PNG specification.
4660If you intend to change the filter type during the course of writing
4661the image, you should start with flags set for all of the filters
4662you intend to use so that libpng can initialize its internal
4663structures appropriately for all of the filter types. (Note that this
4664means the first row must always be adaptively filtered, because libpng
4665currently does not allocate the filter buffers until png_write_row()
4666is called for the first time.)
4667
4668 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
b61cc19c 4669 PNG_FILTER_UP | PNG_FILTER_AVG |
0272a10d
VZ
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
4681It is also possible to influence how libpng chooses from among the
4682available filters. This is done in one or both of two ways - by
4683telling it how important it is to keep the same filter for successive
4684rows, 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
4694The weights are multiplying factors that indicate to libpng that the
4695row filter should be the same for successive rows unless another row filter
4696is that many times better than the previous filter. In the above example,
4697if 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
4699and still be chosen, while the NONE filter could have a sum 1.1 times
4700higher than other filters and still be chosen. Unspecified weights are
4701taken to be 1.0, and the specified weights should probably be declining
4702like those above in order to emphasize recent filters over older filters.
4703
4704The filter costs specify for each filter type a relative decoding cost
4705to be considered when selecting row filters. This means that filters
4706with higher costs are less likely to be chosen over filters with lower
4707costs, unless their "sum of absolute differences" is that much smaller.
4708The costs do not necessarily reflect the exact computational speeds of
4709the various filters, since this would unduly influence the final image
4710size.
4711
4712Note that the numbers above were invented purely for this example and
4713are given only to help explain the function usage. Little testing has
4714been done to find optimum values for either the costs or the weights.
4715
4716.SS Removing unwanted object code
4717
4718There are a bunch of #define's in pngconf.h that control what parts of
4719libpng are compiled. All the defines end in _SUPPORTED. If you are
4720never going to use a capability, you can change the #define to #undef
4721before recompiling libpng and save yourself code and data space, or
4722you can turn off individual capabilities with defines that begin with
4723PNG_NO_.
4724
9c0d9ce3
DS
4725In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
4726
0272a10d
VZ
4727You can also turn all of the transforms and ancillary chunk capabilities
4728off en masse with compiler directives that define
4729PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
4730or all four,
4731along with directives to turn on any of the capabilities that you do
b61cc19c
PC
4732want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
4733transformations but still leave the library fully capable of reading
4734and writing PNG files with all known public chunks. Use of the
4735PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
4736that is incapable of reading or writing ancillary chunks. If you are
4737not using the progressive reading capability, you can turn that off
4738with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
4739capability, which you'll still have).
0272a10d
VZ
4740
4741All the reading and writing specific code are in separate files, so the
4742linker should only grab the files it needs. However, if you want to
4743make sure, or if you are building a stand alone library, all the
9c0d9ce3
DS
4744reading files start with "pngr" and all the writing files start with "pngw".
4745The files that don't match either (like png.c, pngtrans.c, etc.)
0272a10d
VZ
4746are used for both reading and writing, and always need to be included.
4747The progressive reader is in pngpread.c
4748
4749If you are creating or distributing a dynamically linked library (a .so
4750or DLL file), you should not remove or disable any parts of the library,
4751as this will cause applications linked with different versions of the
4752library to fail if they call functions not available in your library.
4753The size of the library itself should not be an issue, because only
4754those sections that are actually used will be loaded into memory.
4755
4756.SS Requesting debug printout
4757
4758The macro definition PNG_DEBUG can be used to request debugging
4759printout. Set it to an integer value in the range 0 to 3. Higher
4760numbers result in increasing amounts of debugging information. The
4761information is printed to the "stderr" file, unless another file
4762name is specified in the PNG_DEBUG_FILE macro definition.
4763
4764When 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
4770in which "level" is compared to PNG_DEBUG to decide whether to print
4771the message, "message" is the formatted string to be printed,
4772and p1 and p2 are parameters that are to be embedded in the string
4773according to printf-style formatting directives. For example,
4774
4775 png_debug1(2, "foo=%d\n", foo);
4776
4777is expanded to
4778
9c0d9ce3
DS
4779 if (PNG_DEBUG > 2)
4780 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
0272a10d
VZ
4781
4782When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
4783can still use PNG_DEBUG to control your own debugging:
4784
4785 #ifdef PNG_DEBUG
4786 fprintf(stderr, ...
4787 #endif
4788
4789When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
4790having level = 0 will be printed. There aren't any such statements in
4791this version of libpng, but if you insert some they will be printed.
4792
fff5f7d5
VZ
4793.SS Prepending a prefix to exported symbols
4794
4795Starting with libpng-1.6.0, you can configure libpng (when using the
4796"configure" script) to prefix all exported symbols by means of the
4797configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
4798string beginning with a letter and containing only uppercase
4799and lowercase letters, digits, and the underscore (i.e., a C language
4800identifier). This creates a set of macros in pnglibconf.h, so this is
4801transparent to applications; their function calls get transformed by
4802the macros to use the modified names.
4803
4804.SH VII. MNG support
0272a10d
VZ
4805
4806The MNG specification (available at http://www.libpng.org/pub/mng) allows
4807certain extensions to PNG for PNG images that are embedded in MNG datastreams.
4808Libpng can support some of these extensions. To enable them, use the
4809png_permit_mng_features() function:
4810
4811 feature_set = png_permit_mng_features(png_ptr, mask)
9c0d9ce3 4812
0272a10d
VZ
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
9c0d9ce3 4818
0272a10d
VZ
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
4823It is an error to use this function when reading or writing a standalone
4824PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
4825in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
4826and the MHDR and MEND chunks. Libpng does not provide support for these
4827or any other MNG chunks; your application must provide its own support for
4828them. You may wish to consider using libmng (available at
4829http://www.libmng.com) instead.
4830
fff5f7d5 4831.SH VIII. Changes to Libpng from version 0.88
0272a10d
VZ
4832
4833It should be noted that versions of libpng later than 0.96 are not
4834distributed by the original libpng author, Guy Schalnat, nor by
4835Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
4836distributed versions 0.89 through 0.96, but rather by another member
4837of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
4838still alive and well, but they have moved on to other things.
4839
4840The old libpng functions png_read_init(), png_write_init(),
4841png_info_init(), png_read_destroy(), and png_write_destroy() have been
4842moved to PNG_INTERNAL in version 0.95 to discourage their use. These
9c0d9ce3 4843functions will be removed from libpng version 1.4.0.
0272a10d
VZ
4844
4845The preferred method of creating and initializing the libpng structures is
4846via the png_create_read_struct(), png_create_write_struct(), and
4847png_create_info_struct() because they isolate the size of the structures
4848from the application, allow version error checking, and also allow the
4849use of custom error handling routines during the initialization, which
4850the old functions do not. The functions png_read_destroy() and
4851png_write_destroy() do not actually free the memory that libpng
4852allocated for these structs, but just reset the data structures, so they
4853can be used instead of png_destroy_read_struct() and
4854png_destroy_write_struct() if you feel there is too much system overhead
4855allocating and freeing the png_struct for each image read.
4856
4857Setting the error callbacks via png_set_message_fn() before
4858png_read_init() as was suggested in libpng-0.88 is no longer supported
4859because this caused applications that do not use custom error functions
4860to fail if the png_ptr was not initialized to zero. It is still possible
4861to set the error callbacks AFTER png_read_init(), or to change them with
4862png_set_error_fn(), which is essentially the same function, but with a new
4863name to force compilation errors with applications that try to use the old
4864method.
4865
4866Starting with version 1.0.7, you can find out which version of the library
4867you are using at run-time:
4868
4869 png_uint_32 libpng_vn = png_access_version_number();
4870
4871The number libpng_vn is constructed from the major version, minor
4872version with leading zero, and release number with leading zero,
4873(e.g., libpng_vn for version 1.0.7 is 10007).
4874
9c0d9ce3
DS
4875Note that this function does not take a png_ptr, so you can call it
4876before you've created one.
4877
0272a10d
VZ
4878You can also check which version of png.h you used when compiling your
4879application:
4880
4881 png_uint_32 application_vn = PNG_LIBPNG_VER;
4882
fff5f7d5 4883.SH IX. Changes to Libpng from version 1.0.x to 1.2.x
b61cc19c
PC
4884
4885Support for user memory management was enabled by default. To
4886accomplish this, the functions png_create_read_struct_2(),
4887png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
4888png_malloc_default(), and png_free_default() were added.
4889
4890Support for the iTXt chunk has been enabled by default as of
4891version 1.2.41.
4892
4893Support for certain MNG features was enabled.
4894
4895Support for numbered error messages was added. However, we never got
4896around to actually numbering the error messages. The function
4897png_set_strip_error_numbers() was added (Note: the prototype for this
4898function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
4899builds of libpng-1.2.15. It was restored in libpng-1.2.36).
4900
4901The png_malloc_warn() function was added at libpng-1.2.3. This issues
4902a png_warning and returns NULL instead of aborting when it fails to
4903acquire the requested memory allocation.
4904
4905Support for setting user limits on image width and height was enabled
4906by default. The functions png_set_user_limits(), png_get_user_width_max(),
4907and png_get_user_height_max() were added at libpng-1.2.6.
4908
4909The png_set_add_alpha() function was added at libpng-1.2.7.
4910
4911The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
4912Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
4913tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
4914deprecated.
4915
4916A number of macro definitions in support of runtime selection of
4917assembler code features (especially Intel MMX code support) were
4918added 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
4934We added the following functions in support of runtime
4935selection 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
4944We replaced all of these functions with simple stubs in libpng-1.2.20,
4945when the Intel assembler code was removed due to a licensing issue.
4946
4947These 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
4956They 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
4965PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
4966deprecated since libpng-1.0.16 and libpng-1.2.6.
4967
4968The function
4969 png_check_sig(sig, num)
4970was replaced with
4971 !png_sig_cmp(sig, 0, num)
4972It has been deprecated since libpng-0.90.
4973
4974The function
4975 png_set_gray_1_2_4_to_8()
4976which also expands tRNS to alpha was replaced with
4977 png_set_expand_gray_1_2_4_to_8()
4978which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
4979
fff5f7d5 4980.SH X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
b61cc19c
PC
4981
4982Private libpng prototypes and macro definitions were moved from
4983png.h and pngconf.h into a new pngpriv.h header file.
4984
4985Functions png_set_benign_errors(), png_benign_error(), and
4986png_chunk_benign_error() were added.
4987
4988Support for setting the maximum amount of memory that the application
4989will allocate for reading chunks was added, as a security measure.
4990The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
4991were added to the library.
4992
4993We implemented support for I/O states by adding png_ptr member io_state
4994and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
4995
4996We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
4997input transforms.
4998
4999Checking for and reporting of errors in the IHDR chunk is more thorough.
5000
5001Support for global arrays was removed, to improve thread safety.
5002
5003Some obsolete/deprecated macros and functions have been removed.
5004
5005Typecasted NULL definitions such as
5006 #define png_voidp_NULL (png_voidp)NULL
5007were eliminated. If you used these in your application, just use
5008NULL instead.
5009
5010The png_struct and info_struct members "trans" and "trans_values" were
5011changed to "trans_alpha" and "trans_color", respectively.
0272a10d 5012
b61cc19c
PC
5013The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
5014were removed.
5015
5016The PNG_1_0_X and PNG_1_2_X macros were eliminated.
5017
5018The PNG_LEGACY_SUPPORTED macro was eliminated.
5019
5020Many WIN32_WCE #ifdefs were removed.
5021
5022The functions png_read_init(info_ptr), png_write_init(info_ptr),
5023png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
5024have been removed. They have been deprecated since libpng-0.95.
5025
5026The png_permit_empty_plte() was removed. It has been deprecated
5027since libpng-1.0.9. Use png_permit_mng_features() instead.
5028
5029We removed the obsolete stub functions png_get_mmx_flagmask(),
5030png_set_mmx_thresholds(), png_get_asm_flags(),
5031png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
5032png_set_asm_flags(), and png_mmx_supported()
5033
5034We removed the obsolete png_check_sig(), png_memcpy_check(), and
9c0d9ce3
DS
5035png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
5036and memset(), respectively.
b61cc19c
PC
5037
5038The function png_set_gray_1_2_4_to_8() was removed. It has been
5039deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
5040png_set_expand_gray_1_2_4_to_8() because the former function also
9c0d9ce3
DS
5041expanded any tRNS chunk to an alpha channel.
5042
5043Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
5044were added and are used by default instead of the corresponding
5045functions. Unfortunately,
5046from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5047function) incorrectly returned a value of type png_uint_32.
b61cc19c
PC
5048
5049We changed the prototype for png_malloc() from
5050 png_malloc(png_structp png_ptr, png_uint_32 size)
5051to
5052 png_malloc(png_structp png_ptr, png_alloc_size_t size)
5053
5054This also applies to the prototype for the user replacement malloc_fn().
5055
5056The png_calloc() function was added and is used in place of
9c0d9ce3 5057of "png_malloc(); memset();" except in the case in png_read_png()
b61cc19c
PC
5058where the array consists of pointers; in this case a "for" loop is used
5059after the png_malloc() to set the pointers to NULL, to give robust.
5060behavior in case the application runs out of memory part-way through
5061the process.
5062
5063We changed the prototypes of png_get_compression_buffer_size() and
5064png_set_compression_buffer_size() to work with png_size_t instead of
5065png_uint_32.
5066
5067Support for numbered error messages was removed by default, since we
5068never got around to actually numbering the error messages. The function
5069png_set_strip_error_numbers() was removed from the library by default.
5070
5071The png_zalloc() and png_zfree() functions are no longer exported.
5072The png_zalloc() function no longer zeroes out the memory that it
fff5f7d5
VZ
5073allocates. Applications that called png_zalloc(png_ptr, number, size)
5074can call png_calloc(png_ptr, number*size) instead, and can call
5075png_free() instead of png_zfree().
b61cc19c
PC
5076
5077Support for dithering was disabled by default in libpng-1.4.0, because
9c0d9ce3
DS
5078it has not been well tested and doesn't actually "dither".
5079The code was not
b61cc19c
PC
5080removed, however, and could be enabled by building libpng with
5081PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
5082was reenabled, but the function was renamed png_set_quantize() to
5083reflect more accurately what it actually does. At the same time,
5084the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
9c0d9ce3
DS
5085PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5086was renamed to PNG_READ_QUANTIZE_SUPPORTED.
b61cc19c
PC
5087
5088We removed the trailing '.' from the warning and error messages.
5089
fff5f7d5 5090.SH XI. Changes to Libpng from version 1.4.x to 1.5.x
9c0d9ce3
DS
5091
5092From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5093function) incorrectly returned a value of type png_uint_32.
5094
fff5f7d5
VZ
5095Checking for invalid palette index on read or write was added at libpng
50961.5.10. When an invalid index is found, libpng issues a benign error.
5097This is enabled by default because this condition is an error according
5098to the PNG specification, Clause 11.3.2, but the error can be ignored in
5099each 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
5110If the error is ignored, or if png_benign_error() treats it as a warning,
5111any invalid pixels are decoded as opaque black by the decoder and written
5112as-is by the encoder.
5113
5114Retrieving the maximum palette index found was added at libpng-1.5.15.
5115This statement must appear after png_read_png() or png_read_image() while
5116reading, 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
5120This will return the maximum palette index found in the image, or "-1" if
5121the palette was not checked, or "0" if no palette was found. Note that this
5122does not account for any palette index used by ancillary chunks such as the
5123bKGD chunk; you must check those separately to determine the maximum
5124palette index actually used.
5125
9c0d9ce3
DS
5126A. Changes that affect users of libpng
5127
5128There are no substantial API changes between the non-deprecated parts of
fff5f7d5
VZ
5129the 1.4.5 API and the 1.5.0 API; however, the ability to directly access
5130members of the main libpng control structures, png_struct and png_info,
5131deprecated in earlier versions of libpng, has been completely removed from
9c0d9ce3
DS
5132libpng 1.5.
5133
fff5f7d5
VZ
5134We no longer include zlib.h in png.h. The include statement has been moved
5135to pngstruct.h, where it is not accessible by applications. Applications that
5136need access to information in zlib.h will need to add the '#include "zlib.h"'
5137directive. It does not matter whether this is placed prior to or after
9c0d9ce3
DS
5138the '"#include png.h"' directive.
5139
fff5f7d5
VZ
5140The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used
5141and were removed.
5142
5143We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp()
5144macros into a private header file (pngpriv.h) that is not accessible to
5145applications.
9c0d9ce3
DS
5146
5147In png_get_iCCP, the type of "profile" was changed from png_charpp
5148to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
5149
5150There are changes of form in png.h, including new and changed macros to
5151declare parts of the API. Some API functions with arguments that are
5152pointers to data not modified within the function have been corrected to
5153declare these arguments with PNG_CONST.
5154
5155Much of the internal use of C macros to control the library build has also
5156changed and some of this is visible in the exported header files, in
5157particular the use of macros to control data and API elements visible
5158during application compilation may require significant revision to
5159application code. (It is extremely rare for an application to do this.)
5160
5161Any program that compiled against libpng 1.4 and did not use deprecated
5162features or access internal library structures should compile and work
5163against libpng 1.5, except for the change in the prototype for
5164png_get_iCCP() and png_set_iCCP() API functions mentioned above.
5165
5166libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5167interlaced images. The macros return the number of rows and columns in
5168each pass and information that can be used to de-interlace and (if
5169absolutely necessary) interlace an image.
5170
5171libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
5172the application-provided png_longjmp_ptr on the internal, but application
5173initialized, longjmp buffer. It is provided as a convenience to avoid
5174the need to use the png_jmpbuf macro, which had the unnecessary side
5175effect of resetting the internal png_longjmp_ptr value.
5176
5177libpng 1.5.0 includes a complete fixed point API. By default this is
5178present along with the corresponding floating point API. In general the
5179fixed point API is faster and smaller than the floating point one because
5180the PNG file format used fixed point, not floating point. This applies
5181even if the library uses floating point in internal calculations. A new
5182macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5183uses floating point arithmetic (the default) or fixed point arithmetic
5184internally for performance critical calculations such as gamma correction.
5185In some cases, the gamma calculations may produce slightly different
5186results. This has changed the results in png_rgb_to_gray and in alpha
5187composition (png_set_background for example). This applies even if the
5188original image was already linear (gamma == 1.0) and, therefore, it is
5189not necessary to linearize the image. This is because libpng has *not*
5190been changed to optimize that case correctly, yet.
5191
5192Fixed point support for the sCAL chunk comes with an important caveat;
5193the sCAL specification uses a decimal encoding of floating point values
5194and the accuracy of PNG fixed point values is insufficient for
5195representation of these values. Consequently a "string" API
5196(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5197arbitrary sCAL chunks in the absence of either the floating point API or
5198internal floating point calculations.
5199
5200Applications no longer need to include the optional distribution header
5201file pngusr.h or define the corresponding macros during application
5202build in order to see the correct variant of the libpng API. From 1.5.0
5203application 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
5209This macro will only be defined if the inch conversion functions have been
5210compiled into libpng. The full set of macros, and whether or not support
5211has been compiled in, are available in the header file pnglibconf.h.
5212This header file is specific to the libpng build. Notice that prior to
52131.5.0 the _SUPPORTED macros would always have the default definition unless
5214reset by pngusr.h or by explicit settings on the compiler command line.
5215These settings may produce compiler warnings or errors in 1.5.0 because
5216of macro redefinition.
5217
5218From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5219function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
5220is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5221did not exist.)
5222
5223Applications can now choose whether to use these macros or to call the
5224corresponding function by defining PNG_USE_READ_MACROS or
5225PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
5226only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
5227will lead to a link failure.
5228
5229Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
5230when compressing the IDAT data and textual data such as zTXt and iCCP.
5231In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
5232We added five png_set_text_*() functions for setting the parameters to
5233use with textual data.
5234
5235Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
5236option was off by default, and slightly inaccurate scaling occurred.
5237This option can no longer be turned off, and the choice of accurate
5238or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5239API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5240chopping.
5241
5242Prior to libpng-1.5.4, the png_set_user_limits() function could only be
5243used to reduce the width and height limits from the value of
5244PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5245that it could be used to override them. Now this function will reduce or
5246increase the limits.
5247
fff5f7d5
VZ
5248Starting in libpng-1.5.10, the user limits can be set en masse with the
5249configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled,
5250a set of "safe" limits is applied in pngpriv.h. These can be overridden by
5251application calls to png_set_user_limits(), png_set_user_chunk_cache_max(),
5252and/or png_set_user_malloc_max() that increase or decrease the limits. Also,
5253in libpng-1.5.10 the default width and height limits were increased
5254from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the
5255limits 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
9c0d9ce3
DS
5262B. Changes to the build and configuration of libpng
5263
5264Details of internal changes to the library code can be found in the CHANGES
5265file and in the GIT repository logs. These will be of no concern to the vast
fff5f7d5 5266majority of library users or builders; however, the few who configure libpng
9c0d9ce3
DS
5267to a non-default feature set may need to change how this is done.
5268
5269There should be no need for library builders to alter build scripts if
5270these use the distributed build support - configure or the makefiles -
fff5f7d5 5271however, users of the makefiles may care to update their build scripts
9c0d9ce3
DS
5272to build pnglibconf.h where the corresponding makefile does not do so.
5273
5274Building libpng with a non-default configuration has changed completely.
5275The old method using pngusr.h should still work correctly even though the
5276way pngusr.h is used in the build has been changed; however, library
5277builders will probably want to examine the changes to take advantage of
5278new capabilities and to simplify their build system.
5279
5280B.1 Specific changes to library configuration capabilities
5281
5282The library now supports a complete fixed point implementation and can
5283thus be used on systems that have no floating point support or very
5284limited or slow support. Previously gamma correction, an essential part
5285of complete PNG support, required reasonably fast floating point.
5286
5287As part of this the choice of internal implementation has been made
5288independent of the choice of fixed versus floating point APIs and all the
5289missing fixed point APIs have been implemented.
5290
5291The exact mechanism used to control attributes of API functions has
5292changed. A single set of operating system independent macro definitions
5293is used and operating system specific directives are defined in
5294pnglibconf.h
5295
5296As part of this the mechanism used to choose procedure call standards on
5297those systems that allow a choice has been changed. At present this only
5298affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
5299running on Intel processors. As before, PNGAPI is defined where required
5300to control the exported API functions; however, two new macros, PNGCBAPI
5301and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5302(PNGCAPI) for functions that must match a C library prototype (currently
5303only png_longjmp_ptr, which must match the C longjmp function.) The new
5304approach is documented in pngconf.h
5305
5306Despite these changes, libpng 1.5.0 only supports the native C function
5307calling standard on those platforms tested so far (__cdecl on Microsoft
5308Windows). This is because the support requirements for alternative
5309calling conventions seem to no longer exist. Developers who find it
5310necessary 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
5312therefore set PNG_API_RULE to 2 should also contact the mailing list.
5313
5314A new test program, pngvalid, is provided in addition to pngtest.
5315pngvalid validates the arithmetic accuracy of the gamma correction
5316calculations and includes a number of validations of the file format.
5317A 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
5319usage to be evaluated and performs additional memory overwrite validation.
5320
5321Many changes to individual feature macros have been made. The following
5322are the changes most likely to be noticed by library builders who
5323configure libpng:
5324
53251) 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
5330pnglibconf.h contains one line for each feature macro which is either:
5331
5332#define PNG_feature_SUPPORTED
5333
5334if the feature is supported or:
5335
5336/*#undef PNG_feature_SUPPORTED*/
5337
5338if it is not. Library code consistently checks for the 'SUPPORTED' macro.
5339It does not, and libpng applications should not, check for the 'NO' macro
5340which will not normally be defined even if the feature is not supported.
5341The 'NO' macros are only used internally for setting or not setting the
5342corresponding 'SUPPORTED' macros.
5343
5344Compatibility with the old names is provided as follows:
5345
5346PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5347
5348And the following definitions disable the corresponding feature:
5349
5350PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5351PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5352PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5353PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5354PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5355PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5356
5357Library builders should remove use of the above, inconsistent, names.
5358
53592) Warning and error message formatting was previously conditional on
5360the STDIO feature. The library has been changed to use the
5361CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5362the library no longer uses the printf(3) functions, even though the
5363default read/write implementations use (FILE) style stdio.h functions.
5364
53653) Three feature macros now control the fixed/floating point decisions:
5366
5367PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5368
5369PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5370practice these are normally required internally anyway (because the PNG
5371file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5372merely stops the function from being exported.
5373
5374PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5375point implementation or the fixed point one. Typically the fixed point
5376implementation is larger and slower than the floating point implementation
fff5f7d5 5377on a system that supports floating point; however, it may be faster on a
9c0d9ce3
DS
5378system which lacks floating point hardware and therefore uses a software
5379emulation.
5380
53814) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
5382functions to read and write ints to be disabled independently of
5383PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5384even though the default is to use the macros - this allows applications
5385to choose at app buildtime whether or not to use macros (previously
5386impossible because the functions weren't in the default build.)
5387
5388B.2 Changes to the configuration mechanism
5389
5390Prior to libpng-1.5.0 library builders who needed to configure libpng
5391had either to modify the exported pngconf.h header file to add system
5392specific configuration or had to write feature selection macros into
5393pngusr.h and cause this to be included into pngconf.h by defining
5394PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5395application built without PNG_USER_CONFIG defined would see the
5396unmodified, default, libpng API and thus would probably fail to link.
5397
5398These mechanisms still work in the configure build and in any makefile
5399build that builds pnglibconf.h, although the feature selection macros
5400have changed somewhat as described above. In 1.5.0, however, pngusr.h is
5401processed only once, when the exported header file pnglibconf.h is built.
5402pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
5403build of pnglibconf.h and it is never included in an application build.
5404
5405The rarely used alternative of adding a list of feature macros to the
fff5f7d5 5406CFLAGS setting in the build also still works; however, the macros will be
9c0d9ce3
DS
5407copied to pnglibconf.h and this may produce macro redefinition warnings
5408when the individual C files are compiled.
5409
5410All configuration now only works if pnglibconf.h is built from
5411scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
5412(the original author of awk) maintains C source code of that awk and this
5413and all known later implementations (often called by subtly different
5414names - nawk and gawk for example) are adequate to build pnglibconf.h.
5415The Sun Microsystems (now Oracle) program 'awk' is an earlier version
5416and does not work; this may also apply to other systems that have a
5417functioning awk called 'nawk'.
5418
5419Configuration options are now documented in scripts/pnglibconf.dfa. This
5420file also includes dependency information that ensures a configuration is
5421consistent; that is, if a feature is switched off dependent features are
5422also removed. As a recommended alternative to using feature macros in
5423pngusr.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
5425DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
5426how to do this, and a case where pngusr.h is still required.
5427
fff5f7d5
VZ
5428.SH XII. Changes to Libpng from version 1.5.x to 1.6.x
5429
5430A "simplified API" has been added (see documentation in png.h and a simple
5431example in contrib/examples/pngtopng.c). The new publicly visible API
5432includes 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
5450Starting with libpng-1.6.0, you can configure libpng to prefix all exported
5451symbols, using the PNG_PREFIX macro.
5452
5453We no longer include string.h in png.h. The include statement has been moved
5454to pngpriv.h, where it is not accessible by applications. Applications that
5455need access to information in string.h must add an '#include "string.h"'
5456directive. It does not matter whether this is placed prior to or after
5457the '"#include png.h"' directive.
5458
5459The 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
5468The 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
5478The 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
5481where "rp" indicates a "restricted pointer".
5482
5483Error detection in some chunks has improved; in particular the iCCP chunk
5484reader now does pretty complete validation of the basic format. Some bad
5485profiles that were previously accepted are now rejected, in particular the
5486very old broken Microsoft/HP sRGB profile. The PNG spec requirement that
5487only grayscale profiles may appear in images with color type 0 or 4 and that
5488even if the image only contains gray pixels, only RGB profiles may appear
5489in images with color type 2, 3, or 6, is now enforced. The sRGB chunk
5490is allowed to appear in images with any color type.
5491
5492The library now issues an error if the application attempts to set a
5493transform after it calls png_read_update_info().
5494
5495The library now issues a warning if both background processing and RGB to
5496gray are used when gamma correction happens. As with previous versions of
5497the library the results are numerically very incorrect in this case.
5498
5499There are some minor arithmetic changes in some transforms such as
5500png_set_background(), that might be detected by certain regression tests.
5501
5502Unknown chunk handling has been improved internally, without any API change.
5503This adds more correct option control of the unknown handling, corrects
5504a pre-existing bug where the per-chunk 'keep' setting is ignored, and makes
5505it possible to skip IDAT chunks in the sequential reader.
5506
5507The machine-generated configure files are no longer included in branches
5508libpng16 and later of the GIT repository. They continue to be included
5509in the tarball releases, however.
5510
5511.SH XIII. Detecting libpng
b61cc19c
PC
5512
5513The png_get_io_ptr() function has been present since libpng-0.88, has never
5514changed, and is unaffected by conditional compilation macros. It is the
5515best choice for use in configure scripts for detecting the presence of any
5516libpng version since 0.88. In an autoconf "configure.in" you could use
5517
5518 AC_CHECK_LIB(png, png_get_io_ptr, ...
5519
fff5f7d5 5520.SH XV. Source code repository
b61cc19c
PC
5521
5522Since about February 2009, version 1.2.34, libpng has been under "git" source
5523control. The git repository was built from old libpng-x.y.z.tar.gz files
5524going back to version 0.70. You can access the git repository (read only)
5525at
5526
fff5f7d5 5527 git://git.code.sf.net/p/libpng/code
b61cc19c 5528
fff5f7d5 5529or you can browse it with a web browser by selecting the "code" button at
b61cc19c 5530
fff5f7d5 5531 https://sourceforge.net/projects/libpng
b61cc19c
PC
5532
5533Patches can be sent to glennrp at users.sourceforge.net or to
5534png-mng-implement at lists.sourceforge.net or you can upload them to
5535the libpng bug tracker at
5536
5537 http://libpng.sourceforge.net
5538
9c0d9ce3
DS
5539We also accept patches built from the tar or zip distributions, and
5540simple verbal discriptions of bug fixes, reported either to the
5541SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5542mailing list, or directly to glennrp.
5543
fff5f7d5 5544.SH XV. Coding style
b61cc19c
PC
5545
5546Our coding style is similar to the "Allman" style, with curly
5547braces on separate lines:
5548
5549 if (condition)
5550 {
5551 action;
5552 }
5553
5554 else if (another condition)
5555 {
5556 another action;
5557 }
5558
5559The braces can be omitted from simple one-line actions:
5560
5561 if (condition)
5562 return (0);
5563
5564We use 3-space indentation, except for continued statements which
5565are usually indented the same as the first line of the statement
5566plus four more spaces.
5567
5568For macro definitions we use 2-space indentation, always leaving the "#"
5569in the first column.
5570
5571 #ifndef PNG_NO_FEATURE
5572 # ifndef PNG_FEATURE_SUPPORTED
5573 # define PNG_FEATURE_SUPPORTED
5574 # endif
5575 #endif
5576
5577Comments appear with the leading "/*" at the same indentation as
5578the 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
5588Very short comments can be placed after the end of the statement
5589to which they pertain:
5590
5591 statement; /* comment */
5592
5593We don't use C++ style ("//") comments. We have, however,
5594used them in the past in some now-abandoned MMX assembler
5595code.
5596
5597Functions and their curly braces are not indented, and
5598exported functions are marked with PNGAPI:
5599
5600 /* This is a public function that is visible to
9c0d9ce3 5601 * application programmers. It does thus-and-so.
b61cc19c
PC
5602 */
5603 void PNGAPI
5604 png_exported_function(png_ptr, png_info, foo)
5605 {
5606 body;
5607 }
5608
5609The prototypes for all exported functions appear in png.h,
5610above the comment that says
5611
5612 /* Maintainer: Put new public prototypes here ... */
5613
5614We 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
5622The prototypes for non-exported functions (except for those in
5623pngtest) appear in
5624pngpriv.h
5625above the comment that says
5626
fff5f7d5
VZ
5627 /* Maintainer: Put new private prototypes here ^ */
5628
5629We put a space after the "sizeof" operator and we omit the
5630optional parentheses around its argument when the argument
5631is an expression, not a type name, and we always enclose the
5632sizeof operator, with its argument, in parentheses:
5633
5634 (sizeof (png_uint_32))
5635 (sizeof array)
5636
5637Prior to libpng-1.6.0 we used a "png_sizeof()" macro, formatted as
5638though it were a function.
b61cc19c 5639
9c0d9ce3 5640To avoid polluting the global namespace, the names of all exported
fff5f7d5
VZ
5641functions and variables begin with "png_", and all publicly visible C
5642preprocessor macros begin with "PNG". We request that applications that
9c0d9ce3 5643use libpng *not* begin any of their own symbols with either of these strings.
b61cc19c
PC
5644
5645We put a space after each comma and after each semicolon
9c0d9ce3 5646in "for" statements, and we put spaces before and after each
b61cc19c
PC
5647C binary operator and after "for" or "while", and before
5648"?". We don't put a space between a typecast and the expression
5649being cast, nor do we put one between a function name and the
5650left parenthesis that follows it:
5651
5652 for (i = 2; i > 0; --i)
5653 y[i] = a(x) + (int)b;
5654
fff5f7d5
VZ
5655We prefer #ifdef and #ifndef to #if defined() and #if !defined()
5656when there is only one macro being tested. We always use parentheses
5657with "defined".
b61cc19c 5658
9c0d9ce3
DS
5659We prefer to express integers that are used as bit masks in hex format,
5660with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
5661
fff5f7d5
VZ
5662We prefer to use underscores in variable names rather than camelCase, except
5663for a few type names that we inherit from zlib.h.
5664
b61cc19c
PC
5665We do not use the TAB character for indentation in the C sources.
5666
5667Lines do not exceed 80 characters.
5668
5669Other rules can be inferred by inspecting the libpng source.
5670
fff5f7d5 5671.SH XVI. Y2K Compliance in libpng
b61cc19c 5672
fff5f7d5 5673April 25, 2013
0272a10d
VZ
5674
5675Since the PNG Development group is an ad-hoc body, we can't make
5676an official declaration.
5677
5678This is your unofficial assurance that libpng from version 0.71 and
fff5f7d5 5679upward through 1.6.2 are Y2K compliant. It is my belief that earlier
0272a10d
VZ
5680versions were also Y2K compliant.
5681
fff5f7d5
VZ
5682Libpng only has two year fields. One is a 2-byte unsigned integer
5683that will hold years up to 65535. The other, which is deprecated,
5684holds the date in text format, and will hold years up to 9999.
0272a10d
VZ
5685
5686The integer is
5687 "png_uint_16 year" in png_time_struct.
5688
fff5f7d5
VZ
5689The string is
5690 "char time_buffer[29]" in png_struct. This is no longer used
5691in libpng-1.6.x and will be removed from libpng-1.7.0.
0272a10d
VZ
5692
5693There 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
5705All appear to handle dates properly in a Y2K environment. The
5706png_convert_from_time_t() function calls gmtime() to convert from system
5707clock time, which returns (year - 1900), which we properly convert to
5708the full 4-digit year. There is a possibility that applications using
5709libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
5710function, or that they are incorrectly passing only a 2-digit year
5711instead of "year - 1900" into the png_convert_from_struct_tm() function,
5712but this is not under our control. The libpng documentation has always
5713stated that it works with 4-digit years, and the APIs have been
5714documented as such.
5715
5716The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
5717integer to hold the year, and can hold years as large as 65535.
5718
5719zlib, upon which libpng depends, is also Y2K compliant. It contains
5720no date-related code.
5721
5722
5723 Glenn Randers-Pehrson
5724 libpng maintainer
5725 PNG Development Group
5726
5727.SH NOTE
5728
5729Note about libpng version numbers:
5730
5731Due to various miscommunications, unforeseen code incompatibilities
5732and occasional factors outside the authors' control, version numbering
5733on the library has not always been consistent and straightforward.
5734The following table summarizes matters since version 0.89c, which was
5735the 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
b61cc19c 5823 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
0272a10d 5824 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
b61cc19c 5825 1.0.17 10 10017 12.so.0.1.0.17
0272a10d
VZ
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
b61cc19c 5828 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
0272a10d 5829 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
b61cc19c 5830 1.0.18 10 10018 12.so.0.1.0.18
0272a10d
VZ
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]
b61cc19c
PC
5836 1.2.10beta1-7 13 10210 12.so.0.10[.0]
5837 1.2.10rc1-2 13 10210 12.so.0.10[.0]
0272a10d 5838 1.2.10 13 10210 12.so.0.10[.0]
b61cc19c
PC
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]
0272a10d 5842 1.2.11 13 10211 12.so.0.11[.0]
0272a10d 5843 1.2.12 13 10212 12.so.0.12[.0]
b61cc19c 5844 1.4.0beta9-14 14 10400 14.so.0.0[.0]
0272a10d 5845 1.2.13 13 10213 12.so.0.13[.0]
b61cc19c
PC
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]
b61cc19c 5855 1.4.1 14 10401 14.so.14.1[.0]
b61cc19c 5856 1.4.2 14 10402 14.so.14.2[.0]
b61cc19c 5857 1.4.3 14 10403 14.so.14.3[.0]
9c0d9ce3
DS
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]
72281370
DS
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]
fff5f7d5
VZ
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]
0272a10d
VZ
5893
5894Henceforth the source version will match the shared-library minor
5895and patch numbers; the shared-library major version number will be
5896used for changes in backward compatibility, as it is intended. The
5897PNG_PNGLIB_VER macro, which is not used within libpng but is available
5898for applications, is an unsigned integer of the form xyyzz corresponding
5899to the source version x.y.z (leading zeros in y and z). Beta versions
5900were given the previous public release number plus a letter, until
5901version 1.0.6j; from then on they were given the upcoming public
5902release number plus "betaNN" or "rcN".
5903
5904.SH "SEE ALSO"
b61cc19c 5905.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
9c0d9ce3 5906
0272a10d
VZ
5907.LP
5908.IR libpng :
5909.IP
5910http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
5911http://www.libpng.org/pub/png
5912
5913.LP
5914.IR zlib :
5915.IP
5916(generally) at the same location as
5917.I libpng
5918or at
5919.br
5920ftp://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
5927or at
5928.br
b61cc19c 5929ftp://ds.internic.net/rfc/rfc2083.txt
0272a10d
VZ
5930.br
5931or (as a W3C Recommendation) at
5932.br
5933http://www.w3.org/TR/REC-png.html
5934
5935.LP
5936In the case of any inconsistency between the PNG specification
5937and this library, the specification takes precedence.
5938
5939.SH AUTHORS
5940This man page: Glenn Randers-Pehrson
5941<glennrp at users.sourceforge.net>
5942
5943The contributing authors would like to thank all those who helped
5944with testing, bug fixes, and patience. This wouldn't have been
5945possible without all of you.
5946
5947Thanks to Frank J. T. Wojcik for helping with the documentation.
5948
fff5f7d5 5949Libpng version 1.6.2 - April 25, 2013:
0272a10d
VZ
5950Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
5951Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
5952
5953Supported by the PNG development group
5954.br
5955png-mng-implement at lists.sf.net
5956(subscription required; visit
5957png-mng-implement at lists.sourceforge.net (subscription required; visit
5958https://lists.sourceforge.net/lists/listinfo/png-mng-implement
5959to 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
5964any discrepancy between this copy and the notices in the file png.h that is
5965included in the libpng distribution, the latter shall prevail.)
5966
5967If you modify libpng you may insert additional notices immediately following
5968this sentence.
5969
b61cc19c
PC
5970This code is released under the libpng license.
5971
fff5f7d5 5972libpng versions 1.2.6, August 15, 2004, through 1.6.2, April 25, 2013, are
b61cc19c 5973Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
0272a10d
VZ
5974distributed according to the same disclaimer and license as libpng-1.2.5
5975with the following individual added to the list of Contributing Authors
5976
5977 Cosmin Truta
5978
5979libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
5980Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
5981distributed according to the same disclaimer and license as libpng-1.0.6
5982with the following individuals added to the list of Contributing Authors
5983
5984 Simon-Pierre Cadieux
5985 Eric S. Raymond
5986 Gilles Vollant
5987
5988and 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
5998libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
5999Copyright (c) 1998, 1999 Glenn Randers-Pehrson
6000Distributed according to the same disclaimer and license as libpng-0.96,
6001with the following individuals added to the list of Contributing Authors:
6002
6003 Tom Lane
6004 Glenn Randers-Pehrson
6005 Willem van Schaik
6006
6007libpng versions 0.89, June 1996, through 0.96, May 1997, are
6008Copyright (c) 1996, 1997 Andreas Dilger
6009Distributed according to the same disclaimer and license as libpng-0.88,
6010with 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
6019libpng versions 0.5, May 1995, through 0.88, January 1996, are
6020Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
6021
6022For the purposes of this copyright and license, "Contributing Authors"
6023is 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
6031The PNG Reference Library is supplied "AS IS". The Contributing Authors
6032and Group 42, Inc. disclaim all warranties, expressed or implied,
6033including, without limitation, the warranties of merchantability and of
6034fitness for any purpose. The Contributing Authors and Group 42, Inc.
6035assume no liability for direct, indirect, incidental, special, exemplary,
6036or consequential damages, which may result from the use of the PNG
6037Reference Library, even if advised of the possibility of such damage.
6038
6039Permission is hereby granted to use, copy, modify, and distribute this
6040source code, or portions hereof, for any purpose, without fee, subject
6041to the following restrictions:
6042
60431. The origin of this source code must not be misrepresented.
6044
60452. Altered versions must be plainly marked as such and
6046 must not be misrepresented as being the original source.
6047
60483. This Copyright notice may not be removed or altered from
6049 any source or altered source distribution.
6050
6051The Contributing Authors and Group 42, Inc. specifically permit, without
6052fee, and encourage the use of this source code as a component to
6053supporting the PNG file format in commercial products. If you use this
6054source code in a product, acknowledgment is not required but would be
6055appreciated.
6056
6057
6058A "png_get_copyright" function is available, for convenient use in "about"
6059boxes and the like:
6060
6061 printf("%s",png_get_copyright(NULL));
6062
6063Also, the PNG logo (in PNG format, of course) is supplied in the
6064files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
6065
6066Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
6067certification mark of the Open Source Initiative.
6068
6069Glenn Randers-Pehrson
6070glennrp at users.sourceforge.net
fff5f7d5 6071April 25, 2013
0272a10d
VZ
6072
6073.\" end of man page
6074