pnginfo.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* pnginfo.h - header file for PNG reference library
  2. *
  3. * Copyright (c) 1998-2011 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.0 [January 6, 2011]
  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. /* png_info is a structure that holds the information in a PNG file so
  14. * that the application can find out the characteristics of the image.
  15. * If you are reading the file, this structure will tell you what is
  16. * in the PNG file. If you are writing the file, fill in the information
  17. * you want to put into the PNG file, using png_set_*() functions, then
  18. * call png_write_info().
  19. *
  20. * The names chosen should be very close to the PNG specification, so
  21. * consult that document for information about the meaning of each field.
  22. *
  23. * With libpng < 0.95, it was only possible to directly set and read the
  24. * the values in the png_info_struct, which meant that the contents and
  25. * order of the values had to remain fixed. With libpng 0.95 and later,
  26. * however, there are now functions that abstract the contents of
  27. * png_info_struct from the application, so this makes it easier to use
  28. * libpng with dynamic libraries, and even makes it possible to use
  29. * libraries that don't have all of the libpng ancillary chunk-handing
  30. * functionality. In libpng-1.5.0 this was moved into a separate private
  31. * file that is not visible to applications.
  32. *
  33. * The following members may have allocated storage attached that should be
  34. * cleaned up before the structure is discarded: palette, trans, text,
  35. * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
  36. * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these
  37. * are automatically freed when the info structure is deallocated, if they were
  38. * allocated internally by libpng. This behavior can be changed by means
  39. * of the png_data_freer() function.
  40. *
  41. * More allocation details: all the chunk-reading functions that
  42. * change these members go through the corresponding png_set_*
  43. * functions. A function to clear these members is available: see
  44. * png_free_data(). The png_set_* functions do not depend on being
  45. * able to point info structure members to any of the storage they are
  46. * passed (they make their own copies), EXCEPT that the png_set_text
  47. * functions use the same storage passed to them in the text_ptr or
  48. * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
  49. * functions do not make their own copies.
  50. */
  51. #ifndef PNGINFO_H
  52. #define PNGINFO_H
  53. struct png_info_def
  54. {
  55. /* the following are necessary for every PNG file */
  56. png_uint_32 width; /* width of image in pixels (from IHDR) */
  57. png_uint_32 height; /* height of image in pixels (from IHDR) */
  58. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  59. png_size_t rowbytes; /* bytes needed to hold an untransformed row */
  60. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  61. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  62. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  63. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  64. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  65. /* The following three should have been named *_method not *_type */
  66. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  67. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  68. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  69. /* The following is informational only on read, and not used on writes. */
  70. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  71. png_byte pixel_depth; /* number of bits per pixel */
  72. png_byte spare_byte; /* to align the data, and for future use */
  73. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  74. /* The rest of the data is optional. If you are reading, check the
  75. * valid field to see if the information in these are valid. If you
  76. * are writing, set the valid field to those chunks you want written,
  77. * and initialize the appropriate fields below.
  78. */
  79. #if defined(PNG_gAMA_SUPPORTED)
  80. /* The gAMA chunk describes the gamma characteristics of the system
  81. * on which the image was created, normally in the range [1.0, 2.5].
  82. * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
  83. */
  84. png_fixed_point gamma;
  85. #endif
  86. #ifdef PNG_sRGB_SUPPORTED
  87. /* GR-P, 0.96a */
  88. /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
  89. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  90. #endif
  91. #ifdef PNG_TEXT_SUPPORTED
  92. /* The tEXt, and zTXt chunks contain human-readable textual data in
  93. * uncompressed, compressed, and optionally compressed forms, respectively.
  94. * The data in "text" is an array of pointers to uncompressed,
  95. * null-terminated C strings. Each chunk has a keyword that describes the
  96. * textual data contained in that chunk. Keywords are not required to be
  97. * unique, and the text string may be empty. Any number of text chunks may
  98. * be in an image.
  99. */
  100. int num_text; /* number of comments read or comments to write */
  101. int max_text; /* current size of text array */
  102. png_textp text; /* array of comments read or comments to write */
  103. #endif /* PNG_TEXT_SUPPORTED */
  104. #ifdef PNG_tIME_SUPPORTED
  105. /* The tIME chunk holds the last time the displayed image data was
  106. * modified. See the png_time struct for the contents of this struct.
  107. */
  108. png_time mod_time;
  109. #endif
  110. #ifdef PNG_sBIT_SUPPORTED
  111. /* The sBIT chunk specifies the number of significant high-order bits
  112. * in the pixel data. Values are in the range [1, bit_depth], and are
  113. * only specified for the channels in the pixel data. The contents of
  114. * the low-order bits is not specified. Data is valid if
  115. * (valid & PNG_INFO_sBIT) is non-zero.
  116. */
  117. png_color_8 sig_bit; /* significant bits in color channels */
  118. #endif
  119. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  120. defined(PNG_READ_BACKGROUND_SUPPORTED)
  121. /* The tRNS chunk supplies transparency data for paletted images and
  122. * other image types that don't need a full alpha channel. There are
  123. * "num_trans" transparency values for a paletted image, stored in the
  124. * same order as the palette colors, starting from index 0. Values
  125. * for the data are in the range [0, 255], ranging from fully transparent
  126. * to fully opaque, respectively. For non-paletted images, there is a
  127. * single color specified that should be treated as fully transparent.
  128. * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
  129. */
  130. png_bytep trans_alpha; /* alpha values for paletted image */
  131. png_color_16 trans_color; /* transparent color for non-palette image */
  132. #endif
  133. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  134. /* The bKGD chunk gives the suggested image background color if the
  135. * display program does not have its own background color and the image
  136. * is needs to composited onto a background before display. The colors
  137. * in "background" are normally in the same color space/depth as the
  138. * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
  139. */
  140. png_color_16 background;
  141. #endif
  142. #ifdef PNG_oFFs_SUPPORTED
  143. /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
  144. * and downwards from the top-left corner of the display, page, or other
  145. * application-specific co-ordinate space. See the PNG_OFFSET_ defines
  146. * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
  147. */
  148. png_int_32 x_offset; /* x offset on page */
  149. png_int_32 y_offset; /* y offset on page */
  150. png_byte offset_unit_type; /* offset units type */
  151. #endif
  152. #ifdef PNG_pHYs_SUPPORTED
  153. /* The pHYs chunk gives the physical pixel density of the image for
  154. * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
  155. * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
  156. */
  157. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  158. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  159. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160. #endif
  161. #ifdef PNG_hIST_SUPPORTED
  162. /* The hIST chunk contains the relative frequency or importance of the
  163. * various palette entries, so that a viewer can intelligently select a
  164. * reduced-color palette, if required. Data is an array of "num_palette"
  165. * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
  166. * is non-zero.
  167. */
  168. png_uint_16p hist;
  169. #endif
  170. #ifdef PNG_cHRM_SUPPORTED
  171. /* The cHRM chunk describes the CIE color characteristics of the monitor
  172. * on which the PNG was created. This data allows the viewer to do gamut
  173. * mapping of the input image to ensure that the viewer sees the same
  174. * colors in the image as the creator. Values are in the range
  175. * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
  176. */
  177. png_fixed_point x_white;
  178. png_fixed_point y_white;
  179. png_fixed_point x_red;
  180. png_fixed_point y_red;
  181. png_fixed_point x_green;
  182. png_fixed_point y_green;
  183. png_fixed_point x_blue;
  184. png_fixed_point y_blue;
  185. #endif
  186. #ifdef PNG_pCAL_SUPPORTED
  187. /* The pCAL chunk describes a transformation between the stored pixel
  188. * values and original physical data values used to create the image.
  189. * The integer range [0, 2^bit_depth - 1] maps to the floating-point
  190. * range given by [pcal_X0, pcal_X1], and are further transformed by a
  191. * (possibly non-linear) transformation function given by "pcal_type"
  192. * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
  193. * defines below, and the PNG-Group's PNG extensions document for a
  194. * complete description of the transformations and how they should be
  195. * implemented, and for a description of the ASCII parameter strings.
  196. * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
  197. */
  198. png_charp pcal_purpose; /* pCAL chunk description string */
  199. png_int_32 pcal_X0; /* minimum value */
  200. png_int_32 pcal_X1; /* maximum value */
  201. png_charp pcal_units; /* Latin-1 string giving physical units */
  202. png_charpp pcal_params; /* ASCII strings containing parameter values */
  203. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  204. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  205. #endif
  206. /* New members added in libpng-1.0.6 */
  207. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  208. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
  209. defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
  210. /* Storage for unknown chunks that the library doesn't recognize. */
  211. png_unknown_chunkp unknown_chunks;
  212. int unknown_chunks_num;
  213. #endif
  214. #ifdef PNG_iCCP_SUPPORTED
  215. /* iCCP chunk data. */
  216. png_charp iccp_name; /* profile name */
  217. png_bytep iccp_profile; /* International Color Consortium profile data */
  218. png_uint_32 iccp_proflen; /* ICC profile data length */
  219. png_byte iccp_compression; /* Always zero */
  220. #endif
  221. #ifdef PNG_sPLT_SUPPORTED
  222. /* Data on sPLT chunks (there may be more than one). */
  223. png_sPLT_tp splt_palettes;
  224. png_uint_32 splt_palettes_num;
  225. #endif
  226. #ifdef PNG_sCAL_SUPPORTED
  227. /* The sCAL chunk describes the actual physical dimensions of the
  228. * subject matter of the graphic. The chunk contains a unit specification
  229. * a byte value, and two ASCII strings representing floating-point
  230. * values. The values are width and height corresponsing to one pixel
  231. * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
  232. * non-zero.
  233. */
  234. png_byte scal_unit; /* unit of physical scale */
  235. png_charp scal_s_width; /* string containing height */
  236. png_charp scal_s_height; /* string containing width */
  237. #endif
  238. #ifdef PNG_INFO_IMAGE_SUPPORTED
  239. /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)
  240. non-zero */
  241. /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
  242. png_bytepp row_pointers; /* the image bits */
  243. #endif
  244. };
  245. #endif /* PNGINFO_H */