Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

490 lines
20KB

  1. /* pngstruct.h - header file for PNG reference library
  2. *
  3. * Copyright (c) 1998-2013 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.6.1 [March 28, 2013]
  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. #ifndef ZLIB_CONST
  25. /* We must ensure that zlib uses 'const' in declarations. */
  26. # define ZLIB_CONST
  27. #endif
  28. #include "../../../juce_core/zip/zlib/zlib.h"
  29. #ifdef const
  30. /* zlib.h sometimes #defines const to nothing, undo this. */
  31. # undef const
  32. #endif
  33. /* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility
  34. * with older builds.
  35. */
  36. #if ZLIB_VERNUM < 0x1260
  37. # define PNGZ_MSG_CAST(s) png_constcast(char*,s)
  38. # define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)
  39. #else
  40. # define PNGZ_MSG_CAST(s) (s)
  41. # define PNGZ_INPUT_CAST(b) (b)
  42. #endif
  43. /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
  44. * can handle at once. This type need be no larger than 16 bits (so maximum of
  45. * 65535), this define allows us to discover how big it is, but limited by the
  46. * maximuum for png_size_t. The value can be overriden in a library build
  47. * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
  48. * lower value (e.g. 255 works). A lower value may help memory usage (slightly)
  49. * and may even improve performance on some systems (and degrade it on others.)
  50. */
  51. #ifndef ZLIB_IO_MAX
  52. # define ZLIB_IO_MAX ((uInt)-1)
  53. #endif
  54. #ifdef PNG_WRITE_SUPPORTED
  55. /* The type of a compression buffer list used by the write code. */
  56. typedef struct png_compression_buffer
  57. {
  58. struct png_compression_buffer *next;
  59. png_byte output[1]; /* actually zbuf_size */
  60. } png_compression_buffer, *png_compression_bufferp;
  61. #define PNG_COMPRESSION_BUFFER_SIZE(pp)\
  62. (offsetof(png_compression_buffer, output) + (pp)->zbuffer_size)
  63. #endif
  64. /* Colorspace support; structures used in png_struct, png_info and in internal
  65. * functions to hold and communicate information about the color space.
  66. *
  67. * PNG_COLORSPACE_SUPPORTED is only required if the application will perform
  68. * colorspace corrections, otherwise all the colorspace information can be
  69. * skipped and the size of libpng can be reduced (significantly) by compiling
  70. * out the colorspace support.
  71. */
  72. #ifdef PNG_COLORSPACE_SUPPORTED
  73. /* The chromaticities of the red, green and blue colorants and the chromaticity
  74. * of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).
  75. */
  76. typedef struct png_xy
  77. {
  78. png_fixed_point redx, redy;
  79. png_fixed_point greenx, greeny;
  80. png_fixed_point bluex, bluey;
  81. png_fixed_point whitex, whitey;
  82. } png_xy;
  83. /* The same data as above but encoded as CIE XYZ values. When this data comes
  84. * from chromaticities the sum of the Y values is assumed to be 1.0
  85. */
  86. typedef struct png_XYZ
  87. {
  88. png_fixed_point red_X, red_Y, red_Z;
  89. png_fixed_point green_X, green_Y, green_Z;
  90. png_fixed_point blue_X, blue_Y, blue_Z;
  91. } png_XYZ;
  92. #endif /* COLORSPACE */
  93. #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
  94. /* A colorspace is all the above plus, potentially, profile information,
  95. * however at present libpng does not use the profile internally so it is only
  96. * stored in the png_info struct (if iCCP is supported.) The rendering intent
  97. * is retained here and is checked.
  98. *
  99. * The file gamma encoding information is also stored here and gamma correction
  100. * is done by libpng, whereas color correction must currently be done by the
  101. * application.
  102. */
  103. typedef struct png_colorspace
  104. {
  105. #ifdef PNG_GAMMA_SUPPORTED
  106. png_fixed_point gamma; /* File gamma */
  107. #endif
  108. #ifdef PNG_COLORSPACE_SUPPORTED
  109. png_xy end_points_xy; /* End points as chromaticities */
  110. png_XYZ end_points_XYZ; /* End points as CIE XYZ colorant values */
  111. png_uint_16 rendering_intent; /* Rendering intent of a profile */
  112. #endif
  113. /* Flags are always defined to simplify the code. */
  114. png_uint_16 flags; /* As defined below */
  115. } png_colorspace, * PNG_RESTRICT png_colorspacerp;
  116. typedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;
  117. /* General flags for the 'flags' field */
  118. #define PNG_COLORSPACE_HAVE_GAMMA 0x0001
  119. #define PNG_COLORSPACE_HAVE_ENDPOINTS 0x0002
  120. #define PNG_COLORSPACE_HAVE_INTENT 0x0004
  121. #define PNG_COLORSPACE_FROM_gAMA 0x0008
  122. #define PNG_COLORSPACE_FROM_cHRM 0x0010
  123. #define PNG_COLORSPACE_FROM_sRGB 0x0020
  124. #define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040
  125. #define PNG_COLORSPACE_MATCHES_sRGB 0x0080 /* exact match on profile */
  126. #define PNG_COLORSPACE_INVALID 0x8000
  127. #define PNG_COLORSPACE_CANCEL(flags) (0xffff ^ (flags))
  128. #endif /* COLORSPACE || GAMMA */
  129. struct png_struct_def
  130. {
  131. #ifdef PNG_SETJMP_SUPPORTED
  132. jmp_buf jmp_buf_local; /* New name in 1.6.0 for jmp_buf in png_struct */
  133. png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
  134. jmp_buf *jmp_buf_ptr; /* passed to longjmp_fn */
  135. size_t jmp_buf_size; /* size of the above, if allocated */
  136. #endif
  137. png_error_ptr error_fn; /* function for printing errors and aborting */
  138. #ifdef PNG_WARNINGS_SUPPORTED
  139. png_error_ptr warning_fn; /* function for printing warnings */
  140. #endif
  141. png_voidp error_ptr; /* user supplied struct for error functions */
  142. png_rw_ptr write_data_fn; /* function for writing output data */
  143. png_rw_ptr read_data_fn; /* function for reading input data */
  144. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  145. #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
  146. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  147. #endif
  148. #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
  149. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  150. #endif
  151. /* These were added in libpng-1.0.2 */
  152. #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
  153. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  154. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  155. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  156. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  157. png_byte user_transform_channels; /* channels in user transformed pixels */
  158. #endif
  159. #endif
  160. png_uint_32 mode; /* tells us where we are in the PNG file */
  161. png_uint_32 flags; /* flags indicating various things to libpng */
  162. png_uint_32 transformations; /* which transformations to perform */
  163. png_uint_32 zowner; /* ID (chunk type) of zstream owner, 0 if none */
  164. z_stream zstream; /* decompression structure */
  165. #ifdef PNG_WRITE_SUPPORTED
  166. png_compression_bufferp zbuffer_list; /* Created on demand during write */
  167. uInt zbuffer_size; /* size of the actual buffer */
  168. int zlib_level; /* holds zlib compression level */
  169. int zlib_method; /* holds zlib compression method */
  170. int zlib_window_bits; /* holds zlib compression window bits */
  171. int zlib_mem_level; /* holds zlib compression memory level */
  172. int zlib_strategy; /* holds zlib compression strategy */
  173. #endif
  174. /* Added at libpng 1.5.4 */
  175. #ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
  176. int zlib_text_level; /* holds zlib compression level */
  177. int zlib_text_method; /* holds zlib compression method */
  178. int zlib_text_window_bits; /* holds zlib compression window bits */
  179. int zlib_text_mem_level; /* holds zlib compression memory level */
  180. int zlib_text_strategy; /* holds zlib compression strategy */
  181. #endif
  182. /* End of material added at libpng 1.5.4 */
  183. /* Added at libpng 1.6.0 */
  184. #ifdef PNG_WRITE_SUPPORTED
  185. int zlib_set_level; /* Actual values set into the zstream on write */
  186. int zlib_set_method;
  187. int zlib_set_window_bits;
  188. int zlib_set_mem_level;
  189. int zlib_set_strategy;
  190. #endif
  191. png_uint_32 width; /* width of image in pixels */
  192. png_uint_32 height; /* height of image in pixels */
  193. png_uint_32 num_rows; /* number of rows in current pass */
  194. png_uint_32 usr_width; /* width of row at start of write */
  195. png_size_t rowbytes; /* size of row in bytes */
  196. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  197. png_uint_32 row_number; /* current row in interlace pass */
  198. png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
  199. png_bytep prev_row; /* buffer to save previous (unfiltered) row.
  200. * This is a pointer into big_prev_row
  201. */
  202. png_bytep row_buf; /* buffer to save current (unfiltered) row.
  203. * This is a pointer into big_row_buf
  204. */
  205. #ifdef PNG_WRITE_SUPPORTED
  206. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  207. png_bytep up_row; /* buffer to save "up" row when filtering */
  208. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  209. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  210. #endif
  211. png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
  212. png_uint_32 idat_size; /* current IDAT size for read */
  213. png_uint_32 crc; /* current chunk CRC value */
  214. png_colorp palette; /* palette from the input file */
  215. png_uint_16 num_palette; /* number of color entries in palette */
  216. /* Added at libpng-1.5.10 */
  217. #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  218. int num_palette_max; /* maximum palette index found in IDAT */
  219. #endif
  220. png_uint_16 num_trans; /* number of transparency values */
  221. png_byte compression; /* file compression type (always 0) */
  222. png_byte filter; /* file filter type (always 0) */
  223. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  224. png_byte pass; /* current interlace pass (0 - 6) */
  225. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  226. png_byte color_type; /* color type of file */
  227. png_byte bit_depth; /* bit depth of file */
  228. png_byte usr_bit_depth; /* bit depth of users row: write only */
  229. png_byte pixel_depth; /* number of bits per pixel */
  230. png_byte channels; /* number of channels in file */
  231. #ifdef PNG_WRITE_SUPPORTED
  232. png_byte usr_channels; /* channels at start of write: write only */
  233. #endif
  234. png_byte sig_bytes; /* magic bytes read/written from start of file */
  235. png_byte maximum_pixel_depth;
  236. /* pixel depth used for the row buffers */
  237. png_byte transformed_pixel_depth;
  238. /* pixel depth after read/write transforms */
  239. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  240. png_uint_16 filler; /* filler bytes for pixel expansion */
  241. #endif
  242. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
  243. defined(PNG_READ_ALPHA_MODE_SUPPORTED)
  244. png_byte background_gamma_type;
  245. png_fixed_point background_gamma;
  246. png_color_16 background; /* background color in screen gamma space */
  247. #ifdef PNG_READ_GAMMA_SUPPORTED
  248. png_color_16 background_1; /* background normalized to gamma 1.0 */
  249. #endif
  250. #endif /* PNG_bKGD_SUPPORTED */
  251. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  252. png_flush_ptr output_flush_fn; /* Function for flushing output */
  253. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  254. png_uint_32 flush_rows; /* number of rows written since last flush */
  255. #endif
  256. #ifdef PNG_READ_GAMMA_SUPPORTED
  257. int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
  258. png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
  259. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  260. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  261. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  262. defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
  263. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  264. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  265. png_bytep gamma_to_1; /* converts from file to 1.0 */
  266. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  267. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  268. #endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
  269. #endif
  270. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  271. png_color_8 sig_bit; /* significant bits in each available channel */
  272. #endif
  273. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  274. png_color_8 shift; /* shift for significant bit tranformation */
  275. #endif
  276. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  277. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  278. png_bytep trans_alpha; /* alpha values for paletted files */
  279. png_color_16 trans_color; /* transparent color for non-paletted files */
  280. #endif
  281. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  282. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  283. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  284. png_progressive_info_ptr info_fn; /* called after header data fully read */
  285. png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
  286. png_progressive_end_ptr end_fn; /* called after image is complete */
  287. png_bytep save_buffer_ptr; /* current location in save_buffer */
  288. png_bytep save_buffer; /* buffer for previously read data */
  289. png_bytep current_buffer_ptr; /* current location in current_buffer */
  290. png_bytep current_buffer; /* buffer for recently used data */
  291. png_uint_32 push_length; /* size of current input chunk */
  292. png_uint_32 skip_length; /* bytes to skip in input data */
  293. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  294. png_size_t save_buffer_max; /* total size of save_buffer */
  295. png_size_t buffer_size; /* total amount of available input data */
  296. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  297. int process_mode; /* what push library is currently doing */
  298. int cur_palette; /* current push library palette index */
  299. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  300. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  301. /* For the Borland special 64K segment handler */
  302. png_bytepp offset_table_ptr;
  303. png_bytep offset_table;
  304. png_uint_16 offset_table_number;
  305. png_uint_16 offset_table_count;
  306. png_uint_16 offset_table_count_free;
  307. #endif
  308. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  309. png_bytep palette_lookup; /* lookup table for quantizing */
  310. png_bytep quantize_index; /* index translation for palette files */
  311. #endif
  312. #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  313. png_byte heuristic_method; /* heuristic for row filter selection */
  314. png_byte num_prev_filters; /* number of weights for previous rows */
  315. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  316. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  317. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  318. png_uint_16p filter_costs; /* relative filter calculation cost */
  319. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  320. #endif
  321. /* Options */
  322. #ifdef PNG_SET_OPTION_SUPPORTED
  323. png_byte options; /* On/off state (up to 4 options) */
  324. #endif
  325. #if PNG_LIBPNG_VER < 10700
  326. /* To do: remove this from libpng-1.7 */
  327. #ifdef PNG_TIME_RFC1123_SUPPORTED
  328. char time_buffer[29]; /* String to hold RFC 1123 time text */
  329. #endif
  330. #endif
  331. /* New members added in libpng-1.0.6 */
  332. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  333. #ifdef PNG_USER_CHUNKS_SUPPORTED
  334. png_voidp user_chunk_ptr;
  335. #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
  336. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  337. #endif
  338. #endif
  339. #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
  340. int unknown_default; /* As PNG_HANDLE_* */
  341. unsigned int num_chunk_list; /* Number of entries in the list */
  342. png_bytep chunk_list; /* List of png_byte[5]; the textual chunk name
  343. * followed by a PNG_HANDLE_* byte */
  344. #endif
  345. /* New members added in libpng-1.0.3 */
  346. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  347. png_byte rgb_to_gray_status;
  348. /* Added in libpng 1.5.5 to record setting of coefficients: */
  349. png_byte rgb_to_gray_coefficients_set;
  350. /* These were changed from png_byte in libpng-1.0.6 */
  351. png_uint_16 rgb_to_gray_red_coeff;
  352. png_uint_16 rgb_to_gray_green_coeff;
  353. /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
  354. #endif
  355. /* New member added in libpng-1.0.4 (renamed in 1.0.9) */
  356. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  357. /* Changed from png_byte to png_uint_32 at version 1.2.0 */
  358. png_uint_32 mng_features_permitted;
  359. #endif
  360. /* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
  361. #ifdef PNG_MNG_FEATURES_SUPPORTED
  362. png_byte filter_type;
  363. #endif
  364. /* New members added in libpng-1.2.0 */
  365. /* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
  366. #ifdef PNG_USER_MEM_SUPPORTED
  367. png_voidp mem_ptr; /* user supplied struct for mem functions */
  368. png_malloc_ptr malloc_fn; /* function for allocating memory */
  369. png_free_ptr free_fn; /* function for freeing memory */
  370. #endif
  371. /* New member added in libpng-1.0.13 and 1.2.0 */
  372. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  373. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  374. /* The following three members were added at version 1.0.14 and 1.2.4 */
  375. png_bytep quantize_sort; /* working sort array */
  376. png_bytep index_to_palette; /* where the original index currently is
  377. in the palette */
  378. png_bytep palette_to_index; /* which original index points to this
  379. palette color */
  380. #endif
  381. /* New members added in libpng-1.0.16 and 1.2.6 */
  382. png_byte compression_type;
  383. #ifdef PNG_USER_LIMITS_SUPPORTED
  384. png_uint_32 user_width_max;
  385. png_uint_32 user_height_max;
  386. /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
  387. * chunks that can be stored (0 means unlimited).
  388. */
  389. png_uint_32 user_chunk_cache_max;
  390. /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
  391. * can occupy when decompressed. 0 means unlimited.
  392. */
  393. png_alloc_size_t user_chunk_malloc_max;
  394. #endif
  395. /* New member added in libpng-1.0.25 and 1.2.17 */
  396. #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  397. /* Temporary storage for unknown chunk that the library doesn't recognize,
  398. * used while reading the chunk.
  399. */
  400. png_unknown_chunk unknown_chunk;
  401. #endif
  402. /* New member added in libpng-1.2.26 */
  403. png_size_t old_big_row_buf_size;
  404. #ifdef PNG_READ_SUPPORTED
  405. /* New member added in libpng-1.2.30 */
  406. png_bytep read_buffer; /* buffer for reading chunk data */
  407. png_alloc_size_t read_buffer_size; /* current size of the buffer */
  408. #endif
  409. #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
  410. uInt IDAT_read_size; /* limit on read buffer size for IDAT */
  411. #endif
  412. #ifdef PNG_IO_STATE_SUPPORTED
  413. /* New member added in libpng-1.4.0 */
  414. png_uint_32 io_state;
  415. #endif
  416. /* New member added in libpng-1.5.6 */
  417. png_bytep big_prev_row;
  418. /* New member added in libpng-1.5.7 */
  419. void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
  420. png_bytep row, png_const_bytep prev_row);
  421. #ifdef PNG_READ_SUPPORTED
  422. #if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
  423. png_colorspace colorspace;
  424. #endif
  425. #endif
  426. };
  427. #endif /* PNGSTRUCT_H */