pngstruct.h 15 KB

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