pngstruct.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* pngstruct.h - header file for PNG reference library
  2. *
  3. * Copyright (c) 1998-2012 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. /* Added at libpng-1.5.10 */
  111. #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  112. int num_palette_max; /* maximum palette index found in IDAT */
  113. #endif
  114. png_uint_16 num_trans; /* number of transparency values */
  115. png_byte compression; /* file compression type (always 0) */
  116. png_byte filter; /* file filter type (always 0) */
  117. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  118. png_byte pass; /* current interlace pass (0 - 6) */
  119. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  120. png_byte color_type; /* color type of file */
  121. png_byte bit_depth; /* bit depth of file */
  122. png_byte usr_bit_depth; /* bit depth of users row: write only */
  123. png_byte pixel_depth; /* number of bits per pixel */
  124. png_byte channels; /* number of channels in file */
  125. png_byte usr_channels; /* channels at start of write: write only */
  126. png_byte sig_bytes; /* magic bytes read/written from start of file */
  127. png_byte maximum_pixel_depth;
  128. /* pixel depth used for the row buffers */
  129. png_byte transformed_pixel_depth;
  130. /* pixel depth after read/write transforms */
  131. png_byte io_chunk_string[5];
  132. /* string name of chunk */
  133. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  134. png_uint_16 filler; /* filler bytes for pixel expansion */
  135. #endif
  136. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
  137. defined(PNG_READ_ALPHA_MODE_SUPPORTED)
  138. png_byte background_gamma_type;
  139. png_fixed_point background_gamma;
  140. png_color_16 background; /* background color in screen gamma space */
  141. #ifdef PNG_READ_GAMMA_SUPPORTED
  142. png_color_16 background_1; /* background normalized to gamma 1.0 */
  143. #endif
  144. #endif /* PNG_bKGD_SUPPORTED */
  145. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  146. png_flush_ptr output_flush_fn; /* Function for flushing output */
  147. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  148. png_uint_32 flush_rows; /* number of rows written since last flush */
  149. #endif
  150. #ifdef PNG_READ_GAMMA_SUPPORTED
  151. int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
  152. png_fixed_point gamma; /* file gamma value */
  153. png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
  154. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  155. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  156. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  157. defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
  158. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  159. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  162. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  163. #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
  164. #endif
  165. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  166. png_color_8 sig_bit; /* significant bits in each available channel */
  167. #endif
  168. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  169. png_color_8 shift; /* shift for significant bit tranformation */
  170. #endif
  171. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  172. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  173. png_bytep trans_alpha; /* alpha values for paletted files */
  174. png_color_16 trans_color; /* transparent color for non-paletted files */
  175. #endif
  176. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  177. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  178. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  179. png_progressive_info_ptr info_fn; /* called after header data fully read */
  180. png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
  181. png_progressive_end_ptr end_fn; /* called after image is complete */
  182. png_bytep save_buffer_ptr; /* current location in save_buffer */
  183. png_bytep save_buffer; /* buffer for previously read data */
  184. png_bytep current_buffer_ptr; /* current location in current_buffer */
  185. png_bytep current_buffer; /* buffer for recently used data */
  186. png_uint_32 push_length; /* size of current input chunk */
  187. png_uint_32 skip_length; /* bytes to skip in input data */
  188. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  189. png_size_t save_buffer_max; /* total size of save_buffer */
  190. png_size_t buffer_size; /* total amount of available input data */
  191. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  192. int process_mode; /* what push library is currently doing */
  193. int cur_palette; /* current push library palette index */
  194. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  195. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  196. /* For the Borland special 64K segment handler */
  197. png_bytepp offset_table_ptr;
  198. png_bytep offset_table;
  199. png_uint_16 offset_table_number;
  200. png_uint_16 offset_table_count;
  201. png_uint_16 offset_table_count_free;
  202. #endif
  203. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  204. png_bytep palette_lookup; /* lookup table for quantizing */
  205. png_bytep quantize_index; /* index translation for palette files */
  206. #endif
  207. #if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  208. png_uint_16p hist; /* histogram */
  209. #endif
  210. #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  211. png_byte heuristic_method; /* heuristic for row filter selection */
  212. png_byte num_prev_filters; /* number of weights for previous rows */
  213. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  214. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  215. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  216. png_uint_16p filter_costs; /* relative filter calculation cost */
  217. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  218. #endif
  219. #ifdef PNG_TIME_RFC1123_SUPPORTED
  220. /* This is going to be unused in libpng16 and removed from libpng17 */
  221. char time_buffer[29]; /* String to hold RFC 1123 time text */
  222. #endif
  223. /* New members added in libpng-1.0.6 */
  224. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  225. #ifdef PNG_USER_CHUNKS_SUPPORTED
  226. png_voidp user_chunk_ptr;
  227. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  228. #endif
  229. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  230. int num_chunk_list;
  231. png_bytep chunk_list;
  232. #endif
  233. #ifdef PNG_READ_sRGB_SUPPORTED
  234. /* Added in 1.5.5 to record an sRGB chunk in the png. */
  235. png_byte is_sRGB;
  236. #endif
  237. /* New members added in libpng-1.0.3 */
  238. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  239. png_byte rgb_to_gray_status;
  240. /* Added in libpng 1.5.5 to record setting of coefficients: */
  241. png_byte rgb_to_gray_coefficients_set;
  242. /* These were changed from png_byte in libpng-1.0.6 */
  243. png_uint_16 rgb_to_gray_red_coeff;
  244. png_uint_16 rgb_to_gray_green_coeff;
  245. /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
  246. #endif
  247. /* New member added in libpng-1.0.4 (renamed in 1.0.9) */
  248. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  249. /* Changed from png_byte to png_uint_32 at version 1.2.0 */
  250. png_uint_32 mng_features_permitted;
  251. #endif
  252. /* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
  253. #ifdef PNG_MNG_FEATURES_SUPPORTED
  254. png_byte filter_type;
  255. #endif
  256. /* New members added in libpng-1.2.0 */
  257. /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
  258. #ifdef PNG_USER_MEM_SUPPORTED
  259. png_voidp mem_ptr; /* user supplied struct for mem functions */
  260. png_malloc_ptr malloc_fn; /* function for allocating memory */
  261. png_free_ptr free_fn; /* function for freeing memory */
  262. #endif
  263. /* New member added in libpng-1.0.13 and 1.2.0 */
  264. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  265. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  266. /* The following three members were added at version 1.0.14 and 1.2.4 */
  267. png_bytep quantize_sort; /* working sort array */
  268. png_bytep index_to_palette; /* where the original index currently is
  269. in the palette */
  270. png_bytep palette_to_index; /* which original index points to this
  271. palette color */
  272. #endif
  273. /* New members added in libpng-1.0.16 and 1.2.6 */
  274. png_byte compression_type;
  275. #ifdef PNG_USER_LIMITS_SUPPORTED
  276. png_uint_32 user_width_max;
  277. png_uint_32 user_height_max;
  278. /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
  279. * chunks that can be stored (0 means unlimited).
  280. */
  281. png_uint_32 user_chunk_cache_max;
  282. /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
  283. * can occupy when decompressed. 0 means unlimited.
  284. */
  285. png_alloc_size_t user_chunk_malloc_max;
  286. #endif
  287. /* New member added in libpng-1.0.25 and 1.2.17 */
  288. #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
  289. /* Storage for unknown chunk that the library doesn't recognize. */
  290. png_unknown_chunk unknown_chunk;
  291. #endif
  292. /* New member added in libpng-1.2.26 */
  293. png_size_t old_big_row_buf_size;
  294. /* New member added in libpng-1.2.30 */
  295. png_charp chunkdata; /* buffer for reading chunk data */
  296. #ifdef PNG_IO_STATE_SUPPORTED
  297. /* New member added in libpng-1.4.0 */
  298. png_uint_32 io_state;
  299. #endif
  300. /* New member added in libpng-1.5.6 */
  301. png_bytep big_prev_row;
  302. void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
  303. png_bytep row, png_const_bytep prev_row);
  304. };
  305. #endif /* PNGSTRUCT_H */