pngstruct.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /* pngstruct.h - header file for PNG reference library
  2. *
  3. * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  4. * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  5. * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  6. *
  7. * Last changed in libpng 1.5.9 [February 18, 2012]
  8. *
  9. * This code is released under the libpng license.
  10. * For conditions of distribution and use, see the disclaimer
  11. * and license in png.h
  12. */
  13. /* The structure that holds the information to read and write PNG files.
  14. * The only people who need to care about what is inside of this are the
  15. * people who will be modifying the library for their own special needs.
  16. * It should NOT be accessed directly by an application.
  17. */
  18. #ifndef PNGSTRUCT_H
  19. #define PNGSTRUCT_H
  20. /* zlib.h defines the structure z_stream, an instance of which is included
  21. * in this structure and is required for decompressing the LZ compressed
  22. * data in PNG files.
  23. */
  24. #include "zlib.h"
  25. struct png_struct_def
  26. {
  27. #ifdef PNG_SETJMP_SUPPORTED
  28. jmp_buf longjmp_buffer; /* used in png_error */
  29. png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
  30. #endif
  31. png_error_ptr error_fn; /* function for printing errors and aborting */
  32. #ifdef PNG_WARNINGS_SUPPORTED
  33. png_error_ptr warning_fn; /* function for printing warnings */
  34. #endif
  35. png_voidp error_ptr; /* user supplied struct for error functions */
  36. png_rw_ptr write_data_fn; /* function for writing output data */
  37. png_rw_ptr read_data_fn; /* function for reading input data */
  38. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  39. #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
  40. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  41. #endif
  42. #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
  43. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  44. #endif
  45. /* These were added in libpng-1.0.2 */
  46. #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
  47. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  48. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  49. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  50. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  51. png_byte user_transform_channels; /* channels in user transformed pixels */
  52. #endif
  53. #endif
  54. 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 */
  57. z_stream zstream; /* pointer to decompression structure (below) */
  58. png_bytep zbuf; /* buffer for zlib */
  59. uInt zbuf_size; /* size of zbuf (typically 65536) */
  60. #ifdef PNG_WRITE_SUPPORTED
  61. /* Added in 1.5.4: state to keep track of whether the zstream has been
  62. * initialized and if so whether it is for IDAT or some other chunk.
  63. */
  64. #define PNG_ZLIB_UNINITIALIZED 0
  65. #define PNG_ZLIB_FOR_IDAT 1
  66. #define PNG_ZLIB_FOR_TEXT 2 /* anything other than IDAT */
  67. #define PNG_ZLIB_USE_MASK 3 /* bottom two bits */
  68. #define PNG_ZLIB_IN_USE 4 /* a flag value */
  69. png_uint_32 zlib_state; /* State of zlib initialization */
  70. /* End of material added at libpng 1.5.4 */
  71. int zlib_level; /* holds zlib compression level */
  72. int zlib_method; /* holds zlib compression method */
  73. int zlib_window_bits; /* holds zlib compression window bits */
  74. int zlib_mem_level; /* holds zlib compression memory level */
  75. int zlib_strategy; /* holds zlib compression strategy */
  76. #endif
  77. /* Added at libpng 1.5.4 */
  78. #if defined(PNG_WRITE_COMPRESSED_TEXT_SUPPORTED) || \
  79. defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED)
  80. int zlib_text_level; /* holds zlib compression level */
  81. int zlib_text_method; /* holds zlib compression method */
  82. int zlib_text_window_bits; /* holds zlib compression window bits */
  83. int zlib_text_mem_level; /* holds zlib compression memory level */
  84. int zlib_text_strategy; /* holds zlib compression strategy */
  85. #endif
  86. /* End of material added at libpng 1.5.4 */
  87. png_uint_32 width; /* width of image in pixels */
  88. png_uint_32 height; /* height of image in pixels */
  89. png_uint_32 num_rows; /* number of rows in current pass */
  90. png_uint_32 usr_width; /* width of row at start of write */
  91. png_size_t rowbytes; /* size of row in bytes */
  92. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  93. png_uint_32 row_number; /* current row in interlace pass */
  94. png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
  95. png_bytep prev_row; /* buffer to save previous (unfiltered) row.
  96. * This is a pointer into big_prev_row
  97. */
  98. png_bytep row_buf; /* buffer to save current (unfiltered) row.
  99. * This is a pointer into big_row_buf
  100. */
  101. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  102. png_bytep up_row; /* buffer to save "up" row when filtering */
  103. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  104. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  105. png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
  106. png_uint_32 idat_size; /* current IDAT size for read */
  107. png_uint_32 crc; /* current chunk CRC value */
  108. png_colorp palette; /* palette from the input file */
  109. png_uint_16 num_palette; /* number of color entries in palette */
  110. png_uint_16 num_trans; /* number of transparency values */
  111. png_byte compression; /* file compression type (always 0) */
  112. png_byte filter; /* file filter type (always 0) */
  113. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  114. png_byte pass; /* current interlace pass (0 - 6) */
  115. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  116. png_byte color_type; /* color type of file */
  117. png_byte bit_depth; /* bit depth of file */
  118. png_byte usr_bit_depth; /* bit depth of users row: write only */
  119. png_byte pixel_depth; /* number of bits per pixel */
  120. png_byte channels; /* number of channels in file */
  121. png_byte usr_channels; /* channels at start of write: write only */
  122. png_byte sig_bytes; /* magic bytes read/written from start of file */
  123. png_byte maximum_pixel_depth;
  124. /* pixel depth used for the row buffers */
  125. png_byte transformed_pixel_depth;
  126. /* pixel depth after read/write transforms */
  127. png_byte io_chunk_string[5];
  128. /* string name of chunk */
  129. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  130. png_uint_16 filler; /* filler bytes for pixel expansion */
  131. #endif
  132. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
  133. defined(PNG_READ_ALPHA_MODE_SUPPORTED)
  134. png_byte background_gamma_type;
  135. png_fixed_point background_gamma;
  136. png_color_16 background; /* background color in screen gamma space */
  137. #ifdef PNG_READ_GAMMA_SUPPORTED
  138. png_color_16 background_1; /* background normalized to gamma 1.0 */
  139. #endif
  140. #endif /* PNG_bKGD_SUPPORTED */
  141. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  142. png_flush_ptr output_flush_fn; /* Function for flushing output */
  143. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  144. png_uint_32 flush_rows; /* number of rows written since last flush */
  145. #endif
  146. #ifdef PNG_READ_GAMMA_SUPPORTED
  147. int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
  148. png_fixed_point gamma; /* file gamma value */
  149. png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
  150. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  151. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  152. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  153. defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
  154. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  155. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  156. png_bytep gamma_to_1; /* converts from file to 1.0 */
  157. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  158. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  159. #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
  160. #endif
  161. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  162. png_color_8 sig_bit; /* significant bits in each available channel */
  163. #endif
  164. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  165. png_color_8 shift; /* shift for significant bit tranformation */
  166. #endif
  167. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  168. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169. png_bytep trans_alpha; /* alpha values for paletted files */
  170. png_color_16 trans_color; /* transparent color for non-paletted files */
  171. #endif
  172. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  173. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  174. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  175. png_progressive_info_ptr info_fn; /* called after header data fully read */
  176. png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
  177. png_progressive_end_ptr end_fn; /* called after image is complete */
  178. png_bytep save_buffer_ptr; /* current location in save_buffer */
  179. png_bytep save_buffer; /* buffer for previously read data */
  180. png_bytep current_buffer_ptr; /* current location in current_buffer */
  181. png_bytep current_buffer; /* buffer for recently used data */
  182. png_uint_32 push_length; /* size of current input chunk */
  183. png_uint_32 skip_length; /* bytes to skip in input data */
  184. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  185. png_size_t save_buffer_max; /* total size of save_buffer */
  186. png_size_t buffer_size; /* total amount of available input data */
  187. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  188. int process_mode; /* what push library is currently doing */
  189. int cur_palette; /* current push library palette index */
  190. # ifdef PNG_TEXT_SUPPORTED
  191. png_size_t current_text_size; /* current size of text input data */
  192. png_size_t current_text_left; /* how much text left to read in input */
  193. png_charp current_text; /* current text chunk buffer */
  194. png_charp current_text_ptr; /* current location in current_text */
  195. # endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
  196. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  197. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  198. /* For the Borland special 64K segment handler */
  199. png_bytepp offset_table_ptr;
  200. png_bytep offset_table;
  201. png_uint_16 offset_table_number;
  202. png_uint_16 offset_table_count;
  203. png_uint_16 offset_table_count_free;
  204. #endif
  205. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  206. png_bytep palette_lookup; /* lookup table for quantizing */
  207. png_bytep quantize_index; /* index translation for palette files */
  208. #endif
  209. #if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  210. png_uint_16p hist; /* histogram */
  211. #endif
  212. #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  213. png_byte heuristic_method; /* heuristic for row filter selection */
  214. png_byte num_prev_filters; /* number of weights for previous rows */
  215. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  216. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  217. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  218. png_uint_16p filter_costs; /* relative filter calculation cost */
  219. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  220. #endif
  221. #ifdef PNG_TIME_RFC1123_SUPPORTED
  222. char time_buffer[29]; /* String to hold RFC 1123 time text */
  223. #endif
  224. /* New members added in libpng-1.0.6 */
  225. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  226. #ifdef PNG_USER_CHUNKS_SUPPORTED
  227. png_voidp user_chunk_ptr;
  228. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  229. #endif
  230. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  231. int num_chunk_list;
  232. png_bytep chunk_list;
  233. #endif
  234. #ifdef PNG_READ_sRGB_SUPPORTED
  235. /* Added in 1.5.5 to record an sRGB chunk in the png. */
  236. png_byte is_sRGB;
  237. #endif
  238. /* New members added in libpng-1.0.3 */
  239. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  240. png_byte rgb_to_gray_status;
  241. /* Added in libpng 1.5.5 to record setting of coefficients: */
  242. png_byte rgb_to_gray_coefficients_set;
  243. /* These were changed from png_byte in libpng-1.0.6 */
  244. png_uint_16 rgb_to_gray_red_coeff;
  245. png_uint_16 rgb_to_gray_green_coeff;
  246. /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
  247. #endif
  248. /* New member added in libpng-1.0.4 (renamed in 1.0.9) */
  249. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  250. /* Changed from png_byte to png_uint_32 at version 1.2.0 */
  251. png_uint_32 mng_features_permitted;
  252. #endif
  253. /* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
  254. #ifdef PNG_MNG_FEATURES_SUPPORTED
  255. png_byte filter_type;
  256. #endif
  257. /* New members added in libpng-1.2.0 */
  258. /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
  259. #ifdef PNG_USER_MEM_SUPPORTED
  260. png_voidp mem_ptr; /* user supplied struct for mem functions */
  261. png_malloc_ptr malloc_fn; /* function for allocating memory */
  262. png_free_ptr free_fn; /* function for freeing memory */
  263. #endif
  264. /* New member added in libpng-1.0.13 and 1.2.0 */
  265. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  266. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  267. /* The following three members were added at version 1.0.14 and 1.2.4 */
  268. png_bytep quantize_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 */
  273. #endif
  274. /* New members added in libpng-1.0.16 and 1.2.6 */
  275. png_byte compression_type;
  276. #ifdef PNG_USER_LIMITS_SUPPORTED
  277. png_uint_32 user_width_max;
  278. png_uint_32 user_height_max;
  279. /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
  280. * chunks that can be stored (0 means unlimited).
  281. */
  282. png_uint_32 user_chunk_cache_max;
  283. /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
  284. * can occupy when decompressed. 0 means unlimited.
  285. */
  286. png_alloc_size_t user_chunk_malloc_max;
  287. #endif
  288. /* New member added in libpng-1.0.25 and 1.2.17 */
  289. #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
  290. /* Storage for unknown chunk that the library doesn't recognize. */
  291. png_unknown_chunk unknown_chunk;
  292. #endif
  293. /* New member added in libpng-1.2.26 */
  294. png_size_t old_big_row_buf_size;
  295. /* New member added in libpng-1.2.30 */
  296. png_charp chunkdata; /* buffer for reading chunk data */
  297. #ifdef PNG_IO_STATE_SUPPORTED
  298. /* New member added in libpng-1.4.0 */
  299. png_uint_32 io_state;
  300. #endif
  301. /* New member added in libpng-1.5.6 */
  302. png_bytep big_prev_row;
  303. void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
  304. png_bytep row, png_const_bytep prev_row);
  305. };
  306. #endif /* PNGSTRUCT_H */