blob: 1f98dedc4284bf788ad884ef5e9350aa5bcaaee4 [file] [log] [blame]
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -06001
2/* pnginfo.h - header file for PNG reference library
3 *
Cosmin Trutaa8738932018-07-28 18:47:21 -04004 * Copyright (c) 2018 Cosmin Truta
Cosmin Truta46aedd82018-07-15 23:58:00 -04005 * Copyright (c) 1998-2002,2004,2006-2013,2018 Glenn Randers-Pehrson
Cosmin Trutaa8738932018-07-28 18:47:21 -04006 * Copyright (c) 1996-1997 Andreas Dilger
7 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -06008 *
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -06009 * 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
14 /* png_info is a structure that holds the information in a PNG file so
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060015 * that the application can find out the characteristics of the image.
16 * If you are reading the file, this structure will tell you what is
17 * in the PNG file. If you are writing the file, fill in the information
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060018 * you want to put into the PNG file, using png_set_*() functions, then
19 * call png_write_info().
20 *
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060021 * The names chosen should be very close to the PNG specification, so
22 * consult that document for information about the meaning of each field.
23 *
24 * With libpng < 0.95, it was only possible to directly set and read the
25 * the values in the png_info_struct, which meant that the contents and
26 * order of the values had to remain fixed. With libpng 0.95 and later,
27 * however, there are now functions that abstract the contents of
28 * png_info_struct from the application, so this makes it easier to use
29 * libpng with dynamic libraries, and even makes it possible to use
30 * libraries that don't have all of the libpng ancillary chunk-handing
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060031 * functionality. In libpng-1.5.0 this was moved into a separate private
32 * file that is not visible to applications.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060033 *
34 * The following members may have allocated storage attached that should be
35 * cleaned up before the structure is discarded: palette, trans, text,
36 * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
37 * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these
38 * are automatically freed when the info structure is deallocated, if they were
39 * allocated internally by libpng. This behavior can be changed by means
40 * of the png_data_freer() function.
41 *
42 * More allocation details: all the chunk-reading functions that
43 * change these members go through the corresponding png_set_*
44 * functions. A function to clear these members is available: see
45 * png_free_data(). The png_set_* functions do not depend on being
46 * able to point info structure members to any of the storage they are
47 * passed (they make their own copies), EXCEPT that the png_set_text
48 * functions use the same storage passed to them in the text_ptr or
49 * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
50 * functions do not make their own copies.
51 */
Glenn Randers-Pehrsonc957b6b2010-03-08 21:47:07 -060052#ifndef PNGINFO_H
53#define PNGINFO_H
54
Glenn Randers-Pehrsonf0cdbe72010-02-08 23:18:15 -060055struct png_info_def
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060056{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -060057 /* The following are necessary for every PNG file */
Cosmin Trutaa74aa9a2018-06-17 22:37:44 -040058 png_uint_32 width; /* width of image in pixels (from IHDR) */
59 png_uint_32 height; /* height of image in pixels (from IHDR) */
60 png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
61 size_t rowbytes; /* bytes needed to hold an untransformed row */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060062 png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
63 png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
64 png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
65 png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
66 png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060067 /* The following three should have been named *_method not *_type */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060068 png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
69 png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
70 png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060071
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -060072 /* The following are set by png_set_IHDR, called from the application on
73 * write, but the are never actually used by the write code.
74 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060075 png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
76 png_byte pixel_depth; /* number of bits per pixel */
77 png_byte spare_byte; /* to align the data, and for future use */
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -060078
79#ifdef PNG_READ_SUPPORTED
80 /* This is never set during write */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -060081 png_byte signature[8]; /* magic bytes read by libpng from start of file */
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -060082#endif
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060083
84 /* The rest of the data is optional. If you are reading, check the
85 * valid field to see if the information in these are valid. If you
86 * are writing, set the valid field to those chunks you want written,
87 * and initialize the appropriate fields below.
88 */
89
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -060090#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
91 /* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are
92 * defined. When COLORSPACE is switched on all the colorspace-defining
93 * chunks should be enabled, when GAMMA is switched on all the gamma-defining
94 * chunks should be enabled. If this is not done it becomes possible to read
95 * inconsistent PNG files and assign a probably incorrect interpretation to
96 * the information. (In other words, by carefully choosing which chunks to
97 * recognize the system configuration can select an interpretation for PNG
98 * files containing ambiguous data and this will result in inconsistent
99 * behavior between different libpng builds!)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600100 */
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600101 png_colorspace colorspace;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600102#endif
103
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600104#ifdef PNG_iCCP_SUPPORTED
105 /* iCCP chunk data. */
106 png_charp iccp_name; /* profile name */
107 png_bytep iccp_profile; /* International Color Consortium profile data */
108 png_uint_32 iccp_proflen; /* ICC profile data length */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600109#endif
110
111#ifdef PNG_TEXT_SUPPORTED
112 /* The tEXt, and zTXt chunks contain human-readable textual data in
113 * uncompressed, compressed, and optionally compressed forms, respectively.
114 * The data in "text" is an array of pointers to uncompressed,
115 * null-terminated C strings. Each chunk has a keyword that describes the
116 * textual data contained in that chunk. Keywords are not required to be
117 * unique, and the text string may be empty. Any number of text chunks may
118 * be in an image.
119 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600120 int num_text; /* number of comments read or comments to write */
121 int max_text; /* current size of text array */
122 png_textp text; /* array of comments read or comments to write */
Glenn Randers-Pehrson05e11002014-11-07 07:41:16 -0600123#endif /* TEXT */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600124
125#ifdef PNG_tIME_SUPPORTED
126 /* The tIME chunk holds the last time the displayed image data was
127 * modified. See the png_time struct for the contents of this struct.
128 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600129 png_time mod_time;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600130#endif
131
132#ifdef PNG_sBIT_SUPPORTED
133 /* The sBIT chunk specifies the number of significant high-order bits
134 * in the pixel data. Values are in the range [1, bit_depth], and are
135 * only specified for the channels in the pixel data. The contents of
136 * the low-order bits is not specified. Data is valid if
137 * (valid & PNG_INFO_sBIT) is non-zero.
138 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600139 png_color_8 sig_bit; /* significant bits in color channels */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600140#endif
141
142#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
143defined(PNG_READ_BACKGROUND_SUPPORTED)
144 /* The tRNS chunk supplies transparency data for paletted images and
145 * other image types that don't need a full alpha channel. There are
146 * "num_trans" transparency values for a paletted image, stored in the
147 * same order as the palette colors, starting from index 0. Values
148 * for the data are in the range [0, 255], ranging from fully transparent
149 * to fully opaque, respectively. For non-paletted images, there is a
150 * single color specified that should be treated as fully transparent.
151 * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
152 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600153 png_bytep trans_alpha; /* alpha values for paletted image */
154 png_color_16 trans_color; /* transparent color for non-palette image */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600155#endif
156
157#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
158 /* The bKGD chunk gives the suggested image background color if the
159 * display program does not have its own background color and the image
160 * is needs to composited onto a background before display. The colors
161 * in "background" are normally in the same color space/depth as the
162 * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
163 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600164 png_color_16 background;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600165#endif
166
167#ifdef PNG_oFFs_SUPPORTED
168 /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
169 * and downwards from the top-left corner of the display, page, or other
170 * application-specific co-ordinate space. See the PNG_OFFSET_ defines
171 * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
172 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600173 png_int_32 x_offset; /* x offset on page */
174 png_int_32 y_offset; /* y offset on page */
175 png_byte offset_unit_type; /* offset units type */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600176#endif
177
178#ifdef PNG_pHYs_SUPPORTED
179 /* The pHYs chunk gives the physical pixel density of the image for
180 * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
181 * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
182 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600183 png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
184 png_uint_32 y_pixels_per_unit; /* vertical pixel density */
185 png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600186#endif
187
Glenn Randers-Pehrson68cb0aa2017-07-13 11:19:53 -0500188#ifdef PNG_eXIf_SUPPORTED
Glenn Randers-Pehrson71a56182017-08-01 21:42:16 -0500189 int num_exif; /* Added at libpng-1.6.31 */
Glenn Randers-Pehrson68cb0aa2017-07-13 11:19:53 -0500190 png_bytep exif;
Glenn Randers-Pehrson71a56182017-08-01 21:42:16 -0500191# ifdef PNG_READ_eXIf_SUPPORTED
192 png_bytep eXIf_buf; /* Added at libpng-1.6.32 */
193# endif
Glenn Randers-Pehrson68cb0aa2017-07-13 11:19:53 -0500194#endif
195
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600196#ifdef PNG_hIST_SUPPORTED
197 /* The hIST chunk contains the relative frequency or importance of the
198 * various palette entries, so that a viewer can intelligently select a
199 * reduced-color palette, if required. Data is an array of "num_palette"
200 * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
201 * is non-zero.
202 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600203 png_uint_16p hist;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600204#endif
205
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600206#ifdef PNG_pCAL_SUPPORTED
207 /* The pCAL chunk describes a transformation between the stored pixel
208 * values and original physical data values used to create the image.
209 * The integer range [0, 2^bit_depth - 1] maps to the floating-point
210 * range given by [pcal_X0, pcal_X1], and are further transformed by a
211 * (possibly non-linear) transformation function given by "pcal_type"
212 * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
213 * defines below, and the PNG-Group's PNG extensions document for a
214 * complete description of the transformations and how they should be
215 * implemented, and for a description of the ASCII parameter strings.
216 * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
217 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600218 png_charp pcal_purpose; /* pCAL chunk description string */
219 png_int_32 pcal_X0; /* minimum value */
220 png_int_32 pcal_X1; /* maximum value */
221 png_charp pcal_units; /* Latin-1 string giving physical units */
222 png_charpp pcal_params; /* ASCII strings containing parameter values */
223 png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
224 png_byte pcal_nparams; /* number of parameters given in pcal_params */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600225#endif
226
227/* New members added in libpng-1.0.6 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600228 png_uint_32 free_me; /* flags items libpng is responsible for freeing */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600229
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600230#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600231 /* Storage for unknown chunks that the library doesn't recognize. */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600232 png_unknown_chunkp unknown_chunks;
Glenn Randers-Pehrson45679352013-01-20 00:44:29 -0600233
Glenn Randers-Pehrson92ec30a2015-11-24 07:34:37 -0600234 /* The type of this field is limited by the type of
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600235 * png_struct::user_chunk_cache_max, else overflow can occur.
236 */
237 int unknown_chunks_num;
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600238#endif
239
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600240#ifdef PNG_sPLT_SUPPORTED
241 /* Data on sPLT chunks (there may be more than one). */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600242 png_sPLT_tp splt_palettes;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600243 int splt_palettes_num; /* Match type returned by png_get API */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600244#endif
245
246#ifdef PNG_sCAL_SUPPORTED
247 /* The sCAL chunk describes the actual physical dimensions of the
248 * subject matter of the graphic. The chunk contains a unit specification
249 * a byte value, and two ASCII strings representing floating-point
Unknownf23b41d2017-11-03 00:52:06 -0400250 * values. The values are width and height corresponding to one pixel
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500251 * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
252 * non-zero.
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600253 */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600254 png_byte scal_unit; /* unit of physical scale */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600255 png_charp scal_s_width; /* string containing height */
256 png_charp scal_s_height; /* string containing width */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600257#endif
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600258
259#ifdef PNG_INFO_IMAGE_SUPPORTED
260 /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)
261 non-zero */
262 /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
Glenn Randers-Pehrson3f506b72010-02-09 00:36:08 -0600263 png_bytepp row_pointers; /* the image bits */
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600264#endif
265
Glenn Randers-Pehrsonf0cdbe72010-02-08 23:18:15 -0600266};
Glenn Randers-Pehrsonc957b6b2010-03-08 21:47:07 -0600267#endif /* PNGINFO_H */