pnginfo.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* pnginfo.h - internal structures for libpng
  2. *
  3. * Copyright (c) 2018-2025 Cosmin Truta
  4. * Copyright (c) 1998-2002,2004,2006-2013,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. #ifndef PNGPRIV_H
  13. # error This file must not be included by applications; please include <png.h>
  14. #endif
  15. /* INTERNAL, PRIVATE definition of a PNG.
  16. *
  17. * png_info is a modifiable description of a PNG datastream. The fields inside
  18. * this structure are accessed through png_get_<CHUNK>() functions and modified
  19. * using png_set_<CHUNK>() functions.
  20. *
  21. * Some functions in libpng do directly access members of png_info. However,
  22. * this should be avoided. png_struct objects contain members which hold
  23. * caches, sometimes optimised, of the values from png_info objects, and
  24. * png_info is not passed to the functions which read and write image data.
  25. */
  26. #ifndef PNGINFO_H
  27. #define PNGINFO_H
  28. struct png_info_def
  29. {
  30. /* The following are necessary for every PNG file */
  31. png_uint_32 width; /* width of image in pixels (from IHDR) */
  32. png_uint_32 height; /* height of image in pixels (from IHDR) */
  33. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  34. size_t rowbytes; /* bytes needed to hold an untransformed row */
  35. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  36. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  37. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  38. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  39. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  40. /* The following three should have been named *_method not *_type */
  41. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  42. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  43. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  44. /* The following are set by png_set_IHDR, called from the application on
  45. * write, but the are never actually used by the write code.
  46. */
  47. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  48. png_byte pixel_depth; /* number of bits per pixel */
  49. png_byte spare_byte; /* to align the data, and for future use */
  50. #ifdef PNG_READ_SUPPORTED
  51. /* This is never set during write */
  52. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  53. #endif
  54. /* The rest of the data is optional. If you are reading, check the
  55. * valid field to see if the information in these are valid. If you
  56. * are writing, set the valid field to those chunks you want written,
  57. * and initialize the appropriate fields below.
  58. */
  59. #ifdef PNG_cICP_SUPPORTED
  60. /* cICP chunk data */
  61. png_byte cicp_colour_primaries;
  62. png_byte cicp_transfer_function;
  63. png_byte cicp_matrix_coefficients;
  64. png_byte cicp_video_full_range_flag;
  65. #endif
  66. #ifdef PNG_iCCP_SUPPORTED
  67. /* iCCP chunk data. */
  68. png_charp iccp_name; /* profile name */
  69. png_bytep iccp_profile; /* International Color Consortium profile data */
  70. png_uint_32 iccp_proflen; /* ICC profile data length */
  71. #endif
  72. #ifdef PNG_cLLI_SUPPORTED
  73. png_uint_32 maxCLL; /* cd/m2 (nits) * 10,000 */
  74. png_uint_32 maxFALL;
  75. #endif
  76. #ifdef PNG_mDCV_SUPPORTED
  77. png_uint_16 mastering_red_x; /* CIE (xy) x * 50,000 */
  78. png_uint_16 mastering_red_y;
  79. png_uint_16 mastering_green_x;
  80. png_uint_16 mastering_green_y;
  81. png_uint_16 mastering_blue_x;
  82. png_uint_16 mastering_blue_y;
  83. png_uint_16 mastering_white_x;
  84. png_uint_16 mastering_white_y;
  85. png_uint_32 mastering_maxDL; /* cd/m2 (nits) * 10,000 */
  86. png_uint_32 mastering_minDL;
  87. #endif
  88. #ifdef PNG_TEXT_SUPPORTED
  89. /* The tEXt, and zTXt chunks contain human-readable textual data in
  90. * uncompressed, compressed, and optionally compressed forms, respectively.
  91. * The data in "text" is an array of pointers to uncompressed,
  92. * null-terminated C strings. Each chunk has a keyword that describes the
  93. * textual data contained in that chunk. Keywords are not required to be
  94. * unique, and the text string may be empty. Any number of text chunks may
  95. * be in an image.
  96. */
  97. int num_text; /* number of comments read or comments to write */
  98. int max_text; /* current size of text array */
  99. png_textp text; /* array of comments read or comments to write */
  100. #endif /* TEXT */
  101. #ifdef PNG_tIME_SUPPORTED
  102. /* The tIME chunk holds the last time the displayed image data was
  103. * modified. See the png_time struct for the contents of this struct.
  104. */
  105. png_time mod_time;
  106. #endif
  107. #ifdef PNG_sBIT_SUPPORTED
  108. /* The sBIT chunk specifies the number of significant high-order bits
  109. * in the pixel data. Values are in the range [1, bit_depth], and are
  110. * only specified for the channels in the pixel data. The contents of
  111. * the low-order bits is not specified. Data is valid if
  112. * (valid & PNG_INFO_sBIT) is non-zero.
  113. */
  114. png_color_8 sig_bit; /* significant bits in color channels */
  115. #endif
  116. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  117. defined(PNG_READ_BACKGROUND_SUPPORTED)
  118. /* The tRNS chunk supplies transparency data for paletted images and
  119. * other image types that don't need a full alpha channel. There are
  120. * "num_trans" transparency values for a paletted image, stored in the
  121. * same order as the palette colors, starting from index 0. Values
  122. * for the data are in the range [0, 255], ranging from fully transparent
  123. * to fully opaque, respectively. For non-paletted images, there is a
  124. * single color specified that should be treated as fully transparent.
  125. * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
  126. */
  127. png_bytep trans_alpha; /* alpha values for paletted image */
  128. png_color_16 trans_color; /* transparent color for non-palette image */
  129. #endif
  130. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  131. /* The bKGD chunk gives the suggested image background color if the
  132. * display program does not have its own background color and the image
  133. * is needs to composited onto a background before display. The colors
  134. * in "background" are normally in the same color space/depth as the
  135. * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
  136. */
  137. png_color_16 background;
  138. #endif
  139. #ifdef PNG_oFFs_SUPPORTED
  140. /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
  141. * and downwards from the top-left corner of the display, page, or other
  142. * application-specific co-ordinate space. See the PNG_OFFSET_ defines
  143. * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
  144. */
  145. png_int_32 x_offset; /* x offset on page */
  146. png_int_32 y_offset; /* y offset on page */
  147. png_byte offset_unit_type; /* offset units type */
  148. #endif
  149. #ifdef PNG_pHYs_SUPPORTED
  150. /* The pHYs chunk gives the physical pixel density of the image for
  151. * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
  152. * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
  153. */
  154. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  155. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  156. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  157. #endif
  158. #ifdef PNG_eXIf_SUPPORTED
  159. png_uint_32 num_exif; /* Added at libpng-1.6.31 */
  160. png_bytep exif;
  161. #endif
  162. #ifdef PNG_hIST_SUPPORTED
  163. /* The hIST chunk contains the relative frequency or importance of the
  164. * various palette entries, so that a viewer can intelligently select a
  165. * reduced-color palette, if required. Data is an array of "num_palette"
  166. * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
  167. * is non-zero.
  168. */
  169. png_uint_16p hist;
  170. #endif
  171. #ifdef PNG_pCAL_SUPPORTED
  172. /* The pCAL chunk describes a transformation between the stored pixel
  173. * values and original physical data values used to create the image.
  174. * The integer range [0, 2^bit_depth - 1] maps to the floating-point
  175. * range given by [pcal_X0, pcal_X1], and are further transformed by a
  176. * (possibly non-linear) transformation function given by "pcal_type"
  177. * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
  178. * defines below, and the PNG-Group's PNG extensions document for a
  179. * complete description of the transformations and how they should be
  180. * implemented, and for a description of the ASCII parameter strings.
  181. * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
  182. */
  183. png_charp pcal_purpose; /* pCAL chunk description string */
  184. png_int_32 pcal_X0; /* minimum value */
  185. png_int_32 pcal_X1; /* maximum value */
  186. png_charp pcal_units; /* Latin-1 string giving physical units */
  187. png_charpp pcal_params; /* ASCII strings containing parameter values */
  188. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  189. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  190. #endif
  191. /* New members added in libpng-1.0.6 */
  192. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  193. #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
  194. /* Storage for unknown chunks that the library doesn't recognize. */
  195. png_unknown_chunkp unknown_chunks;
  196. /* The type of this field is limited by the type of
  197. * png_struct::user_chunk_cache_max, else overflow can occur.
  198. */
  199. int unknown_chunks_num;
  200. #endif
  201. #ifdef PNG_sPLT_SUPPORTED
  202. /* Data on sPLT chunks (there may be more than one). */
  203. png_sPLT_tp splt_palettes;
  204. int splt_palettes_num; /* Match type returned by png_get API */
  205. #endif
  206. #ifdef PNG_sCAL_SUPPORTED
  207. /* The sCAL chunk describes the actual physical dimensions of the
  208. * subject matter of the graphic. The chunk contains a unit specification
  209. * a byte value, and two ASCII strings representing floating-point
  210. * values. The values are width and height corresponding to one pixel
  211. * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
  212. * non-zero.
  213. */
  214. png_byte scal_unit; /* unit of physical scale */
  215. png_charp scal_s_width; /* string containing height */
  216. png_charp scal_s_height; /* string containing width */
  217. #endif
  218. #ifdef PNG_INFO_IMAGE_SUPPORTED
  219. /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)
  220. non-zero */
  221. /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
  222. png_bytepp row_pointers; /* the image bits */
  223. #endif
  224. #ifdef PNG_cHRM_SUPPORTED
  225. png_xy cHRM;
  226. #endif
  227. #ifdef PNG_gAMA_SUPPORTED
  228. png_fixed_point gamma;
  229. #endif
  230. #ifdef PNG_sRGB_SUPPORTED
  231. int rendering_intent;
  232. #endif
  233. };
  234. #endif /* PNGINFO_H */