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.

492 lines
20KB

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