blob: 5133fda4c58a3351cf5e1ed03c9a5709c2cd4375 [file] [log] [blame]
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -06001
2/* pngstruct.h - header file for PNG reference library
3 *
4 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7 *
Glenn Randers-Pehrsonc6fecfb2010-03-09 22:27:26 -06008 * Last changed in libpng version 1.5.0 - March 10, 2010
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -06009 *
10 * This code is released under the libpng license.
11 * For conditions of distribution and use, see the disclaimer
12 * and license in png.h
13 */
14
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060015/* The structure that holds the information to read and write PNG files.
16 * The only people who need to care about what is inside of this are the
17 * people who will be modifying the library for their own special needs.
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060018 * It should NOT be accessed directly by an application.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060019 */
20
Glenn Randers-Pehrsonc957b6b2010-03-08 21:47:07 -060021#ifndef PNGSTRUCT_H
22#define PNGSTRUCT_H
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060023struct png_struct_def
24{
25#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson95ca51b2010-02-19 14:09:09 -060026 jmp_buf png_jmpbuf; /* used in png_error */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060027 png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060028#endif
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060029 png_error_ptr error_fn; /* function for printing errors and aborting */
30 png_error_ptr warning_fn; /* function for printing warnings */
31 png_voidp error_ptr; /* user supplied struct for error functions */
32 png_rw_ptr write_data_fn; /* function for writing output data */
33 png_rw_ptr read_data_fn; /* function for reading input data */
34 png_voidp io_ptr; /* ptr to application struct for I/O functions */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060035
36#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060037 png_user_transform_ptr read_user_transform_fn; /* user read transform */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060038#endif
39
40#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060041 png_user_transform_ptr write_user_transform_fn; /* user write transform */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060042#endif
43
44/* These were added in libpng-1.0.2 */
45#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
46#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
47 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060048 png_voidp user_transform_ptr; /* user supplied struct for user transform */
49 png_byte user_transform_depth; /* bit depth of user transformed pixels */
50 png_byte user_transform_channels; /* channels in user transformed pixels */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060051#endif
52#endif
53
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060054 png_uint_32 mode; /* tells us where we are in the PNG file */
55 png_uint_32 flags; /* flags indicating various things to libpng */
56 png_uint_32 transformations; /* which transformations to perform */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060057
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060058 z_stream zstream; /* pointer to decompression structure (below) */
59 png_bytep zbuf; /* buffer for zlib */
60 png_size_t zbuf_size; /* size of zbuf */
61 int zlib_level; /* holds zlib compression level */
62 int zlib_method; /* holds zlib compression method */
63 int zlib_window_bits; /* holds zlib compression window bits */
64 int zlib_mem_level; /* holds zlib compression memory level */
65 int zlib_strategy; /* holds zlib compression strategy */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060066
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060067 png_uint_32 width; /* width of image in pixels */
68 png_uint_32 height; /* height of image in pixels */
69 png_uint_32 num_rows; /* number of rows in current pass */
70 png_uint_32 usr_width; /* width of row at start of write */
71 png_size_t rowbytes; /* size of row in bytes */
72 png_uint_32 iwidth; /* width of current interlaced row in pixels */
73 png_uint_32 row_number; /* current row in interlace pass */
74 png_bytep prev_row; /* buffer to save previous (unfiltered) row */
75 png_bytep row_buf; /* buffer to save current (unfiltered) row */
76 png_bytep sub_row; /* buffer to save "sub" row when filtering */
77 png_bytep up_row; /* buffer to save "up" row when filtering */
78 png_bytep avg_row; /* buffer to save "avg" row when filtering */
79 png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
80 png_row_info row_info; /* used for transformation routines */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060081
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060082 png_uint_32 idat_size; /* current IDAT size for read */
83 png_uint_32 crc; /* current chunk CRC value */
84 png_colorp palette; /* palette from the input file */
85 png_uint_16 num_palette; /* number of color entries in palette */
86 png_uint_16 num_trans; /* number of transparency values */
87 png_byte chunk_name[5]; /* null-terminated name of current chunk */
88 png_byte compression; /* file compression type (always 0) */
89 png_byte filter; /* file filter type (always 0) */
90 png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
91 png_byte pass; /* current interlace pass (0 - 6) */
92 png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
93 png_byte color_type; /* color type of file */
94 png_byte bit_depth; /* bit depth of file */
95 png_byte usr_bit_depth; /* bit depth of users row */
96 png_byte pixel_depth; /* number of bits per pixel */
97 png_byte channels; /* number of channels in file */
98 png_byte usr_channels; /* channels at start of write */
99 png_byte sig_bytes; /* magic bytes read/written from start of file */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600100
101#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600102 png_uint_16 filler; /* filler bytes for pixel expansion */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600103#endif
104
105#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600106 png_byte background_gamma_type;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600107# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600108 float background_gamma;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600109# endif
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600110 png_color_16 background; /* background color in screen gamma space */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600111#ifdef PNG_READ_GAMMA_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600112 png_color_16 background_1; /* background normalized to gamma 1.0 */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600113#endif
114#endif /* PNG_bKGD_SUPPORTED */
115
116#ifdef PNG_WRITE_FLUSH_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600117 png_flush_ptr output_flush_fn; /* Function for flushing output */
118 png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
119 png_uint_32 flush_rows; /* number of rows written since last flush */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600120#endif
121
122#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600123 int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600124#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600125 float gamma; /* file gamma value */
126 float screen_gamma; /* screen gamma value (display_exponent) */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600127#endif
128#endif
129
130#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600131 png_bytep gamma_table; /* gamma table for 8-bit depth files */
132 png_bytep gamma_from_1; /* converts from 1.0 to screen */
133 png_bytep gamma_to_1; /* converts from file to 1.0 */
134 png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
135 png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
136 png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600137#endif
138
139#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600140 png_color_8 sig_bit; /* significant bits in each available channel */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600141#endif
142
143#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600144 png_color_8 shift; /* shift for significant bit tranformation */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600145#endif
146
147#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
148 || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600149 png_bytep trans_alpha; /* alpha values for paletted files */
150 png_color_16 trans_color; /* transparent color for non-paletted files */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600151#endif
152
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600153 png_read_status_ptr read_row_fn; /* called after each row is decoded */
154 png_write_status_ptr write_row_fn; /* called after each row is encoded */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600155#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600156 png_progressive_info_ptr info_fn; /* called after header data fully read */
157 png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
158 png_progressive_end_ptr end_fn; /* called after image is complete */
159 png_bytep save_buffer_ptr; /* current location in save_buffer */
160 png_bytep save_buffer; /* buffer for previously read data */
161 png_bytep current_buffer_ptr; /* current location in current_buffer */
162 png_bytep current_buffer; /* buffer for recently used data */
163 png_uint_32 push_length; /* size of current input chunk */
164 png_uint_32 skip_length; /* bytes to skip in input data */
165 png_size_t save_buffer_size; /* amount of data now in save_buffer */
166 png_size_t save_buffer_max; /* total size of save_buffer */
167 png_size_t buffer_size; /* total amount of available input data */
168 png_size_t current_buffer_size; /* amount of data now in current_buffer */
169 int process_mode; /* what push library is currently doing */
170 int cur_palette; /* current push library palette index */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600171
172# ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600173 png_size_t current_text_size; /* current size of text input data */
174 png_size_t current_text_left; /* how much text left to read in input */
175 png_charp current_text; /* current text chunk buffer */
176 png_charp current_text_ptr; /* current location in current_text */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600177# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
178
179#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
180
181#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
182/* For the Borland special 64K segment handler */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600183 png_bytepp offset_table_ptr;
184 png_bytep offset_table;
185 png_uint_16 offset_table_number;
186 png_uint_16 offset_table_count;
187 png_uint_16 offset_table_count_free;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600188#endif
189
190#ifdef PNG_READ_DITHER_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600191 png_bytep palette_lookup; /* lookup table for dithering */
192 png_bytep dither_index; /* index translation for palette files */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600193#endif
194
195#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600196 png_uint_16p hist; /* histogram */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600197#endif
198
199#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600200 png_byte heuristic_method; /* heuristic for row filter selection */
201 png_byte num_prev_filters; /* number of weights for previous rows */
202 png_bytep prev_filters; /* filter type(s) of previous row(s) */
203 png_uint_16p filter_weights; /* weight(s) for previous line(s) */
204 png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
205 png_uint_16p filter_costs; /* relative filter calculation cost */
206 png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600207#endif
208
209#ifdef PNG_TIME_RFC1123_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600210 png_charp time_buffer; /* String to hold RFC 1123 time text */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600211#endif
212
213/* New members added in libpng-1.0.6 */
214
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600215 png_uint_32 free_me; /* flags items libpng is responsible for freeing */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600216
217#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600218 png_voidp user_chunk_ptr;
219 png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600220#endif
221
222#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600223 int num_chunk_list;
224 png_bytep chunk_list;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600225#endif
226
227/* New members added in libpng-1.0.3 */
228#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600229 png_byte rgb_to_gray_status;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600230 /* These were changed from png_byte in libpng-1.0.6 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600231 png_uint_16 rgb_to_gray_red_coeff;
232 png_uint_16 rgb_to_gray_green_coeff;
233 png_uint_16 rgb_to_gray_blue_coeff;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600234#endif
235
236/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
237#if defined(PNG_MNG_FEATURES_SUPPORTED) || \
238 defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
239 defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
240/* Changed from png_byte to png_uint_32 at version 1.2.0 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600241 png_uint_32 mng_features_permitted;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600242#endif
243
244/* New member added in libpng-1.0.7 */
245#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600246 png_fixed_point int_gamma;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600247#endif
248
249/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
250#ifdef PNG_MNG_FEATURES_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600251 png_byte filter_type;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600252#endif
253
254/* New members added in libpng-1.2.0 */
255
256/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
257#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600258 png_voidp mem_ptr; /* user supplied struct for mem functions */
259 png_malloc_ptr malloc_fn; /* function for allocating memory */
260 png_free_ptr free_fn; /* function for freeing memory */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600261#endif
262
263/* New member added in libpng-1.0.13 and 1.2.0 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600264 png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600265
266#ifdef PNG_READ_DITHER_SUPPORTED
267/* The following three members were added at version 1.0.14 and 1.2.4 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600268 png_bytep dither_sort; /* working sort array */
269 png_bytep index_to_palette; /* where the original index currently is
270 in the palette */
271 png_bytep palette_to_index; /* which original index points to this
272 palette color */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600273#endif
274
275/* New members added in libpng-1.0.16 and 1.2.6 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600276 png_byte compression_type;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600277
278#ifdef PNG_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600279 png_uint_32 user_width_max;
280 png_uint_32 user_height_max;
281
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600282 /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
283 * chunks that can be stored (0 means unlimited).
284 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600285 png_uint_32 user_chunk_cache_max;
286
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600287 /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
288 * can occupy when decompressed. 0 means unlimited.
289 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600290 png_uint_32 user_chunk_malloc_max;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600291#endif
292
293/* New member added in libpng-1.0.25 and 1.2.17 */
294#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
295 /* Storage for unknown chunk that the library doesn't recognize. */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600296 png_unknown_chunk unknown_chunk;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600297#endif
298
299/* New members added in libpng-1.2.26 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600300 png_uint_32 old_big_row_buf_size;
301 png_uint_32 old_prev_row_size;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600302
303/* New member added in libpng-1.2.30 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600304 png_charp chunkdata; /* buffer for reading chunk data */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600305
306#ifdef PNG_IO_STATE_SUPPORTED
307/* New member added in libpng-1.4.0 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600308 png_uint_32 io_state;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600309#endif
310};
Glenn Randers-Pehrsonc957b6b2010-03-08 21:47:07 -0600311#endif /* PNGSTRUCT_H */